#include "BugDriver.h"
#include "ListReducer.h"
#include "ToolRunner.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Transforms/Utils/Local.h"
#include <set>
usingnamespacellvm;
namespace {
cl::opt<bool> KeepMain("keep-main",
cl::desc("Force function reduction to keep main"),
cl::init(false));
cl::opt<bool> NoGlobalRM("disable-global-remove",
cl::desc("Do not remove global variables"),
cl::init(false));
cl::opt<bool> NoAttributeRM("disable-attribute-remove",
cl::desc("Do not remove function attributes"),
cl::init(false));
cl::opt<bool> ReplaceFuncsWithNull(
"replace-funcs-with-null",
cl::desc("When stubbing functions, replace all uses will null"),
cl::init(false));
cl::opt<bool> DontReducePassList("disable-pass-list-reduction",
cl::desc("Skip pass list reduction steps"),
cl::init(false));
cl::opt<bool> NoNamedMDRM("disable-namedmd-remove",
cl::desc("Do not remove global named metadata"),
cl::init(false));
cl::opt<bool> NoStripDebugInfo("disable-strip-debuginfo",
cl::desc("Do not strip debug info metadata"),
cl::init(false));
cl::opt<bool> NoStripDebugTypeInfo("disable-strip-debug-types",
cl::desc("Do not strip debug type info metadata"),
cl::init(false));
cl::opt<bool> VerboseErrors("verbose-errors",
cl::desc("Print the output of crashing program"),
cl::init(false));
}
static bool isValidModule(std::unique_ptr<Module> &M,
bool ExitOnFailure = true) { … }
namespace llvm {
class ReducePassList : public ListReducer<std::string> { … };
}
Expected<ReducePassList::TestResult>
ReducePassList::doTest(std::vector<std::string> &Prefix,
std::vector<std::string> &Suffix) { … }
BugTester;
namespace {
class ReduceCrashingGlobalInitializers : public ListReducer<GlobalVariable *> { … };
}
bool ReduceCrashingGlobalInitializers::TestGlobalVariables(
std::vector<GlobalVariable *> &GVs) { … }
namespace {
class ReduceCrashingFunctions : public ListReducer<Function *> { … };
}
static void RemoveFunctionReferences(Module *M, const char *Name) { … }
bool ReduceCrashingFunctions::TestFuncs(std::vector<Function *> &Funcs) { … }
namespace {
class ReduceCrashingFunctionAttributes : public ListReducer<Attribute> { … };
}
bool ReduceCrashingFunctionAttributes::TestFuncAttrs(
std::vector<Attribute> &Attrs) { … }
namespace {
void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { … }
class ReduceCrashingBlocks : public ListReducer<const BasicBlock *> { … };
}
bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock *> &BBs) { … }
namespace {
class ReduceCrashingConditionals : public ListReducer<const BasicBlock *> { … };
}
bool ReduceCrashingConditionals::TestBlocks(
std::vector<const BasicBlock *> &BBs) { … }
namespace {
class ReduceSimplifyCFG : public ListReducer<const BasicBlock *> { … };
}
bool ReduceSimplifyCFG::TestBlocks(std::vector<const BasicBlock *> &BBs) { … }
namespace {
class ReduceCrashingInstructions : public ListReducer<const Instruction *> { … };
}
bool ReduceCrashingInstructions::TestInsts(
std::vector<const Instruction *> &Insts) { … }
namespace {
class ReduceCrashingMetadata : public ListReducer<Instruction *> { … };
}
bool ReduceCrashingMetadata::TestInsts(std::vector<Instruction *> &Insts) { … }
namespace {
class ReduceCrashingNamedMD : public ListReducer<std::string> { … };
}
bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) { … }
namespace {
class ReduceCrashingNamedMDOps : public ListReducer<const MDNode *> { … };
}
bool ReduceCrashingNamedMDOps::TestNamedMDOps(
std::vector<const MDNode *> &NamedMDOps) { … }
static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { … }
static Error ReduceInsts(BugDriver &BD, BugTester TestFn) { … }
static Error DebugACrash(BugDriver &BD, BugTester TestFn) { … }
static bool TestForOptimizerCrash(const BugDriver &BD, Module *M) { … }
Error BugDriver::debugOptimizerCrash(const std::string &ID) { … }
static bool TestForCodeGenCrash(const BugDriver &BD, Module *M) { … }
Error BugDriver::debugCodeGeneratorCrash() { … }