[Mlir-commits] [mlir] 8be2c19 - [MLIR] Fix mlir-opt crash in ReshapeOpsUtils.cpp when collapse_shape index is invalid (#173791)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Dec 30 02:35:57 PST 2025
Author: Arjun Parmar
Date: 2025-12-30T11:35:53+01:00
New Revision: 8be2c19f883109ab8e1d750beb8cf1816025d906
URL: https://github.com/llvm/llvm-project/commit/8be2c19f883109ab8e1d750beb8cf1816025d906
DIFF: https://github.com/llvm/llvm-project/commit/8be2c19f883109ab8e1d750beb8cf1816025d906.diff
LOG: [MLIR] Fix mlir-opt crash in ReshapeOpsUtils.cpp when collapse_shape index is invalid (#173791)
This patch fixes a crash occurring in mlir-opt when running
collapse_shape with an invalid index configuration. Instead of crashing,
an error message is returned to the user.
Fixes: #173567
---------
Co-authored-by: Bazinga! <akparmar004>
Added:
Modified:
mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
mlir/test/Dialect/Tensor/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index 204e9bb73e12c..bed30d29db047 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -2072,6 +2072,11 @@ LogicalResult ExpandShapeOp::verify() {
}
LogicalResult CollapseShapeOp::verify() {
+ CollapseShapeOp op = *this;
+ if (llvm::any_of(op.getReassociationIndices(),
+ [](ReassociationIndices group) { return group.empty(); })) {
+ return op.emitOpError("reassociation indices must not be empty");
+ }
return verifyTensorReshapeOp(*this, getSrcType(), getResultType());
}
diff --git a/mlir/test/Dialect/Tensor/invalid.mlir b/mlir/test/Dialect/Tensor/invalid.mlir
index 665657a67dc61..f36678c3d7589 100644
--- a/mlir/test/Dialect/Tensor/invalid.mlir
+++ b/mlir/test/Dialect/Tensor/invalid.mlir
@@ -681,3 +681,12 @@ func.func @bitcast_index_1(%arg0 : tensor<?xindex>) -> tensor<?xi64> {
%0 = tensor.bitcast %arg0 : tensor<?xindex> to tensor<?xi64>
return %0 : tensor<?xi64>
}
+
+// -----
+
+func.func @test_empty_reassociation(%arg0: tensor<1x?xf32>) -> tensor<?x10xf32> {
+ // expected-error at 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>
+}
+
More information about the Mlir-commits
mailing list