Skip to content

Commit

Permalink
Point to spv.AccessChain when reporting spv.AccessChain errors
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 264742130
  • Loading branch information
antiagainst authored and tensorflower-gardener committed Aug 22, 2019
1 parent 62ced38 commit 1d10eb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions mlir/lib/Dialect/SPIRV/SPIRVOps.cpp
Expand Up @@ -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();
}
Expand Down
14 changes: 7 additions & 7 deletions mlir/test/Dialect/SPIRV/ops.mlir
Expand Up @@ -45,17 +45,17 @@ 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
}

// -----

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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -102,17 +102,17 @@ 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
}

// -----

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

Expand Down

0 comments on commit 1d10eb1

Please sign in to comment.