skia2/resources/sksl/folding/IntFoldingES3.sksl
Brian Osman a7eb6819da SkSL: Do left-shift constant-folding with unsigned integers
Every GPU API defines things this way, but C++ does not (until C++20).
Forcing the shift-as-unsigned prevents UBSAN warnings.

Bug: oss-fuzz:29093
Change-Id: Ie82e25c46e28446ffc42a40172ca6b272bf1c362
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/363937
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-02-01 19:51:28 +00:00

27 lines
616 B
Plaintext

uniform half4 colorRed, colorGreen;
bool test() {
bool ok = true;
int x = 12 | 6;
ok = ok && (x == 14);
x = 254 & 7;
ok = ok && (x == 6);
x = 2 ^ 7;
ok = ok && (x == 5);
x = 1 << 4;
ok = ok && (x == 16);
// Left-shifting a negative integer is undefined in C++, but allowed in GPU shading languages.
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29093
x = -2 << 2;
ok = ok && (x == -8);
x = 128 >> 2;
ok = ok && (x == 32);
x = 123 % 45;
ok = ok && (x == 33);
return ok;
}
half4 main() {
return test() ? colorGreen : colorRed;
}