Skip to content

[mlir] Fix crash in testNoSkipErasureCallbacks on empty blocks - #183757

Merged
joker-eph merged 1 commit into
llvm:mainfrom
joker-eph:fix/issue-183511
Feb 28, 2026
Merged

joker-eph merged 1 commit into
llvm:mainfrom
joker-eph:fix/issue-183511

Conversation

@joker-eph

Copy link
Copy Markdown
Contributor

The noSkipBlockErasure callback in testNoSkipErasureCallbacks called block->front().getParentRegion() to get the parent region of a block. This dereferences the ilist sentinel node when the block has no operations, triggering an assertion failure.

Use block->getParent() instead, which directly returns the region containing the block without requiring any operations to be present.

Fixes #183511

@llvmbot

llvmbot commented Feb 27, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-mlir

Author: Mehdi Amini (joker-eph)

Changes

The noSkipBlockErasure callback in testNoSkipErasureCallbacks called block->front().getParentRegion() to get the parent region of a block. This dereferences the ilist sentinel node when the block has no operations, triggering an assertion failure.

Use block->getParent() instead, which directly returns the region containing the block without requiring any operations to be present.

Fixes #183511


Full diff: https://github.com/llvm/llvm-project/pull/183757.diff

2 Files Affected:

  • (modified) mlir/test/IR/visitors.mlir (+11-1)
  • (modified) mlir/test/lib/IR/TestVisitors.cpp (+1-1)
diff --git a/mlir/test/IR/visitors.mlir b/mlir/test/IR/visitors.mlir
index 0e6ac879f5b94..03eff9106981e 100644
--- a/mlir/test/IR/visitors.mlir
+++ b/mlir/test/IR/visitors.mlir
@@ -385,7 +385,7 @@ func.func @unordered_cfg_with_loop() {
 
 // -----
 
-// The following test should not crash while visiting the intra-op blocks (inside the top level 
+// The following test should not crash while visiting the intra-op blocks (inside the top level
 // function in this case). We are testing that the intra-block ops are erased after dropping their
 // uses from ops with same parent region.
 // CHECK-LABEL: func.func @test_no_skip_block_erasure
@@ -399,3 +399,13 @@ func.func @test_no_skip_block_erasure() {
 ^bb4:
   return
 }
+
+// -----
+
+// Regression test for https://github.com/llvm/llvm-project/issues/183511:
+// testNoSkipErasureCallbacks should not crash when visiting an empty block.
+// The module body block has no ops, so block->front() would previously dereference
+// the ilist sentinel, causing an assertion failure.
+module {}
+// CHECK-LABEL: Block post-order erasures (no skip)
+// CHECK-NEXT:  Erasing block ^bb0 from region 0 from operation 'builtin.module'
diff --git a/mlir/test/lib/IR/TestVisitors.cpp b/mlir/test/lib/IR/TestVisitors.cpp
index 2667001ee10a7..e88d43bf86ffc 100644
--- a/mlir/test/lib/IR/TestVisitors.cpp
+++ b/mlir/test/lib/IR/TestVisitors.cpp
@@ -192,7 +192,7 @@ static void testNoSkipErasureCallbacks(Operation *op) {
       // it, because this means that the use's region holding op is a child of
       // the region holding op containing the current block and was expected to
       // be visited and erased first - we should correctly fail here.
-      Region *blockParentRegion = block->front().getParentRegion();
+      Region *blockParentRegion = block->getParent();
       for (Operation &op : *block) {
         for (OpOperand &use : llvm::make_early_inc_range(op.getUses())) {
           // Early continue if the parent regions are not same.

The `noSkipBlockErasure` callback in `testNoSkipErasureCallbacks` called
`block->front().getParentRegion()` to get the parent region of a block.
This dereferences the ilist sentinel node when the block has no operations,
triggering an assertion failure.

Use `block->getParent()` instead, which directly returns the region
containing the block without requiring any operations to be present.

Fixes llvm#183511
@joker-eph
joker-eph enabled auto-merge (squash) February 28, 2026 10:58
@joker-eph
joker-eph merged commit f05b705 into llvm:main Feb 28, 2026
10 checks passed
sahas3 pushed a commit to sahas3/llvm-project that referenced this pull request Mar 4, 2026
…183757)

The `noSkipBlockErasure` callback in `testNoSkipErasureCallbacks` called
`block->front().getParentRegion()` to get the parent region of a block.
This dereferences the ilist sentinel node when the block has no
operations, triggering an assertion failure.

Use `block->getParent()` instead, which directly returns the region
containing the block without requiring any operations to be present.

Fixes llvm#183511
sujianIBM pushed a commit to sujianIBM/llvm-project that referenced this pull request Mar 5, 2026
…183757)

The `noSkipBlockErasure` callback in `testNoSkipErasureCallbacks` called
`block->front().getParentRegion()` to get the parent region of a block.
This dereferences the ilist sentinel node when the block has no
operations, triggering an assertion failure.

Use `block->getParent()` instead, which directly returns the region
containing the block without requiring any operations to be present.

Fixes llvm#183511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MLIR] Crash in testNoSkipErasureCallbacks when accessing parent region during walk

3 participants