diff options
author | Patrick Jenkins <pjenkins@apple.com> | 2006-08-15 16:41:52 +0000 |
---|---|---|
committer | Patrick Jenkins <pjenkins@apple.com> | 2006-08-15 16:41:52 +0000 |
commit | 032091d7f62774443c282915964189ea3d8930de (patch) | |
tree | ed8611886db2d3fb3d6532a5878584f0c82618be /tools/bugpoint/FindBugs.cpp | |
parent | 6a3f31cb707972ebde1e45a61fa8f5bcff132eba (diff) | |
download | external_llvm-032091d7f62774443c282915964189ea3d8930de.zip external_llvm-032091d7f62774443c282915964189ea3d8930de.tar.gz external_llvm-032091d7f62774443c282915964189ea3d8930de.tar.bz2 |
Adding FindBugs.cpp so the -find-bugs option will work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/bugpoint/FindBugs.cpp')
-rw-r--r-- | tools/bugpoint/FindBugs.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/tools/bugpoint/FindBugs.cpp b/tools/bugpoint/FindBugs.cpp new file mode 100644 index 0000000..385a357 --- /dev/null +++ b/tools/bugpoint/FindBugs.cpp @@ -0,0 +1,119 @@ +//===-- FindBugs.cpp - Run Many Different Optimizations -------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Patrick Jenkins and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines an interface that allows bugpoint to choose different +// combinations of optimizations to run on the selected input. Bugpoint will +// run these optimizations and record the success/failure of each. This way +// we can hopefully spot bugs in the optimizations. +// +//===----------------------------------------------------------------------===// +#include "BugDriver.h" +#include "ToolRunner.h" + +#include "llvm/Bytecode/WriteBytecodePass.h" + +#include <algorithm> +#include <ctime> +using namespace llvm; + +/// runManyPasses - Take the specified pass list and create different +/// combinations of passes to compile the program with. Compile the program with +/// each set and mark test to see if it compiled correctly. If the passes +/// compiled correctly output nothing and rearrange the passes into a new order. +/// 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) +{ + std::string Filename; + std::vector<const PassInfo*> TempPass(AllPasses); + std::cout << "Starting bug finding procedure...\n\n"; + + // Creating a reference output if necessary + if (initializeExecutionEnvironment()) return false; + std::cout << "\n"; + if (ReferenceOutputFile.empty()) { + std::cout << "Generating reference output from raw program: \n"; + if(!createReferenceFile(Program)){ + return false; + } + } + + srand(time(NULL)); + std::vector<const PassInfo*>::iterator I = TempPass.begin(); + std::vector<const PassInfo*>::iterator E = TempPass.end(); + + int num=1; + while(1){ + // + // Step 1: Randomize the order of the optimizer passes. + // + std::random_shuffle(TempPass.begin(), TempPass.end()); + + // + // Step 2: Run optimizer passes on the program and check for success. + // + std::cout << "Running selected passes on program to test for crash: "; + for(int i=0, e=TempPass.size(); i!=e; i++) { + std::cout << "-" << TempPass[i]->getPassArgument( )<< " "; + } + std::string Filename; + if(runPasses(TempPass, Filename, false)) { + std::cout << "\n"; + std::cout << "Optimizer passes caused failure!\n\n"; + debugOptimizerCrash(); + return true; + } + else{ + std::cout << "Combination "<<num<<" optimized successfully!\n"; + } + + // + // Step 3: Compile the optimized code. + // + std::cout << "Running the code generator to test for a crash: "; + try { + compileProgram(Program); + std::cout << '\n'; + } catch (ToolExecutionError &TEE) { + std::cout << "\n*** compileProgram threw an exception: "; + std::cout << TEE.what(); + return debugCodeGeneratorCrash(); + } + + // + // Step 4: Run the program and compare its output to the reference + // output (created above). + // + std::cout << "*** Checking if passes caused miscompliation:\n"; + try { + if (diffProgram(Filename, "", false)) { + std::cout << "\n*** diffProgram returned true!\n"; + debugMiscompilation(); + return true; + } + else{ + std::cout << "\n*** diff'd output matches!\n"; + } + } catch (ToolExecutionError &TEE) { + std::cerr << TEE.what(); + debugCodeGeneratorCrash(); + return true; + } + + sys::Path(Filename).eraseFromDisk(); + + std::cout << "\n\n"; + num++; + } //end while + + // This will never be reached + std::cout << "Did not find any bugs :-( \n"; + return false; +} |