diff options
author | Dan Gohman <gohman@apple.com> | 2010-09-02 22:32:38 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-09-02 22:32:38 +0000 |
commit | 776339ee273c55beb3073a6dee5a8d34e4c34493 (patch) | |
tree | 7a0279508afb4748c669fb69907114e9c5d8d600 /lib | |
parent | 514ca3a021ea0aa421ac4163e553364514fe651c (diff) | |
download | external_llvm-776339ee273c55beb3073a6dee5a8d34e4c34493.zip external_llvm-776339ee273c55beb3073a6dee5a8d34e4c34493.tar.gz external_llvm-776339ee273c55beb3073a6dee5a8d34e4c34493.tar.bz2 |
Use the FindProgramByName fallback only with known absolute paths.
I wasn't able to convince myself that all GetMainExecutable
implementations always return absolute paths; this prevents
unexpected behavior in case they ever don't.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112888 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/SystemUtils.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Support/SystemUtils.cpp b/lib/Support/SystemUtils.cpp index 421b381..c8b260c 100644 --- a/lib/Support/SystemUtils.cpp +++ b/lib/Support/SystemUtils.cpp @@ -49,10 +49,16 @@ sys::Path llvm::FindExecutable(const std::string &ExeName, Result.appendComponent(ExeName); if (Result.canExecute()) return Result; - // Expect to retrieve the pathname with suffix .exe. - Result = sys::Program::FindProgramByName(Result.str()); - if (!Result.empty()) - return Result; + // If the path is absolute (and it usually is), call FindProgramByName to + // allow it to try platform-specific logic, such as appending a .exe suffix + // on Windows. Don't do this if we somehow have a relative path, because + // we don't want to go searching the PATH and accidentally find an unrelated + // version of the program. + if (Result.isAbsolute()) { + Result = sys::Program::FindProgramByName(Result.str()); + if (!Result.empty()) + return Result; + } } return sys::Path(); |