[llvm-commits] [PATCH] Win32's Hybrid path separator in argv[0] should be accepted to bugpoint
NAKAMURA Takumi
geek4civic at gmail.com
Mon Aug 23 07:37:11 PDT 2010
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.
...Takumi
-------------- next part --------------
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index 6966671..211ce70 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -128,7 +128,8 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
outs() << "Linking in input file: '" << Filenames[i] << "'\n";
std::string ErrorMessage;
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
- errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
+ errs() << ToolName.str()
+ << ": error linking in '" << Filenames[i] << "': "
<< ErrorMessage << '\n';
return true;
}
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index e48806a..ce0d495 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -17,6 +17,7 @@
#define BUGDRIVER_H
#include "llvm/ADT/ValueMap.h"
+#include "llvm/System/Path.h"
#include <vector>
#include <string>
@@ -44,7 +45,7 @@ extern bool BugpointIsInterrupted;
class BugDriver {
LLVMContext& Context;
- const char *ToolName; // argv[0] of bugpoint
+ const sys::Path ToolName; // argv[0] of bugpoint
std::string ReferenceOutputFile; // Name of `good' output file
Module *Program; // The raw program, linked together
std::vector<std::string> PassesToRun;
@@ -66,7 +67,7 @@ public:
LLVMContext& ctxt);
~BugDriver();
- const char *getToolName() const { return ToolName; }
+ const char *getToolName() const { return ToolName.str().c_str(); }
LLVMContext& getContext() const { return Context; }
diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp
index 7312484..c9b5908 100644
--- a/tools/bugpoint/ExecutionDriver.cpp
+++ b/tools/bugpoint/ExecutionDriver.cpp
@@ -298,12 +298,12 @@ void BugDriver::compileProgram(Module *M, std::string *Error) const {
sys::Path BitcodeFile (OutputPrefix + "-test-program.bc");
std::string ErrMsg;
if (BitcodeFile.makeUnique(true, &ErrMsg)) {
- errs() << ToolName << ": Error making unique filename: " << ErrMsg
+ errs() << ToolName.str() << ": Error making unique filename: " << ErrMsg
<< "\n";
exit(1);
}
if (writeProgramToFile(BitcodeFile.str(), M)) {
- errs() << ToolName << ": Error emitting bitcode to file '"
+ errs() << ToolName.str() << ": Error emitting bitcode to file '"
<< BitcodeFile.str() << "'!\n";
exit(1);
}
@@ -334,14 +334,14 @@ std::string BugDriver::executeProgram(const Module *Program,
// Emit the program to a bitcode file...
sys::Path uniqueFilename(OutputPrefix + "-test-program.bc");
if (uniqueFilename.makeUnique(true, &ErrMsg)) {
- errs() << ToolName << ": Error making unique filename: "
+ errs() << ToolName.str() << ": Error making unique filename: "
<< ErrMsg << "!\n";
exit(1);
}
BitcodeFile = uniqueFilename.str();
if (writeProgramToFile(BitcodeFile, Program)) {
- errs() << ToolName << ": Error emitting bitcode to file '"
+ errs() << ToolName.str() << ": Error emitting bitcode to file '"
<< BitcodeFile << "'!\n";
exit(1);
}
@@ -357,7 +357,7 @@ std::string BugDriver::executeProgram(const Module *Program,
// Check to see if this is a valid output filename...
sys::Path uniqueFile(OutputFile);
if (uniqueFile.makeUnique(true, &ErrMsg)) {
- errs() << ToolName << ": Error making unique filename: "
+ errs() << ToolName.str() << ": Error making unique filename: "
<< ErrMsg << "\n";
exit(1);
}
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp
index ffd4099..e0b3862 100644
--- a/tools/bugpoint/OptimizerDriver.cpp
+++ b/tools/bugpoint/OptimizerDriver.cpp
@@ -139,12 +139,11 @@ bool BugDriver::runPasses(Module *Program,
// setup the child process' arguments
SmallVector<const char*, 8> Args;
std::string Opt;
- llvm::StringRef TN(ToolName);
+ llvm::StringRef TN(ToolName.str());
if (TN.find('/') == llvm::StringRef::npos) {
Opt = "opt";
} else {
- std::pair<llvm::StringRef, llvm::StringRef> P = TN.rsplit('/');
- Opt = P.first.str() + "/" + "opt";
+ Opt = ToolName.getDirname().str() + "/" + "opt";
}
sys::Path tool = sys::Program::FindProgramByName(Opt);
More information about the llvm-commits
mailing list