Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,11 @@ LogicalResult ExpandShapeOp::verify() {
}

LogicalResult CollapseShapeOp::verify() {
CollapseShapeOp op = *this;
if (llvm::any_of(op.getReassociationIndices(),
[](auto &group) { return group.empty(); })) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please expand auto unless the type is obvious from the statement-level context or unavoidable. Here I suspect it should be something like ValueRange, at which point you don't need a reference.

return op.emitOpError("reassociation indices must not be empty");
}
return verifyTensorReshapeOp(*this, getSrcType(), getResultType());
}

Expand Down
4 changes: 3 additions & 1 deletion mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down
13 changes: 13 additions & 0 deletions mlir/test/Dialect/Tensor/invalid-collapse-shape.mlir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go to

// RUN: mlir-opt %s -split-input-file -verify-diagnostics
, we don't want one file per a tiny test.

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}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// expected-error@+1 {{'tensor.collapse_shape' op reassociation indices must not be empty}}
// expected-error@below {{'tensor.collapse_shape' op reassociation indices must not be empty}}

%0 = tensor.collapse_shape %arg0 [[0, 1], []] : tensor<1x?xf32> into tensor<?x10xf32>
return %0 : tensor<?x10xf32>
}