Index: tools/bugpoint/CrashDebugger.cpp =================================================================== --- tools/bugpoint/CrashDebugger.cpp +++ tools/bugpoint/CrashDebugger.cpp @@ -726,13 +726,9 @@ } } - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); - - // Try running on the hacked up program... - if (TestFn(BD, M.get())) { + // Verify that the Module is still valid and then + // try running on the hacked up program... + if (!verifyModule(*M, &llvm::outs()) && TestFn(BD, M.get())) { BD.setNewProgram(std::move(M)); // It crashed, keep the trimmed version... // Make sure to use instruction pointers that point into the now-current @@ -742,7 +738,8 @@ Insts.push_back(Inst); return true; } - // It didn't crash, try something else. + + // It didn't crash (or the hacked up module was invalid), try something else. return false; } @@ -801,13 +798,8 @@ for (auto *NamedMD : ToDelete) NamedMD->eraseFromParent(); - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); - // Try running on the hacked up program... - if (TestFn(BD, M.get())) { + if (!verifyModule(*M, &llvm::outs()) && TestFn(BD, M.get())) { BD.setNewProgram(std::move(M)); // It crashed, keep the trimmed version... return true; } @@ -866,13 +858,8 @@ NewNamedMDNode->addOperand(cast(MapMetadata(op, VMap))); } - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); - // Try running on the hacked up program... - if (TestFn(BD, M.get())) { + if (!verifyModule(*M, &llvm::outs()) && TestFn(BD, M.get())) { // Make sure to use instruction pointers that point into the now-current // module, and that they don't include any deleted blocks. NamedMDOps.clear(); @@ -1006,7 +993,7 @@ BD.deleteInstructionFromProgram(&*I, Simplification); // Find out if the pass still crashes on this pass... - if (TestFn(BD, M.get())) { + if (M && TestFn(BD, M.get())) { // Yup, it does, we delete the old module, and continue trying // to reduce the testcase... BD.setNewProgram(std::move(M)); Index: tools/bugpoint/ExtractFunction.cpp =================================================================== --- tools/bugpoint/ExtractFunction.cpp +++ tools/bugpoint/ExtractFunction.cpp @@ -108,6 +108,10 @@ // Remove the instruction from the program. TheInst->getParent()->getInstList().erase(TheInst); + // Verify that removing this instruction didn't cause a verifier error + if (verifyModule(*Clone, &llvm::outs())) + return nullptr; + // Spiff up the output a little bit. std::vector Passes;