[cfe-commits] r135308 - /cfe/trunk/lib/Driver/Driver.cpp

Chad Rosier mcrosier at apple.com
Fri Jul 15 14:54:29 PDT 2011


Author: mcrosier
Date: Fri Jul 15 16:54:29 2011
New Revision: 135308

URL: http://llvm.org/viewvc/llvm-project?rev=135308&view=rev
Log:
Prevent the -save-temps flag from modifying the input file if the input filename
conflicts with a to be produced temp filename.
rdar://9724657

Modified:
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=135308&r1=135307&r2=135308&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Jul 15 16:54:29 2011
@@ -1252,6 +1252,15 @@
     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);





More information about the cfe-commits mailing list