xref: /aosp_15_r20/external/skia/resources/sksl/shared/TernarySideEffects.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorGreen, colorRed;
2
3half4 main(float2 coords) {
4    // Verify that side effects in the not-taken side of a ternary do not occur.
5    half x = 1, y = 1;
6    (x == y) ? (x += 1) : (y += 1);  // TRUE,   x=2 y=1
7    (x == y) ? (x += 3) : (y += 3);  // FALSE,  x=2 y=4
8    (x <  y) ? (x += 5) : (y += 5);  // TRUE,   x=7 y=4
9    (y >= x) ? (x += 9) : (y += 9);  // FALSE,  x=7 y=13
10    (x != y) ? (x += 1) : (y     );  // TRUE,   x=8 y=13
11    (x == y) ? (x += 2) : (y     );  // FALSE,  x=8 y=13
12    (x != y) ? (x     ) : (y += 3);  // TRUE,   x=8 y=13
13    (x == y) ? (x     ) : (y += 4);  // FALSE,  x=8 y=17
14
15    // Verify that side effects in the test-condition of a ternary always occur before the if-true
16    // and if-false expressions are evaluated.
17    bool b = true;
18    bool c = (b = false) ? false : b;
19
20    return c ? colorRed : (x == 8 && y == 17) ? colorGreen : colorRed;
21}
22