-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][cf] Do not access erased operation in cf.cond_br lowering
#148358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][cf] Do not access erased operation in cf.cond_br lowering
#148358
Conversation
|
@llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesDo not access the erased After the One-Shot Dialect Conversion refactoring, a Full diff: https://github.com/llvm/llvm-project/pull/148358.diff 1 Files Affected:
diff --git a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp
index 88a8b7fb185c5..716ab140ad6c7 100644
--- a/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp
+++ b/mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp
@@ -138,11 +138,12 @@ struct BranchOpLowering : public ConvertOpToLLVMPattern<cf::BranchOp> {
TypeRange(adaptor.getOperands()));
if (failed(convertedBlock))
return failure();
+ auto attrs = op->getAttrDictionary();
Operation *newOp = rewriter.replaceOpWithNewOp<LLVM::BrOp>(
op, adaptor.getOperands(), *convertedBlock);
// TODO: We should not just forward all attributes like that. But there are
// existing Flang tests that depend on this behavior.
- newOp->setAttrs(op->getAttrDictionary());
+ newOp->setAttrs(attrs);
return success();
}
};
@@ -166,18 +167,14 @@ struct CondBranchOpLowering : public ConvertOpToLLVMPattern<cf::CondBranchOp> {
TypeRange(adaptor.getFalseDestOperands()));
if (failed(convertedFalseBlock))
return failure();
+ auto attrs = op->getAttrDictionary();
auto newOp = rewriter.replaceOpWithNewOp<LLVM::CondBrOp>(
- op, adaptor.getCondition(), *convertedTrueBlock,
- adaptor.getTrueDestOperands(), *convertedFalseBlock,
- adaptor.getFalseDestOperands());
- ArrayRef<int32_t> weights = op.getWeights();
- if (!weights.empty()) {
- newOp.setWeights(weights);
- op.removeBranchWeightsAttr();
- }
+ op, adaptor.getCondition(), adaptor.getTrueDestOperands(),
+ adaptor.getFalseDestOperands(), op.getBranchWeightsAttr(),
+ *convertedTrueBlock, *convertedFalseBlock);
// TODO: We should not just forward all attributes like that. But there are
// existing Flang tests that depend on this behavior.
- newOp->setAttrs(op->getAttrDictionary());
+ newOp->setAttrs(attrs);
return success();
}
};
|
zero9178
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Co-authored-by: Markus Böck <[email protected]>
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/15986 Here is the relevant piece of the build log for the reference |
Do not access the erased
cf.cond_broperation 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
ConversionPatternRewriterwill behave more like a normalPatternRewriter.