Point to spv.AccessChain when reporting spv.AccessChain errors
authorLei Zhang <antiagainst@google.com>
Thu, 22 Aug 2019 01:53:32 +0000 (18:53 -0700)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Thu, 22 Aug 2019 01:54:06 +0000 (18:54 -0700)
PiperOrigin-RevId: 264742130

mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
mlir/test/Dialect/SPIRV/ops.mlir

index 93d59968480ec0c798e753159512cf46999cbce2..00f63e2a3290e288b828879f9e1e8acf7eabfb98 100644 (file)
@@ -390,9 +390,8 @@ static ParseResult parseAccessChainOp(OpAsmParser *parser,
     return failure();
   }
 
-  Location baseLoc = state->operands.front()->getLoc();
   auto resultType = getElementPtrType(
-      type, llvm::makeArrayRef(state->operands).drop_front(), baseLoc);
+      type, llvm::makeArrayRef(state->operands).drop_front(), state->location);
   if (!resultType) {
     return failure();
   }
index 74f341f1d117fa7373a3c2754fe1bb0fc8c7089b..dd93c450d568294d3d778ca0f65586c1647a549c 100644 (file)
@@ -45,8 +45,8 @@ func @access_chain_2D_array_2(%arg0 : i32) -> () {
 
 func @access_chain_non_composite() -> () {
   %0 = spv.constant 1: i32
-  // expected-error @+1 {{cannot extract from non-composite type 'f32' with index 0}}
   %1 = spv.Variable : !spv.ptr<f32, Function>
+  // expected-error @+1 {{cannot extract from non-composite type 'f32' with index 0}}
   %2 = spv.AccessChain %1[%0] : !spv.ptr<f32, Function>
   return
 }
@@ -54,8 +54,8 @@ func @access_chain_non_composite() -> () {
 // -----
 
 func @access_chain_no_indices(%index0 : i32) -> () {
-  // expected-error @+1 {{expected at least one index}}
   %0 = spv.Variable : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
+  // expected-error @+1 {{expected at least one index}}
   %1 = spv.AccessChain %0[] : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
   return
 }
@@ -64,8 +64,8 @@ func @access_chain_no_indices(%index0 : i32) -> () {
 
 func @access_chain_invalid_type(%index0 : i32) -> () {
   %0 = spv.Variable : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
-  // expected-error @+1 {{expected a pointer to composite type, but provided '!spv.array<4 x !spv.array<4 x f32>>'}}
   %1 = spv.Load "Function" %0 ["Volatile"] : !spv.array<4x!spv.array<4xf32>>
+  // expected-error @+1 {{expected a pointer to composite type, but provided '!spv.array<4 x !spv.array<4 x f32>>'}}
   %2 = spv.AccessChain %1[%index0] : !spv.array<4x!spv.array<4xf32>>
   return
 }
@@ -82,8 +82,8 @@ func @access_chain_invalid_index_1(%index0 : i32) -> () {
 // -----
 
 func @access_chain_invalid_index_2(%index0 : i32) -> () {
-  // expected-error @+1 {{index must be an integer spv.constant to access element of spv.struct}}
   %0 = spv.Variable : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
+  // expected-error @+1 {{index must be an integer spv.constant to access element of spv.struct}}
   %1 = spv.AccessChain %0[%index0, %index0] : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
   return
 }
@@ -92,8 +92,8 @@ func @access_chain_invalid_index_2(%index0 : i32) -> () {
 
 func @access_chain_invalid_constant_type_1() -> () {
   %0 = std.constant 1: i32
-  // expected-error @+1 {{index must be an integer spv.constant to access element of spv.struct, but provided std.constant}}
   %1 = spv.Variable : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
+  // expected-error @+1 {{index must be an integer spv.constant to access element of spv.struct, but provided std.constant}}
   %2 = spv.AccessChain %1[%0, %0] : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
   return
 }
@@ -102,8 +102,8 @@ func @access_chain_invalid_constant_type_1() -> () {
 
 func @access_chain_out_of_bounds() -> () {
   %index0 = "spv.constant"() { value = 12: i32} : () -> i32
-  // expected-error @+1 {{'spv.AccessChain' op index 12 out of bounds for '!spv.struct<f32, !spv.array<4 x f32>>'}}
   %0 = spv.Variable : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
+  // expected-error @+1 {{'spv.AccessChain' op index 12 out of bounds for '!spv.struct<f32, !spv.array<4 x f32>>'}}
   %1 = spv.AccessChain %0[%index0, %index0] : !spv.ptr<!spv.struct<f32, !spv.array<4xf32>>, Function>
   return
 }
@@ -111,8 +111,8 @@ func @access_chain_out_of_bounds() -> () {
 // -----
 
 func @access_chain_invalid_accessing_type(%index0 : i32) -> () {
-  // expected-error @+1 {{cannot extract from non-composite type 'f32' with index 0}}
   %0 = spv.Variable : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
+  // expected-error @+1 {{cannot extract from non-composite type 'f32' with index 0}}
   %1 = spv.AccessChain %0[%index, %index0, %index0] : !spv.ptr<!spv.array<4x!spv.array<4xf32>>, Function>
   return