[mlir] Fix crash in testNoSkipErasureCallbacks on empty blocks - #183757
Merged
Merged
Conversation
Member
|
@llvm/pr-subscribers-mlir Author: Mehdi Amini (joker-eph) ChangesThe Use Fixes #183511 Full diff: https://github.com/llvm/llvm-project/pull/183757.diff 2 Files Affected:
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.
|
matthias-springer
approved these changes
Feb 28, 2026
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
force-pushed
the
fix/issue-183511
branch
from
February 28, 2026 10:58
5d6677e to
7db3ebd
Compare
joker-eph
enabled auto-merge (squash)
February 28, 2026 10:58
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
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
noSkipBlockErasurecallback intestNoSkipErasureCallbackscalledblock->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