diff options
Diffstat (limited to 'contrib/llvm/tools/bugpoint/BugDriver.cpp')
-rw-r--r-- | contrib/llvm/tools/bugpoint/BugDriver.cpp | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/contrib/llvm/tools/bugpoint/BugDriver.cpp b/contrib/llvm/tools/bugpoint/BugDriver.cpp index 030749f..78f3529 100644 --- a/contrib/llvm/tools/bugpoint/BugDriver.cpp +++ b/contrib/llvm/tools/bugpoint/BugDriver.cpp @@ -29,20 +29,20 @@ using namespace llvm; namespace llvm { - Triple TargetTriple; +Triple TargetTriple; } // Anonymous namespace to define command line options for debugging. // namespace { - // Output - The user can specify a file containing the expected output of the - // program. If this filename is set, it is used as the reference diff source, - // otherwise the raw input run through an interpreter is used as the reference - // source. - // - cl::opt<std::string> - OutputFile("output", cl::desc("Specify a reference program output " - "(for miscompilation detection)")); +// Output - The user can specify a file containing the expected output of the +// program. If this filename is set, it is used as the reference diff source, +// otherwise the raw input run through an interpreter is used as the reference +// source. +// +cl::opt<std::string> OutputFile("output", + cl::desc("Specify a reference program output " + "(for miscompilation detection)")); } /// setNewProgram - If we reduce or update the program somehow, call this method @@ -53,27 +53,26 @@ void BugDriver::setNewProgram(Module *M) { Program = M; } - /// getPassesString - Turn a list of passes into a string which indicates the /// command line options that must be passed to add the passes. /// std::string llvm::getPassesString(const std::vector<std::string> &Passes) { std::string Result; for (unsigned i = 0, e = Passes.size(); i != e; ++i) { - if (i) Result += " "; + if (i) + Result += " "; Result += "-"; Result += Passes[i]; } return Result; } -BugDriver::BugDriver(const char *toolname, bool find_bugs, - unsigned timeout, unsigned memlimit, bool use_valgrind, - LLVMContext& ctxt) - : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile), - Program(nullptr), Interpreter(nullptr), SafeInterpreter(nullptr), - cc(nullptr), run_find_bugs(find_bugs), Timeout(timeout), - MemoryLimit(memlimit), UseValgrind(use_valgrind) {} +BugDriver::BugDriver(const char *toolname, bool find_bugs, unsigned timeout, + unsigned memlimit, bool use_valgrind, LLVMContext &ctxt) + : Context(ctxt), ToolName(toolname), ReferenceOutputFile(OutputFile), + Program(nullptr), Interpreter(nullptr), SafeInterpreter(nullptr), + cc(nullptr), run_find_bugs(find_bugs), Timeout(timeout), + MemoryLimit(memlimit), UseValgrind(use_valgrind) {} BugDriver::~BugDriver() { delete Program; @@ -123,13 +122,15 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) { // Load the first input file. Program = parseInputFile(Filenames[0], Context).release(); - if (!Program) return true; + if (!Program) + return true; outs() << "Read input file : '" << Filenames[0] << "'\n"; for (unsigned i = 1, e = Filenames.size(); i != e; ++i) { std::unique_ptr<Module> M = parseInputFile(Filenames[i], Context); - if (!M.get()) return true; + if (!M.get()) + return true; outs() << "Linking in input file: '" << Filenames[i] << "'\n"; if (Linker::linkModules(*Program, std::move(M))) @@ -142,16 +143,14 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) { return false; } - - /// 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) { +Error 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 @@ -168,15 +167,14 @@ bool BugDriver::run(std::string &ErrMsg) { } // Set up the execution environment, selecting a method to run LLVM bitcode. - if (initializeExecutionEnvironment()) return true; + if (Error E = initializeExecutionEnvironment()) + return E; // Test to see if we have a code generator crash. outs() << "Running the code generator to test for a crash: "; - std::string Error; - compileProgram(Program, &Error); - if (!Error.empty()) { - outs() << Error; - return debugCodeGeneratorCrash(ErrMsg); + if (Error E = compileProgram(Program)) { + outs() << toString(std::move(E)); + return debugCodeGeneratorCrash(); } outs() << '\n'; @@ -187,8 +185,9 @@ bool BugDriver::run(std::string &ErrMsg) { bool CreatedOutput = false; if (ReferenceOutputFile.empty()) { outs() << "Generating reference output from raw program: "; - if (!createReferenceFile(Program)) { - return debugCodeGeneratorCrash(ErrMsg); + if (Error E = createReferenceFile(Program)) { + errs() << toString(std::move(E)); + return debugCodeGeneratorCrash(); } CreatedOutput = true; } @@ -202,34 +201,33 @@ bool BugDriver::run(std::string &ErrMsg) { // matches, then we assume there is a miscompilation bug and try to // diagnose it. outs() << "*** Checking the code generator...\n"; - bool Diff = diffProgram(Program, "", "", false, &Error); - if (!Error.empty()) { - errs() << Error; - return debugCodeGeneratorCrash(ErrMsg); + Expected<bool> Diff = diffProgram(Program, "", "", false); + if (Error E = Diff.takeError()) { + errs() << toString(std::move(E)); + return debugCodeGeneratorCrash(); } - if (!Diff) { + if (!*Diff) { outs() << "\n*** Output matches: Debugging miscompilation!\n"; - debugMiscompilation(&Error); - if (!Error.empty()) { - errs() << Error; - return debugCodeGeneratorCrash(ErrMsg); + if (Error E = debugMiscompilation()) { + errs() << toString(std::move(E)); + return debugCodeGeneratorCrash(); } - return false; + return Error::success(); } outs() << "\n*** Input program does not match reference diff!\n"; outs() << "Debugging code generator problem!\n"; - bool Failure = debugCodeGenerator(&Error); - if (!Error.empty()) { - errs() << Error; - return debugCodeGeneratorCrash(ErrMsg); + if (Error E = debugCodeGenerator()) { + errs() << toString(std::move(E)); + return debugCodeGeneratorCrash(); } - return Failure; + return Error::success(); } -void llvm::PrintFunctionList(const std::vector<Function*> &Funcs) { +void llvm::PrintFunctionList(const std::vector<Function *> &Funcs) { unsigned NumPrint = Funcs.size(); - if (NumPrint > 10) NumPrint = 10; + if (NumPrint > 10) + NumPrint = 10; for (unsigned i = 0; i != NumPrint; ++i) outs() << " " << Funcs[i]->getName(); if (NumPrint < Funcs.size()) @@ -237,9 +235,10 @@ void llvm::PrintFunctionList(const std::vector<Function*> &Funcs) { outs().flush(); } -void llvm::PrintGlobalVariableList(const std::vector<GlobalVariable*> &GVs) { +void llvm::PrintGlobalVariableList(const std::vector<GlobalVariable *> &GVs) { unsigned NumPrint = GVs.size(); - if (NumPrint > 10) NumPrint = 10; + if (NumPrint > 10) + NumPrint = 10; for (unsigned i = 0; i != NumPrint; ++i) outs() << " " << GVs[i]->getName(); if (NumPrint < GVs.size()) |