From ed30a968b5d6cb1adc94f246a064eeb71a314120 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 14 Jan 2022 12:08:33 +0100 Subject: [PATCH] [Verifier] Avoid asserting on invalid cleanuppad chain The invalid undef value already triggers a verifier failure, but then the upwards scan from the cleanuppad ends up asserting. Make sure this is handled gacefully instead. --- llvm/lib/IR/Verifier.cpp | 5 +++++ llvm/test/Verifier/invalid-cleanuppad-chain.ll | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 llvm/test/Verifier/invalid-cleanuppad-chain.ll diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index fecbfc7a3ab7..cb689e14e6f0 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3999,6 +3999,11 @@ void Verifier::visitEHPadPredecessors(Instruction &I) { "A single unwind edge may only enter one EH pad", TI); Assert(Seen.insert(FromPad).second, "EH pad jumps through a cycle of pads", FromPad); + + // This will be diagnosed on the corresponding instruction already. We + // need the extra check here to make sure getParentPad() works. + Assert(isa(FromPad) || isa(FromPad), + "Parent pad must be catchpad/cleanuppad/catchswitch", TI); } } } diff --git a/llvm/test/Verifier/invalid-cleanuppad-chain.ll b/llvm/test/Verifier/invalid-cleanuppad-chain.ll new file mode 100644 index 000000000000..4523ce89da4f --- /dev/null +++ b/llvm/test/Verifier/invalid-cleanuppad-chain.ll @@ -0,0 +1,18 @@ +; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s + +; CHECK: CleanupReturnInst needs to be provided a CleanupPad +; CHECK-NEXT: cleanupret from undef unwind label %bb2 +; CHECK-NEXT: token undef +; CHECK: Parent pad must be catchpad/cleanuppad/catchswitch +; CHECK-NEXT: cleanupret from undef unwind label %bb2 + +define void @test() personality i32 (...)* undef { + br label %bb1 + +bb1: + cleanupret from undef unwind label %bb2 + +bb2: + %pad = cleanuppad within none [] + cleanupret from %pad unwind to caller +}