[llvm] 182ca95 - [Verifier] Don't look up the funclet color of an unreachable block (#222500)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 19:07:08 PDT 2026


Author: Timur Baidusenov
Date: 2026-09-15T19:07:03-07:00
New Revision: 182ca95eed3feb7c7ba83ed2b35a0c5f29517b9b

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

LOG: [Verifier] Don't look up the funclet color of an unreachable block (#222500)

Fixes #192015.

Added: 
    llvm/test/Verifier/funclet-unreachable-block.ll

Modified: 
    llvm/lib/IR/Verifier.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index bb5466219f461..4c42d512c5513 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -7308,26 +7308,32 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
       if (BlockEHFuncletColors.empty())
         BlockEHFuncletColors = colorEHFunclets(*F);
 
-      // Check for catch-/cleanup-pad in first funclet block
-      bool InEHFunclet = false;
+      // colorEHFunclets() leaves unreachable blocks colorless. Such a call
+      // is in no funclet and WinEHPrepare will not see it, so there is
+      // nothing to check.
       BasicBlock *CallBB = Call.getParent();
-      const ColorVector &CV = BlockEHFuncletColors.find(CallBB)->second;
-      assert(CV.size() > 0 && "Uncolored block");
-      for (BasicBlock *ColorFirstBB : CV)
-        if (auto It = ColorFirstBB->getFirstNonPHIIt();
-            It != ColorFirstBB->end())
-          if (isa_and_nonnull<FuncletPadInst>(&*It))
-            InEHFunclet = true;
-
-      // Check for funclet operand bundle
-      bool HasToken = false;
-      for (unsigned I = 0, E = Call.getNumOperandBundles(); I != E; ++I)
-        if (Call.getOperandBundleAt(I).getTagID() == LLVMContext::OB_funclet)
-          HasToken = true;
-
-      // This would cause silent code truncation in WinEHPrepare
-      if (InEHFunclet)
-        Check(HasToken, "Missing funclet token on intrinsic call", &Call);
+      auto ColorsIt = BlockEHFuncletColors.find(CallBB);
+      if (ColorsIt != BlockEHFuncletColors.end()) {
+        // Check for catch-/cleanup-pad in first funclet block
+        bool InEHFunclet = false;
+        const ColorVector &CV = ColorsIt->second;
+        assert(CV.size() > 0 && "Uncolored block");
+        for (BasicBlock *ColorFirstBB : CV)
+          if (auto It = ColorFirstBB->getFirstNonPHIIt();
+              It != ColorFirstBB->end())
+            if (isa_and_nonnull<FuncletPadInst>(&*It))
+              InEHFunclet = true;
+
+        // Check for funclet operand bundle
+        bool HasToken = false;
+        for (unsigned I = 0, E = Call.getNumOperandBundles(); I != E; ++I)
+          if (Call.getOperandBundleAt(I).getTagID() == LLVMContext::OB_funclet)
+            HasToken = true;
+
+        // This would cause silent code truncation in WinEHPrepare
+        if (InEHFunclet)
+          Check(HasToken, "Missing funclet token on intrinsic call", &Call);
+      }
     }
   }
 

diff  --git a/llvm/test/Verifier/funclet-unreachable-block.ll b/llvm/test/Verifier/funclet-unreachable-block.ll
new file mode 100644
index 0000000000000..4ecc8902a9a30
--- /dev/null
+++ b/llvm/test/Verifier/funclet-unreachable-block.ll
@@ -0,0 +1,17 @@
+; RUN: llvm-as -disable-output %s
+
+; colorEHFunclets() leaves unreachable blocks colorless, so there is no funclet
+; color to look up for a call in one. The verifier must not crash on that.
+
+declare i32 @__CxxFrameHandler3(...)
+declare ptr @llvm.objc.retain(ptr returned) nounwind
+
+define void @f(ptr %p) personality ptr @__CxxFrameHandler3 {
+entry:
+  ret void
+
+unreachable.funclet:                              ; No predecessors!
+  %pad = cleanuppad within none []
+  %call = call ptr @llvm.objc.retain(ptr %p) [ "funclet"(token %pad) ]
+  cleanupret from %pad unwind to caller
+}


        


More information about the llvm-commits mailing list