aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Böck <markus.boeck02@gmail.com>2024-12-04 09:36:05 +0100
committerGitHub <noreply@github.com>2024-12-04 09:36:05 +0100
commit2a30bfcef368667247ebbe30be84f73b92dbe800 (patch)
treedea529a88769e748ab54e21664018e0c33edbbe7
parent455b4fd01ae9b2a78be98bcd26db2b700709c545 (diff)
downloadllvm-2a30bfcef368667247ebbe30be84f73b92dbe800.zip
llvm-2a30bfcef368667247ebbe30be84f73b92dbe800.tar.gz
llvm-2a30bfcef368667247ebbe30be84f73b92dbe800.tar.bz2
[mlir] Improve error message when number of operands and types differ (#118488)
If using a variadic operand, the error message given if the number of types and operands do not match would be along the lines of: ``` 3 operands present, but expected 2 ``` This error message is confusing for multiple reasons, particular for beginners: * If the intention is to have 3 operands, it does not point out why it expects 2. The user may actually just want to add a type to the type list * It reads as if a verifier error rather than a parser error, giving the impression the Op only supports 2 operands. This PR attempts to improve the error message by first noting the issue ("number of operands and types mismatch") and mentioning how many operands and types it received.
-rw-r--r--mlir/include/mlir/IR/OpImplementation.h3
-rw-r--r--mlir/test/Dialect/LLVMIR/invalid.mlir4
-rw-r--r--mlir/test/Dialect/Linalg/transform-ops-invalid.mlir2
-rw-r--r--mlir/test/Dialect/SCF/invalid.mlir4
-rw-r--r--mlir/test/Dialect/SPIRV/IR/memory-ops.mlir6
-rw-r--r--mlir/test/Dialect/Tensor/invalid.mlir2
-rw-r--r--mlir/test/Dialect/Vector/invalid.mlir2
7 files changed, 12 insertions, 11 deletions
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index a722279..6c1ff4d 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -1604,7 +1604,8 @@ public:
size_t typeSize = llvm::range_size(types);
if (operandSize != typeSize)
return emitError(loc)
- << operandSize << " operands present, but expected " << typeSize;
+ << "number of operands and types do not match: got " << operandSize
+ << " operands and " << typeSize << " types";
for (auto [operand, type] : llvm::zip_equal(operands, types))
if (resolveOperand(operand, type, result))
diff --git a/mlir/test/Dialect/LLVMIR/invalid.mlir b/mlir/test/Dialect/LLVMIR/invalid.mlir
index 5677d7f..25806d9 100644
--- a/mlir/test/Dialect/LLVMIR/invalid.mlir
+++ b/mlir/test/Dialect/LLVMIR/invalid.mlir
@@ -91,14 +91,14 @@ func.func @alloca_non_integer_alignment() {
// -----
func.func @gep_missing_input_result_type(%pos : i64, %base : !llvm.ptr) {
- // expected-error@+1 {{2 operands present, but expected 0}}
+ // expected-error@+1 {{number of operands and types do not match: got 2 operands and 0 types}}
llvm.getelementptr %base[%pos] : () -> (), i64
}
// -----
func.func @gep_missing_input_type(%pos : i64, %base : !llvm.ptr) {
- // expected-error@+1 {{2 operands present, but expected 0}}
+ // expected-error@+1 {{number of operands and types do not match: got 2 operands and 0 types}}
llvm.getelementptr %base[%pos] : () -> (!llvm.ptr), i64
}
diff --git a/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir b/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
index fbebb97..6584596 100644
--- a/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
+++ b/mlir/test/Dialect/Linalg/transform-ops-invalid.mlir
@@ -77,7 +77,7 @@ transform.sequence failures(propagate) {
transform.sequence failures(propagate) {
^bb0(%arg0: !transform.any_op):
%0 = transform.param.constant 2 : i64 -> !transform.param<i64>
- // expected-error@below {{custom op 'transform.structured.vectorize' 1 operands present, but expected 2}}
+ // expected-error@+1 {{custom op 'transform.structured.vectorize' number of operands and types do not match: got 1 operands and 2 types}}
transform.structured.vectorize %arg0 vector_sizes [%0, 2] : !transform.any_op, !transform.param<i64>, !transform.param<i64>
}
diff --git a/mlir/test/Dialect/SCF/invalid.mlir b/mlir/test/Dialect/SCF/invalid.mlir
index 337eb9e..80576be 100644
--- a/mlir/test/Dialect/SCF/invalid.mlir
+++ b/mlir/test/Dialect/SCF/invalid.mlir
@@ -247,7 +247,7 @@ func.func @parallel_more_results_than_reduces(
func.func @parallel_more_results_than_initial_values(
%arg0 : index, %arg1: index, %arg2: index) {
- // expected-error@+1 {{'scf.parallel' 0 operands present, but expected 1}}
+ // expected-error@+1 {{'scf.parallel' number of operands and types do not match: got 0 operands and 1 types}}
%res = scf.parallel (%i0) = (%arg0) to (%arg1) step (%arg2) -> f32 {
scf.reduce(%arg0 : index) {
^bb0(%lhs: index, %rhs: index):
@@ -609,7 +609,7 @@ func.func @wrong_num_results(%in: tensor<100xf32>, %out: tensor<100xf32>) {
%c1 = arith.constant 1 : index
%num_threads = arith.constant 100 : index
- // expected-error @+1 {{1 operands present, but expected 2}}
+ // expected-error@+1 {{number of operands and types do not match: got 1 operands and 2 types}}
%result:2 = scf.forall (%thread_idx) in (%num_threads) shared_outs(%o = %out) -> (tensor<100xf32>, tensor<100xf32>) {
%1 = tensor.extract_slice %in[%thread_idx][1][1] : tensor<100xf32> to tensor<1xf32>
scf.forall.in_parallel {
diff --git a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
index 5aef613..57ff947 100644
--- a/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/memory-ops.mlir
@@ -57,7 +57,7 @@ func.func @access_chain_non_composite() -> () {
func.func @access_chain_no_indices(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 0 operands present, but expected 1}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 0 operands and 1 types}}
%1 = spirv.AccessChain %0[] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
return
}
@@ -75,7 +75,7 @@ func.func @access_chain_missing_comma(%index0 : i32) -> () {
func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 1 operands present, but expected 2}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 1 operands and 2 types}}
%1 = spirv.AccessChain %0[%index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32, i32 -> !spirv.ptr<!spirv.array<4xf32>, Function>
return
}
@@ -84,7 +84,7 @@ func.func @access_chain_invalid_indices_types_count(%index0 : i32) -> () {
func.func @access_chain_missing_indices_type(%index0 : i32) -> () {
%0 = spirv.Variable : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>
- // expected-error @+1 {{custom op 'spirv.AccessChain' 2 operands present, but expected 1}}
+ // expected-error @+1 {{custom op 'spirv.AccessChain' number of operands and types do not match: got 2 operands and 1 types}}
%1 = spirv.AccessChain %0[%index0, %index0] : !spirv.ptr<!spirv.array<4x!spirv.array<4xf32>>, Function>, i32 -> !spirv.ptr<f32, Function>
return
}
diff --git a/mlir/test/Dialect/Tensor/invalid.mlir b/mlir/test/Dialect/Tensor/invalid.mlir
index 77cae1c..83cb4b9 100644
--- a/mlir/test/Dialect/Tensor/invalid.mlir
+++ b/mlir/test/Dialect/Tensor/invalid.mlir
@@ -90,7 +90,7 @@ func.func @tensor.from_elements_wrong_result_type() {
// -----
func.func @tensor.from_elements_wrong_elements_count() {
- // expected-error@+2 {{1 operands present, but expected 2}}
+ // expected-error@+2 {{number of operands and types do not match: got 1 operands and 2 types}}
%c0 = arith.constant 0 : index
%0 = tensor.from_elements %c0 : tensor<2xindex>
return
diff --git a/mlir/test/Dialect/Vector/invalid.mlir b/mlir/test/Dialect/Vector/invalid.mlir
index 9f7efa1..1a70791 100644
--- a/mlir/test/Dialect/Vector/invalid.mlir
+++ b/mlir/test/Dialect/Vector/invalid.mlir
@@ -1803,7 +1803,7 @@ func.func @deinterleave_scalable_rank_fail(%vec : vector<2x[4]xf32>) {
// -----
func.func @invalid_from_elements(%a: f32) {
- // expected-error @+1 {{'vector.from_elements' 1 operands present, but expected 2}}
+ // expected-error @+1 {{'vector.from_elements' number of operands and types do not match: got 1 operands and 2 types}}
vector.from_elements %a : vector<2xf32>
return
}