aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/bugpoint/BugDriver.cpp85
-rw-r--r--tools/bugpoint/BugDriver.h51
-rw-r--r--tools/bugpoint/CrashDebugger.cpp63
-rw-r--r--tools/bugpoint/ExecutionDriver.cpp72
-rw-r--r--tools/bugpoint/FindBugs.cpp35
-rw-r--r--tools/bugpoint/ListReducer.h30
-rw-r--r--tools/bugpoint/Miscompilation.cpp287
-rw-r--r--tools/bugpoint/ToolRunner.cpp93
-rw-r--r--tools/bugpoint/ToolRunner.h64
-rw-r--r--tools/bugpoint/bugpoint.cpp24
10 files changed, 463 insertions, 341 deletions
diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp
index d676a4374a..45a0d4dd17 100644
--- a/tools/bugpoint/BugDriver.cpp
+++ b/tools/bugpoint/BugDriver.cpp
@@ -115,30 +115,25 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
assert(Program == 0 && "Cannot call addSources multiple times!");
assert(!Filenames.empty() && "Must specify at least on input filename!");
- try {
- // Load the first input file.
- Program = ParseInputFile(Filenames[0], Context);
- if (Program == 0) return true;
+ // Load the first input file.
+ Program = ParseInputFile(Filenames[0], Context);
+ if (Program == 0) return true;
- if (!run_as_child)
- outs() << "Read input file : '" << Filenames[0] << "'\n";
+ if (!run_as_child)
+ outs() << "Read input file : '" << Filenames[0] << "'\n";
- for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
- std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
- if (M.get() == 0) return true;
+ for (unsigned i = 1, e = Filenames.size(); i != e; ++i) {
+ std::auto_ptr<Module> M(ParseInputFile(Filenames[i], Context));
+ if (M.get() == 0) return true;
- if (!run_as_child)
- 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] << "': "
- << ErrorMessage << '\n';
- return true;
- }
+ if (!run_as_child)
+ 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] << "': "
+ << ErrorMessage << '\n';
+ return true;
}
- } catch (const std::string &Error) {
- errs() << ToolName << ": error reading input '" << Error << "'\n";
- return true;
}
if (!run_as_child)
@@ -153,7 +148,7 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
/// run - The top level method that is invoked after all of the instance
/// variables are set up from command line arguments.
///
-bool BugDriver::run() {
+bool BugDriver::run(std::string &ErrMsg) {
// The first thing to do is determine if we're running as a child. If we are,
// then what to do is very narrow. This form of invocation is only called
// from the runPasses method to actually run those passes in a child process.
@@ -165,7 +160,7 @@ bool BugDriver::run() {
if (run_find_bugs) {
// Rearrange the passes and apply them to the program. Repeat this process
// until the user kills the program or we find a bug.
- return runManyPasses(PassesToRun);
+ return runManyPasses(PassesToRun, ErrMsg);
}
// If we're not running as a child, the first thing that we must do is
@@ -186,14 +181,13 @@ bool BugDriver::run() {
// Test to see if we have a code generator crash.
outs() << "Running the code generator to test for a crash: ";
- try {
- compileProgram(Program);
- outs() << '\n';
- } catch (ToolExecutionError &TEE) {
- outs() << TEE.what();
- return debugCodeGeneratorCrash();
+ std::string Error;
+ compileProgram(Program, &Error);
+ if (!Error.empty()) {
+ outs() << Error;
+ return debugCodeGeneratorCrash(ErrMsg);
}
-
+ outs() << '\n';
// Run the raw input to see where we are coming from. If a reference output
// was specified, make sure that the raw output matches it. If not, it's a
@@ -202,8 +196,8 @@ bool BugDriver::run() {
bool CreatedOutput = false;
if (ReferenceOutputFile.empty()) {
outs() << "Generating reference output from raw program: ";
- if(!createReferenceFile(Program)){
- return debugCodeGeneratorCrash();
+ if (!createReferenceFile(Program)) {
+ return debugCodeGeneratorCrash(ErrMsg);
}
CreatedOutput = true;
}
@@ -217,24 +211,29 @@ bool BugDriver::run() {
// matches, then we assume there is a miscompilation bug and try to
// diagnose it.
outs() << "*** Checking the code generator...\n";
- try {
- if (!diffProgram()) {
- outs() << "\n*** Output matches: Debugging miscompilation!\n";
- return debugMiscompilation();
+ bool Diff = diffProgram("", "", false, &Error);
+ if (!Error.empty()) {
+ errs() << Error;
+ return debugCodeGeneratorCrash(ErrMsg);
+ }
+ if (!Diff) {
+ outs() << "\n*** Output matches: Debugging miscompilation!\n";
+ debugMiscompilation(&Error);
+ if (!Error.empty()) {
+ errs() << Error;
+ return debugCodeGeneratorCrash(ErrMsg);
}
- } catch (ToolExecutionError &TEE) {
- errs() << TEE.what();
- return debugCodeGeneratorCrash();
+ return false;
}
outs() << "\n*** Input program does not match reference diff!\n";
outs() << "Debugging code generator problem!\n";
- try {
- return debugCodeGenerator();
- } catch (ToolExecutionError &TEE) {
- errs() << TEE.what();
- return debugCodeGeneratorCrash();
+ bool Failure = debugCodeGenerator(&Error);
+ if (!Error.empty()) {
+ errs() << Error;
+ return debugCodeGeneratorCrash(ErrMsg);
}
+ return Failure;
}
void llvm::PrintFunctionList(const std::vector<Function*> &Funcs) {
diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h
index 819cc9834a..c3c847f2a6 100644
--- a/tools/bugpoint/BugDriver.h
+++ b/tools/bugpoint/BugDriver.h
@@ -88,7 +88,7 @@ public:
/// variables are set up from command line arguments. The \p as_child argument
/// indicates whether the driver is to run in parent mode or child mode.
///
- bool run();
+ bool run(std::string &ErrMsg);
/// debugOptimizerCrash - This method is called when some optimizer pass
/// crashes on input. It attempts to prune down the testcase to something
@@ -99,12 +99,12 @@ public:
/// debugCodeGeneratorCrash - This method is called when the code generator
/// crashes on an input. It attempts to reduce the input as much as possible
/// while still causing the code generator to crash.
- bool debugCodeGeneratorCrash();
+ bool debugCodeGeneratorCrash(std::string &Error);
/// debugMiscompilation - This method is used when the passes selected are not
/// crashing, but the generated output is semantically different from the
/// input.
- bool debugMiscompilation();
+ void debugMiscompilation(std::string *Error);
/// debugPassMiscompilation - This method is called when the specified pass
/// miscompiles Program as input. It tries to reduce the testcase to
@@ -118,12 +118,13 @@ public:
/// compileSharedObject - This method creates a SharedObject from a given
/// BitcodeFile for debugging a code generator.
///
- std::string compileSharedObject(const std::string &BitcodeFile);
+ std::string compileSharedObject(const std::string &BitcodeFile,
+ std::string &Error);
/// debugCodeGenerator - This method narrows down a module to a function or
/// set of functions, using the CBE as a ``safe'' code generator for other
/// functions that are not under consideration.
- bool debugCodeGenerator();
+ bool debugCodeGenerator(std::string *Error);
/// isExecutingJIT - Returns true if bugpoint is currently testing the JIT
///
@@ -164,27 +165,29 @@ public:
/// the specified one as the current program.
void setNewProgram(Module *M);
- /// compileProgram - Try to compile the specified module, throwing an
- /// exception if an error occurs, or returning normally if not. This is used
- /// for code generation crash testing.
+ /// compileProgram - Try to compile the specified module, returning false and
+ /// setting Error if an error occurs. This is used for code generation
+ /// crash testing.
///
- void compileProgram(Module *M);
+ void compileProgram(Module *M, std::string *Error);
/// executeProgram - This method runs "Program", capturing the output of the
- /// program to a file, returning the filename of the file. A recommended
- /// filename may be optionally specified. If there is a problem with the code
- /// generator (e.g., llc crashes), this will throw an exception.
+ /// program to a file. The recommended filename will be filled in with the
+ /// name of the file with the captured output. If there is a problem with
+ /// the code generator (e.g., llc crashes), this will throw an exception.
///
- std::string executeProgram(std::string RequestedOutputFilename = "",
- std::string Bitcode = "",
- const std::string &SharedObjects = "",
- AbstractInterpreter *AI = 0);
+ std::string executeProgram(std::string OutputFilename,
+ std::string Bitcode,
+ const std::string &SharedObjects,
+ AbstractInterpreter *AI,
+ std::string *Error);
/// executeProgramSafely - Used to create reference output with the "safe"
/// backend, if reference output is not provided. If there is a problem with
- /// the code generator (e.g., llc crashes), this will throw an exception.
+ /// the code generator (e.g., llc crashes), this will return false and set
+ /// Error.
///
- std::string executeProgramSafely(std::string OutputFile = "");
+ std::string executeProgramSafely(std::string OutputFile, std::string *Error);
/// createReferenceFile - calls compileProgram and then records the output
/// into ReferenceOutputFile. Returns true if reference file created, false
@@ -196,13 +199,14 @@ public:
/// diffProgram - This method executes the specified module and diffs the
/// output against the file specified by ReferenceOutputFile. If the output
- /// is different, true is returned. If there is a problem with the code
- /// generator (e.g., llc crashes), this will throw an exception.
+ /// is different, 1 is returned. If there is a problem with the code
+ /// generator (e.g., llc crashes), this will return -1 and set Error.
///
bool diffProgram(const std::string &BitcodeFile = "",
const std::string &SharedObj = "",
- bool RemoveBitcode = false);
-
+ bool RemoveBitcode = false,
+ std::string *Error = 0);
+
/// EmitProgressBitcode - This function is used to output the current Program
/// to a file named "bugpoint-ID.bc".
///
@@ -266,7 +270,8 @@ public:
/// If the passes did not compile correctly, output the command required to
/// recreate the failure. This returns true if a compiler error is found.
///
- bool runManyPasses(const std::vector<const PassInfo*> &AllPasses);
+ bool runManyPasses(const std::vector<const PassInfo*> &AllPasses,
+ std::string &ErrMsg);
/// writeProgramToFile - This writes the current "Program" to the named
/// bitcode file. If an error occurs, true is returned.
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index b51bdb4509..46b33d2a72 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -53,13 +53,15 @@ namespace llvm {
// passes. If we return true, we update the current module of bugpoint.
//
virtual TestResult doTest(std::vector<const PassInfo*> &Removed,
- std::vector<const PassInfo*> &Kept);
+ std::vector<const PassInfo*> &Kept,
+ std::string &Error);
};
}
ReducePassList::TestResult
ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
- std::vector<const PassInfo*> &Suffix) {
+ std::vector<const PassInfo*> &Suffix,
+ std::string &Error) {
sys::Path PrefixOutput;
Module *OrigProgram = 0;
if (!Prefix.empty()) {
@@ -107,27 +109,26 @@ namespace {
bool (*TestFn)(BugDriver &, Module *);
public:
ReduceCrashingGlobalVariables(BugDriver &bd,
- bool (*testFn)(BugDriver&, Module*))
+ bool (*testFn)(BugDriver &, Module *))
: BD(bd), TestFn(testFn) {}
- virtual TestResult doTest(std::vector<GlobalVariable*>& Prefix,
- std::vector<GlobalVariable*>& Kept) {
+ virtual TestResult doTest(std::vector<GlobalVariable*> &Prefix,
+ std::vector<GlobalVariable*> &Kept,
+ std::string &Error) {
if (!Kept.empty() && TestGlobalVariables(Kept))
return KeepSuffix;
-
if (!Prefix.empty() && TestGlobalVariables(Prefix))
return KeepPrefix;
-
return NoFailure;
}
- bool TestGlobalVariables(std::vector<GlobalVariable*>& GVs);
+ bool TestGlobalVariables(std::vector<GlobalVariable*> &GVs);
};
}
bool
ReduceCrashingGlobalVariables::TestGlobalVariables(
- std::vector<GlobalVariable*>& GVs) {
+ std::vector<GlobalVariable*> &GVs) {
// Clone the program to try hacking it apart...
DenseMap<const Value*, Value*> ValueMap;
Module *M = CloneModule(BD.getProgram(), ValueMap);
@@ -182,7 +183,8 @@ namespace llvm {
: BD(bd), TestFn(testFn) {}
virtual TestResult doTest(std::vector<Function*> &Prefix,
- std::vector<Function*> &Kept) {
+ std::vector<Function*> &Kept,
+ std::string &Error) {
if (!Kept.empty() && TestFuncs(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestFuncs(Prefix))
@@ -253,7 +255,8 @@ namespace {
: BD(bd), TestFn(testFn) {}
virtual TestResult doTest(std::vector<const BasicBlock*> &Prefix,
- std::vector<const BasicBlock*> &Kept) {
+ std::vector<const BasicBlock*> &Kept,
+ std::string &Error) {
if (!Kept.empty() && TestBlocks(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestBlocks(Prefix))
@@ -355,7 +358,8 @@ namespace {
: BD(bd), TestFn(testFn) {}
virtual TestResult doTest(std::vector<const Instruction*> &Prefix,
- std::vector<const Instruction*> &Kept) {
+ std::vector<const Instruction*> &Kept,
+ std::string &Error) {
if (!Kept.empty() && TestInsts(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestInsts(Prefix))
@@ -421,7 +425,8 @@ bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*>
/// DebugACrash - Given a predicate that determines whether a component crashes
/// on a program, try to destructively reduce the program while still keeping
/// the predicate true.
-static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) {
+static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *),
+ std::string &Error) {
// See if we can get away with nuking some of the global variable initializers
// in the program...
if (!NoGlobalRM &&
@@ -464,7 +469,9 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) {
<< "variables in the testcase\n";
unsigned OldSize = GVs.size();
- ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs);
+ ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs, Error);
+ if (!Error.empty())
+ return true;
if (GVs.size() < OldSize)
BD.EmitProgressBitcode("reduced-global-variables");
@@ -485,7 +492,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) {
"in the testcase\n";
unsigned OldSize = Functions.size();
- ReduceCrashingFunctions(BD, TestFn).reduceList(Functions);
+ ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
if (Functions.size() < OldSize)
BD.EmitProgressBitcode("reduced-function");
@@ -503,7 +510,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) {
for (Function::const_iterator FI = I->begin(), E = I->end(); FI !=E; ++FI)
Blocks.push_back(FI);
unsigned OldSize = Blocks.size();
- ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks);
+ ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode("reduced-blocks");
}
@@ -521,7 +528,7 @@ static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) {
if (!isa<TerminatorInst>(I))
Insts.push_back(I);
- ReduceCrashingInstructions(BD, TestFn).reduceList(Insts);
+ ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error);
}
// FIXME: This should use the list reducer to converge faster by deleting
@@ -614,9 +621,11 @@ static bool TestForOptimizerCrash(BugDriver &BD, Module *M) {
bool BugDriver::debugOptimizerCrash(const std::string &ID) {
outs() << "\n*** Debugging optimizer crash!\n";
+ std::string Error;
// Reduce the list of passes which causes the optimizer to crash...
if (!BugpointIsInterrupted)
- ReducePassList(*this).reduceList(PassesToRun);
+ ReducePassList(*this).reduceList(PassesToRun, Error);
+ assert(Error.empty());
outs() << "\n*** Found crashing pass"
<< (PassesToRun.size() == 1 ? ": " : "es: ")
@@ -624,25 +633,27 @@ bool BugDriver::debugOptimizerCrash(const std::string &ID) {
EmitProgressBitcode(ID);
- return DebugACrash(*this, TestForOptimizerCrash);
+ bool Success = DebugACrash(*this, TestForOptimizerCrash, Error);
+ assert(Error.empty());
+ return Success;
}
static bool TestForCodeGenCrash(BugDriver &BD, Module *M) {
- try {
- BD.compileProgram(M);
- errs() << '\n';
- return false;
- } catch (ToolExecutionError &) {
+ std::string Error;
+ BD.compileProgram(M, &Error);
+ if (!Error.empty()) {
errs() << "<crash>\n";
return true; // Tool is still crashing.
}
+ errs() << '\n';
+ return false;
}
/// debugCodeGeneratorCrash - This method is called when the code generator
/// crashes on an input. It attempts to reduce the input as much as possible
/// while still causing the code generator to crash.
-bool BugDriver::debugCodeGeneratorCrash() {
+bool BugDriver::debugCodeGeneratorCrash(std::string &Error) {
errs() << "*** Debugging code generator crash!\n";
- return DebugACrash(*this, TestForCodeGenCrash);
+ return DebugACrash(*this, TestForCodeGenCrash, Error);
}
diff --git a/tools/bugpoint/ExecutionDriver.cpp b/tools/bugpoint/ExecutionDriver.cpp
index 3b93a1a322..9eb3314969 100644
--- a/tools/bugpoint/ExecutionDriver.cpp
+++ b/tools/bugpoint/ExecutionDriver.cpp
@@ -278,15 +278,15 @@ bool BugDriver::initializeExecutionEnvironment() {
return Interpreter == 0;
}
-/// compileProgram - Try to compile the specified module, throwing an exception
-/// if an error occurs, or returning normally if not. This is used for code
-/// generation crash testing.
+/// compileProgram - Try to compile the specified module, returning false and
+/// setting Error if an error occurs. This is used for code generation
+/// crash testing.
///
-void BugDriver::compileProgram(Module *M) {
+void BugDriver::compileProgram(Module *M, std::string *Error) {
// Emit the program to a bitcode file...
sys::Path BitcodeFile (OutputPrefix + "-test-program.bc");
std::string ErrMsg;
- if (BitcodeFile.makeUnique(true,&ErrMsg)) {
+ if (BitcodeFile.makeUnique(true, &ErrMsg)) {
errs() << ToolName << ": Error making unique filename: " << ErrMsg
<< "\n";
exit(1);
@@ -297,11 +297,11 @@ void BugDriver::compileProgram(Module *M) {
exit(1);
}
- // Remove the temporary bitcode file when we are done.
+ // Remove the temporary bitcode file when we are done.
FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
// Actually compile the program!
- Interpreter->compileProgram(BitcodeFile.str());
+ Interpreter->compileProgram(BitcodeFile.str(), Error);
}
@@ -312,7 +312,8 @@ void BugDriver::compileProgram(Module *M) {
std::string BugDriver::executeProgram(std::string OutputFile,
std::string BitcodeFile,
const std::string &SharedObj,
- AbstractInterpreter *AI) {
+ AbstractInterpreter *AI,
+ std::string *Error) {
if (AI == 0) AI = Interpreter;
assert(AI && "Interpreter should have been created already!");
bool CreatedBitcode = false;
@@ -355,9 +356,11 @@ std::string BugDriver::executeProgram(std::string OutputFile,
if (!SharedObj.empty())
SharedObjs.push_back(SharedObj);
- int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile,
- OutputFile, AdditionalLinkerArgs, SharedObjs,
+ int RetVal = AI->ExecuteProgram(BitcodeFile, InputArgv, InputFile, OutputFile,
+ Error, AdditionalLinkerArgs, SharedObjs,
Timeout, MemoryLimit);
+ if (!Error->empty())
+ return OutputFile;
if (RetVal == -1) {
errs() << "<timeout>";
@@ -385,21 +388,28 @@ std::string BugDriver::executeProgram(std::string OutputFile,
/// executeProgramSafely - Used to create reference output with the "safe"
/// backend, if reference output is not provided.
///
-std::string BugDriver::executeProgramSafely(std::string OutputFile) {
- std::string outFN = executeProgram(OutputFile, "", "", SafeInterpreter);
- return outFN;
+std::string BugDriver::executeProgramSafely(std::string OutputFile,
+ std::string *Error) {
+ return executeProgram(OutputFile, "", "", SafeInterpreter, Error);
}
-std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
+std::string BugDriver::compileSharedObject(const std::string &BitcodeFile,
+ std::string &Error) {
assert(Interpreter && "Interpreter should have been created already!");
sys::Path OutputFile;
// Using the known-good backend.
- GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
+ GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile,
+ Error);
+ if (!Error.empty())
+ return "";
std::string SharedObjectFile;
- if (gcc->MakeSharedObject(OutputFile.str(), FT,
- SharedObjectFile, AdditionalLinkerArgs))
+ bool Failure = gcc->MakeSharedObject(OutputFile.str(), FT, SharedObjectFile,
+ AdditionalLinkerArgs, Error);
+ if (!Error.empty())
+ return "";
+ if (Failure)
exit(1);
// Remove the intermediate C file
@@ -414,16 +424,14 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
/// this function.
///
bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
- try {
- compileProgram(Program);
- } catch (ToolExecutionError &) {
+ std::string Error;
+ compileProgram(Program, &Error);
+ if (!Error.empty())
return false;
- }
- try {
- ReferenceOutputFile = executeProgramSafely(Filename);
- outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n";
- } catch (ToolExecutionError &TEE) {
- errs() << TEE.what();
+
+ ReferenceOutputFile = executeProgramSafely(Filename, &Error);
+ if (!Error.empty()) {
+ errs() << Error;
if (Interpreter != SafeInterpreter) {
errs() << "*** There is a bug running the \"safe\" backend. Either"
<< " debug it (for example with the -run-cbe bugpoint option,"
@@ -432,19 +440,23 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
}
return false;
}
+ outs() << "\nReference output is: " << ReferenceOutputFile << "\n\n";
return true;
}
/// diffProgram - This method executes the specified module and diffs the
/// output against the file specified by ReferenceOutputFile. If the output
-/// is different, true is returned. If there is a problem with the code
-/// generator (e.g., llc crashes), this will throw an exception.
+/// is different, 1 is returned. If there is a problem with the code
+/// generator (e.g., llc crashes), this will return -1 and set Error.
///
bool BugDriver::diffProgram(const std::string &BitcodeFile,
const std::string &SharedObject,
- bool RemoveBitcode) {
+ bool RemoveBitcode,
+ std::string *ErrMsg) {
// Execute the program, generating an output file...
- sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0));
+ sys::Path Output(executeProgram("", BitcodeFile, SharedObject, 0, ErrMsg));
+ if (!ErrMsg->empty())
+ return false;
std::string Error;
bool FilesDifferent = false;
diff --git a/tools/bugpoint/FindBugs.cpp b/tools/bugpoint/FindBugs.cpp
index b27a25c27a..224c71747a 100644
--- a/tools/bugpoint/FindBugs.cpp
+++ b/tools/bugpoint/FindBugs.cpp
@@ -29,7 +29,8 @@ using namespace llvm;
/// If the passes did not compile correctly, output the command required to
/// recreate the failure. This returns true if a compiler error is found.
///
-bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
+bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses,
+ std::string &ErrMsg) {
setPassesToRun(AllPasses);
outs() << "Starting bug finding procedure...\n\n";
@@ -74,33 +75,33 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
// Step 3: Compile the optimized code.
//
outs() << "Running the code generator to test for a crash: ";
- try {
- compileProgram(Program);
- outs() << '\n';
- } catch (ToolExecutionError &TEE) {
+ std::string Error;
+ compileProgram(Program, &Error);
+ if (!Error.empty()) {
outs() << "\n*** compileProgram threw an exception: ";
- outs() << TEE.what();
- return debugCodeGeneratorCrash();
+ outs() << Error;
+ return debugCodeGeneratorCrash(ErrMsg);
}
+ outs() << '\n';
//
// Step 4: Run the program and compare its output to the reference
// output (created above).
//
outs() << "*** Checking if passes caused miscompliation:\n";
- try {
- if (diffProgram(Filename, "", false)) {
- outs() << "\n*** diffProgram returned true!\n";
- debugMiscompilation();
+ bool Diff = diffProgram(Filename, "", false, &Error);
+ if (Error.empty() && Diff) {
+ outs() << "\n*** diffProgram returned true!\n";
+ debugMiscompilation(&Error);
+ if (Error.empty())
return true;
- } else {
- outs() << "\n*** diff'd output matches!\n";
- }
- } catch (ToolExecutionError &TEE) {
- errs() << TEE.what();
- debugCodeGeneratorCrash();
+ }
+ if (!Error.empty()) {
+ errs() << Error;
+ debugCodeGeneratorCrash(ErrMsg);
return true;
}
+ outs() << "\n*** diff'd output matches!\n";
sys::Path(Filename).eraseFromDisk();
diff --git a/tools/bugpoint/ListReducer.h b/tools/bugpoint/ListReducer.h
index 8036d1f544..5e9cff0efa 100644
--- a/tools/bugpoint/ListReducer.h
+++ b/tools/bugpoint/ListReducer.h
@@ -16,6 +16,7 @@
#define BUGPOINT_LIST_REDUCER_H
#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/ErrorHandling.h"
#include <vector>
#include <cstdlib>
#include <algorithm>
@@ -29,7 +30,8 @@ struct ListReducer {
enum TestResult {
NoFailure, // No failure of the predicate was detected
KeepSuffix, // The suffix alone satisfies the predicate
- KeepPrefix // The prefix alone satisfies the predicate
+ KeepPrefix, // The prefix alone satisfies the predicate
+ InternalError // Encountered an error trying to run the predicate
};
virtual ~ListReducer() {}
@@ -40,16 +42,17 @@ struct ListReducer {
// the prefix anyway, it can.
//
virtual TestResult doTest(std::vector<ElTy> &Prefix,
- std::vector<ElTy> &Kept) = 0;
+ std::vector<ElTy> &Kept,
+ std::string &Error) = 0;
// reduceList - This function attempts to reduce the length of the specified
// list while still maintaining the "test" property. This is the core of the
// "work" that bugpoint does.
//
- bool reduceList(std::vector<ElTy> &TheList) {
+ bool reduceList(std::vector<ElTy> &TheList, std::string &Error) {
std::vector<ElTy> empty;
std::srand(0x6e5ea738); // Seed the random number generator
- switch (doTest(TheList, empty)) {
+ switch (doTest(TheList, empty, Error)) {
case KeepPrefix:
if (TheList.size() == 1) // we are done, it's the base case and it fails
return true;
@@ -58,11 +61,15 @@ struct ListReducer {
case KeepSuffix:
// cannot be reached!
- errs() << "bugpoint ListReducer internal error: selected empty set.\n";
- abort();
+ llvm_unreachable("bugpoint ListReducer internal error: "
+ "selected empty set.");
case NoFailure:
return false; // there is no failure with the full set of passes/funcs!
+
+ case InternalError:
+ assert(!Error.empty());
+ return true;
}
// Maximal number of allowed splitting iterations,
@@ -90,7 +97,7 @@ Backjump:
std::random_shuffle(ShuffledList.begin(), ShuffledList.end());
errs() << "\n\n*** Testing shuffled set...\n\n";
// Check that random shuffle doesn't loose the bug
- if (doTest(ShuffledList, empty) == KeepPrefix) {
+ if (doTest(ShuffledList, empty, Error) == KeepPrefix) {
// If the bug is still here, use the shuffled list.
TheList.swap(ShuffledList);
MidTop = TheList.size();
@@ -109,7 +116,7 @@ Backjump:
std::vector<ElTy> Prefix(TheList.begin(), TheList.begin()+Mid);
std::vector<ElTy> Suffix(TheList.begin()+Mid, TheList.end());
- switch (doTest(Prefix, Suffix)) {
+ switch (doTest(Prefix, Suffix, Error)) {
case KeepSuffix:
// The property still holds. We can just drop the prefix elements, and
// shorten the list to the "kept" elements.
@@ -133,7 +140,10 @@ Backjump:
MidTop = Mid;
NumOfIterationsWithoutProgress++;
break;
+ case InternalError:
+ return true; // Error was set by doTest.
}
+ assert(Error.empty() && "doTest did not return InternalError for error");
}
// Probability of backjumping from the trimming loop back to the binary
@@ -167,12 +177,14 @@ Backjump:
std::vector<ElTy> TestList(TheList);
TestList.erase(TestList.begin()+i);
- if (doTest(EmptyList, TestList) == KeepSuffix) {
+ if (doTest(EmptyList, TestList, Error) == KeepSuffix) {
// We can trim down the list!
TheList.swap(TestList);
--i; // Don't skip an element of the list
Changed = true;
}
+ if (!Error.empty())
+ return true;
}
// This can take a long time if left uncontrolled. For now, don't
// iterate.
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index c2b002f9dd..96aab95a5b 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -49,7 +49,8 @@ namespace {
ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {}
virtual TestResult doTest(std::vector<const PassInfo*> &Prefix,
- std::vector<const PassInfo*> &Suffix);
+ std::vector<const PassInfo*> &Suffix,
+ std::string &Error);
};
}
@@ -58,7 +59,8 @@ namespace {
///
ReduceMiscompilingPasses::TestResult
ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
- std::vector<const PassInfo*> &Suffix) {
+ std::vector<const PassInfo*> &Suffix,
+ std::string &Error) {
// First, run the program with just the Suffix passes. If it is still broken
// with JUST the kept passes, discard the prefix passes.
outs() << "Checking to see if '" << getPassesString(Suffix)
@@ -74,7 +76,11 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
}
// Check to see if the finished program matches the reference output...
- if (BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/)) {
+ bool Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/,
+ &Error);
+ if (!Error.empty())
+ return InternalError;
+ if (Diff) {
outs() << " nope.\n";
if (Suffix.empty()) {
errs() << BD.getToolName() << ": I'm confused: the test fails when "
@@ -107,7 +113,10 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
}
// If the prefix maintains the predicate by itself, only keep the prefix!
- if (BD.diffProgram(BitcodeResult)) {
+ Diff = BD.diffProgram(BitcodeResult, "", false, &Error);
+ if (!Error.empty())
+ return InternalError;
+ if (Diff) {
outs() << " nope.\n";
sys::Path(BitcodeResult).eraseFromDisk();
return KeepPrefix;
@@ -143,7 +152,10 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
}
// Run the result...
- if (BD.diffProgram(BitcodeResult, "", true/*delete bitcode*/)) {
+ Diff = BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/, &Error);
+ if (!Error.empty())
+ return InternalError;
+ if (Diff) {
outs() << " nope.\n";
delete OriginalInput; // We pruned down the original input...
return KeepSuffix;
@@ -158,22 +170,34 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
namespace {
class ReduceMiscompilingFunctions : public ListReducer<Function*> {
BugDriver &BD;
- bool (*TestFn)(BugDriver &, Module *, Module *);
+ bool (*TestFn)(BugDriver &, Module *, Module *, std::string &);
public:
ReduceMiscompilingFunctions(BugDriver &bd,
- bool (*F)(BugDriver &, Module *, Module *))
+ bool (*F)(BugDriver &, Module *, Module *,
+