[Mlir-commits] [mlir] [mlir] Fix assert in TestWrittenToPass for unreachable private functions (PR #186162)
Mehdi Amini
llvmlistbot at llvm.org
Thu Mar 12 09:04:44 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/186162
TestSparseBackwardDataFlowAnalysis::TestWrittenToPass asserted that the WrittenTo sparse lattice was always computed for tagged operands and results. This assertion fires when analyzing a private function that is never called from anywhere: in interprocedural mode the backward data flow solver does not visit such dead code, leaving the lattice state uninitialized.
Replace the assertions with null checks that print "<not computed>" instead, matching the approach used in TestDenseForwardDataFlowAnalysis for the analogous dense forward case.
Fixes #128339
Assisted-by: Claude Code
>From d63543f2aee62834e8d92ee3cf5fb27e905bcdc9 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Fri, 6 Mar 2026 08:45:33 -0800
Subject: [PATCH] [mlir] Fix assert in TestWrittenToPass for unreachable
private functions
TestSparseBackwardDataFlowAnalysis::TestWrittenToPass asserted that
the WrittenTo sparse lattice was always computed for tagged operands
and results. This assertion fires when analyzing a private function
that is never called from anywhere: in interprocedural mode the
backward data flow solver does not visit such dead code, leaving the
lattice state uninitialized.
Replace the assertions with null checks that print "<not computed>"
instead, matching the approach used in TestDenseForwardDataFlowAnalysis
for the analogous dense forward case.
Fixes #128339
Assisted-by: Claude Code
---
mlir/test/Analysis/DataFlow/test-written-to.mlir | 15 +++++++++++++++
.../TestSparseBackwardDataFlowAnalysis.cpp | 13 +++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/mlir/test/Analysis/DataFlow/test-written-to.mlir b/mlir/test/Analysis/DataFlow/test-written-to.mlir
index 4fc9af164d48e..8d951f4819985 100644
--- a/mlir/test/Analysis/DataFlow/test-written-to.mlir
+++ b/mlir/test/Analysis/DataFlow/test-written-to.mlir
@@ -364,3 +364,18 @@ func.func @test_external_callee(%arg0: i32, %m0: memref<i32>) {
memref.store %1, %m0[] {tag_name = "a"} : memref<i32>
return
}
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/128339
+// A private function that is never called should not crash the analysis —
+// its lattice state is simply not computed.
+
+// CHECK-LABEL: test_tag: in_private2
+// CHECK-NEXT: operand #0: <not computed>
+// CHECK-NEXT: result #0: <not computed>
+
+func.func private @private2(%arg0: i32) {
+ %0 = arith.index_cast %arg0 {tag = "in_private2"} : i32 to index
+ return
+}
diff --git a/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
index 86d4b972de953..4f19cc7144afc 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestSparseBackwardDataFlowAnalysis.cpp
@@ -198,14 +198,23 @@ struct TestWrittenToPass
os << "test_tag: " << tag.getValue() << ":\n";
for (auto [index, operand] : llvm::enumerate(op->getOperands())) {
const WrittenTo *writtenTo = solver.lookupState<WrittenTo>(operand);
- assert(writtenTo && "expected a sparse lattice");
+ if (!writtenTo) {
+ // The lattice may not be computed for values in unreachable code
+ // (e.g., private functions not called from anywhere in
+ // interprocedural analysis mode).
+ os << " operand #" << index << ": <not computed>\n";
+ continue;
+ }
os << " operand #" << index << ": ";
writtenTo->print(os);
os << "\n";
}
for (auto [index, operand] : llvm::enumerate(op->getResults())) {
const WrittenTo *writtenTo = solver.lookupState<WrittenTo>(operand);
- assert(writtenTo && "expected a sparse lattice");
+ if (!writtenTo) {
+ os << " result #" << index << ": <not computed>\n";
+ continue;
+ }
os << " result #" << index << ": ";
writtenTo->print(os);
os << "\n";
More information about the Mlir-commits
mailing list