[Mlir-commits] [mlir] [MLIR][SymbolTable] Fix crash in SymbolUserMap on unregistered-dialect (PR #226630)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 25 20:12:30 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Vinicius Silva (viniciusfdasilva)
<details>
<summary>Changes</summary>
## Summary
Fixes #<!-- -->226052
`SymbolUserMap::SymbolUserMap` asserted that `SymbolTable::getSymbolUses()`
always succeeds:
```cpp
auto symbolUses = SymbolTable::getSymbolUses(&nestedOp);
assert(symbolUses && "expected uses to be valid");
```
However, `getSymbolUses()` legitimately returns `std::nullopt` when it
encounters an operation from an **unregistered dialect**, since its symbol
uses cannot be statically analyzed (this is documented behavior of
`getSymbolUses`, not an error condition). As a result, `mlir-opt` aborted
instead of running passes such as `remove-dead-values` on IR containing
unregistered-dialect ops, even though `--allow-unregistered-dialect` is a
supported mode and `remove-dead-values` is part of the default pipeline.
### Reproducer (from #<!-- -->226052)
```mlir
func.func @<!-- -->bbarg_of_unknown_op_2(%f: f32) {
%0 = tensor.empty() : tensor<10xf32>
%1 = linalg.fill ins(%f : f32) outs(%0 : tensor<10xf32>) -> tensor<10xf32>
"dummy.dummy_op"(%1) ({
}) : (tensor<10xf32>) -> ()
}
```
Note: This PR message was AI-generated and reviewed before the PR was opened.
---
Full diff: https://github.com/llvm/llvm-project/pull/226630.diff
1 Files Affected:
- (modified) mlir/lib/IR/SymbolTable.cpp (+7-2)
``````````diff
diff --git a/mlir/lib/IR/SymbolTable.cpp b/mlir/lib/IR/SymbolTable.cpp
index b0288185ae0ab..bbca03fa410d3 100644
--- a/mlir/lib/IR/SymbolTable.cpp
+++ b/mlir/lib/IR/SymbolTable.cpp
@@ -1055,7 +1055,12 @@ SymbolUserMap::SymbolUserMap(SymbolTableCollection &symbolTable,
auto walkFn = [&](Operation *symbolTableOp, bool allUsesVisible) {
for (Operation &nestedOp : symbolTableOp->getRegion(0).getOps()) {
auto symbolUses = SymbolTable::getSymbolUses(&nestedOp);
- assert(symbolUses && "expected uses to be valid");
+ if (!symbolUses) {
+ for (Operation &maybeSymbol : symbolTableOp->getRegion(0).getOps())
+ if (getNameIfSymbol(&maybeSymbol))
+ symbolToUsers[&maybeSymbol].insert(&nestedOp);
+ continue;
+ }
for (const SymbolTable::SymbolUse &use : *symbolUses) {
symbols.clear();
@@ -1122,4 +1127,4 @@ ParseResult impl::parseOptionalVisibilityKeyword(OpAsmParser &parser,
/// Include the generated symbol interfaces.
#include "mlir/IR/SymbolInterfaces.cpp.inc"
-#include "mlir/IR/SymbolInterfacesAttrInterface.cpp.inc"
+#include "mlir/IR/SymbolInterfacesAttrInterface.cpp.inc"
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/226630
More information about the Mlir-commits
mailing list