]> granicus.if.org Git - clang/commitdiff
Prevent the -save-temps flag from modifying the input file if the input filename
authorChad Rosier <mcrosier@apple.com>
Fri, 15 Jul 2011 21:54:29 +0000 (21:54 +0000)
committerChad Rosier <mcrosier@apple.com>
Fri, 15 Jul 2011 21:54:29 +0000 (21:54 +0000)
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

lib/Driver/Driver.cpp

index 3a78b6a988fc2089d227a48468d2556ba195af30..616207bf7616eecc16ff4032ff924f08a53b437a 100644 (file)
@@ -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);