• Home
  • Raw
  • Download

Lines Matching +full:- +full:bd

1 //===- CrashDebugger.cpp - Debug compilation crashes ----------------------===//
8 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
37 KeepMain("keep-main",
41 NoGlobalRM ("disable-global-remove",
46 ReplaceFuncsWithNull("replace-funcs-with-null",
50 DontReducePassList("disable-pass-list-reduction",
54 cl::opt<bool> NoNamedMDRM("disable-namedmd-remove",
61 BugDriver &BD; member in llvm::ReducePassList
63 ReducePassList(BugDriver &bd) : BD(bd) {} in ReducePassList() argument
65 // doTest - Return true iff running the "removed" passes succeeds, and
84 if (BD.runPasses(BD.getProgram(), Prefix, PrefixOutput)) in doTest()
87 OrigProgram = BD.Program; in doTest()
89 BD.Program = parseInputFile(PrefixOutput, BD.getContext()).release(); in doTest()
90 if (BD.Program == nullptr) { in doTest()
91 errs() << BD.getToolName() << ": Error reading bitcode file '" in doTest()
101 if (BD.runPasses(BD.getProgram(), Suffix)) { in doTest()
108 delete BD.Program; in doTest()
109 BD.Program = OrigProgram; in doTest()
115 /// ReduceCrashingGlobalVariables - This works by removing the global
120 BugDriver &BD; member in __anon8d90c2ef0211::ReduceCrashingGlobalVariables
123 ReduceCrashingGlobalVariables(BugDriver &bd, in ReduceCrashingGlobalVariables() argument
125 : BD(bd), TestFn(testFn) {} in ReduceCrashingGlobalVariables()
146 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestGlobalVariables()
163 for (GlobalVariable &I : M->globals()) in TestGlobalVariables()
171 if (TestFn(BD, M)) { in TestGlobalVariables()
172 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestGlobalVariables()
174 // Make sure to use global variable pointers that point into the now-current in TestGlobalVariables()
185 /// ReduceCrashingFunctions reducer - This works by removing functions and
190 BugDriver &BD; member in __anon8d90c2ef0311::ReduceCrashingFunctions
193 ReduceCrashingFunctions(BugDriver &bd, in ReduceCrashingFunctions() argument
195 : BD(bd), TestFn(testFn) {} in ReduceCrashingFunctions()
212 auto *UsedVar = M->getGlobalVariable(Name, true); in RemoveFunctionReferences()
213 if (!UsedVar || !UsedVar->hasInitializer()) return; in RemoveFunctionReferences()
214 if (isa<ConstantAggregateZero>(UsedVar->getInitializer())) { in RemoveFunctionReferences()
215 assert(UsedVar->use_empty()); in RemoveFunctionReferences()
216 UsedVar->eraseFromParent(); in RemoveFunctionReferences()
219 auto *OldUsedVal = cast<ConstantArray>(UsedVar->getInitializer()); in RemoveFunctionReferences()
221 for(Value *V : OldUsedVal->operand_values()) { in RemoveFunctionReferences()
222 Constant *Op = cast<Constant>(V->stripPointerCasts()); in RemoveFunctionReferences()
223 if(!Op->isNullValue()) { in RemoveFunctionReferences()
227 auto *NewValElemTy = OldUsedVal->getType()->getElementType(); in RemoveFunctionReferences()
230 UsedVar->mutateType(NewUsedVal->getType()->getPointerTo()); in RemoveFunctionReferences()
231 UsedVar->setInitializer(NewUsedVal); in RemoveFunctionReferences()
237 BD.getProgram()->getFunction("main")) == in TestFuncs()
243 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestFuncs()
250 assert(CMF->getFunctionType() == Funcs[i]->getFunctionType() && "wrong ty"); in TestFuncs()
251 assert(CMF->getName() == Funcs[i]->getName() && "wrong name"); in TestFuncs()
267 for (GlobalAlias &Alias : M->aliases()) { in TestFuncs()
274 } else if (Root->isNullValue()) { in TestFuncs()
298 F->eraseFromParent(); in TestFuncs()
306 if (TestFn(BD, M)) { in TestFuncs()
307 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestFuncs()
309 // Make sure to use function pointers that point into the now-current in TestFuncs()
320 /// ReduceCrashingBlocks reducer - This works by setting the terminators of
322 /// then running the simplify-cfg pass. This has the effect of chopping up
326 BugDriver &BD; member in __anon8d90c2ef0411::ReduceCrashingBlocks
329 ReduceCrashingBlocks(BugDriver &bd, in ReduceCrashingBlocks() argument
331 : BD(bd), TestFn(testFn) {} in ReduceCrashingBlocks()
350 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestBlocks()
361 outs() << " " << BBs[i]->getName(); in TestBlocks()
367 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) in TestBlocks()
368 for (Function::iterator BB = I->begin(), E = I->end(); BB != E; ++BB) in TestBlocks()
369 if (!Blocks.count(&*BB) && BB->getTerminator()->getNumSuccessors()) { in TestBlocks()
374 (*SI)->removePredecessor(&*BB); in TestBlocks()
376 TerminatorInst *BBTerm = BB->getTerminator(); in TestBlocks()
377 if (BBTerm->isEHPad() || BBTerm->getType()->isTokenTy()) in TestBlocks()
379 if (!BBTerm->getType()->isVoidTy()) in TestBlocks()
380 BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType())); in TestBlocks()
383 BB->getInstList().pop_back(); in TestBlocks()
384 new UnreachableInst(BB->getContext(), &*BB); in TestBlocks()
395 BlockInfo.emplace_back(BB->getParent()->getName(), BB->getName()); in TestBlocks()
401 std::unique_ptr<Module> New = BD.runPassesOn(M, Passes); in TestBlocks()
410 if (TestFn(BD, M)) { in TestBlocks()
411 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestBlocks()
413 // Make sure to use basic block pointers that point into the now-current in TestBlocks()
416 const ValueSymbolTable &GST = M->getValueSymbolTable(); in TestBlocks()
419 ValueSymbolTable &ST = F->getValueSymbolTable(); in TestBlocks()
421 if (V && V->getType() == Type::getLabelTy(V->getContext())) in TestBlocks()
431 /// ReduceCrashingInstructions reducer - This works by removing the specified
432 /// non-terminator instructions and replacing them with undef.
435 BugDriver &BD; member in __anon8d90c2ef0511::ReduceCrashingInstructions
438 ReduceCrashingInstructions(BugDriver &bd, in ReduceCrashingInstructions() argument
440 : BD(bd), TestFn(testFn) {} in ReduceCrashingInstructions()
460 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestInsts()
475 for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) in TestInsts()
476 for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI) in TestInsts()
477 for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { in TestInsts()
480 !Inst->isEHPad() && !Inst->getType()->isTokenTy()) { in TestInsts()
481 if (!Inst->getType()->isVoidTy()) in TestInsts()
482 Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); in TestInsts()
483 Inst->eraseFromParent(); in TestInsts()
493 if (TestFn(BD, M)) { in TestInsts()
494 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestInsts()
496 // Make sure to use instruction pointers that point into the now-current in TestInsts()
511 BugDriver &BD; member in __anon8d90c2ef0611::ReduceCrashingNamedMD
515 ReduceCrashingNamedMD(BugDriver &bd, in ReduceCrashingNamedMD() argument
517 : BD(bd), TestFn(testFn) {} in ReduceCrashingNamedMD()
536 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestNamedMDs()
554 ToDelete.reserve(M->named_metadata_size() - Names.size()); in TestNamedMDs()
555 for (auto &NamedMD : M->named_metadata()) in TestNamedMDs()
562 NamedMD->eraseFromParent(); in TestNamedMDs()
570 if (TestFn(BD, M)) { in TestNamedMDs()
571 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestNamedMDs()
581 BugDriver &BD; member in __anon8d90c2ef0711::ReduceCrashingNamedMDOps
585 ReduceCrashingNamedMDOps(BugDriver &bd, in ReduceCrashingNamedMDOps() argument
587 : BD(bd), TestFn(testFn) {} in ReduceCrashingNamedMDOps()
618 Module *M = CloneModule(BD.getProgram(), VMap).release(); in TestNamedMDOps()
622 for (auto &NamedMD : BD.getProgram()->named_metadata()) { in TestNamedMDOps()
624 M->eraseNamedMetadata(M->getNamedMetadata(NamedMD.getName())); in TestNamedMDOps()
626 M->getOrInsertNamedMetadata(NamedMD.getName()); in TestNamedMDOps()
629 NewNamedMDNode->addOperand(cast<MDNode>(MapMetadata(op, VMap))); in TestNamedMDOps()
638 if (TestFn(BD, M)) { in TestNamedMDOps()
639 // Make sure to use instruction pointers that point into the now-current in TestNamedMDOps()
645 BD.setNewProgram(M); // It crashed, keep the trimmed version... in TestNamedMDOps()
652 static void ReduceGlobalInitializers(BugDriver &BD, in ReduceGlobalInitializers() argument
655 if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) { in ReduceGlobalInitializers()
658 Module *M = CloneModule(BD.getProgram()).release(); in ReduceGlobalInitializers()
661 for (Module::global_iterator I = M->global_begin(), E = M->global_end(); in ReduceGlobalInitializers()
663 if (I->hasInitializer()) { in ReduceGlobalInitializers()
665 I->setLinkage(GlobalValue::ExternalLinkage); in ReduceGlobalInitializers()
666 I->setComdat(nullptr); in ReduceGlobalInitializers()
676 if (TestFn(BD, M)) { // Still crashes? in ReduceGlobalInitializers()
677 BD.setNewProgram(M); in ReduceGlobalInitializers()
680 outs() << " - Removing all global inits hides problem!\n"; in ReduceGlobalInitializers()
685 for (Module::global_iterator I = BD.getProgram()->global_begin(), in ReduceGlobalInitializers()
686 E = BD.getProgram()->global_end(); I != E; ++I) in ReduceGlobalInitializers()
687 if (I->hasInitializer()) in ReduceGlobalInitializers()
695 ReduceCrashingGlobalVariables(BD, TestFn).reduceList(GVs, Error); in ReduceGlobalInitializers()
699 BD.EmitProgressBitcode(BD.getProgram(), "reduced-global-variables"); in ReduceGlobalInitializers()
706 static void ReduceInsts(BugDriver &BD, in ReduceInsts() argument
713 for (const Function &F : *BD.getProgram()) in ReduceInsts()
719 ReduceCrashingInstructions(BD, TestFn).reduceList(Insts, Error); in ReduceInsts()
726 --Simplification; in ReduceInsts()
741 // Loop over all of the (non-terminator) instructions remaining in the in ReduceInsts()
744 for (Module::const_iterator FI = BD.getProgram()->begin(), in ReduceInsts()
745 E = BD.getProgram()->end(); FI != E; ++FI) in ReduceInsts()
746 if (!FI->isDeclaration()) in ReduceInsts()
747 for (Function::const_iterator BI = FI->begin(), E = FI->end(); BI != E; in ReduceInsts()
749 for (BasicBlock::const_iterator I = BI->begin(), E = --BI->end(); in ReduceInsts()
752 --InstructionsToSkipBeforeDeleting; in ReduceInsts()
757 if (I->isEHPad() || I->getType()->isTokenTy()) in ReduceInsts()
762 BD.deleteInstructionFromProgram(&*I, Simplification); in ReduceInsts()
765 if (TestFn(BD, M.get())) { in ReduceInsts()
768 BD.setNewProgram(M.release()); in ReduceInsts()
770 goto TryAgain; // I wish I had a multi-level break here! in ReduceInsts()
781 BD.EmitProgressBitcode(BD.getProgram(), "reduced-instructions"); in ReduceInsts()
785 /// DebugACrash - Given a predicate that determines whether a component crashes
788 static bool DebugACrash(BugDriver &BD, in DebugACrash() argument
794 ReduceGlobalInitializers(BD, TestFn, Error); in DebugACrash()
798 for (Function &F : *BD.getProgram()) in DebugACrash()
807 ReduceCrashingFunctions(BD, TestFn).reduceList(Functions, Error); in DebugACrash()
810 BD.EmitProgressBitcode(BD.getProgram(), "reduced-function"); in DebugACrash()
820 for (Function &F : *BD.getProgram()) in DebugACrash()
824 ReduceCrashingBlocks(BD, TestFn).reduceList(Blocks, Error); in DebugACrash()
826 BD.EmitProgressBitcode(BD.getProgram(), "reduced-blocks"); in DebugACrash()
832 ReduceInsts(BD, TestFn, Error); in DebugACrash()
840 for (auto &NamedMD : BD.getProgram()->named_metadata()) in DebugACrash()
842 ReduceCrashingNamedMD(BD, TestFn).reduceList(NamedMDNames, Error); in DebugACrash()
849 for (auto &NamedMD : BD.getProgram()->named_metadata()) in DebugACrash()
852 ReduceCrashingNamedMDOps(BD, TestFn).reduceList(NamedMDOps, Error); in DebugACrash()
854 BD.EmitProgressBitcode(BD.getProgram(), "reduced-named-md"); in DebugACrash()
860 Module *M = CloneModule(BD.getProgram()).release(); in DebugACrash()
861 M = BD.performFinalCleanups(M, true).release(); in DebugACrash()
864 if (TestFn(BD, M)) { in DebugACrash()
865 BD.setNewProgram(M); // Yup, it does, keep the reduced version... in DebugACrash()
871 BD.EmitProgressBitcode(BD.getProgram(), "reduced-simplified"); in DebugACrash()
876 static bool TestForOptimizerCrash(const BugDriver &BD, Module *M) { in TestForOptimizerCrash() argument
877 return BD.runPasses(M, BD.getPassesToRun()); in TestForOptimizerCrash()
880 /// debugOptimizerCrash - This method is called when some pass crashes on input.
904 static bool TestForCodeGenCrash(const BugDriver &BD, Module *M) { in TestForCodeGenCrash() argument
906 BD.compileProgram(M, &Error); in TestForCodeGenCrash()
915 /// debugCodeGeneratorCrash - This method is called when the code generator