Skip to content

Conversation

@matthias-springer
Copy link
Member

Fix a crash in ConversionPatternRewriter::replaceUsesOfBlockArgument when running with -debug. The block that owns the block argument can be a detached block. In that case, do not attempt to print the name of the owner op.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Feb 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 4, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Matthias Springer (matthias-springer)

Changes

Fix a crash in ConversionPatternRewriter::replaceUsesOfBlockArgument when running with -debug. The block that owns the block argument can be a detached block. In that case, do not attempt to print the name of the owner op.


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

1 Files Affected:

  • (modified) mlir/lib/Transforms/Utils/DialectConversion.cpp (+7-4)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 403321d40d53c9..7bfcd192c9aa9c 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -1708,10 +1708,13 @@ FailureOr<Block *> ConversionPatternRewriter::convertRegionTypes(
 void ConversionPatternRewriter::replaceUsesOfBlockArgument(BlockArgument from,
                                                            Value to) {
   LLVM_DEBUG({
-    Operation *parentOp = from.getOwner()->getParentOp();
-    impl->logger.startLine() << "** Replace Argument : '" << from
-                             << "'(in region of '" << parentOp->getName()
-                             << "'(" << from.getOwner()->getParentOp() << ")\n";
+    impl->logger.startLine() << "** Replace Argument : '" << from << "'";
+    if (Operation *parentOp = from.getOwner()->getParentOp()) {
+      impl->logger.getOStream() << " (in region of '" << parentOp->getName()
+                                << "' (" << parentOp << ")\n";
+    } else {
+      impl->logger.getOStream() << " (unlinked block)\n";
+    }
   });
   impl->appendRewrite<ReplaceBlockArgRewrite>(from.getOwner(), from,
                                               impl->currentTypeConverter);

@matthias-springer matthias-springer merged commit e63d543 into main Feb 4, 2025
9 of 10 checks passed
@matthias-springer matthias-springer deleted the users/matthias-springer/fix_debug_crash branch February 4, 2025 10:31
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Fix a crash in `ConversionPatternRewriter::replaceUsesOfBlockArgument`
when running with `-debug`. The block that owns the block argument can
be a detached block. In that case, do not attempt to print the name of
the owner op.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants