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 +}