skia2/tests/sksl/shared/SwitchWithLoopsStandaloneSettings.glsl
Arman Uguray 9c242fff99 [sksl] Eliminate unreachable blocks inside switch cases
Added code to remove code within switch statements due to break, return,
and continue statements. The logic is applied conservatively and only
among the statements of an individual switch-case statement without
affecting other cases.

Bug: skia:13484
Change-Id: Id5b936ca91e562a5180a31a039a85de9e093961d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556376
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-07-07 21:23:54 +00:00

46 lines
1008 B
GLSL

out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bool switch_with_continue_in_loop_bi(int x) {
int val = 0;
switch (x) {
case 1:
for (int i = 0;i < 10; ++i) {
++val;
continue;
}
default:
++val;
}
return val == 11;
}
bool loop_with_break_in_switch_bi(int x) {
int val = 0;
for (int i = 0;i < 10; ++i) {
switch (x) {
case 1:
++val;
break;
default:
return false;
}
++val;
}
return val == 20;
}
vec4 main() {
int x = int(colorGreen.y);
int _0_val = 0;
switch (x) {
case 1:
for (int _1_i = 0;_1_i < 10; ++_1_i) {
++_0_val;
break;
}
default:
++_0_val;
}
return (_0_val == 2 && switch_with_continue_in_loop_bi(x)) && loop_with_break_in_switch_bi(x) ? colorGreen : colorRed;
}