[llvm] [LowerTypeTests] avoid null dereference on invalid branch funnel operand (PR #204951)

Arda Serdar Pektezol via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 20 14:28:21 PDT 2026


https://github.com/pektezol created https://github.com/llvm/llvm-project/pull/204951

On the linked issue, a null dereference happens when looping over` ArrayRef<GlobalTypeMember *> Globals` at `LowerTypeTestsModule::buildBitSetsFromDisjointSet()`. This stems from the external globals in the IR which don't enter GlobalTypeMembers. Following that, operator[] over the DenseMap returns null and it propagates to the looped over GlobalTypeMember.

Prevent the null dereference via `.find()` and reporting fatal usage error if it is not present. Add a negative regression test.

Additionally, the LangRef for the `@llvm.icall.branch.funnel` intrinsic is missing (see #133635). It would also be nice to have a Verifier entry for this intrinsic, and get rid of most report_fatal_error() in this file since it's deprecated.

Fixes #191985

>From 3e12819f1d039013f8fbc35d6effd1da6bce9cc0 Mon Sep 17 00:00:00 2001
From: Arda Serdar Pektezol <arda at pektezol.dev>
Date: Sun, 21 Jun 2026 00:07:42 +0300
Subject: [PATCH] [LowerTypeTests] avoid null dereference on invalid branch
 funnel operand

---
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp      |  6 +++++-
 .../icall-branch-funnel-invalid-operand.ll      | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/Transforms/LowerTypeTests/icall-branch-funnel-invalid-operand.ll

diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 55accff3b148f..80c2ba6299b6f 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2452,7 +2452,11 @@ bool LowerTypeTestsModule::lower() {
           report_fatal_error(
               "Expected branch funnel operand to be global value");
 
-        GlobalTypeMember *GTM = GlobalTypeMembers[Base];
+        auto It = GlobalTypeMembers.find(Base);
+        if (It == GlobalTypeMembers.end())
+            reportFatalUsageError(
+                "Expected branch funnel operand to be global value");
+        GlobalTypeMember *GTM = It->second;
         Targets.push_back(GTM);
         GlobalClassesTy::member_iterator NewSet =
             GlobalClasses.findLeader(GlobalClasses.insert(GTM));
diff --git a/llvm/test/Transforms/LowerTypeTests/icall-branch-funnel-invalid-operand.ll b/llvm/test/Transforms/LowerTypeTests/icall-branch-funnel-invalid-operand.ll
new file mode 100644
index 0000000000000..aa39dd43fd670
--- /dev/null
+++ b/llvm/test/Transforms/LowerTypeTests/icall-branch-funnel-invalid-operand.ll
@@ -0,0 +1,17 @@
+; RUN: not opt -S -passes=lowertypetests %s 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: Expected branch funnel operand to be global value
+
+target triple = "x86_64--"
+
+ at g1 = external constant i32
+ at g2 = external constant i32
+
+define void @jt2(...) {
+  musttail call void (...) @llvm.icall.branch.funnel(ptr null, ptr @g1, ptr null, ptr @g2, ptr null, ...)
+  ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind willreturn
+declare void @llvm.icall.branch.funnel(...) #0
+
+attributes #0 = { nocallback nofree nosync nounwind willreturn }



More information about the llvm-commits mailing list