From c9f63297e24a1b29c2236ac2e2d1afd96b83114e Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 18 May 2020 12:41:36 -0700 Subject: [PATCH] Fix several places that were calling verifyFunction or verifyModule without checking the return value. verifyFunction/verifyModule don't assert or error internally. They also don't print anything if you don't pass a raw_ostream to them. So the caller needs to check the result and ideally pass a stream to get the messages. Otherwise they're just really expensive no-ops. I've filed PR45965 for another instance in SLPVectorizer that causes a lit test failure. Differential Revision: https://reviews.llvm.org/D80106 --- llvm/lib/CodeGen/WinEHPrepare.cpp | 4 ++-- llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp | 3 ++- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 3 ++- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 4 ++-- llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp | 3 ++- llvm/tools/llvm-split/llvm-split.cpp | 6 +++++- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp index bd03984f2079..e8157b1e8c8d 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -1071,10 +1071,10 @@ bool WinEHPrepare::prepareExplicitEH(Function &F) { DemoteCatchSwitchPHIOnlyOpt); if (!DisableCleanups) { - LLVM_DEBUG(verifyFunction(F)); + assert(!verifyFunction(F, &dbgs())); removeImplausibleInstructions(F); - LLVM_DEBUG(verifyFunction(F)); + assert(!verifyFunction(F, &dbgs())); cleanupPreparedFunclets(F); } diff --git a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp index 789f222c8934..6a5192c866cc 100644 --- a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp +++ b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp @@ -1292,7 +1292,8 @@ bool HexagonCommonGEP::runOnFunction(Function &F) { #ifdef EXPENSIVE_CHECKS // Run this only when expensive checks are enabled. - verifyFunction(F); + if (verifyFunction(F, &dbgs())) + report_fatal_error("Broken function"); #endif return true; } diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index e1ac5e92cbd9..520aa9d04d32 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -894,7 +894,8 @@ static void postSplitCleanup(Function &F) { // For now, we do a mandatory verification step because we don't // entirely trust this pass. Note that we don't want to add a verifier // pass to FPM below because it will also verify all the global data. - verifyFunction(F); + if (verifyFunction(F, &errs())) + report_fatal_error("Broken function"); legacy::FunctionPassManager FPM(F.getParent()); diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 247211f36076..1d9d617c93b2 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7669,7 +7669,7 @@ static bool processLoopInVPlanNativePath( // Mark the loop as already vectorized to avoid vectorizing again. Hints.setAlreadyVectorized(); - LLVM_DEBUG(verifyFunction(*L->getHeader()->getParent())); + assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs())); return true; } @@ -7971,7 +7971,7 @@ bool LoopVectorizePass::processLoop(Loop *L) { Hints.setAlreadyVectorized(); } - LLVM_DEBUG(verifyFunction(*L->getHeader()->getParent())); + assert(!verifyFunction(*L->getHeader()->getParent())); return true; } diff --git a/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp b/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp index 81c6e3f1f035..ec3ccbd17363 100644 --- a/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp +++ b/llvm/tools/llvm-as-fuzzer/llvm-as-fuzzer.cpp @@ -70,6 +70,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { if (!M.get()) return 0; - verifyModule(*M.get()); + if (verifyModule(*M.get(), &errs())) + report_fatal_error("Broken module"); return 0; } diff --git a/llvm/tools/llvm-split/llvm-split.cpp b/llvm/tools/llvm-split/llvm-split.cpp index 102188b43bd9..be020c4fcc95 100644 --- a/llvm/tools/llvm-split/llvm-split.cpp +++ b/llvm/tools/llvm-split/llvm-split.cpp @@ -61,7 +61,11 @@ int main(int argc, char **argv) { exit(1); } - verifyModule(*MPart); + if (verifyModule(*MPart, &errs())) { + errs() << "Broken module!\n"; + exit(1); + } + WriteBitcodeToFile(*MPart, Out->os()); // Declare success.