Prevent the -save-temps flag from modifying the input file if the input filename

conflicts with a to be produced temp filename.
rdar://9724657

llvm-svn: 135308
This commit is contained in:
Chad Rosier 2011-07-15 21:54:29 +00:00
parent 795da1c108
commit f8412cdae9
1 changed files with 9 additions and 0 deletions

View 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);