fix check for non-positive array size

This commit is contained in:
GregF 2016-05-09 17:07:04 -06:00
parent d3d3ce7160
commit 5bdf49cdc8
4 changed files with 42 additions and 4 deletions

View File

@ -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

View File

@ -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
}

View File

@ -128,4 +128,5 @@ varyingArrayIndirect.frag
voidFunction.frag
whileLoop.frag
nonVulkan.frag
negativeArraySize.comp
spv.atomic.comp

View File

@ -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;
}