/// run - The top level method that is invoked after all of the instance
/// variables are set up from command line arguments.
///
-bool BugDriver::run(std::string &ErrMsg) {
+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, ErrMsg);
+ return runManyPasses(PassesToRun);
}
// If we're not running as a child, the first thing that we must do is
compileProgram(Program, &Error);
if (!Error.empty()) {
outs() << Error;
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
outs() << '\n';
if (ReferenceOutputFile.empty()) {
outs() << "Generating reference output from raw program: ";
if (!createReferenceFile(Program)) {
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
CreatedOutput = true;
}
bool Diff = diffProgram(Program, "", "", false, &Error);
if (!Error.empty()) {
errs() << Error;
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
if (!Diff) {
outs() << "\n*** Output matches: Debugging miscompilation!\n";
debugMiscompilation(&Error);
if (!Error.empty()) {
errs() << Error;
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
return false;
}
bool Failure = debugCodeGenerator(&Error);
if (!Error.empty()) {
errs() << Error;
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
return Failure;
}
/// 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(std::string &ErrMsg);
+ bool run();
/// debugOptimizerCrash - This method is called when some optimizer pass
/// crashes on input. It attempts to prune down the testcase to something
/// 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(std::string &Error);
+ bool debugCodeGeneratorCrash();
/// debugMiscompilation - This method is used when the passes selected are not
/// crashing, but the generated output is semantically different from the
/// 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<std::string> &AllPasses,
- std::string &ErrMsg);
+ bool runManyPasses(const std::vector<std::string> &AllPasses);
/// writeProgramToFile - This writes the current "Program" to the named
/// bitcode file. If an error occurs, true is returned.
// passes. If we return true, we update the current module of bugpoint.
//
TestResult doTest(std::vector<std::string> &Removed,
- std::vector<std::string> &Kept,
- std::string &Error) override;
+ std::vector<std::string> &Kept) override;
};
}
ReducePassList::TestResult
ReducePassList::doTest(std::vector<std::string> &Prefix,
- std::vector<std::string> &Suffix, std::string &Error) {
+ std::vector<std::string> &Suffix) {
std::string PrefixOutput;
Module *OrigProgram = nullptr;
if (!Prefix.empty()) {
: BD(bd), TestFn(testFn) {}
TestResult doTest(std::vector<GlobalVariable *> &Prefix,
- std::vector<GlobalVariable *> &Kept,
- std::string &Error) override {
+ std::vector<GlobalVariable *> &Kept) override {
if (!Kept.empty() && TestGlobalVariables(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestGlobalVariables(Prefix))
: BD(bd), TestFn(testFn) {}
TestResult doTest(std::vector<Function *> &Prefix,
- std::vector<Function *> &Kept,
- std::string &Error) override {
+ std::vector<Function *> &Kept) override {
if (!Kept.empty() && TestFuncs(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestFuncs(Prefix))
: BD(BD), TestFn(testFn) {}
TestResult doTest(std::vector<const BasicBlock *> &Prefix,
- std::vector<const BasicBlock *> &Kept,
- std::string &Error) override {
+ std::vector<const BasicBlock *> &Kept) override {
if (!Kept.empty() && TestBlocks(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestBlocks(Prefix))
: BD(bd), TestFn(testFn), Direction(Direction) {}
TestResult doTest(std::vector<const BasicBlock *> &Prefix,
- std::vector<const BasicBlock *> &Kept,
- std::string &Error) override {
+ std::vector<const BasicBlock *> &Kept) override {
if (!Kept.empty() && TestBlocks(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestBlocks(Prefix))
: BD(bd), TestFn(testFn), TTI(bd.getProgram()->getDataLayout()) {}
TestResult doTest(std::vector<const BasicBlock *> &Prefix,
- std::vector<const BasicBlock *> &Kept,
- std::string &Error) override {
+ std::vector<const BasicBlock *> &Kept) override {
if (!Kept.empty() && TestBlocks(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestBlocks(Prefix))
: BD(bd), TestFn(testFn) {}
TestResult doTest(std::vector<const Instruction *> &Prefix,
- std::vector<const Instruction *> &Kept,
- std::string &Error) override {
+ std::vector<const Instruction *> &Kept) override {
if (!Kept.empty() && TestInsts(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestInsts(Prefix))
: BD(bd), TestFn(testFn) {}
TestResult doTest(std::vector<std::string> &Prefix,
- std::vector<std::string> &Kept,
- std::string &Error) override {
+ std::vector<std::string> &Kept) override {
if (!Kept.empty() && TestNamedMDs(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestNamedMDs(Prefix))
: BD(bd), TestFn(testFn) {}
TestResult doTest(std::vector<const MDNode *> &Prefix,
- std::vector<const MDNode *> &Kept,
- std::string &Error) override {
+ std::vector<const MDNode *> &Kept) override {
if (!Kept.empty() && TestNamedMDOps(Kept))
return KeepSuffix;
if (!Prefix.empty() && TestNamedMDOps(Prefix))
static void ReduceGlobalInitializers(BugDriver &BD,
bool (*TestFn)(const BugDriver &,
- Module *),
- std::string &Error) {
+ Module *)) {
if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
// Now try to reduce the number of global variable initializers in the
// module to something small.
<< "variables in the testcase\n";
unsigned OldSize = GVs.size();
- ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs, Error);
- assert(!Error.empty());
+ ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs);
if (GVs.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables");
}
static void ReduceInsts(BugDriver &BD,
- bool (*TestFn)(const BugDriver &, Module *),
- std::string &Error) {
+ bool (*TestFn)(const BugDriver &, Module *)) {
// Attempt to delete instructions using bisection. This should help out nasty
// cases with large basic blocks where the problem is at one end.
if (!BugpointIsInterrupted) {
if (!isa<TerminatorInst>(&I))
Insts.push_back(&I);
- ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error);
+ ReduceCrashingInstructions(BD, TestFn).reduceList(Insts);
}
unsigned Simplification = 2;
/// on a program, try to destructively reduce the program while still keeping
/// the predicate true.
static bool DebugACrash(BugDriver &BD,
- bool (*TestFn)(const BugDriver &, Module *),
- std::string &Error) {
+ bool (*TestFn)(const BugDriver &, Module *)) {
// See if we can get away with nuking some of the global variable initializers
// in the program...
if (!NoGlobalRM)
- ReduceGlobalInitializers(BD, TestFn, Error);
+ ReduceGlobalInitializers(BD, TestFn);
// Now try to reduce the number of functions in the module to something small.
std::vector<Function *> Functions;
"in the testcase\n";
unsigned OldSize = Functions.size();
- ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error);
+ ReduceCrashingFunctions(BD, TestFn).reduceList(Functions);
if (Functions.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-function");
for (BasicBlock &BB : F)
Blocks.push_back(&BB);
unsigned OldSize = Blocks.size();
- ReduceCrashingConditionals(BD, TestFn, true).reduceList(Blocks, Error);
- ReduceCrashingConditionals(BD, TestFn, false).reduceList(Blocks, Error);
+ ReduceCrashingConditionals(BD, TestFn, true).reduceList(Blocks);
+ ReduceCrashingConditionals(BD, TestFn, false).reduceList(Blocks);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-conditionals");
}
for (BasicBlock &BB : F)
Blocks.push_back(&BB);
unsigned OldSize = Blocks.size();
- ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error);
+ ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks");
}
for (BasicBlock &BB : F)
Blocks.push_back(&BB);
unsigned OldSize = Blocks.size();
- ReduceSimplifyCFG(BD, TestFn).reduceList(Blocks, Error);
+ ReduceSimplifyCFG(BD, TestFn).reduceList(Blocks);
if (Blocks.size() < OldSize)
BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplifycfg");
}
// Attempt to delete instructions using bisection. This should help out nasty
// cases with large basic blocks where the problem is at one end.
if (!BugpointIsInterrupted)
- ReduceInsts(BD, TestFn, Error);
+ ReduceInsts(BD, TestFn);
if (!NoNamedMDRM) {
if (!BugpointIsInterrupted) {
std::vector<std::string> NamedMDNames;
for (auto &NamedMD : BD.getProgram()->named_metadata())
NamedMDNames.push_back(NamedMD.getName().str());
- ReduceCrashingNamedMD(BD, TestFn).reduceList(NamedMDNames, Error);
+ ReduceCrashingNamedMD(BD, TestFn).reduceList(NamedMDNames);
}
if (!BugpointIsInterrupted) {
for (auto &NamedMD : BD.getProgram()->named_metadata())
for (auto op : NamedMD.operands())
NamedMDOps.push_back(op);
- ReduceCrashingNamedMDOps(BD, TestFn).reduceList(NamedMDOps, Error);
+ ReduceCrashingNamedMDOps(BD, TestFn).reduceList(NamedMDOps);
}
BD.EmitProgressBitcode(BD.getProgram(), "reduced-named-md");
}
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 && !DontReducePassList)
- ReducePassList(*this).reduceList(PassesToRun, Error);
- assert(Error.empty());
+ ReducePassList(*this).reduceList(PassesToRun);
outs() << "\n*** Found crashing pass"
<< (PassesToRun.size() == 1 ? ": " : "es: ")
EmitProgressBitcode(Program, ID);
- bool Success = DebugACrash(*this, TestForOptimizerCrash, Error);
- assert(Error.empty());
+ bool Success = DebugACrash(*this, TestForOptimizerCrash);
return Success;
}
/// 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(std::string &Error) {
+bool BugDriver::debugCodeGeneratorCrash() {
errs() << "*** Debugging code generator crash!\n";
- return DebugACrash(*this, TestForCodeGenCrash, Error);
+ return DebugACrash(*this, TestForCodeGenCrash);
}
/// 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<std::string> &AllPasses,
- std::string &ErrMsg) {
+bool BugDriver::runManyPasses(const std::vector<std::string> &AllPasses) {
setPassesToRun(AllPasses);
outs() << "Starting bug finding procedure...\n\n";
if (!Error.empty()) {
outs() << "\n*** compileProgram threw an exception: ";
outs() << Error;
- return debugCodeGeneratorCrash(ErrMsg);
+ return debugCodeGeneratorCrash();
}
outs() << '\n';
}
if (!Error.empty()) {
errs() << Error;
- debugCodeGeneratorCrash(ErrMsg);
+ debugCodeGeneratorCrash();
return true;
}
outs() << "\n*** diff'd output matches!\n";
#ifndef LLVM_TOOLS_BUGPOINT_LISTREDUCER_H
#define LLVM_TOOLS_BUGPOINT_LISTREDUCER_H
-#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstdlib>
/// test desired. The testcase is only required to test to see if the Kept
/// list still satisfies the property, but if it is going to check the prefix
/// anyway, it can.
- virtual TestResult doTest(std::vector<ElTy> &Prefix, std::vector<ElTy> &Kept,
- std::string &Error) = 0;
+ virtual TestResult doTest(std::vector<ElTy> &Prefix,
+ std::vector<ElTy> &Kept) = 0;
/// 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, std::string &Error) {
+ bool reduceList(std::vector<ElTy> &TheList) {
std::vector<ElTy> empty;
std::srand(0x6e5ea738); // Seed the random number generator
- switch (doTest(TheList, empty, Error)) {
+ switch (doTest(TheList, empty)) {
case KeepPrefix:
if (TheList.size() == 1) // we are done, it's the base case and it fails
return true;
return false; // there is no failure with the full set of passes/funcs!
case InternalError:
- assert(!Error.empty());
return true;
}
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, Error) == KeepPrefix) {
+ if (doTest(ShuffledList, empty) == KeepPrefix) {
// If the bug is still here, use the shuffled list.
TheList.swap(ShuffledList);
MidTop = TheList.size();
std::vector<ElTy> Prefix(TheList.begin(), TheList.begin() + Mid);
std::vector<ElTy> Suffix(TheList.begin() + Mid, TheList.end());
- switch (doTest(Prefix, Suffix, Error)) {
+ switch (doTest(Prefix, Suffix)) {
case KeepSuffix:
// The property still holds. We can just drop the prefix elements, and
// shorten the list to the "kept" elements.
NumOfIterationsWithoutProgress++;
break;
case InternalError:
- return true; // Error was set by doTest.
+ return true;
}
- assert(Error.empty() && "doTest did not return InternalError for error");
}
// Probability of backjumping from the trimming loop back to the binary
std::vector<ElTy> TestList(TheList);
TestList.erase(TestList.begin() + i);
- if (doTest(EmptyList, TestList, Error) == KeepSuffix) {
+ switch (doTest(EmptyList, TestList)) {
+ case KeepSuffix:
// We can trim down the list!
TheList.swap(TestList);
--i; // Don't skip an element of the list
Changed = true;
- }
- if (!Error.empty())
+ break;
+ case InternalError:
return true;
+ default:
+ break;
+ }
}
if (TrimIterations >= MaxTrimIterationsWithoutBackJump)
break;
class ReduceMiscompilingPasses : public ListReducer<std::string> {
BugDriver &BD;
+ std::string &Error;
public:
- ReduceMiscompilingPasses(BugDriver &bd) : BD(bd) {}
+ ReduceMiscompilingPasses(BugDriver &bd, std::string &Error)
+ : BD(bd), Error(Error) {}
TestResult doTest(std::vector<std::string> &Prefix,
- std::vector<std::string> &Suffix,
- std::string &Error) override;
+ std::vector<std::string> &Suffix) override;
};
} // end anonymous namespace
///
ReduceMiscompilingPasses::TestResult
ReduceMiscompilingPasses::doTest(std::vector<std::string> &Prefix,
- std::vector<std::string> &Suffix,
- std::string &Error) {
+ std::vector<std::string> &Suffix) {
// 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)
BugDriver &BD;
bool (*TestFn)(BugDriver &, std::unique_ptr<Module>, std::unique_ptr<Module>,
std::string &);
+ std::string &Error;
public:
ReduceMiscompilingFunctions(BugDriver &bd,
bool (*F)(BugDriver &, std::unique_ptr<Module>,
- std::unique_ptr<Module>, std::string &))
- : BD(bd), TestFn(F) {}
+ std::unique_ptr<Module>, std::string &),
+ std::string &Error)
+ : BD(bd), TestFn(F), Error(Error) {}
TestResult doTest(std::vector<Function *> &Prefix,
- std::vector<Function *> &Suffix,
- std::string &Error) override {
+ std::vector<Function *> &Suffix) override {
if (!Suffix.empty()) {
- bool Ret = TestFuncs(Suffix, Error);
+ bool Ret = TestFuncs(Suffix);
if (!Error.empty())
return InternalError;
if (Ret)
return KeepSuffix;
}
if (!Prefix.empty()) {
- bool Ret = TestFuncs(Prefix, Error);
+ bool Ret = TestFuncs(Prefix);
if (!Error.empty())
return InternalError;
if (Ret)
return NoFailure;
}
- bool TestFuncs(const std::vector<Function *> &Prefix, std::string &Error);
+ bool TestFuncs(const std::vector<Function *> &Prefix);
};
} // end anonymous namespace
/// accordingly. Each group of functions becomes a separate Module.
///
bool ReduceMiscompilingFunctions::TestFuncs(
- const std::vector<Function *> &Funcs, std::string &Error) {
+ const std::vector<Function *> &Funcs) {
// Test to see if the function is misoptimized if we ONLY run it on the
// functions listed in Funcs.
outs() << "Checking to see if the program is misoptimized when "
bool (*TestFn)(BugDriver &, std::unique_ptr<Module>, std::unique_ptr<Module>,
std::string &);
std::vector<Function *> FunctionsBeingTested;
+ std::string &Error;
public:
ReduceMiscompiledBlocks(BugDriver &bd,
bool (*F)(BugDriver &, std::unique_ptr<Module>,
std::unique_ptr<Module>, std::string &),
- const std::vector<Function *> &Fns)
- : BD(bd), TestFn(F), FunctionsBeingTested(Fns) {}
+ const std::vector<Function *> &Fns,
+ std::string &Error)
+ : BD(bd), TestFn(F), FunctionsBeingTested(Fns), Error(Error) {}
TestResult doTest(std::vector<BasicBlock *> &Prefix,
- std::vector<BasicBlock *> &Suffix,
- std::string &Error) override {
+ std::vector<BasicBlock *> &Suffix) override {
if (!Suffix.empty()) {
- bool Ret = TestFuncs(Suffix, Error);
+ bool Ret = TestFuncs(Suffix);
if (!Error.empty())
return InternalError;
if (Ret)
return KeepSuffix;
}
if (!Prefix.empty()) {
- bool Ret = TestFuncs(Prefix, Error);
+ bool Ret = TestFuncs(Prefix);
if (!Error.empty())
return InternalError;
if (Ret)
return NoFailure;
}
- bool TestFuncs(const std::vector<BasicBlock *> &BBs, std::string &Error);
+ bool TestFuncs(const std::vector<BasicBlock *> &BBs);
};
} // end anonymous namespace
/// TestFuncs - Extract all blocks for the miscompiled functions except for the
/// specified blocks. If the problem still exists, return true.
///
-bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock *> &BBs,
- std::string &Error) {
+bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock *> &BBs) {
// Test to see if the function is misoptimized if we ONLY run it on the
// functions listed in Funcs.
outs() << "Checking to see if the program is misoptimized when all ";
unsigned OldSize = Blocks.size();
// Check to see if all blocks are extractible first.
- bool Ret = ReduceMiscompiledBlocks(BD, TestFn, MiscompiledFunctions)
- .TestFuncs(std::vector<BasicBlock *>(), Error);
+ bool Ret = ReduceMiscompiledBlocks(BD, TestFn, MiscompiledFunctions, Error)
+ .TestFuncs(std::vector<BasicBlock *>());
if (!Error.empty())
return false;
if (Ret) {
Blocks.clear();
} else {
- ReduceMiscompiledBlocks(BD, TestFn, MiscompiledFunctions)
- .reduceList(Blocks, Error);
+ ReduceMiscompiledBlocks(BD, TestFn, MiscompiledFunctions, Error)
+ .reduceList(Blocks);
if (!Error.empty())
return false;
if (Blocks.size() == OldSize)
// Do the reduction...
if (!BugpointIsInterrupted)
- ReduceMiscompilingFunctions(BD, TestFn)
- .reduceList(MiscompiledFunctions, Error);
+ ReduceMiscompilingFunctions(BD, TestFn, Error)
+ .reduceList(MiscompiledFunctions);
if (!Error.empty()) {
errs() << "\n***Cannot reduce functions: ";
return MiscompiledFunctions;
// Do the reduction...
if (!BugpointIsInterrupted)
- ReduceMiscompilingFunctions(BD, TestFn)
- .reduceList(MiscompiledFunctions, Error);
+ ReduceMiscompilingFunctions(BD, TestFn, Error)
+ .reduceList(MiscompiledFunctions);
if (!Error.empty())
return MiscompiledFunctions;
DisambiguateGlobalSymbols(BD.getProgram());
// Do the reduction...
- ReduceMiscompilingFunctions(BD, TestFn)
- .reduceList(MiscompiledFunctions, Error);
+ ReduceMiscompilingFunctions(BD, TestFn, Error)
+ .reduceList(MiscompiledFunctions);
if (!Error.empty())
return MiscompiledFunctions;
void BugDriver::debugMiscompilation(std::string *Error) {
// Make sure something was miscompiled...
if (!BugpointIsInterrupted)
- if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun, *Error)) {
+ if (!ReduceMiscompilingPasses(*this, *Error).reduceList(PassesToRun)) {
if (Error->empty())
errs() << "*** Optimized program matches reference output! No problem"
<< " detected...\nbugpoint can't help you with your problem!\n";
sys::Process::PreventCoreFiles();
#endif
- std::string Error;
- bool Failure = D.run(Error);
- if (!Error.empty()) {
- errs() << Error;
- return 1;
- }
- return Failure;
+ return D.run();
}