r305600 - [Driver] Do a PATH lookup if needed when using -no-canonical-prefixes
Joerg Sonnenberger via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 16 15:50:30 PDT 2017
On Fri, Jun 16, 2017 at 10:40:18PM -0000, Petr Hosek via cfe-commits wrote:
> @@ -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.
This will fail if the current directory contains a file with the name of
the program, won't it? I think the correct order here would be to check
if ExecutablePath contains a path separator and if it doesn't, call
findProgramByName.
Joerg
More information about the cfe-commits
mailing list