diff --git a/Test/baseResults/spv.bufferhandle_Error.frag.out b/Test/baseResults/spv.bufferhandle_Error.frag.out index a1ee9a4bb..345bfa599 100644 --- a/Test/baseResults/spv.bufferhandle_Error.frag.out +++ b/Test/baseResults/spv.bufferhandle_Error.frag.out @@ -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 diff --git a/Test/spv.bufferhandle_Error.frag b/Test/spv.bufferhandle_Error.frag index 98cbac86c..034e05449 100644 --- a/Test/spv.bufferhandle_Error.frag +++ b/Test/spv.bufferhandle_Error.frag @@ -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() { diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index ea89e4307..117c16449 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -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()))