[PATCH] D34290: [Driver] Do a PATH lookup when using only program name with -no-canonical-prefixes

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 16 15:40:59 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL305600: [Driver] Do a PATH lookup if needed when using -no-canonical-prefixes (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D34290?vs=102881&id=102894#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34290

Files:
  cfe/trunk/tools/driver/driver.cpp


Index: cfe/trunk/tools/driver/driver.cpp
===================================================================
--- cfe/trunk/tools/driver/driver.cpp
+++ cfe/trunk/tools/driver/driver.cpp
@@ -53,8 +53,15 @@
 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34290.102894.patch
Type: text/x-patch
Size: 824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170616/efec787e/attachment.bin>


More information about the cfe-commits mailing list