[Mlir-commits] [mlir] [mlir][LLVM] Fix verifier crash for llvm.blockaddress with missing function (PR #181519)
Ayush Kumar Gaur
llvmlistbot at llvm.org
Sat Feb 14 17:14:42 PST 2026
https://github.com/Ayush3941 created https://github.com/llvm/llvm-project/pull/181519
### Whats the Problem
Fix verifier crash in `llvm.blockaddress` when the referenced function symbol is missing by guarding null before `dyn_cast`.
Adds regression test using `-verify-diagnostics` to ensure invalid IR emits an error instead of aborting.
### Why it happened
`SymbolTable::lookupNearestSymbolFrom` may return null, and `dyn_cast` on a non-existent value triggers an assertion in `mlir-opt`.
Invalid IR must never crash the compiler — it should produce a proper verifier diagnostic.
### Whats the Fix
Split symbol lookup returning early if lookup fails or symbol is not an `LLVMFuncOp`.
Verifier now reports “expects an existing block label target” instead of hitting `dyn_cast` assert.
>From c703f9a029c536814e4bb9cf1c45c558e9797b45 Mon Sep 17 00:00:00 2001
From: Ayush3941 <ayushkgaur1 at gmail.com>
Date: Sat, 14 Feb 2026 20:10:26 -0500
Subject: [PATCH] [mlir][LLVM] Fix verifier crash for llvm.blockaddress with
missing function symbol
---
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 8 ++++----
mlir/test/Dialect/LLVMIR/invalid.mlir | 7 +++++++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 4c67720654f83..a86777dd602b8 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -4151,11 +4151,11 @@ LLVMFuncOp BlockAddressOp::getFunction(SymbolTableCollection &symbolTable) {
}
BlockTagOp BlockAddressOp::getBlockTagOp() {
- auto funcOp = dyn_cast<LLVMFuncOp>(mlir::SymbolTable::lookupNearestSymbolFrom(
- parentLLVMModule(*this), getBlockAddr().getFunction()));
- if (!funcOp)
+ Operation *sym = mlir::SymbolTable::lookupNearestSymbolFrom(
+ parentLLVMModule(*this), getBlockAddr().getFunction());
+ if (!sym)
return nullptr;
-
+ auto funcOp = dyn_cast<LLVMFuncOp>(sym);
BlockTagOp blockTagOp = nullptr;
funcOp.walk([&](LLVM::BlockTagOp labelOp) {
if (labelOp.getTag() == getBlockAddr().getTag()) {
diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 49b6342aea538..b736cde7689ed 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -2065,3 +2065,10 @@ llvm.func @invalid_sincos_gt_2_element_struct_return_type(%f: f32) -> () {
// expected-error at +1 {{op expected result type to be an homogeneous struct with two elements matching the operand type}}
llvm.intr.sincos(%f) : (f32) -> !llvm.struct<(f32, f32, f32)>
}
+
+// -----
+
+module {
+ // expected-error at +1 {{'llvm.blockaddress' op expects an existing block label target in the referenced function}}
+ %0 = llvm.blockaddress <function = @missing_func, tag = <id = 1>> : !llvm.ptr
+}
More information about the Mlir-commits
mailing list