[llvm-commits] [PATCH] Win32's Hybrid path separator in argv[0] should be accepted to bugpoint

NAKAMURA Takumi geek4civic at gmail.com
Tue Aug 24 02:56:09 PDT 2010


Hello, Chris,

Okay, I made a simplified patch, referred to ToolRunner.cpp,
confirmed on cygwin, mingw and ppc-f12.

I am worried whether 3rd parameter of llvm::FindExecutable() would be
valid or not.
I don't have any environments 3rd parameter is effective on.

I will wait for sys::Path 2.0 XD

thank you, ... Takumi


2010/8/24 Chris Lattner <clattner at apple.com>:
>
> On Aug 23, 2010, at 7:37 AM, NAKAMURA Takumi wrote:
>
>> Hello guys,
>>
>> I saw argv[0], as below, with mingw-configured Python/w32 lit.
>>
>>    "c:/path/to/build/Release+Asserts/bin\bugpoint.exe"
>>
>> Bugpoint assumes path separator consists only with '/'
>> to extract directory as "c:/path/to/build/Release+Asserts". (w/o "bin")
>>
>> My patch, attached, canonicalize BugDriver::ToolName(==argv[0])
>> with llvm::sys::Path.
>> confirmed on cygwin and ppc-f12.
>>
>> Please take a look into my patch, thank you.
>
> This patch looks functionally fine, but I'd prefer if you could change OptimizerDriver.cpp to use sys::path locally, instead of changing the BugDriver class to contain a sys::Path.  This will reduce the amount of change, and will make it easier when we eventually eliminate sys::Path in the future.
>
> -Chris
-------------- next part --------------
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index ffd4099..6b360a6 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -27,6 +27,7 @@
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/FileUtilities.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/System/Path.h"
@@ -138,16 +139,8 @@ bool BugDriver::runPasses(Module *Program,
 
   // setup the child process' arguments
   SmallVector<const char*, 8> Args;
-  std::string Opt;
-  llvm::StringRef TN(ToolName);
-  if (TN.find('/') == llvm::StringRef::npos) {
-    Opt = "opt";
-  } else {
-    std::pair<llvm::StringRef, llvm::StringRef> P = TN.rsplit('/');
-    Opt = P.first.str() + "/" + "opt";
-  }
-
-  sys::Path tool = sys::Program::FindProgramByName(Opt);
+  sys::Path tool = FindExecutable("opt", getToolName(), (void*)"opt");
+  std::string Opt = tool.str();
   if (UseValgrind) {
     Args.push_back("valgrind");
     Args.push_back("--error-exitcode=1");


More information about the llvm-commits mailing list