diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp --- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp +++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp @@ -214,9 +214,9 @@ } static LogicalResult verify(ToPointersOp op) { - if (failed(isInBounds(op.dim(), op.tensor()))) - return op.emitError("requested pointers dimension out of bounds"); if (auto e = getSparseTensorEncoding(op.tensor().getType())) { + if (failed(isInBounds(op.dim(), op.tensor()))) + return op.emitError("requested pointers dimension out of bounds"); if (failed(isMatchingWidth(op.result(), e.getPointerBitWidth()))) return op.emitError("unexpected type for pointers"); return success(); @@ -225,9 +225,9 @@ } static LogicalResult verify(ToIndicesOp op) { - if (failed(isInBounds(op.dim(), op.tensor()))) - return op.emitError("requested indices dimension out of bounds"); if (auto e = getSparseTensorEncoding(op.tensor().getType())) { + if (failed(isInBounds(op.dim(), op.tensor()))) + return op.emitError("requested indices dimension out of bounds"); if (failed(isMatchingWidth(op.result(), e.getIndexBitWidth()))) return op.emitError("unexpected type for indices"); return success(); diff --git a/mlir/test/Dialect/SparseTensor/invalid.mlir b/mlir/test/Dialect/SparseTensor/invalid.mlir --- a/mlir/test/Dialect/SparseTensor/invalid.mlir +++ b/mlir/test/Dialect/SparseTensor/invalid.mlir @@ -17,6 +17,15 @@ // ----- +func @invalid_pointers_unranked(%arg0: tensor<*xf64>) -> memref { + %c = constant 0 : index + // expected-error@+1 {{expected a sparse tensor to get pointers}} + %0 = sparse_tensor.pointers %arg0, %c : tensor<*xf64> to memref + return %0 : memref +} + +// ----- + #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"], pointerBitWidth=32}> func @mismatch_pointers_types(%arg0: tensor<128xf64, #SparseVector>) -> memref { @@ -48,6 +57,15 @@ // ----- +func @invalid_indices_unranked(%arg0: tensor<*xf64>) -> memref { + %c = constant 0 : index + // expected-error@+1 {{expected a sparse tensor to get indices}} + %0 = sparse_tensor.indices %arg0, %c : tensor<*xf64> to memref + return %0 : memref +} + +// ----- + #SparseVector = #sparse_tensor.encoding<{dimLevelType = ["compressed"]}> func @mismatch_indices_types(%arg0: tensor) -> memref {