WIP: [mlir][func] Fix potential crash in FuncOp::verify#184607
Closed
ingomueller-net wants to merge 1 commit into
Closed
WIP: [mlir][func] Fix potential crash in FuncOp::verify#184607ingomueller-net wants to merge 1 commit into
FuncOp::verify#184607ingomueller-net wants to merge 1 commit into
Conversation
This PR fixes a potential crash in `FuncOp::verify`. This can happen if one of the operands of the return op inside the verified op is a `<<NULL>>` value, for example, because the original value had all uses dropped. The original implementation used the operands without checking their validity, which could lead to a crash. The fix consists in adding a test and failing verificiation if not all operands exist. Signed-off-by: Ingo Müller <ingomueller@google.com>
Member
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-func Author: Ingo Müller (ingomueller-net) ChangesThis PR fixes a potential crash in Full diff: https://github.com/llvm/llvm-project/pull/184607.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Func/IR/FuncOps.cpp b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
index 8ee2c9956d2d6..7c4c5a593d5fd 100644
--- a/mlir/lib/Dialect/Func/IR/FuncOps.cpp
+++ b/mlir/lib/Dialect/Func/IR/FuncOps.cpp
@@ -305,9 +305,12 @@ LogicalResult FuncOp::verify() {
<< " operands, but enclosing function (@" << getName()
<< ") returns " << resultTypes.size();
- for (auto [i, opType] :
- llvm::enumerate(llvm::zip(returnOp->getOperandTypes(), resultTypes))) {
- auto [opTy, resTy] = opType;
+ for (auto [i, operand] :
+ llvm::enumerate(llvm::zip(returnOp->getOpOperands(), resultTypes))) {
+ auto [opOperand, resTy] = operand;
+ if (!opOperand.get())
+ return returnOp->emitOpError("null operand at index ") << i;
+ auto opTy = opOperand.get().getType();
if (opTy != resTy)
return returnOp->emitError()
<< "type of return operand " << i << " (" << opTy
|
Contributor
Author
|
Closing in favor of #184612. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a potential crash in
FuncOp::verify. This can happen if one of the operands of the return op inside the verified op is a<<NULL>>value, for example, because the original value had all uses dropped. The original implementation used the operands without checking their validity, which could lead to a crash. The fix consists in adding a test and failing verificiation if not all operands exist.