Skip to content

Commit 5e940b6

Browse files
matthias-springermahesh-attarde
authored andcommitted
[mlir][SCF] Do not access erased operation in scf.while lowering (llvm#150741)
Do not access the erased `scf.while` operation in the lowering pattern. That won't work anymore in a One-Shot Dialect Conversion and triggers a use-after-free sanitizer error. After the One-Shot Dialect Conversion refactoring, a `ConversionPatternRewriter` will behave more like a normal `PatternRewriter`.
1 parent b2dd990 commit 5e940b6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
582582
// block. This should be reconsidered if we allow break/continue in SCF.
583583
rewriter.setInsertionPointToEnd(before);
584584
auto condOp = cast<ConditionOp>(before->getTerminator());
585+
SmallVector<Value> args = llvm::to_vector(condOp.getArgs());
585586
rewriter.replaceOpWithNewOp<cf::CondBranchOp>(condOp, condOp.getCondition(),
586587
after, condOp.getArgs(),
587588
continuation, ValueRange());
@@ -593,7 +594,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
593594

594595
// Replace the op with values "yielded" from the "before" region, which are
595596
// visible by dominance.
596-
rewriter.replaceOp(whileOp, condOp.getArgs());
597+
rewriter.replaceOp(whileOp, args);
597598

598599
return success();
599600
}

0 commit comments

Comments
 (0)