[llvm-commits] [llvm] r112888 - /llvm/trunk/lib/Support/SystemUtils.cpp

Dan Gohman gohman at apple.com
Thu Sep 2 15:32:38 PDT 2010


Author: djg
Date: Thu Sep  2 17:32:38 2010
New Revision: 112888

URL: http://llvm.org/viewvc/llvm-project?rev=112888&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/SystemUtils.cpp

Modified: llvm/trunk/lib/Support/SystemUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SystemUtils.cpp?rev=112888&r1=112887&r2=112888&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SystemUtils.cpp (original)
+++ llvm/trunk/lib/Support/SystemUtils.cpp Thu Sep  2 17:32:38 2010
@@ -49,10 +49,16 @@
     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();





More information about the llvm-commits mailing list