From 3e4d10917a7ef84ebf86062e8c912de9c00597c9 Mon Sep 17 00:00:00 2001 From: Chad Rosier Date: Fri, 15 Jul 2011 21:54:29 +0000 Subject: [PATCH] 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 --- lib/Driver/Driver.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) 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); -- 2.40.0