[Mlir-commits] [mlir] [mlir] Fix crash in testNoSkipErasureCallbacks on empty blocks (PR #183757)

Mehdi Amini llvmlistbot at llvm.org
Fri Feb 27 07:49:31 PST 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/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 #183511

>From 5d6677e8e9e0d5b6e8bcbf5b4a5fd880114a9743 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Fri, 27 Feb 2026 07:46:06 -0800
Subject: [PATCH] [mlir] Fix crash in testNoSkipErasureCallbacks on empty
 blocks

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
---
 mlir/test/IR/visitors.mlir        | 12 +++++++++++-
 mlir/test/lib/IR/TestVisitors.cpp |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

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.



More information about the Mlir-commits mailing list