[Mlir-commits] [mlir] [mlir][DataFlow] Fix crash in TestLastModifiedPass for unreachable private functions (PR #186160)
Mehdi Amini
llvmlistbot at llvm.org
Thu Mar 12 09:00:05 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/186160
TestLastModifiedPass asserted that a dense lattice state is always present after running the data flow solver. However, in interprocedural analysis mode (the default), private functions that are never called from any callee in the module are not analyzed, so no lattice state is computed for their program points.
Replace the assertion with a null check that prints "<not computed>" when the lattice state is absent. This matches the expected behavior: unreachable code in interprocedural mode simply has no computed analysis result.
Add a regression test for the case where a tagged op is inside an unreachable private function.
Fixes #128333
Assisted-by: Claude Code
>From 5bfcd5ab836585e7a5b92f93b7310f8c76fd8fb1 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Fri, 6 Mar 2026 07:16:20 -0800
Subject: [PATCH] [mlir][DataFlow] Fix crash in TestLastModifiedPass for
unreachable private functions
TestLastModifiedPass asserted that a dense lattice state is always present after
running the data flow solver. However, in interprocedural analysis mode (the
default), private functions that are never called from any callee in the module
are not analyzed, so no lattice state is computed for their program points.
Replace the assertion with a null check that prints "<not computed>" when the
lattice state is absent. This matches the expected behavior: unreachable code
in interprocedural mode simply has no computed analysis result.
Add a regression test for the case where a tagged op is inside an unreachable
private function.
Fixes #128333
Assisted-by: Claude Code
---
mlir/test/Analysis/DataFlow/test-last-modified.mlir | 11 +++++++++++
.../DataFlow/TestDenseForwardDataFlowAnalysis.cpp | 8 +++++++-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/mlir/test/Analysis/DataFlow/test-last-modified.mlir b/mlir/test/Analysis/DataFlow/test-last-modified.mlir
index 43326614d6793..da22fdbf56e84 100644
--- a/mlir/test/Analysis/DataFlow/test-last-modified.mlir
+++ b/mlir/test/Analysis/DataFlow/test-last-modified.mlir
@@ -348,3 +348,14 @@ func.func @store_with_a_loop_region_after_containing_a_store(%arg0: memref<f32>)
memref.store %1, %arg0[] {tag_name = "post"} : memref<f32>
return {tag = "return"} %arg0 : memref<f32>
}
+
+// Regression test for https://github.com/llvm/llvm-project/issues/128333:
+// In interprocedural analysis mode, private functions that are never called
+// should not cause an assertion failure when querying the dense lattice.
+// Instead, the pass should gracefully report "<not computed>".
+// CHECK-LABEL: test_tag: tag_in_unreachable_private
+// CHECK-NEXT: - <not computed>
+func.func private @unreachable_private(%arg0: i32) {
+ %cond = arith.index_cast %arg0 {tag = "tag_in_unreachable_private"} : i32 to index
+ return
+}
diff --git a/mlir/test/lib/Analysis/DataFlow/TestDenseForwardDataFlowAnalysis.cpp b/mlir/test/lib/Analysis/DataFlow/TestDenseForwardDataFlowAnalysis.cpp
index a88ed7f8dea8b..9236e98168883 100644
--- a/mlir/test/lib/Analysis/DataFlow/TestDenseForwardDataFlowAnalysis.cpp
+++ b/mlir/test/lib/Analysis/DataFlow/TestDenseForwardDataFlowAnalysis.cpp
@@ -256,7 +256,13 @@ struct TestLastModifiedPass
os << "test_tag: " << tag.getValue() << ":\n";
const LastModification *lastMods =
solver.lookupState<LastModification>(solver.getProgramPointAfter(op));
- assert(lastMods && "expected a dense lattice");
+ if (!lastMods) {
+ // The lattice may not be computed for operations in unreachable code
+ // (e.g., private functions not called from anywhere in interprocedural
+ // analysis mode).
+ os << " - <not computed>\n";
+ return;
+ }
for (auto [index, operand] : llvm::enumerate(op->getOperands())) {
os << " operand #" << index << "\n";
std::optional<Value> underlyingValue =
More information about the Mlir-commits
mailing list