diff options
Diffstat (limited to 'llvm/tools/bugpoint/CrashDebugger.cpp')
-rw-r--r-- | llvm/tools/bugpoint/CrashDebugger.cpp | 124 |
1 files changed, 66 insertions, 58 deletions
diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp index fcac014..240300b 100644 --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -36,39 +36,44 @@ #include <set> using namespace llvm; -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( +static cl::opt<bool> KeepMain("keep-main", + cl::desc("Force function reduction to keep main"), + cl::init(false)); +static cl::opt<bool> NoGlobalRM("disable-global-remove", + cl::desc("Do not remove global variables"), + cl::init(false)); + +static cl::opt<bool> + NoAttributeRM("disable-attribute-remove", + cl::desc("Do not remove function attributes"), + cl::init(false)); + +static 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 cl::opt<bool> + DontReducePassList("disable-pass-list-reduction", + cl::desc("Skip pass list reduction steps"), + cl::init(false)); + +static cl::opt<bool> + NoNamedMDRM("disable-namedmd-remove", + cl::desc("Do not remove global named metadata"), + cl::init(false)); +static cl::opt<bool> + NoStripDebugInfo("disable-strip-debuginfo", + cl::desc("Do not strip debug info metadata"), + cl::init(false)); +static cl::opt<bool> + NoStripDebugTypeInfo("disable-strip-debug-types", + cl::desc("Do not strip debug type info metadata"), + cl::init(false)); +static 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) { @@ -83,6 +88,8 @@ static bool isValidModule(std::unique_ptr<Module> &M, } namespace llvm { +// Note this class needs to be in llvm namespace since its declared as a friend +// of BugDriver. class ReducePassList : public ListReducer<std::string> { BugDriver &BD; @@ -95,7 +102,7 @@ public: Expected<TestResult> doTest(std::vector<std::string> &Removed, std::vector<std::string> &Kept) override; }; -} +} // namespace llvm Expected<ReducePassList::TestResult> ReducePassList::doTest(std::vector<std::string> &Prefix, @@ -156,7 +163,7 @@ public: bool TestGlobalVariables(std::vector<GlobalVariable *> &GVs); }; -} +} // namespace bool ReduceCrashingGlobalInitializers::TestGlobalVariables( std::vector<GlobalVariable *> &GVs) { @@ -174,14 +181,14 @@ bool ReduceCrashingGlobalInitializers::TestGlobalVariables( } outs() << "Checking for crash with only these global variables: "; - PrintGlobalVariableList(GVs); + printGlobalVariableList(GVs); outs() << ": "; // Loop over and delete any global variables which we aren't supposed to be // playing with... for (GlobalVariable &I : M->globals()) if (I.hasInitializer() && !GVSet.count(&I)) { - DeleteGlobalInitializer(&I); + deleteGlobalInitializer(&I); I.setLinkage(GlobalValue::ExternalLinkage); I.setComdat(nullptr); } @@ -223,7 +230,7 @@ public: bool TestFuncs(std::vector<Function *> &Prefix); }; -} +} // namespace static void RemoveFunctionReferences(Module *M, const char *Name) { auto *UsedVar = M->getGlobalVariable(Name, true); @@ -269,14 +276,14 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector<Function *> &Funcs) { } outs() << "Checking for crash with only these functions: "; - PrintFunctionList(Funcs); + printFunctionList(Funcs); outs() << ": "; if (!ReplaceFuncsWithNull) { // Loop over and delete any functions which we aren't supposed to be playing // with... for (Function &I : *M) if (!I.isDeclaration() && !Functions.count(&I)) - DeleteFunctionBody(&I); + deleteFunctionBody(&I); } else { std::vector<GlobalValue *> ToRemove; // First, remove aliases to functions we're about to purge. @@ -356,7 +363,7 @@ public: bool TestFuncAttrs(std::vector<Attribute> &Attrs); }; -} +} // namespace bool ReduceCrashingFunctionAttributes::TestFuncAttrs( std::vector<Attribute> &Attrs) { @@ -396,12 +403,11 @@ bool ReduceCrashingFunctionAttributes::TestFuncAttrs( return false; } -namespace { /// Simplify the CFG without completely destroying it. /// This is not well defined, but basically comes down to "try to eliminate /// unreachable blocks and constant fold terminators without deciding that /// certain undefined behavior cuts off the program at the legs". -void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { +static void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { if (F.empty()) return; @@ -435,6 +441,8 @@ void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) { for (auto *BB : Unreachable) BB->eraseFromParent(); } + +namespace { /// ReduceCrashingBlocks reducer - This works by setting the terminators of /// all terminators except the specified basic blocks to a 'ret' instruction, /// then running the simplifycfg pass. This has the effect of chopping up @@ -459,7 +467,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... @@ -571,7 +579,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceCrashingConditionals::TestBlocks( std::vector<const BasicBlock *> &BBs) { @@ -670,7 +678,7 @@ public: bool TestBlocks(std::vector<const BasicBlock *> &Prefix); }; -} +} // namespace bool ReduceSimplifyCFG::TestBlocks(std::vector<const BasicBlock *> &BBs) { // Clone the program to try hacking it apart... @@ -755,7 +763,7 @@ public: bool TestInsts(std::vector<const Instruction *> &Prefix); }; -} +} // namespace bool ReduceCrashingInstructions::TestInsts( std::vector<const Instruction *> &Insts) { @@ -896,7 +904,7 @@ public: bool TestNamedMDs(std::vector<std::string> &NamedMDs); }; -} +} // namespace bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) { @@ -959,7 +967,7 @@ public: bool TestNamedMDOps(std::vector<const MDNode *> &NamedMDOps); }; -} +} // namespace bool ReduceCrashingNamedMDOps::TestNamedMDOps( std::vector<const MDNode *> &NamedMDOps) { @@ -1018,7 +1026,7 @@ static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { for (GlobalVariable &GV : M->globals()) { if (GV.hasInitializer()) { - DeleteGlobalInitializer(&GV); + deleteGlobalInitializer(&GV); GV.setLinkage(GlobalValue::ExternalLinkage); GV.setComdat(nullptr); DeletedInit = true; @@ -1056,7 +1064,7 @@ static Error ReduceGlobalInitializers(BugDriver &BD, BugTester TestFn) { return E; if (GVs.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-global-variables"); } return Error::success(); } @@ -1155,7 +1163,7 @@ static Error ReduceInsts(BugDriver &BD, BugTester TestFn) { return E; } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-instructions"); return Error::success(); } @@ -1186,7 +1194,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { return E; if (Functions.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-function"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-function"); } if (!NoAttributeRM) { @@ -1218,7 +1226,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { } if (OldSize < NewSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-function-attributes"); } } @@ -1238,7 +1246,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-conditionals"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-conditionals"); } // Attempt to delete entire basic blocks at a time to speed up @@ -1256,7 +1264,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-blocks"); } if (!DisableSimplifyCFG && !BugpointIsInterrupted) { @@ -1269,7 +1277,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; if (Blocks.size() < OldSize) - BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplifycfg"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-simplifycfg"); } // Attempt to delete instructions using bisection. This should help out nasty @@ -1319,7 +1327,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { if (Error E = Result.takeError()) return E; } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-named-md"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-named-md"); } // Try to clean up the testcase by running funcresolve and globaldce... @@ -1334,7 +1342,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) { std::move(M)); // Yup, it does, keep the reduced version... } - BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplified"); + BD.emitProgressBitcode(BD.getProgram(), "reduced-simplified"); return Error::success(); } @@ -1361,7 +1369,7 @@ Error BugDriver::debugOptimizerCrash(const std::string &ID) { << (PassesToRun.size() == 1 ? ": " : "es: ") << getPassesString(PassesToRun) << '\n'; - EmitProgressBitcode(*Program, ID); + emitProgressBitcode(*Program, ID); auto Res = DebugACrash(*this, TestForOptimizerCrash); if (Res || DontReducePassList) @@ -1376,7 +1384,7 @@ Error BugDriver::debugOptimizerCrash(const std::string &ID) { << (PassesToRun.size() == 1 ? ": " : "es: ") << getPassesString(PassesToRun) << '\n'; - EmitProgressBitcode(getProgram(), "reduced-simplified"); + emitProgressBitcode(getProgram(), "reduced-simplified"); return Res; } |