[Mlir-commits] [mlir] cccde9b - [mlir][SCF] Do not access erased operation in `scf.while` lowering (#150741)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Jul 26 02:07:09 PDT 2025
Author: Matthias Springer
Date: 2025-07-26T11:07:06+02:00
New Revision: cccde9b2b1aa05f2797b29cba209c7642b7ac0f6
URL: https://github.com/llvm/llvm-project/commit/cccde9b2b1aa05f2797b29cba209c7642b7ac0f6
DIFF: https://github.com/llvm/llvm-project/commit/cccde9b2b1aa05f2797b29cba209c7642b7ac0f6.diff
LOG: [mlir][SCF] Do not access erased operation in `scf.while` lowering (#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`.
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 240491a51d2b9..807be7e1003c0 100644
--- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
+++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
@@ -582,6 +582,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
// block. This should be reconsidered if we allow break/continue in SCF.
rewriter.setInsertionPointToEnd(before);
auto condOp = cast<ConditionOp>(before->getTerminator());
+ SmallVector<Value> args = llvm::to_vector(condOp.getArgs());
rewriter.replaceOpWithNewOp<cf::CondBranchOp>(condOp, condOp.getCondition(),
after, condOp.getArgs(),
continuation, ValueRange());
@@ -593,7 +594,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
// Replace the op with values "yielded" from the "before" region, which are
// visible by dominance.
- rewriter.replaceOp(whileOp, condOp.getArgs());
+ rewriter.replaceOp(whileOp, args);
return success();
}
More information about the Mlir-commits
mailing list