mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-08 11:30:06 +00:00
fix check for non-positive array size
This commit is contained in:
parent
d3d3ce7160
commit
5bdf49cdc8
24
Test/baseResults/negativeArraySize.comp.out
Normal file
24
Test/baseResults/negativeArraySize.comp.out
Normal 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
|
||||
|
10
Test/negativeArraySize.comp
Normal file
10
Test/negativeArraySize.comp
Normal 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
|
||||
}
|
@ -128,4 +128,5 @@ varyingArrayIndirect.frag
|
||||
voidFunction.frag
|
||||
whileLoop.frag
|
||||
nonVulkan.frag
|
||||
negativeArraySize.comp
|
||||
spv.atomic.comp
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user