[Mlir-commits] [mlir] [mlir][vector] Add verification for incorrect vector.extract (PR #115824)

Andrzej WarzyƄski llvmlistbot at llvm.org
Thu Nov 21 06:59:53 PST 2024


================
@@ -151,58 +151,142 @@ func.func @extract_vector_type(%arg0: index) {
 // -----
 
 func.func @extract_position_rank_overflow(%arg0: vector<4x8x16xf32>) {
-  // expected-error at +1 {{expected position attribute of rank no greater than vector rank}}
+  // expected-error at +1 {{'vector.extract' op expected a number of indices no greater than the source vector rank}}
   %1 = vector.extract %arg0[0, 0, 0, 0] : f32 from vector<4x8x16xf32>
 }
 
 // -----
 
 func.func @extract_position_rank_overflow_generic(%arg0: vector<4x8x16xf32>) {
-  // expected-error at +1 {{expected position attribute of rank no greater than vector rank}}
+  // expected-error at +1 {{'vector.extract' op expected a number of indices no greater than the source vector rank}}
   %1 = "vector.extract" (%arg0) <{static_position = array<i64: 0, 0, 0, 0>}> : (vector<4x8x16xf32>) -> (vector<16xf32>)
 }
 
 // -----
 
 func.func @extract_position_overflow(%arg0: vector<4x8x16xf32>) {
-  // expected-error at +1 {{expected position attribute #2 to be a non-negative integer smaller than the corresponding vector dimension}}
+  // expected-error at +1 {{'vector.extract' op expected position attribute #2 to be a non-negative integer smaller than the corresponding vector dimension}}
   %1 = vector.extract %arg0[0, 43, 0] : f32 from vector<4x8x16xf32>
 }
 
 // -----
 
 func.func @extract_precise_position_overflow(%arg0: vector<4x8x16xf32>) {
-  // expected-error at +1 {{expected position attribute #3 to be a non-negative integer smaller than the corresponding vector dimension}}
+  // expected-error at +1 {{'vector.extract' op expected position attribute #3 to be a non-negative integer smaller than the corresponding vector dimension}}
   %1 = vector.extract %arg0[3, 7, 16] : f32 from vector<4x8x16xf32>
 }
 
 // -----
 
-func.func @extract_0d(%arg0: vector<f32>) {
-  // expected-error at +1 {{expected position attribute of rank no greater than vector rank}}
+func.func @extract_scalar_from_0d_wrong_index(%arg0: vector<f32>) {
+  // expected-error at +1 {{'vector.extract' op expected a number of indices no greater than the source vector rank}}
   %1 = vector.extract %arg0[0] : f32 from vector<f32>
 }
 
 // -----
 
+func.func @extract_0d_from_0d_wrong_index(%arg0: vector<f32>) {
+  // expected-error at +1 {{'vector.extract' op expected a number of indices no greater than the source vector rank}}
+  %2 = vector.extract %arg0[0] : vector<f32> from vector<f32>
+}
+
+// -----
+
+func.func @extract_1d_from_0d_wrong_index(%arg0: vector<f32>) {
+  // expected-error at +1 {{'vector.extract' op expected a number of indices no greater than the source vector rank}}
+  %3 = vector.extract %arg0[0] : vector<1xf32> from vector<f32>
+}
+
+// -----
+
+func.func @extract_scalar_from_1d_wrong_index(%arg0: vector<1xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source vector rank to match the number of indices for scalar cases}}
+  %1 = vector.extract %arg0[] : f32 from vector<1xf32>
+}
+
+// -----
+
+func.func @extract_0d_from_1d_wrong_index(%arg0: vector<1xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source and destination vectors with different number of elements}}
+  %2 = vector.extract %arg0[] : vector<f32> from vector<1xf32>
+}
+
+// -----
+
+func.func @extract_0d_from_1d(%arg0: vector<1xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source and destination vectors with different number of elements}}
+  %4 = vector.extract %arg0[0] : vector<f32> from vector<1xf32>
+}
+
+// -----
+
+func.func @extract_1d_from_0d(%arg0: vector<f32>) {
+  // expected-error at +1 {{'vector.extract' op expected source and destination vectors with different number of elements}}
+  %4 = vector.extract %arg0[] : vector<1xf32> from vector<f32>
+}
+
+// -----
+
+func.func @extract_scalar_from_2d(%arg0: vector<4x1xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source vector rank to match the number of indices for scalar cases}}
+  %6 = vector.extract %arg0[2] : f32 from vector<4x1xf32>
+}
+
+// -----
+
+func.func @extract_0d_from_2d(%arg0: vector<4x1xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source vector rank minus number of indices to match the rank of the extracted vector}}
+  %7 = vector.extract %arg0[2] : vector<f32> from vector<4x1xf32>
+}
+
+// -----
+
+func.func @extract_scalar_from_2d_wrong_index(%arg0: vector<4x8xf32>) {
+  // expected-error at +1 {{'vector.extract' op expected source vector rank to match the number of indices for scalar cases}}
+  %8 = vector.extract %arg0[3] : f32 from vector<4x8xf32>
+}
----------------
banach-space wrote:

This looks almost identical to `@extract_scalar_from_2d`  - the error is also the same.

https://github.com/llvm/llvm-project/pull/115824


More information about the Mlir-commits mailing list