Skip to content

Commit 65a8e3a

Browse files
committed
[MLIR] Fix crash in notifyBlockInserted() debug output (NFC)
notifyBlockInserted can be called when inserting a block in a region before the op is built (like when building a scf::ForOp). This make us defensive by checking the parent op before printing it.
1 parent 377feae commit 65a8e3a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,17 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
14781478
Block *block, Region *previous, Region::iterator previousIt) {
14791479
assert(!wasOpReplaced(block->getParentOp()) &&
14801480
"attempting to insert into a region within a replaced/erased op");
1481-
LLVM_DEBUG({
1482-
logger.startLine() << "** Insert Block into : '"
1483-
<< block->getParentOp()->getName() << "'("
1484-
<< block->getParentOp() << ")\n";
1485-
});
1481+
LLVM_DEBUG(
1482+
{
1483+
Operation *parent = block->getParentOp();
1484+
if (parent) {
1485+
logger.startLine() << "** Insert Block into : '" << parent->getName()
1486+
<< "'(" << parent << ")\n";
1487+
} else {
1488+
logger.startLine()
1489+
<< "** Insert Block into detached Region (nullptr parent op)'";
1490+
}
1491+
});
14861492

14871493
if (!previous) {
14881494
// This is a newly created block.

0 commit comments

Comments
 (0)