[Mlir-commits] [mlir] 7f7cf27 - [mlir][SCF] Do not access erased op in `scf.while` lowering (#148356)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 12 07:14:07 PDT 2025
Author: Matthias Springer
Date: 2025-07-12T16:14:04+02:00
New Revision: 7f7cf2743a80848fb6a02814dfa82251efd3631a
URL: https://github.com/llvm/llvm-project/commit/7f7cf2743a80848fb6a02814dfa82251efd3631a
DIFF: https://github.com/llvm/llvm-project/commit/7f7cf2743a80848fb6a02814dfa82251efd3631a.diff
LOG: [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`.
Added:
Modified:
mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
index 03c5c2239ed7a..0df91a243d07a 100644
--- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
+++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
@@ -630,14 +630,16 @@ DoWhileLowering::matchAndRewrite(WhileOp whileOp,
// Loop around the "before" region based on condition.
rewriter.setInsertionPointToEnd(before);
auto condOp = cast<ConditionOp>(before->getTerminator());
- rewriter.replaceOpWithNewOp<cf::CondBranchOp>(condOp, condOp.getCondition(),
- before, condOp.getArgs(),
- continuation, ValueRange());
+ rewriter.create<cf::CondBranchOp>(condOp.getLoc(), condOp.getCondition(),
+ before, condOp.getArgs(), continuation,
+ ValueRange());
// Replace the op with values "yielded" from the "before" region, which are
// visible by dominance.
rewriter.replaceOp(whileOp, condOp.getArgs());
+ // Erase the condition op.
+ rewriter.eraseOp(condOp);
return success();
}
More information about the Mlir-commits
mailing list