diff --git a/Test/baseResults/negativeArraySize.comp.out b/Test/baseResults/negativeArraySize.comp.out new file mode 100644 index 00000000..ccbabf5f --- /dev/null +++ b/Test/baseResults/negativeArraySize.comp.out @@ -0,0 +1,24 @@ +negativeArraySize.comp +Warning, version 310 is not yet complete; most version-specific features are present, but some are missing. +ERROR: 0:9: '' : array size must be a positive integer +ERROR: 1 compilation errors. No code generated. + + +Shader version: 310 +local_size = (1, 1, 1) +ERROR: node is still EOpNull! +0:7 Function Definition: main( (global void) +0:7 Function Parameters: +0:? Linker Objects + + +Linked compute stage: + + +Shader version: 310 +local_size = (1, 1, 1) +ERROR: node is still EOpNull! +0:7 Function Definition: main( (global void) +0:7 Function Parameters: +0:? Linker Objects + diff --git a/Test/negativeArraySize.comp b/Test/negativeArraySize.comp new file mode 100644 index 00000000..20636c0a --- /dev/null +++ b/Test/negativeArraySize.comp @@ -0,0 +1,10 @@ +#version 310 es + +#ifdef GL_ES +precision mediump float; +#endif + +void main() +{ + float f[-2]; // cannot declare arrays with negative size +} diff --git a/Test/testlist b/Test/testlist index d60fbca4..1be8b8e2 100644 --- a/Test/testlist +++ b/Test/testlist @@ -128,4 +128,5 @@ varyingArrayIndirect.frag voidFunction.frag whileLoop.frag nonVulkan.frag +negativeArraySize.comp spv.atomic.comp diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index b9d77f2d..a98b3429 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -2869,13 +2869,14 @@ bool TParseContext::containsFieldWithBasicType(const TType& type, TBasicType bas void TParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair) { bool isConst = false; - sizePair.size = 1; sizePair.node = nullptr; + int size = 1; + TIntermConstantUnion* constant = expr->getAsConstantUnion(); if (constant) { // handle true (non-specialization) constant - sizePair.size = constant->getConstArray()[0].getIConst(); + size = constant->getConstArray()[0].getIConst(); isConst = true; } else { // see if it's a specialization constant instead @@ -2884,16 +2885,18 @@ void TParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TA sizePair.node = expr; TIntermSymbol* symbol = expr->getAsSymbolNode(); if (symbol && symbol->getConstArray().size() > 0) - sizePair.size = symbol->getConstArray()[0].getIConst(); + size = symbol->getConstArray()[0].getIConst(); } } + sizePair.size = size; + if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) { error(loc, "array size must be a constant integer expression", "", ""); return; } - if (sizePair.size <= 0) { + if (size <= 0) { error(loc, "array size must be a positive integer", "", ""); return; }