[llvm] ed30a96 - [Verifier] Avoid asserting on invalid cleanuppad chain

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 14 03:10:49 PST 2022


Author: Nikita Popov
Date: 2022-01-14T12:10:41+01:00
New Revision: ed30a968b5d6cb1adc94f246a064eeb71a314120

URL: https://github.com/llvm/llvm-project/commit/ed30a968b5d6cb1adc94f246a064eeb71a314120
DIFF: https://github.com/llvm/llvm-project/commit/ed30a968b5d6cb1adc94f246a064eeb71a314120.diff

LOG: [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.

Added: 
    llvm/test/Verifier/invalid-cleanuppad-chain.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
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<FuncletPadInst>(FromPad) || isa<CatchSwitchInst>(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
+}


        


More information about the llvm-commits mailing list