diff --git a/llvm/tools/bugpoint/CrashDebugger.cpp b/llvm/tools/bugpoint/CrashDebugger.cpp --- a/llvm/tools/bugpoint/CrashDebugger.cpp +++ b/llvm/tools/bugpoint/CrashDebugger.cpp @@ -70,6 +70,18 @@ cl::init(false)); } +static bool isValidModule (std::unique_ptr &M, bool exitOnFailure=true) { + bool isNotValid = llvm::verifyModule(*(M.get()), &llvm::errs()); + if (isNotValid) { + if (exitOnFailure) { + llvm::errs() << "verify failed!\n"; + exit(1); + } + return false; + } + return true; +} + namespace llvm { class ReducePassList : public ListReducer { BugDriver &BD; @@ -368,6 +380,10 @@ if (F->hasFnAttribute(Attribute::OptimizeNone)) F->addFnAttr(Attribute::NoInline); + // If modifying the attribute list leads to invalid IR, revert the change + if (!isValidModule(M, false)) + return false; + // Try running on the hacked up program... if (TestFn(BD, M.get())) { BD.setNewProgram(std::move(M)); // It crashed, keep the trimmed version... @@ -510,14 +526,7 @@ ToProcess.clear(); } // Verify we didn't break anything - std::vector Passes; - Passes.push_back("verify"); - std::unique_ptr New = BD.runPassesOn(M.get(), Passes); - if (!New) { - errs() << "verify failed!\n"; - exit(1); - } - M = std::move(New); + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -618,14 +627,7 @@ ToProcess.clear(); } // Verify we didn't break anything - std::vector Passes; - Passes.push_back("verify"); - std::unique_ptr New = BD.runPassesOn(M.get(), Passes); - if (!New) { - errs() << "verify failed!\n"; - exit(1); - } - M = std::move(New); + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -711,14 +713,7 @@ simplifyCFG(&*BBIt++, TTI); } // Verify we didn't break anything - std::vector Passes; - Passes.push_back("verify"); - std::unique_ptr New = BD.runPassesOn(M.get(), Passes); - if (!New) { - errs() << "verify failed!\n"; - exit(1); - } - M = std::move(New); + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -796,10 +791,8 @@ } } - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + // Verify we didn't break anything + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -868,10 +861,8 @@ } } - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + // Verify we didn't break anything + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -943,10 +934,8 @@ for (auto *NamedMD : ToDelete) NamedMD->eraseFromParent(); - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + // Verify we didn't break anything + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -1008,10 +997,8 @@ NewNamedMDNode->addOperand(cast(MapMetadata(op, VMap))); } - // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + // Verify we didn't break anything + isValidModule(M); // Try running on the hacked up program... if (TestFn(BD, M.get())) {