aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2011-07-15 21:54:29 +0000
committerChad Rosier <mcrosier@apple.com>2011-07-15 21:54:29 +0000
commit3e4d10917a7ef84ebf86062e8c912de9c00597c9 (patch)
treee0ec01b608f04459d420a20a31c2c2819c858f9e /lib/Driver/Driver.cpp
parentba6ffaf21e465c0926d7fc5fa294ea52f8d45faf (diff)
Prevent the -save-temps flag from modifying the input file if the input filename
conflicts with a to be produced temp filename. rdar://9724657 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135308 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Driver.cpp')
-rw-r--r--lib/Driver/Driver.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 3a78b6a988..616207bf76 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1252,6 +1252,15 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
NamedOutput = C.getArgs().MakeArgString(Suffixed.c_str());
}
+ // If we're saving temps and the temp filename conflicts with the input
+ // filename, then avoid overwriting input file.
+ if (!AtTopLevel && C.getArgs().hasArg(options::OPT_save_temps) &&
+ NamedOutput == BaseName) {
+ std::string TmpName =
+ GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+ return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
+ }
+
// As an annoying special case, PCH generation doesn't strip the pathname.
if (JA.getType() == types::TY_PCH) {
llvm::sys::path::remove_filename(BasePath);