-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[MLIR] Fix mlir-opt crash in ReshapeOpsUtils.cpp when collapse_shape index is invalid #173791
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -451,7 +451,9 @@ mlir::getSymbolLessAffineMaps(ArrayRef<ReassociationExprs> reassociation) { | |
| SmallVector<AffineMap, 4> maps; | ||
| maps.reserve(reassociation.size()); | ||
| for (const auto &exprs : reassociation) { | ||
| assert(!exprs.empty()); | ||
| if (exprs.empty()) { | ||
| return {}; | ||
| } | ||
|
Comment on lines
+454
to
+456
Member
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. Generally, compiler code should assume/assert that the IR has passed the verifier, so this should stay as an assertion unless it is somehow called on unverified code. |
||
| maps.push_back(AffineMap::get(maxDim + 1, 0, exprs, exprs[0].getContext())); | ||
| } | ||
| return maps; | ||
|
|
||
|
Member
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. This should go to
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||
| // RUN: mlir-opt %s -split-input-file -verify-diagnostics | ||||||
|
|
||||||
| // This test checks that an empty reassociation group in `tensor.collapse_shape` | ||||||
| // results in a proper error instead of an assert/crash. | ||||||
|
|
||||||
| // ----- | ||||||
|
|
||||||
| func.func @test_empty_reassociation(%arg0: tensor<1x?xf32>) -> tensor<?x10xf32> { | ||||||
| // expected-error@+1 {{'tensor.collapse_shape' op reassociation indices must not be empty}} | ||||||
|
Member
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.
Suggested change
|
||||||
| %0 = tensor.collapse_shape %arg0 [[0, 1], []] : tensor<1x?xf32> into tensor<?x10xf32> | ||||||
| return %0 : tensor<?x10xf32> | ||||||
| } | ||||||
|
|
||||||
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.
Nit: please expand
autounless the type is obvious from the statement-level context or unavoidable. Here I suspect it should be something likeValueRange, at which point you don't need a reference.