[Mlir-commits] [mlir] [mlir][LLVM] Fix verifier crash for llvm.blockaddress with missing function (PR #181519)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Feb 14 17:15:16 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Ayush Kumar Gaur (Ayush3941)
<details>
<summary>Changes</summary>
### 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.
---
Full diff: https://github.com/llvm/llvm-project/pull/181519.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp (+4-4)
- (modified) mlir/test/Dialect/LLVMIR/invalid.mlir (+7)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/181519
More information about the Mlir-commits
mailing list