Commit 0876a582 by John Kessenich

Misc. constant-folding fixes: Check % for 0, mat(mat) constructor, index range…

Misc. constant-folding fixes: Check % for 0, mat(mat) constructor, index range checking (within constant objects). Also, rationalize addConst*() methods. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23973 e7fa87d3-cd2b-0410-9028-fcbf551c1848
parent 6d7fe63d
...@@ -6,12 +6,12 @@ ERROR: 0:31: 'assign' : cannot convert from '4-element array of float' to 'unsi ...@@ -6,12 +6,12 @@ ERROR: 0:31: 'assign' : cannot convert from '4-element array of float' to 'unsi
ERROR: 0:33: 'foo' : no matching overloaded function found ERROR: 0:33: 'foo' : no matching overloaded function found
ERROR: 0:42: '[' : array index out of range '5' ERROR: 0:42: '[' : array index out of range '5'
ERROR: 0:45: '[' : array index out of range '1000' ERROR: 0:45: '[' : array index out of range '1000'
ERROR: 0:46: '[' : array index out of range '-1' ERROR: 0:46: '[' : index out of range '-1'
ERROR: 0:52: '[' : array index '2' out of range ERROR: 0:52: '[' : array index out of range '2'
ERROR: 0:54: 'const' : non-matching or non-convertible constant type for const initializer ERROR: 0:54: 'const' : non-matching or non-convertible constant type for const initializer
ERROR: 0:56: '=' : cannot convert from 'const 2-element array of int' to '3-element array of int' ERROR: 0:56: '=' : cannot convert from 'const 2-element array of int' to '3-element array of int'
ERROR: 0:57: '[]' : scalar integer expression required ERROR: 0:57: '[]' : scalar integer expression required
ERROR: 0:57: '[' : array index out of range '-858993459' ERROR: 0:57: '[' : index out of range '-858993459'
ERROR: 0:58: '[]' : scalar integer expression required ERROR: 0:58: '[]' : scalar integer expression required
ERROR: 14 compilation errors. No code generated. ERROR: 14 compilation errors. No code generated.
...@@ -157,7 +157,7 @@ ERROR: node is still EOpNull! ...@@ -157,7 +157,7 @@ ERROR: node is still EOpNull!
0:52 add second child into first child (int) 0:52 add second child into first child (int)
0:52 'sum' (int) 0:52 'sum' (int)
0:52 Constant: 0:52 Constant:
0:52 3 (const int) 0:52 2 (const int)
0:55 Sequence 0:55 Sequence
0:55 move second child to first child (2-element array of int) 0:55 move second child to first child (2-element array of int)
0:55 'ica' (2-element array of int) 0:55 'ica' (2-element array of int)
......
...@@ -14,7 +14,7 @@ ERROR: 0:31: 'arrayed constructor' : not supported for this version or the enabl ...@@ -14,7 +14,7 @@ ERROR: 0:31: 'arrayed constructor' : not supported for this version or the enabl
ERROR: 0:31: 'array comparison' : not supported for this version or the enabled extensions ERROR: 0:31: 'array comparison' : not supported for this version or the enabled extensions
ERROR: 0:35: '[' : array index out of range '5' ERROR: 0:35: '[' : array index out of range '5'
ERROR: 0:38: '[' : array index out of range '1000' ERROR: 0:38: '[' : array index out of range '1000'
ERROR: 0:39: '[' : array index out of range '-1' ERROR: 0:39: '[' : index out of range '-1'
ERROR: 17 compilation errors. No code generated. ERROR: 17 compilation errors. No code generated.
ERROR: node is still EOpNull! ERROR: node is still EOpNull!
......
Warning, version 430 is not yet complete; some version-specific features are present, but many are missing. Warning, version 430 is not yet complete; some version-specific features are present, but many are missing.
0:? Sequence ERROR: 0:109: '[' : index out of range '-1'
ERROR: 0:110: '[' : vector index out of range '4'
ERROR: 0:111: '[' : index out of range '-2'
ERROR: 0:112: '[' : index out of range '-1'
ERROR: 0:113: '[' : vector index out of range '3'
ERROR: 0:114: '[' : matrix index out of range '3'
ERROR: 6 compilation errors. No code generated.
ERROR: node is still EOpNull!
0:28 Function Definition: main( (void) 0:28 Function Definition: main( (void)
0:28 Function Parameters: 0:28 Function Parameters:
0:30 Sequence 0:30 Sequence
...@@ -163,6 +171,51 @@ Warning, version 430 is not yet complete; some version-specific features are pre ...@@ -163,6 +171,51 @@ Warning, version 430 is not yet complete; some version-specific features are pre
0:81 0 (const int) 0:81 0 (const int)
0:81 Constant: 0:81 Constant:
0:81 7.000000 0:81 7.000000
0:82 Constant:
0:82 2 (const int)
0:83 Constant:
0:83 2147483647 (const int)
0:84 Constant:
0:84 1.#INF00
0:88 Constant:
0:88 2 (const uint)
0:88 3 (const uint)
0:89 Constant:
0:89 0 (const uint)
0:90 Constant:
0:90 6 (const uint)
0:90 7 (const uint)
0:103 Function Definition: foo2( (void)
0:103 Function Parameters:
0:105 Sequence
0:105 direct index (float)
0:105 'a1' (1-element array of float)
0:105 Constant:
0:105 0 (const int)
0:106 direct index (float)
0:106 'a2' (2-element array of float)
0:106 Constant:
0:106 0 (const int)
0:107 direct index (float)
0:107 'a3' (4-element array of float)
0:107 Constant:
0:107 0 (const int)
0:108 direct index (float)
0:108 'a4' (2-element array of float)
0:108 Constant:
0:108 0 (const int)
0:109 Constant:
0:109 1.000000
0:110 Constant:
0:110 5.000000
0:111 Constant:
0:111 2.000000
0:112 Constant:
0:112 3.000000
0:113 Constant:
0:113 0.000000
0:114 Constant:
0:114 0.000000
0:? Linker Objects 0:? Linker Objects
0:? 'a' (const int) 0:? 'a' (const int)
0:? 1 (const int) 0:? 1 (const int)
...@@ -209,4 +262,32 @@ Warning, version 430 is not yet complete; some version-specific features are pre ...@@ -209,4 +262,32 @@ Warning, version 430 is not yet complete; some version-specific features are pre
0:? 6.000000 0:? 6.000000
0:? 7.000000 0:? 7.000000
0:? 8.000000 0:? 8.000000
0:? 'm2' (const 2X2 matrix of float)
0:? 2.000000
0:? 3.000000
0:? 4.000000
0:? 5.000000
0:? 'm3' (const 3X3 matrix of float)
0:? 2.000000
0:? 3.000000
0:? 0.000000
0:? 4.000000
0:? 5.000000
0:? 0.000000
0:? 0.000000
0:? 0.000000
0:? 1.000000
0:? 'mc' (const int)
0:? 1 (const int)
0:? 'a1' (1-element array of float)
0:? 'a2' (2-element array of float)
0:? 'a3' (4-element array of float)
0:? 'v2' (const 2-component vector of float)
0:? 1.000000
0:? 2.000000
0:? 'v3' (const 3-component vector of float)
0:? 3.000000
0:? 4.000000
0:? 5.000000
0:? 'a4' (2-element array of float)
...@@ -3,8 +3,8 @@ ERROR: 0:7: 'const' : non-matching or non-convertible constant type for const in ...@@ -3,8 +3,8 @@ ERROR: 0:7: 'const' : non-matching or non-convertible constant type for const in
ERROR: 0:17: 'assign' : cannot convert from '2-component vector of float' to '3-component vector of float' ERROR: 0:17: 'assign' : cannot convert from '2-component vector of float' to '3-component vector of float'
ERROR: 0:18: 'assign' : cannot convert from '2-component vector of float' to '3-component vector of float' ERROR: 0:18: 'assign' : cannot convert from '2-component vector of float' to '3-component vector of float'
ERROR: 0:19: '.' : field selection not allowed on matrix ERROR: 0:19: '.' : field selection not allowed on matrix
ERROR: 0:21: '[' : index out of range '2' ERROR: 0:21: '[' : matrix index out of range '2'
ERROR: 0:21: '[' : index out of range '4' ERROR: 0:21: '[' : vector index out of range '4'
ERROR: 7 compilation errors. No code generated. ERROR: 7 compilation errors. No code generated.
ERROR: node is still EOpNull! ERROR: node is still EOpNull!
......
...@@ -79,4 +79,37 @@ void foo() ...@@ -79,4 +79,37 @@ void foo()
{ {
float a[s.iv2.y]; // 3 element array float a[s.iv2.y]; // 3 element array
a[0] = s.m[1].z; // 7.0 a[0] = s.m[1].z; // 7.0
b % 0; // int
b / 0;
e / 0;
const uint ua = 5;
const uvec2 ub = uvec2(6, 7);
const uint uc = 8;
ub % 4u;
0u % uc;
ub % 0u;
} }
const mat2 m2 = mat2(2, 3, 4, 5);
const mat3 m3 = mat3(m2);
const int mc = int(m3[2][2]);
float a1[mc];
float a2[int(m3[2][1]) + 2]; // size 2
float a3[int(m3[1][0])]; // size 4
const vec2 v2 = vec2(1, 2);
const vec3 v3 = vec3(3, 4, 5);
float a4[uint(mat3(v2, v3, v2, v2)[2][2])]; // size 2
void foo2()
{
a1[0]; // array size 1
a2[0]; // array size 2
a3[0]; // array size 4
a4[0]; // array size 2
v2[-1]; // ERROR
v3[4]; // ERROR
m3[0][-2]; // ERROR
m2[-1][1]; // ERROR
m3[1][3]; // ERROR
m3[3][1]; // ERROR
}
\ No newline at end of file
...@@ -166,7 +166,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -166,7 +166,7 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
case EbtInt: case EbtInt:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == 0) {
newConstArray[i].setIConst(0xEFFFFFFF); newConstArray[i].setIConst(0x7FFFFFFF);
} else } else
newConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst()); newConstArray[i].setIConst(unionArray[i].getIConst() / rightUnionArray[i].getIConst());
break; break;
...@@ -207,8 +207,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -207,8 +207,12 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
break; break;
case EOpMod: case EOpMod:
for (int i = 0; i < objectSize; i++) for (int i = 0; i < objectSize; i++) {
newConstArray[i] = unionArray[i] % rightUnionArray[i]; if (rightUnionArray[i] == 0)
newConstArray[i] = unionArray[i];
else
newConstArray[i] = unionArray[i] % rightUnionArray[i];
}
break; break;
case EOpRightShift: case EOpRightShift:
......
...@@ -81,6 +81,7 @@ public: ...@@ -81,6 +81,7 @@ public:
void handlePragma(const char **tokens, int numTokens); void handlePragma(const char **tokens, int numTokens);
TIntermTyped* handleVariable(TSourceLoc, TSymbol* symbol, TString* string); TIntermTyped* handleVariable(TSourceLoc, TSymbol* symbol, TString* string);
TIntermTyped* handleBracketDereference(TSourceLoc, TIntermTyped* base, TIntermTyped* index); TIntermTyped* handleBracketDereference(TSourceLoc, TIntermTyped* base, TIntermTyped* index);
void checkIndex(TSourceLoc, const TType&, int& index);
void handleIndexLimits(TSourceLoc, TIntermTyped* base, TIntermTyped* index); void handleIndexLimits(TSourceLoc, TIntermTyped* base, TIntermTyped* index);
void handleInputArrayAccess(TSourceLoc, TIntermTyped* base); void handleInputArrayAccess(TSourceLoc, TIntermTyped* base);
void checkInputArrayConsistency(TSourceLoc, bool tailOnly = false); void checkInputArrayConsistency(TSourceLoc, bool tailOnly = false);
...@@ -159,10 +160,10 @@ public: ...@@ -159,10 +160,10 @@ public:
void updateTypedDefaults(TSourceLoc, const TQualifier&, const TString* id); void updateTypedDefaults(TSourceLoc, const TQualifier&, const TString* id);
void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode); void wrapupSwitchSubsequence(TIntermAggregate* statements, TIntermNode* branchNode);
TIntermNode* addSwitch(TSourceLoc, TIntermTyped* expression, TIntermAggregate* body); TIntermNode* addSwitch(TSourceLoc, TIntermTyped* expression, TIntermAggregate* body);
TIntermTyped* addConstVectorNode(TVectorFields&, TIntermTyped*, TSourceLoc); TIntermTyped* addConstVectorNode(TSourceLoc, TVectorFields&, TIntermTyped*);
TIntermTyped* addConstMatrixNode(int , TIntermTyped*, TSourceLoc); TIntermTyped* addConstMatrixNode(TSourceLoc, int index, TIntermTyped*);
TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc); TIntermTyped* addConstArrayNode(TSourceLoc, int index, TIntermTyped* node);
TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); TIntermTyped* addConstStruct(TSourceLoc, TString& , TIntermTyped*);
void updateMaxArraySize(TSourceLoc, TIntermNode*, int index); void updateMaxArraySize(TSourceLoc, TIntermNode*, int index);
......
...@@ -118,28 +118,23 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) ...@@ -118,28 +118,23 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
if (oit->index >= instanceSize) if (oit->index >= instanceSize)
return; return;
if (!oit->singleConstantParam) { if (! oit->singleConstantParam) {
int size = node->getType().getObjectSize(); int size = node->getType().getObjectSize();
const TConstUnionArray& rightUnionArray = node->getConstArray(); const TConstUnionArray& rightUnionArray = node->getConstArray();
for (int i=0; i < size; i++) { for (int i = 0; i < size; i++) {
if (oit->index >= instanceSize) if (oit->index >= instanceSize)
return; return;
leftUnionArray[oit->index] = rightUnionArray[i]; leftUnionArray[oit->index] = rightUnionArray[i];
(oit->index)++; oit->index++;
} }
} else { } else {
int size, totalSize, matrixRows; int endIndex = oit->index + oit->size;
bool isMatrix = false;
size = oit->size;
matrixRows = oit->matrixRows;
isMatrix = oit->isMatrix;
totalSize = oit->index + size;
const TConstUnionArray& rightUnionArray = node->getConstArray(); const TConstUnionArray& rightUnionArray = node->getConstArray();
if (! isMatrix) { if (! oit->isMatrix) {
int count = 0; int count = 0;
for (int i = oit->index; i < totalSize; i++) { for (int i = oit->index; i < endIndex; i++) {
if (i >= instanceSize) if (i >= instanceSize)
return; return;
...@@ -150,21 +145,41 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it) ...@@ -150,21 +145,41 @@ void ParseConstantUnion(TIntermConstantUnion* node, TIntermTraverser* it)
if (node->getType().getObjectSize() > 1) if (node->getType().getObjectSize() > 1)
count++; count++;
} }
} else { // for matrix constructors } else {
int count = 0; // constructing a matrix, but from what?
int index = oit->index; if (node->isMatrix()) {
for (int i = index; i < totalSize; i++) { // Matrix from a matrix; oit has the outer matrix, node is the argument matrix.
if (i >= instanceSize) // Traverse the outer, potentially bigger matrix, fill in missing pieces with the
return; // identity matrix.
if (index - i == 0 || (i - index) % (matrixRows + 1) == 0 ) for (int c = 0; c < oit->matrixCols; ++c) {
leftUnionArray[i] = rightUnionArray[count]; for (int r = 0; r < oit->matrixRows; ++r) {
else int targetOffset = oit->index + c * oit->matrixRows + r;
leftUnionArray[i].setDConst(0.0); if (r < node->getType().getMatrixRows() && c < node->getType().getMatrixCols()) {
int srcOffset = c * node->getType().getMatrixRows() + r;
(oit->index)++; leftUnionArray[targetOffset] = rightUnionArray[srcOffset];
} else if (r == c)
if (node->getType().getObjectSize() > 1) leftUnionArray[targetOffset].setDConst(1.0);
count++; else
leftUnionArray[targetOffset].setDConst(0.0);
}
}
} else {
// matrix from vector
int count = 0;
int index = oit->index;
for (int i = index; i < endIndex; i++) {
if (i >= instanceSize)
return;
if (i == index || (i - index) % (oit->matrixRows + 1) == 0 )
leftUnionArray[i] = rightUnionArray[count];
else
leftUnionArray[i].setDConst(0.0);
oit->index++;
if (node->getType().getObjectSize() > 1)
count++;
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment