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) { + if (!llvm::verifyModule(*M.get(), &llvm::errs())) + return true; + + if (ExitOnFailure) { + llvm::errs() << "verify failed!\n"; + exit(1); + } + return false; +} + 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, /*ExitOnFailure=*/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())) { @@ -797,9 +792,7 @@ } // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + isValidModule(M, /*ExitOnFailure=*/false); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -869,9 +862,7 @@ } // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + isValidModule(M, /*ExitOnFailure=*/false); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -944,9 +935,7 @@ NamedMD->eraseFromParent(); // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + isValidModule(M, /*ExitOnFailure=*/false); // Try running on the hacked up program... if (TestFn(BD, M.get())) { @@ -1009,9 +998,7 @@ } // Verify that this is still valid. - legacy::PassManager Passes; - Passes.add(createVerifierPass(/*FatalErrors=*/false)); - Passes.run(*M); + isValidModule(M, /*ExitOnFailure=*/false); // Try running on the hacked up program... if (TestFn(BD, M.get())) {