[MLIR][DataFlow] Fix two crashes in DeadCodeAnalysis on empty/no-terminator regions#188548
Conversation
…inator regions Two related assertion failures in DeadCodeAnalysis when processing OpenACC operations: 1. visitRegionBranchEdges (issue llvm#187972): When a RegionSuccessor refers to an empty region (no blocks), calling getSuccessor()->front() dereferences a sentinel ilist iterator, crashing with "\!NodePtr->isKnownSentinel()". Fix: skip successors whose region is empty. 2. isRegionOrCallableReturn (issue llvm#188408): When iterating over ops in a nested acc region whose blocks do not have a required terminator, Block::getTerminator() is called without first checking mightHaveTerminator(), triggering "Assertion `mightHaveTerminator()' failed". Fix: guard the getTerminator() call with mightHaveTerminator(). Fixes llvm#187972, llvm#188408 Assisted-by: Claude Code
|
@llvm/pr-subscribers-mlir Author: Mehdi Amini (joker-eph) ChangesTwo related assertion failures in DeadCodeAnalysis when processing OpenACC operations:
Fixes #187972, #188408 Assisted-by: Claude Code Full diff: https://github.com/llvm/llvm-project/pull/188548.diff 2 Files Affected:
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 936b0c678f20c..38811d06ecd8c 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -249,6 +249,7 @@ void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
static bool isRegionOrCallableReturn(Operation *op) {
return op->getBlock() != nullptr && !op->getNumSuccessors() &&
isa<RegionBranchOpInterface, CallableOpInterface>(op->getParentOp()) &&
+ op->getBlock()->mightHaveTerminator() &&
op->getBlock()->getTerminator() == op;
}
@@ -521,6 +522,9 @@ void DeadCodeAnalysis::visitRegionBranchEdges(
const SmallVector<RegionSuccessor> &successors) {
for (const RegionSuccessor &successor : successors) {
// The successor can be either an entry block or the parent operation.
+ // Skip empty regions — they have no entry block to mark executable.
+ if (!successor.isParent() && successor.getSuccessor()->empty())
+ continue;
ProgramPoint *point =
successor.isParent()
? getProgramPointAfter(regionBranchOp)
diff --git a/mlir/test/Transforms/sccp.mlir b/mlir/test/Transforms/sccp.mlir
index c78c8594c0ba5..138acbb42d1a9 100644
--- a/mlir/test/Transforms/sccp.mlir
+++ b/mlir/test/Transforms/sccp.mlir
@@ -255,3 +255,34 @@ func.func @no_crash_with_different_source_type() {
%1 = vector.broadcast %0 : i64 to vector<128xi64>
llvm.return
}
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/187972
+// DeadCodeAnalysis::visitRegionBranchEdges must not dereference the front()
+// of an empty region (acc.serial with no blocks).
+
+// CHECK-LABEL: no_crash_acc_serial_empty_region
+func.func @no_crash_acc_serial_empty_region() {
+ // CHECK: acc.serial
+ acc.serial {
+ }
+ return
+}
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/188408
+// isRegionOrCallableReturn must guard getTerminator() with mightHaveTerminator()
+// to avoid asserting on blocks in nested acc regions without terminators.
+
+// CHECK-LABEL: no_crash_acc_kernel_environment
+func.func @no_crash_acc_kernel_environment(%data: memref<8xi32>) {
+ // CHECK: acc.kernel_environment
+ acc.kernel_environment {
+ acc.compute_region {
+ acc.yield
+ } {origin = "acc.parallel"}
+ }
+ return
+}
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/41367 Here is the relevant piece of the build log for the reference |
…inator regions (llvm#188548) Two related assertion failures in DeadCodeAnalysis when processing OpenACC operations: 1. visitRegionBranchEdges (issue llvm#187972): When a RegionSuccessor refers to an empty region (no blocks), calling getSuccessor()->front() dereferences a sentinel ilist iterator, crashing with "\!NodePtr->isKnownSentinel()". Fix: skip successors whose region is empty. 2. isRegionOrCallableReturn (issue llvm#188408): When iterating over ops in a nested acc region whose blocks do not have a required terminator, Block::getTerminator() is called without first checking mightHaveTerminator(), triggering "Assertion `mightHaveTerminator()' failed". Fix: guard the getTerminator() call with mightHaveTerminator(). Fixes llvm#187972, llvm#188408 Assisted-by: Claude Code
Two related assertion failures in DeadCodeAnalysis when processing OpenACC operations:
visitRegionBranchEdges (issue [MLIR] Assertion !NodePtr->isKnownSentinel() in DeadCodeAnalysis::visitRegionBranchEdges when processing acc.serial with empty region #187972): When a RegionSuccessor refers to an empty region (no blocks), calling getSuccessor()->front() dereferences a sentinel ilist iterator, crashing with "!NodePtr->isKnownSentinel()". Fix: skip successors whose region is empty.
isRegionOrCallableReturn (issue [MLIR][SCCP][OpenACC] Assertion mightHaveTerminator() in Block::getTerminator when DeadCodeAnalysis::initializeRecursively walks into acc.kernel_environment containing acc.compute_region #188408): When iterating over ops in a nested acc region whose blocks do not have a required terminator, Block::getTerminator() is called without first checking mightHaveTerminator(), triggering "Assertion `mightHaveTerminator()' failed". Fix: guard the getTerminator() call with mightHaveTerminator().
Fixes #187972, #188408
Assisted-by: Claude Code