summaryrefslogtreecommitdiffstats
path: root/clang/tools/driver/driver.cpp
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2017-06-16 22:40:18 +0000
committerPetr Hosek <phosek@chromium.org>2017-06-16 22:40:18 +0000
commit8f90efe3469d6fb991cef73bc4b189bce7328ec2 (patch)
tree0aa2b041e6e44042d71d00f82b7fa46841283c38 /clang/tools/driver/driver.cpp
parent274bcbc139463b72d949cd32b972b3721c99f4be (diff)
downloadbcm5719-llvm-8f90efe3469d6fb991cef73bc4b189bce7328ec2.tar.gz
bcm5719-llvm-8f90efe3469d6fb991cef73bc4b189bce7328ec2.zip
[Driver] Do a PATH lookup if needed when using -no-canonical-prefixes
When -no-canonical-prefixes option is used and argv0 contains only a program name, we need to do a PATH lookup to get an executable path, otherwise the return value won't be a valid path and any subsequent uses of it (e.g. when invoking -cc1) will fail with an error. This patch fixes PR9576. Differential Revision: https://reviews.llvm.org/D34290 llvm-svn: 305600
Diffstat (limited to 'clang/tools/driver/driver.cpp')
-rw-r--r--clang/tools/driver/driver.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/tools/driver/driver.cpp b/clang/tools/driver/driver.cpp
index 4bd3b228d0f..af25d959802 100644
--- a/clang/tools/driver/driver.cpp
+++ b/clang/tools/driver/driver.cpp
@@ -53,8 +53,15 @@ using namespace clang::driver;
using namespace llvm::opt;
std::string GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
- if (!CanonicalPrefixes)
- return Argv0;
+ if (!CanonicalPrefixes) {
+ SmallString<128> ExecutablePath(Argv0);
+ // Do a PATH lookup if Argv0 isn't a valid path.
+ if (!llvm::sys::fs::exists(ExecutablePath))
+ if (llvm::ErrorOr<std::string> P =
+ llvm::sys::findProgramByName(ExecutablePath))
+ ExecutablePath = *P;
+ return ExecutablePath.str();
+ }
// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
OpenPOWER on IntegriCloud