[Mlir-commits] [mlir] [mlir] Fix crash in dialect conversion for detached root ops (PR #185068)

Mehdi Amini llvmlistbot at llvm.org
Mon Mar 9 04:11:05 PDT 2026


================
@@ -3459,6 +3463,16 @@ LogicalResult ConversionPatternRewriter::legalize(Region *r) {
 LogicalResult OperationConverter::applyConversion(ArrayRef<Operation *> ops) {
   // Convert each operation and discard rewrites on failure.
   ConversionPatternRewriterImpl &rewriterImpl = rewriter.getImpl();
+
+  // Track which root ops are detached (not in any block). If a detached root
+  // op is replaced or erased during conversion, we must report an error because
+  // the newly inserted replacement op would have no parent context, and the
+  // original op cannot be properly unlinked.
+  SmallPtrSet<Operation *, 4> detachedRootOps;
----------------
joker-eph wrote:

I saw this before as something that users can trigger, but actually thinking about it again I think you're right: this is a pass-pipeline design question likely. The test case is an Operation pass, but it likely should be a ModulePass to be made safe.

https://github.com/llvm/llvm-project/pull/185068


More information about the Mlir-commits mailing list