[cfe-commits] r155224 - /cfe/trunk/lib/Driver/Driver.cpp
Chad Rosier
mcrosier at apple.com
Fri Apr 20 13:05:08 PDT 2012
Author: mcrosier
Date: Fri Apr 20 15:05:08 2012
New Revision: 155224
URL: http://llvm.org/viewvc/llvm-project?rev=155224&view=rev
Log:
In r135308, -save-temps was modified to prevent a temporary file from
overwriting the input file. For example,
clang -c foo.s -o foo.o -save-temps
Unfortunately, the original patch didn't compare the paths of the input and
output files. Thus, something like the following would fail to create foo.s.
cd /tmp/obj
clang -c ../src/foo.s -o foo.o -save-temps
rdar://11252615
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=155224&r1=155223&r2=155224&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Apr 20 15:05:08 2012
@@ -1468,15 +1468,24 @@
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 we're saving temps and the temp file conflicts with the input file,
+ // then avoid overwriting input file.
if (!AtTopLevel && C.getArgs().hasArg(options::OPT_save_temps) &&
NamedOutput == BaseName) {
- StringRef Name = llvm::sys::path::filename(BaseInput);
- std::pair<StringRef, StringRef> Split = Name.split('.');
- std::string TmpName =
- GetTemporaryPath(Split.first, types::getTypeTempSuffix(JA.getType()));
- return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
+
+ bool SameFile = false;
+ SmallString<256> Result;
+ llvm::sys::fs::current_path(Result);
+ llvm::sys::path::append(Result, BaseName);
+ llvm::sys::fs::equivalent(BaseInput, Result.c_str(), SameFile);
+ // Must share the same path to conflict.
+ if (SameFile) {
+ StringRef Name = llvm::sys::path::filename(BaseInput);
+ std::pair<StringRef, StringRef> Split = Name.split('.');
+ std::string TmpName =
+ GetTemporaryPath(Split.first, 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.
More information about the cfe-commits
mailing list