[Mlir-commits] [mlir] [mlir] Fix crash in TestSymbolUses when erasing functions from nested modules (PR #186161)
Mehdi Amini
llvmlistbot at llvm.org
Thu Mar 12 09:00:45 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/186161
SymbolUsesPass collected dead functions via a recursive walk, then tried to erase them using a SymbolTable constructed from the top-level module. When a dead function was nested inside an inner module, the outer module's symbol table did not contain it, causing the assertion "expected no unknown operations" to fail.
Fix by constructing the SymbolTable from the nearest symbol table parent of each dead function instead of from the top-level module, so the lookup and erase operate on the correct scope.
Fixes #60583
Assisted-by: Claude Code
>From 11c3f59d6d6d51f4a164418a35e4c38194897beb Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Fri, 6 Mar 2026 07:24:23 -0800
Subject: [PATCH] [mlir] Fix crash in TestSymbolUses when erasing functions
from nested modules
SymbolUsesPass collected dead functions via a recursive walk, then tried to
erase them using a SymbolTable constructed from the top-level module. When
a dead function was nested inside an inner module, the outer module's symbol
table did not contain it, causing the assertion "expected no unknown
operations" to fail.
Fix by constructing the SymbolTable from the nearest symbol table parent of
each dead function instead of from the top-level module, so the lookup and
erase operate on the correct scope.
Fixes #60583
Assisted-by: Claude Code
---
mlir/test/IR/test-symbol-uses.mlir | 15 +++++++++++++++
mlir/test/lib/IR/TestSymbolUses.cpp | 8 ++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/mlir/test/IR/test-symbol-uses.mlir b/mlir/test/IR/test-symbol-uses.mlir
index d9d839e9fc307..96eb40107e8e2 100644
--- a/mlir/test/IR/test-symbol-uses.mlir
+++ b/mlir/test/IR/test-symbol-uses.mlir
@@ -93,3 +93,18 @@ module {
return
}
}
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/60583:
+// Erasing a dead private function nested inside an inner module must not
+// crash. Previously, SymbolTable was constructed from the outer module and
+// lookup of the inner function asserted because it was in the inner module's
+// symbol table instead.
+// expected-remark at below {{printMemrefF32 function successfully erased}}
+module {
+ module {
+ // expected-remark at below {{symbol has no uses}}
+ func.func private @printMemrefF32(%ptr : memref<*xf32>)
+ }
+}
diff --git a/mlir/test/lib/IR/TestSymbolUses.cpp b/mlir/test/lib/IR/TestSymbolUses.cpp
index 24f7d8505bebd..7d2bdf1b12a9d 100644
--- a/mlir/test/lib/IR/TestSymbolUses.cpp
+++ b/mlir/test/lib/IR/TestSymbolUses.cpp
@@ -79,11 +79,15 @@ struct SymbolUsesPass
return operateOnSymbol(nestedOp, module, deadFunctions);
});
- SymbolTable table(module);
for (Operation *op : deadFunctions) {
// In order to test the SymbolTable::erase method, also erase completely
- // useless functions.
+ // useless functions. Use the nearest symbol table parent of the function
+ // to handle the case where it is nested inside another symbol table.
auto name = SymbolTable::getSymbolName(op);
+ Operation *symbolTableOp =
+ SymbolTable::getNearestSymbolTable(op->getParentOp());
+ assert(symbolTableOp && "expected a parent symbol table");
+ SymbolTable table(symbolTableOp);
assert(table.lookup(name) && "expected no unknown operations");
table.erase(op);
assert(!table.lookup(name) &&
More information about the Mlir-commits
mailing list