Improve array-indexing tests.

Previously, we didn't have tests which leveraged constant-evaluation of
array indexing (because we didn't support it), and our test files
commingled constant-indexing into vectors with constant-indexing into
arrays.

The test files now separate vector- and array-handling into separate
tests, and a ton of new cases have been added to ArrayFolding. The
ArrayFolding tests now require constant-evaluation of array indexing,
so they fail in this CL, but will be fixed in the followup CL.

Change-Id: I3b663e743d97d6db80627bc9b7808f88c99917a7
Bug: skia:12472
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/469528
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2021-11-10 09:58:32 -05:00 committed by SkCQ
parent a8888cff15
commit 0b84159e3b
12 changed files with 159 additions and 115 deletions

View File

@ -9,6 +9,7 @@ sksl_error_tests = [
"/sksl/errors/ArgumentModifiers.sksl",
"/sksl/errors/ArrayConstructorElementCount.sksl",
"/sksl/errors/ArrayIndexOutOfRange.sksl",
"/sksl/errors/ArrayInlinedIndexOutOfRange.sksl",
"/sksl/errors/ArrayNegation.sksl",
"/sksl/errors/ArrayOfInvalidSize.sksl",
"/sksl/errors/ArrayOfVoid.sksl",
@ -65,7 +66,6 @@ sksl_error_tests = [
"/sksl/errors/InVarWithInitializerExpression.sksl",
"/sksl/errors/IncompleteExpression.sksl",
"/sksl/errors/IncompleteFunctionCall.sksl",
"/sksl/errors/IndexOutOfVectorRange.sksl",
"/sksl/errors/InterfaceBlockScope.sksl",
"/sksl/errors/InterfaceBlockStorageModifiers.sksl",
"/sksl/errors/InterfaceBlockWithNoMembers.sksl",
@ -214,6 +214,8 @@ sksl_error_tests = [
"/sksl/errors/UnscopedVariableInIf.sksl",
"/sksl/errors/UnscopedVariableInWhile.sksl",
"/sksl/errors/UsingInvalidValue.sksl",
"/sksl/errors/VectorIndexOutOfRange.sksl",
"/sksl/errors/VectorInlinedIndexOutOfRange.sksl",
"/sksl/errors/VectorSlice.sksl",
"/sksl/errors/VertexEarlyReturn.vert",
"/sksl/errors/WhileTypeMismatch.sksl",

View File

@ -5,72 +5,3 @@ void array_123 () { half4x4 a[123]; half4x4 v = a[123]; }
void array_huge () { int4 a[123]; int4 v = a[1000000000]; }
void array_overflow () { half3 a[123]; half3 v = a[3000000000]; }
void array_no_index () { int a[123]; int v = a[]; }
void half4_neg1() { half4 h; half v = h[-1]; }
void half4_0() { half4 h; half v = h[0]; }
void half4_1() { half4 h; half v = h[1]; }
void half4_2() { half4 h; half v = h[2]; }
void half4_3() { half4 h; half v = h[3]; }
void half4_4() { half4 h; half v = h[4]; }
void half4_huge() { half4 h; half v = h[1000000000]; }
void half3_neg1() { half3 h; half v = h[-1]; }
void half3_0() { half3 h; half v = h[0]; }
void half3_1() { half3 h; half v = h[1]; }
void half3_2() { half3 h; half v = h[2]; }
void half3_3() { half3 h; half v = h[3]; }
void half3_4() { half3 h; half v = h[4]; }
void half3_huge() { half3 h; half v = h[1000000000]; }
void half2_neg1() { half2 h; half v = h[-1]; }
void half2_0() { half2 h; half v = h[0]; }
void half2_1() { half2 h; half v = h[1]; }
void half2_2() { half2 h; half v = h[2]; }
void half2_3() { half2 h; half v = h[3]; }
void half2_4() { half2 h; half v = h[4]; }
void half2_huge() { half2 h; half v = h[1000000000]; }
void half2x4_neg1() { half2x4 m; half4 v = m[-1]; }
void half2x4_0() { half2x4 m; half4 v = m[0]; }
void half2x4_1() { half2x4 m; half4 v = m[1]; }
void half2x4_2() { half2x4 m; half4 v = m[2]; }
void half2x4_3() { half2x4 m; half4 v = m[3]; }
void half2x4_4() { half2x4 m; half4 v = m[4]; }
void half2x4_huge() { half2x4 m; half4 v = m[1000000000]; }
void half3x3_neg1() { half3x3 m; half3 v = m[-1]; }
void half3x3_0() { half3x3 m; half3 v = m[0]; }
void half3x3_1() { half3x3 m; half3 v = m[1]; }
void half3x3_2() { half3x3 m; half3 v = m[2]; }
void half3x3_3() { half3x3 m; half3 v = m[3]; }
void half3x3_4() { half3x3 m; half3 v = m[4]; }
void half3x3_huge() { half3x3 m; half3 v = m[1000000000]; }
void half4x2_neg1() { half4x2 m; half2 v = m[-1]; }
void half4x2_0() { half4x2 m; half2 v = m[0]; }
void half4x2_1() { half4x2 m; half2 v = m[1]; }
void half4x2_2() { half4x2 m; half2 v = m[2]; }
void half4x2_3() { half4x2 m; half2 v = m[3]; }
void half4x2_4() { half4x2 m; half2 v = m[4]; }
void half4x2_huge() { half4x2 m; half2 v = m[1000000000]; }
void half2_neg1_constidx() { half2 h; const int INDEX = -1; half v = h[INDEX]; }
void half2_0_constidx() { half2 h; const int INDEX = 0; half v = h[INDEX]; }
void half2_1_constidx() { half2 h; const int INDEX = 1; half v = h[INDEX]; }
void half2_2_constidx() { half2 h; const int INDEX = 2; half v = h[INDEX]; }
void half2_huge_constidx() { half2 h; const int INDEX = 1000000000; half v = h[INDEX]; }
void half3_neg1_constidx() { half3 h; const int INDEX = -1; half v = h[INDEX]; }
void half3_0_constidx() { half3 h; const int INDEX = 0; half v = h[INDEX]; }
void half3_1_constidx() { half3 h; const int INDEX = 1; half v = h[INDEX]; }
void half3_2_constidx() { half3 h; const int INDEX = 2; half v = h[INDEX]; }
void half3_3_constidx() { half3 h; const int INDEX = 3; half v = h[INDEX]; }
void half3_huge_constidx() { half3 h; const int INDEX = 1000000000; half v = h[INDEX]; }
void half4_neg1_constidx() { half4 h; const int INDEX = -1; half v = h[INDEX]; }
void half4_0_constidx() { half4 h; const int INDEX = 0; half v = h[INDEX]; }
void half4_1_constidx() { half4 h; const int INDEX = 1; half v = h[INDEX]; }
void half4_2_constidx() { half4 h; const int INDEX = 2; half v = h[INDEX]; }
void half4_3_constidx() { half4 h; const int INDEX = 3; half v = h[INDEX]; }
void half4_4_constidx() { half4 h; const int INDEX = 4; half v = h[INDEX]; }
void half4_huge_constidx() { half4 h; const int INDEX = 1000000000; half v = h[INDEX]; }

View File

@ -0,0 +1,13 @@
uniform half4 colorGreen, colorRed;
const int[3] values = int[3](1, 1, 1);
inline int indexArray(int index) {
return values[index];
}
half4 main(float2 coords) {
int ok = indexArray(0) + indexArray(1) + indexArray(2);
int undefined = indexArray(-1) + indexArray(3);
return colorGreen;
}

View File

@ -0,0 +1,68 @@
void half4_neg1() { half4 h; half v = h[-1]; }
void half4_0() { half4 h; half v = h[0]; }
void half4_1() { half4 h; half v = h[1]; }
void half4_2() { half4 h; half v = h[2]; }
void half4_3() { half4 h; half v = h[3]; }
void half4_4() { half4 h; half v = h[4]; }
void half4_huge() { half4 h; half v = h[1000000000]; }
void half3_neg1() { half3 h; half v = h[-1]; }
void half3_0() { half3 h; half v = h[0]; }
void half3_1() { half3 h; half v = h[1]; }
void half3_2() { half3 h; half v = h[2]; }
void half3_3() { half3 h; half v = h[3]; }
void half3_4() { half3 h; half v = h[4]; }
void half3_huge() { half3 h; half v = h[1000000000]; }
void half2_neg1() { half2 h; half v = h[-1]; }
void half2_0() { half2 h; half v = h[0]; }
void half2_1() { half2 h; half v = h[1]; }
void half2_2() { half2 h; half v = h[2]; }
void half2_3() { half2 h; half v = h[3]; }
void half2_4() { half2 h; half v = h[4]; }
void half2_huge() { half2 h; half v = h[1000000000]; }
void half2x4_neg1() { half2x4 m; half4 v = m[-1]; }
void half2x4_0() { half2x4 m; half4 v = m[0]; }
void half2x4_1() { half2x4 m; half4 v = m[1]; }
void half2x4_2() { half2x4 m; half4 v = m[2]; }
void half2x4_3() { half2x4 m; half4 v = m[3]; }
void half2x4_4() { half2x4 m; half4 v = m[4]; }
void half2x4_huge() { half2x4 m; half4 v = m[1000000000]; }
void half3x3_neg1() { half3x3 m; half3 v = m[-1]; }
void half3x3_0() { half3x3 m; half3 v = m[0]; }
void half3x3_1() { half3x3 m; half3 v = m[1]; }
void half3x3_2() { half3x3 m; half3 v = m[2]; }
void half3x3_3() { half3x3 m; half3 v = m[3]; }
void half3x3_4() { half3x3 m; half3 v = m[4]; }
void half3x3_huge() { half3x3 m; half3 v = m[1000000000]; }
void half4x2_neg1() { half4x2 m; half2 v = m[-1]; }
void half4x2_0() { half4x2 m; half2 v = m[0]; }
void half4x2_1() { half4x2 m; half2 v = m[1]; }
void half4x2_2() { half4x2 m; half2 v = m[2]; }
void half4x2_3() { half4x2 m; half2 v = m[3]; }
void half4x2_4() { half4x2 m; half2 v = m[4]; }
void half4x2_huge() { half4x2 m; half2 v = m[1000000000]; }
void half2_neg1_constidx() { half2 h; const int INDEX = -1; half v = h[INDEX]; }
void half2_0_constidx() { half2 h; const int INDEX = 0; half v = h[INDEX]; }
void half2_1_constidx() { half2 h; const int INDEX = 1; half v = h[INDEX]; }
void half2_2_constidx() { half2 h; const int INDEX = 2; half v = h[INDEX]; }
void half2_huge_constidx() { half2 h; const int INDEX = 1000000000; half v = h[INDEX]; }
void half3_neg1_constidx() { half3 h; const int INDEX = -1; half v = h[INDEX]; }
void half3_0_constidx() { half3 h; const int INDEX = 0; half v = h[INDEX]; }
void half3_1_constidx() { half3 h; const int INDEX = 1; half v = h[INDEX]; }
void half3_2_constidx() { half3 h; const int INDEX = 2; half v = h[INDEX]; }
void half3_3_constidx() { half3 h; const int INDEX = 3; half v = h[INDEX]; }
void half3_huge_constidx() { half3 h; const int INDEX = 1000000000; half v = h[INDEX]; }
void half4_neg1_constidx() { half4 h; const int INDEX = -1; half v = h[INDEX]; }
void half4_0_constidx() { half4 h; const int INDEX = 0; half v = h[INDEX]; }
void half4_1_constidx() { half4 h; const int INDEX = 1; half v = h[INDEX]; }
void half4_2_constidx() { half4 h; const int INDEX = 2; half v = h[INDEX]; }
void half4_3_constidx() { half4 h; const int INDEX = 3; half v = h[INDEX]; }
void half4_4_constidx() { half4 h; const int INDEX = 4; half v = h[INDEX]; }
void half4_huge_constidx() { half4 h; const int INDEX = 1000000000; half v = h[INDEX]; }

View File

@ -1,11 +1,35 @@
uniform half4 colorRed, colorGreen;
int globalValue = 0;
noinline int side_effecting(int value) {
globalValue++;
return value;
}
bool test() {
const int x [3] = int[3](1, 2, 3);
const int xx[3] = int[3](1, 2, 3);
const int y [3] = int[3](1, 2, 4);
return (x == xx) && !(x != xx) && (x != y) && !(x == y);
const int z = x[0] - y[0];
const int a [x[z]] = int[1](1);
const int b [x[x[z]]] = int[2](1, 2);
const int c [x[x[x[z]]]] = int[3](1, 2, 3);
// The unreferenced array elements are safe to eliminate.
int flatten0 = (int[3](side_effecting(1), 2, 3))[0];
int flatten1 = (int[3](1, side_effecting(2), 3))[1];
int flatten2 = (int[3](1, 2, side_effecting(3)))[2];
// Some unreferenced array elements have a side effect and are not safe to eliminate.
int noFlatten0 = (int[3](1, side_effecting(2), 3))[0];
int noFlatten1 = (int[3](side_effecting(1), 2, 3))[1];
int noFlatten2 = (int[3](side_effecting(1), side_effecting(2), 3))[2];
return (x == xx) && !(x != xx) && (x != y) && !(x == y) &&
(x[0] == y[0]) && (c == x) &&
(flatten0 == noFlatten0) && (flatten1 == noFlatten1) && (flatten2 == noFlatten2);
}
half4 main(float2 coords) {

View File

@ -5,37 +5,4 @@ error: 4: index 123 out of range for 'half4x4[123]'
error: 5: index 1000000000 out of range for 'int4[123]'
error: 6: index 3000000000 out of range for 'half3[123]'
error: 7: missing index in '[]'
error: 9: index -1 out of range for 'half4'
error: 14: index 4 out of range for 'half4'
error: 15: index 1000000000 out of range for 'half4'
error: 17: index -1 out of range for 'half3'
error: 21: index 3 out of range for 'half3'
error: 22: index 4 out of range for 'half3'
error: 23: index 1000000000 out of range for 'half3'
error: 25: index -1 out of range for 'half2'
error: 28: index 2 out of range for 'half2'
error: 29: index 3 out of range for 'half2'
error: 30: index 4 out of range for 'half2'
error: 31: index 1000000000 out of range for 'half2'
error: 33: index -1 out of range for 'half2x4'
error: 36: index 2 out of range for 'half2x4'
error: 37: index 3 out of range for 'half2x4'
error: 38: index 4 out of range for 'half2x4'
error: 39: index 1000000000 out of range for 'half2x4'
error: 41: index -1 out of range for 'half3x3'
error: 45: index 3 out of range for 'half3x3'
error: 46: index 4 out of range for 'half3x3'
error: 47: index 1000000000 out of range for 'half3x3'
error: 49: index -1 out of range for 'half4x2'
error: 54: index 4 out of range for 'half4x2'
error: 55: index 1000000000 out of range for 'half4x2'
error: 57: index -1 out of range for 'half2'
error: 60: index 2 out of range for 'half2'
error: 61: index 1000000000 out of range for 'half2'
error: 63: index -1 out of range for 'half3'
error: 67: index 3 out of range for 'half3'
error: 68: index 1000000000 out of range for 'half3'
error: 70: index -1 out of range for 'half4'
error: 75: index 4 out of range for 'half4'
error: 76: index 1000000000 out of range for 'half4'
38 errors
5 errors

View File

@ -0,0 +1,5 @@
### Compilation failed:
error: 6: index -1 out of range for 'int[3]'
error: 6: index 3 out of range for 'int[3]'
2 errors

View File

@ -1,4 +0,0 @@
### Compilation failed:
error: 1: expected an identifier, but found 'asm'
1 error

View File

@ -0,0 +1,36 @@
### Compilation failed:
error: 1: index -1 out of range for 'half4'
error: 6: index 4 out of range for 'half4'
error: 7: index 1000000000 out of range for 'half4'
error: 9: index -1 out of range for 'half3'
error: 13: index 3 out of range for 'half3'
error: 14: index 4 out of range for 'half3'
error: 15: index 1000000000 out of range for 'half3'
error: 17: index -1 out of range for 'half2'
error: 20: index 2 out of range for 'half2'
error: 21: index 3 out of range for 'half2'
error: 22: index 4 out of range for 'half2'
error: 23: index 1000000000 out of range for 'half2'
error: 25: index -1 out of range for 'half2x4'
error: 28: index 2 out of range for 'half2x4'
error: 29: index 3 out of range for 'half2x4'
error: 30: index 4 out of range for 'half2x4'
error: 31: index 1000000000 out of range for 'half2x4'
error: 33: index -1 out of range for 'half3x3'
error: 37: index 3 out of range for 'half3x3'
error: 38: index 4 out of range for 'half3x3'
error: 39: index 1000000000 out of range for 'half3x3'
error: 41: index -1 out of range for 'half4x2'
error: 46: index 4 out of range for 'half4x2'
error: 47: index 1000000000 out of range for 'half4x2'
error: 49: index -1 out of range for 'half2'
error: 52: index 2 out of range for 'half2'
error: 53: index 1000000000 out of range for 'half2'
error: 55: index -1 out of range for 'half3'
error: 59: index 3 out of range for 'half3'
error: 60: index 1000000000 out of range for 'half3'
error: 62: index -1 out of range for 'half4'
error: 67: index 4 out of range for 'half4'
error: 68: index 1000000000 out of range for 'half4'
33 errors

View File

@ -1,7 +1,9 @@
### Compilation failed:
out vec4 sk_FragColor;
uniform vec4 colorRed;
uniform vec4 colorGreen;
vec4 main() {
return true ? colorGreen : colorRed;
}
error: 16: array size must be an integer
error: 17: array size must be an integer
error: 17: expected 'int[1]', but found 'int[2]'
error: 18: array size must be an integer
error: 18: expected 'int[1]', but found 'int[3]'
error: 31: unknown identifier 'c'
6 errors