-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[mlir][tensor] Check the EmptyOp's dynamicSize to be non-negative #65577
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
Conversation
@@ -621,6 +621,18 @@ LogicalResult EmptyOp::verify() { | |||
return emitOpError("incorrect number of dynamic sizes, has ") | |||
<< getDynamicSizes().size() << ", expected " | |||
<< getType().getNumDynamicDims(); | |||
|
|||
if (getDynamicSizes().size() > 0) { |
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.
This check does not seem needed?
if (getDynamicSizes().size() > 0) { | ||
if (llvm::any_of(getDynamicSizes(), [](Value operand) { | ||
APInt constSizeArg; | ||
if (!matchPattern(operand, m_ConstantInt(&constSizeArg))) { |
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.
This does not belong to the verifier, because: https://mlir.llvm.org/getting_started/DeveloperGuide/#ir-verifier
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.
Thank you for teaching me about IR's verifier.
This is why the guidelines to write verifier is to stick to information local to an operation (think “what I see when I print this operation alone”). Looking through operands or results is extremely unusual and should be avoided.
I understand it, so i will remove this checker from verifier.
@@ -691,6 +703,9 @@ struct ReplaceEmptyTensorStaticShapeDims : OpRewritePattern<EmptyOp> { | |||
Value dynamicSize = op.getDynamicSizes()[ctr++]; | |||
std::optional<int64_t> cst = getConstantIntValue(dynamicSize); | |||
if (cst.has_value()) { | |||
// dynamic size must be non-negative. | |||
if (cst.value() < 0) | |||
return failure(); |
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.
This should be enough without the verifier right?
@joker-eph Could you merge it? |
…vm#65577) This patch addresses a crash that occurs when negative dynamic sizes are provided in tensor.emptyOp by adding a check to ensure that dynamic sizes are non-negative. Fixes llvm#64064
This patch addresses a crash that occurs when negative dynamic sizes are provided in tensor.emptyOp by adding a check to ensure that dynamic sizes are non-negative.
Fixes #64064