Skip to content

Commit

Permalink
Fix #2191: Error check for indexing reference containing unsize array.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkslang committed May 1, 2020
1 parent 2ac3c5b commit b5f003d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 7 additions & 4 deletions Test/baseResults/spv.bufferhandle_Error.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ ERROR: 0:14: 'buffer_reference' : can only be used with buffer
ERROR: 0:14: 'buffer_reference' : can only be used with buffer
ERROR: 0:30: 'length' : array must be declared with a size before using this method
ERROR: 0:31: 'length' : array must be declared with a size before using this method
ERROR: 0:35: '=' : cannot convert from 'layout( column_major std430) buffer reference' to ' temp reference'
ERROR: 0:40: 'assign' : cannot convert from 'layout( column_major std430) buffer reference' to 'layout( column_major std430) buffer reference'
ERROR: 0:32: 'buffer reference indexing' : required extension not requested: GL_EXT_buffer_reference2
ERROR: 0:32: '' : cannot index reference to buffer containing an unsized array
ERROR: 0:32: '' : cannot index buffer reference
ERROR: 0:36: '=' : cannot convert from 'layout( column_major std430) buffer reference' to ' temp reference'
ERROR: 0:41: 'assign' : cannot convert from 'layout( column_major std430) buffer reference' to 'layout( column_major std430) buffer reference'
ERROR: 0:42: 'assign' : cannot convert from 'layout( column_major std430) buffer reference' to 'layout( column_major std430) buffer reference'
ERROR: 0:45: '' : syntax error, unexpected LEFT_BRACE, expecting COMMA or SEMICOLON
ERROR: 20 compilation errors. No code generated.
ERROR: 0:43: 'assign' : cannot convert from 'layout( column_major std430) buffer reference' to 'layout( column_major std430) buffer reference'
ERROR: 0:46: '' : syntax error, unexpected LEFT_BRACE, expecting COMMA or SEMICOLON
ERROR: 23 compilation errors. No code generated.


SPIR-V is not generated for failed compile or link
1 change: 1 addition & 0 deletions Test/spv.bufferhandle_Error.frag
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void f()
bufType6 b;
b.x.length();
b4.b6.x.length();
b[2]; // ERROR, can't index due to unsized array
}

void main() {
Expand Down
14 changes: 12 additions & 2 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,18 @@ TIntermTyped* TParseContext::handleBracketDereference(const TSourceLoc& loc, TIn
#ifndef GLSLANG_WEB
if (base->isReference() && ! base->isArray()) {
requireExtensions(loc, 1, &E_GL_EXT_buffer_reference2, "buffer reference indexing");
result = intermediate.addBinaryMath(EOpAdd, base, index, loc);
result->setType(base->getType());
if (base->getType().getReferentType()->containsUnsizedArray()) {
error(loc, "cannot index reference to buffer containing an unsized array", "", "");
result = nullptr;
} else {
result = intermediate.addBinaryMath(EOpAdd, base, index, loc);
if (result != nullptr)
result->setType(base->getType());
}
if (result == nullptr) {
error(loc, "cannot index buffer reference", "", "");
result = intermediate.addConstantUnion(0.0, EbtFloat, loc);
}
return result;
}
if (base->getAsSymbolNode() && isIoResizeArray(base->getType()))
Expand Down

0 comments on commit b5f003d

Please sign in to comment.