//===- 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
#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"
#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;
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.
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;
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))
return KeepPrefix;
return NoFailure;
}
-
+
bool TestFuncs(std::vector<Function*> &Prefix);
};
}
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);
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))
return KeepPrefix;
return NoFailure;
}
-
+
bool TestBlocks(std::vector<const BasicBlock*> &Prefix);
};
}
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) {
// 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 :
// 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 {
}
}
}
-
+
// 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(),
//
unsigned InstructionsToSkipBeforeDeleting = 0;
TryAgain:
-
+
// Loop over all of the (non-terminator) instructions remaining in the
// function, attempting to delete them.
unsigned CurInstructionNum = 0;
} 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
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;
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...
if (AnyReduction)
BD.EmitProgressBytecode("reduced-simplified");
- return false;
+ return false;
}
static bool TestForOptimizerCrash(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.
}