[Mlir-commits] [mlir] 65a8e3a - [MLIR] Fix crash in notifyBlockInserted() debug output (NFC)

Mehdi Amini llvmlistbot at llvm.org
Mon Mar 4 18:39:20 PST 2024


Author: Mehdi Amini
Date: 2024-03-04T18:39:07-08:00
New Revision: 65a8e3a400f23eaa1270a5a000e262df954a4ef6

URL: https://github.com/llvm/llvm-project/commit/65a8e3a400f23eaa1270a5a000e262df954a4ef6
DIFF: https://github.com/llvm/llvm-project/commit/65a8e3a400f23eaa1270a5a000e262df954a4ef6.diff

LOG: [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.

Added: 
    

Modified: 
    mlir/lib/Transforms/Utils/DialectConversion.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 9dc806730d01a1..4741110bc60682 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1478,11 +1478,17 @@ void ConversionPatternRewriterImpl::notifyBlockInserted(
     Block *block, Region *previous, Region::iterator previousIt) {
   assert(!wasOpReplaced(block->getParentOp()) &&
          "attempting to insert into a region within a replaced/erased op");
-  LLVM_DEBUG({
-    logger.startLine() << "** Insert Block into : '"
-                       << block->getParentOp()->getName() << "'("
-                       << block->getParentOp() << ")\n";
-  });
+  LLVM_DEBUG(
+      {
+        Operation *parent = block->getParentOp();
+        if (parent) {
+          logger.startLine() << "** Insert Block into : '" << parent->getName()
+                             << "'(" << parent << ")\n";
+        } else {
+          logger.startLine()
+              << "** Insert Block into detached Region (nullptr parent op)'";
+        }
+      });
 
   if (!previous) {
     // This is a newly created block.


        


More information about the Mlir-commits mailing list