summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2012-04-20 20:05:08 +0000
committerChad Rosier <mcrosier@apple.com>2012-04-20 20:05:08 +0000
commit5b58af0381f7a9eb5c4e0f5135cde4fc817b8e2d (patch)
treec4b45ff18fb3542adab7955607090750a2b359c2 /clang/lib/Driver/Driver.cpp
parent3e10cf3b5135a4e0f9a7769169d15bc37c8ccfc0 (diff)
downloadbcm5719-llvm-5b58af0381f7a9eb5c4e0f5135cde4fc817b8e2d.tar.gz
bcm5719-llvm-5b58af0381f7a9eb5c4e0f5135cde4fc817b8e2d.zip
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 llvm-svn: 155224
Diffstat (limited to 'clang/lib/Driver/Driver.cpp')
-rw-r--r--clang/lib/Driver/Driver.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c293b7fab63..0465827ed28 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1468,15 +1468,24 @@ 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 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.
OpenPOWER on IntegriCloud