Skip to content

Commit 7f7cf27

Browse files
[mlir][SCF] Do not access erased op in scf.while lowering (#148356)
Do not access the erased `scf.condition` 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 4cca22f commit 7f7cf27

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,16 @@ DoWhileLowering::matchAndRewrite(WhileOp whileOp,
630630
// Loop around the "before" region based on condition.
631631
rewriter.setInsertionPointToEnd(before);
632632
auto condOp = cast<ConditionOp>(before->getTerminator());
633-
rewriter.replaceOpWithNewOp<cf::CondBranchOp>(condOp, condOp.getCondition(),
634-
before, condOp.getArgs(),
635-
continuation, ValueRange());
633+
rewriter.create<cf::CondBranchOp>(condOp.getLoc(), condOp.getCondition(),
634+
before, condOp.getArgs(), continuation,
635+
ValueRange());
636636

637637
// Replace the op with values "yielded" from the "before" region, which are
638638
// visible by dominance.
639639
rewriter.replaceOp(whileOp, condOp.getArgs());
640640

641+
// Erase the condition op.
642+
rewriter.eraseOp(condOp);
641643
return success();
642644
}
643645

0 commit comments

Comments
 (0)