Remove trailing whitespace
[oota-llvm.git] / tools / bugpoint / CrashDebugger.cpp
index 92aa99643729fab5b6b745ee935ee1827acf0ff8..6f0e3de0f4c143ecc9c1d84af20b6d515035fa2a 100644 (file)
@@ -1,10 +1,10 @@
 //===- CrashDebugger.cpp - Debug compilation crashes ----------------------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This file defines the bugpoint internals that narrow down compilation crashes
@@ -14,7 +14,7 @@
 #include "BugDriver.h"
 #include "ListReducer.h"
 #include "llvm/Constant.h"
-#include "llvm/iTerminators.h"
+#include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/PassManager.h"
@@ -26,7 +26,7 @@
 #include "llvm/Support/ToolRunner.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/Cloning.h"
-#include "Support/FileUtilities.h"
+#include "llvm/Support/FileUtilities.h"
 #include <fstream>
 #include <set>
 using namespace llvm;
@@ -36,7 +36,7 @@ namespace llvm {
     BugDriver &BD;
   public:
     ReducePassList(BugDriver &bd) : BD(bd) {}
-    
+
     // doTest - Return true iff running the "removed" passes succeeds, and
     // running the "Kept" passes fail when run on the output of the "removed"
     // passes.  If we return true, we update the current module of bugpoint.
@@ -49,28 +49,30 @@ namespace llvm {
 ReducePassList::TestResult
 ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
                        std::vector<const PassInfo*> &Suffix) {
-  std::string PrefixOutput;
+  sys::Path PrefixOutput;
   Module *OrigProgram = 0;
   if (!Prefix.empty()) {
     std::cout << "Checking to see if these passes crash: "
               << getPassesString(Prefix) << ": ";
-    if (BD.runPasses(Prefix, PrefixOutput))
+    std::string PfxOutput;
+    if (BD.runPasses(Prefix, PfxOutput))
       return KeepPrefix;
 
+    PrefixOutput.setFile(PfxOutput);
     OrigProgram = BD.Program;
 
-    BD.Program = ParseInputFile(PrefixOutput);
+    BD.Program = ParseInputFile(PrefixOutput.toString());
     if (BD.Program == 0) {
       std::cerr << BD.getToolName() << ": Error reading bytecode file '"
                 << PrefixOutput << "'!\n";
       exit(1);
     }
-    removeFile(PrefixOutput);
+    PrefixOutput.destroyFile();
   }
 
   std::cout << "Checking to see if these passes crash: "
             << getPassesString(Suffix) << ": ";
-  
+
   if (BD.runPasses(Suffix)) {
     delete OrigProgram;            // The suffix crashes alone...
     return KeepSuffix;
@@ -92,7 +94,7 @@ namespace llvm {
     ReduceCrashingFunctions(BugDriver &bd,
                             bool (*testFn)(BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
-    
+
     virtual TestResult doTest(std::vector<Function*> &Prefix,
                               std::vector<Function*> &Kept) {
       if (!Kept.empty() && TestFuncs(Kept))
@@ -101,7 +103,7 @@ namespace llvm {
         return KeepPrefix;
       return NoFailure;
     }
-    
+
     bool TestFuncs(std::vector<Function*> &Prefix);
   };
 }
@@ -109,11 +111,11 @@ namespace llvm {
 bool ReduceCrashingFunctions::TestFuncs(std::vector<Function*> &Funcs) {
   // Clone the program to try hacking it apart...
   Module *M = CloneModule(BD.getProgram());
-  
+
   // Convert list to set for fast lookup...
   std::set<Function*> Functions;
   for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
-    Function *CMF = M->getFunction(Funcs[i]->getName(), 
+    Function *CMF = M->getFunction(Funcs[i]->getName(),
                                    Funcs[i]->getFunctionType());
     assert(CMF && "Function not in module?!");
     Functions.insert(CMF);
@@ -155,7 +157,7 @@ namespace {
   public:
     ReduceCrashingBlocks(BugDriver &bd, bool (*testFn)(BugDriver &, Module *))
       : BD(bd), TestFn(testFn) {}
-    
+
     virtual TestResult doTest(std::vector<const BasicBlock*> &Prefix,
                               std::vector<const BasicBlock*> &Kept) {
       if (!Kept.empty() && TestBlocks(Kept))
@@ -164,7 +166,7 @@ namespace {
         return KeepPrefix;
       return NoFailure;
     }
-    
+
     bool TestBlocks(std::vector<const BasicBlock*> &Prefix);
   };
 }
@@ -172,7 +174,7 @@ namespace {
 bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
   // Clone the program to try hacking it apart...
   Module *M = CloneModule(BD.getProgram());
-  
+
   // Convert list to set for fast lookup...
   std::set<BasicBlock*> Blocks;
   for (unsigned i = 0, e = BBs.size(); i != e; ++i) {
@@ -212,7 +214,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
 
         // Delete the old terminator instruction...
         BB->getInstList().pop_back();
-        
+
         // Add a new return instruction of the appropriate type...
         const Type *RetTy = BB->getParent()->getReturnType();
         new ReturnInst(RetTy == Type::VoidTy ? 0 :
@@ -263,16 +265,16 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
 
   // See if we can get away with nuking all of the global variable initializers
   // in the program...
-  if (BD.getProgram()->gbegin() != BD.getProgram()->gend()) {
+  if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) {
     Module *M = CloneModule(BD.getProgram());
     bool DeletedInit = false;
-    for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
+    for (Module::global_iterator I = M->global_begin(), E = M->global_end(); I != E; ++I)
       if (I->hasInitializer()) {
         I->setInitializer(0);
         I->setLinkage(GlobalValue::ExternalLinkage);
         DeletedInit = true;
       }
-    
+
     if (!DeletedInit) {
       delete M;  // No change made...
     } else {
@@ -288,7 +290,7 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
       }
     }
   }
-  
+
   // Now try to reduce the number of functions in the module to something small.
   std::vector<Function*> Functions;
   for (Module::iterator I = BD.getProgram()->begin(),
@@ -341,7 +343,7 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
     //
     unsigned InstructionsToSkipBeforeDeleting = 0;
   TryAgain:
-    
+
     // Loop over all of the (non-terminator) instructions remaining in the
     // function, attempting to delete them.
     unsigned CurInstructionNum = 0;
@@ -357,7 +359,7 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
             } else {
               std::cout << "Checking instruction '" << I->getName() << "': ";
               Module *M = BD.deleteInstructionFromProgram(I, Simplification);
-              
+
               // Find out if the pass still crashes on this pass...
               if (TestFn(BD, M)) {
                 // Yup, it does, we delete the old module, and continue trying
@@ -367,7 +369,7 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
                 InstructionsToSkipBeforeDeleting = CurInstructionNum;
                 goto TryAgain;  // I wish I had a multi-level break here!
               }
-              
+
               // This pass didn't crash without this instruction, try the next
               // one.
               delete M;
@@ -377,14 +379,14 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
       InstructionsToSkipBeforeDeleting = 0;
       goto TryAgain;
     }
-      
+
   } while (Simplification);
 
   // Try to clean up the testcase by running funcresolve and globaldce...
   std::cout << "\n*** Attempting to perform final cleanups: ";
   Module *M = CloneModule(BD.getProgram());
   M = BD.performFinalCleanups(M, true);
-            
+
   // Find out if the pass still crashes on the cleaned up program...
   if (TestFn(BD, M)) {
     BD.setNewProgram(M);     // Yup, it does, keep the reduced version...
@@ -396,7 +398,7 @@ static bool DebugACrash(BugDriver &BD,  bool (*TestFn)(BugDriver &, Module *)) {
   if (AnyReduction)
     BD.EmitProgressBytecode("reduced-simplified");
 
-  return false;  
+  return false;
 }
 
 static bool TestForOptimizerCrash(BugDriver &BD, Module *M) {
@@ -429,7 +431,7 @@ static bool TestForCodeGenCrash(BugDriver &BD, Module *M) {
     BD.compileProgram(M);
     std::cerr << '\n';
     return false;
-  } catch (ToolExecutionError &TEE) {
+  } catch (ToolExecutionError &) {
     std::cerr << "<crash>\n";
     return true;  // Tool is still crashing.
   }