Array-sizing bug fix: multiple array initializers of different size in the same declaration.

Handles the case of
    float[] x = float[] (1.0, 2.0, 3.0),
            y = float[] (1.0, 2.0, 3.0, 4.0);
where a shallow copy of the type arrayness from the left-most float[]
was getting used twice.
This commit is contained in:
John Kessenich 2015-11-28 12:52:29 -07:00
parent dad6408542
commit 989df85dcd
5 changed files with 74 additions and 5 deletions

View File

@ -174,3 +174,14 @@ layout(std430) uniform B430 { int a; } B430i; // ERROR
struct SNA {
int a[]; // ERROR
};
void fooDeeparray()
{
float[] x = float[] (1.0, 2.0, 3.0),
y = float[] (1.0, 2.0, 3.0, 4.0);
float xp[3], yp[4];
xp = x;
yp = y;
xp = y; // ERROR, wrong size
yp = x; // ERROR, wrong size
}

View File

@ -41,7 +41,9 @@ ERROR: 0:170: 'Bfoo' : cannot add storage, auxiliary, memory, interpolation, lay
ERROR: 0:172: 'std430' : not supported for this version or the enabled extensions
ERROR: 0:172: 'std430 on a uniform block' : not supported with this profile: es
ERROR: 0:175: '' : array size required
ERROR: 42 compilation errors. No code generated.
ERROR: 0:185: 'assign' : cannot convert from 'temp 4-element array of highp float' to 'temp 3-element array of highp float'
ERROR: 0:186: 'assign' : cannot convert from 'temp 3-element array of highp float' to 'temp 4-element array of highp float'
ERROR: 44 compilation errors. No code generated.
Shader version: 300
@ -262,6 +264,31 @@ ERROR: node is still EOpNull!
0:158 Branch: Return with expression
0:158 Constant:
0:158 2 (const int)
0:178 Function Definition: fooDeeparray( (global void)
0:178 Function Parameters:
0:181 Sequence
0:181 Sequence
0:180 move second child to first child (temp 3-element array of highp float)
0:180 'x' (temp 3-element array of highp float)
0:180 Constant:
0:180 1.000000
0:180 2.000000
0:180 3.000000
0:181 move second child to first child (temp 4-element array of highp float)
0:181 'y' (temp 4-element array of highp float)
0:181 Constant:
0:181 1.000000
0:181 2.000000
0:181 3.000000
0:181 4.000000
0:183 move second child to first child (temp 3-element array of highp float)
0:183 'xp' (temp 3-element array of highp float)
0:183 'x' (temp 3-element array of highp float)
0:184 move second child to first child (temp 4-element array of highp float)
0:184 'yp' (temp 4-element array of highp float)
0:184 'y' (temp 4-element array of highp float)
0:185 'xp' (temp 3-element array of highp float)
0:186 'yp' (temp 4-element array of highp float)
0:? Linker Objects
0:? 'm43' (uniform highp 4X3 matrix of float)
0:? 'm33' (uniform highp 3X3 matrix of float)
@ -521,6 +548,31 @@ ERROR: node is still EOpNull!
0:158 Branch: Return with expression
0:158 Constant:
0:158 2 (const int)
0:178 Function Definition: fooDeeparray( (global void)
0:178 Function Parameters:
0:181 Sequence
0:181 Sequence
0:180 move second child to first child (temp 3-element array of highp float)
0:180 'x' (temp 3-element array of highp float)
0:180 Constant:
0:180 1.000000
0:180 2.000000
0:180 3.000000
0:181 move second child to first child (temp 4-element array of highp float)
0:181 'y' (temp 4-element array of highp float)
0:181 Constant:
0:181 1.000000
0:181 2.000000
0:181 3.000000
0:181 4.000000
0:183 move second child to first child (temp 3-element array of highp float)
0:183 'xp' (temp 3-element array of highp float)
0:183 'x' (temp 3-element array of highp float)
0:184 move second child to first child (temp 4-element array of highp float)
0:184 'yp' (temp 4-element array of highp float)
0:184 'y' (temp 4-element array of highp float)
0:185 'xp' (temp 3-element array of highp float)
0:186 'yp' (temp 4-element array of highp float)
0:? Linker Objects
0:? 'm43' (uniform highp 4X3 matrix of float)
0:? 'm33' (uniform highp 3X3 matrix of float)

View File

@ -930,7 +930,7 @@ public:
qualifier.precision = p;
assert(p >= 0 && p <= EpqHigh);
}
// for turning a TPublicType into a TType
// for turning a TPublicType into a TType, using a shallow copy
explicit TType(const TPublicType& p) :
basicType(p.basicType), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), arraySizes(p.arraySizes),
structure(nullptr), fieldName(nullptr), typeName(nullptr)

View File

@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "SPIRV99.798"
#define GLSLANG_DATE "16-Nov-2015"
#define GLSLANG_REVISION "SPIRV99.807"
#define GLSLANG_DATE "28-Nov-2015"

View File

@ -4447,7 +4447,13 @@ void TParseContext::declareTypeDefaults(const TSourceLoc& loc, const TPublicType
//
TIntermNode* TParseContext::declareVariable(const TSourceLoc& loc, TString& identifier, const TPublicType& publicType, TArraySizes* arraySizes, TIntermTyped* initializer)
{
TType type(publicType);
TType type(publicType); // shallow copy; 'type' shares the arrayness and structure definition with 'publicType'
if (type.isImplicitlySizedArray()) {
// Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b
// of different sizes, for this case sharing the shallow copy of arrayness
// with the publicType oversubscribes it, so get a deep copy of the arrayness.
type.newArraySizes(*publicType.arraySizes);
}
if (voidErrorCheck(loc, identifier, type.getBasicType()))
return nullptr;