-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][memref] Verify out-of-bounds access for memref.subview
#131876
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
Changes from 4 commits
48a9cdd
8a291be
4da5c1a
5682413
042bcf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2977,6 +2977,9 @@ static LogicalResult produceSubViewErrorMsg(SliceVerificationResult result, | |
| LogicalResult SubViewOp::verify() { | ||
| MemRefType baseType = getSourceType(); | ||
| MemRefType subViewType = getType(); | ||
| ArrayRef<int64_t> staticOffsets = getStaticOffsets(); | ||
| ArrayRef<int64_t> staticSizes = getStaticSizes(); | ||
| ArrayRef<int64_t> staticStrides = getStaticStrides(); | ||
|
|
||
| // The base memref and the view memref should be in the same memory space. | ||
| if (baseType.getMemorySpace() != subViewType.getMemorySpace()) | ||
|
|
@@ -2991,7 +2994,7 @@ LogicalResult SubViewOp::verify() { | |
| // Compute the expected result type, assuming that there are no rank | ||
| // reductions. | ||
| MemRefType expectedType = SubViewOp::inferResultType( | ||
| baseType, getStaticOffsets(), getStaticSizes(), getStaticStrides()); | ||
| baseType, staticOffsets, staticSizes, staticStrides); | ||
|
|
||
| // Verify all properties of a shaped type: rank, element type and dimension | ||
| // sizes. This takes into account potential rank reductions. | ||
|
|
@@ -3025,6 +3028,14 @@ LogicalResult SubViewOp::verify() { | |
| return produceSubViewErrorMsg(SliceVerificationResult::LayoutMismatch, | ||
| *this, expectedType); | ||
|
|
||
| // Verify that offsets, sizes, strides do not run out-of-bounds with respect | ||
| // to the base memref. | ||
| SliceBoundsVerificationResult boundsResult = | ||
| verifyInBoundsSlice(baseType.getShape(), staticOffsets, staticSizes, | ||
| staticStrides, /*generateErrorMessage=*/true); | ||
| if (!boundsResult.isValid) | ||
| return getOperation()->emitError(boundsResult.errorMessage); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not re-use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to reuse
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth refactoring this in a follow-up PR. |
||
|
|
||
| return success(); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.