Add a missing error handling to llvm-lto.
[oota-llvm.git] / tools / bugpoint / FindBugs.cpp
index fd1f84b7286bdda1822b792ee31dce2cc0ef5a95..a0c859b7f33e9a1c8f1d217d0bb00f6fdc862458 100644 (file)
@@ -17,6 +17,8 @@
 #include "BugDriver.h"
 #include "ToolRunner.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <ctime>
 using namespace llvm;
@@ -28,7 +30,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<std::string> &AllPasses,
+                              std::string &ErrMsg) {
   setPassesToRun(AllPasses);
   outs() << "Starting bug finding procedure...\n\n";
   
@@ -42,7 +45,7 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
       return false;
   }
   
-  srand(time(NULL));  
+  srand(time(nullptr));
   
   unsigned num = 1;
   while(1) {  
@@ -56,11 +59,11 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
     //
     outs() << "Running selected passes on program to test for crash: ";
     for(int i = 0, e = PassesToRun.size(); i != e; i++) {
-      outs() << "-" << PassesToRun[i]->getPassArgument( )<< " ";
+      outs() << "-" << PassesToRun[i] << " ";
     }
     
     std::string Filename;
-    if(runPasses(PassesToRun, Filename, false)) {
+    if(runPasses(Program, PassesToRun, Filename, false)) {
       outs() << "\n";
       outs() << "Optimizer passes caused failure!\n\n";
       debugOptimizerCrash();
@@ -73,35 +76,35 @@ 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(Program, 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();
+    sys::fs::remove(Filename);
     
     outs() << "\n\n";
     num++;