Recognize more non-fallthrough cases in switch/case
RemoveSwitchFallThrough now treats cases where break; or return; is
nested inside a block as non-fallthrough to avoid unnecessary
duplication of code. For example, the case 1 below would previously
get treated as fall-through:
switch(foo)
{
case 1:
{
break;
}
default:
break;
}
Now RemoveSwitchFallThrough doesn't do anything to this code.
BUG=chromium:772695
TEST=angle_end2end_tests
Change-Id: Iafab6d8b05c63bcdb5f54834dbc1f41192c31dd4
Reviewed-on: https://chromium-review.googlesource.com/709197
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index 9dcdeaf..ff79852 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -3580,6 +3580,48 @@
ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
}
+// Test switch/case where break/return statements are within blocks.
+TEST_P(GLSLTest_ES3, SwitchBreakOrReturnInsideBlocks)
+{
+ const std::string &fragmentShader =
+ R"(#version 300 es
+
+ precision highp float;
+
+ uniform int u_zero;
+ out vec4 my_FragColor;
+
+ bool test(int n)
+ {
+ switch(n) {
+ case 0:
+ {
+ {
+ break;
+ }
+ }
+ case 1:
+ {
+ return true;
+ }
+ case 2:
+ {
+ n++;
+ }
+ }
+ return false;
+ }
+
+ void main()
+ {
+ my_FragColor = test(u_zero + 1) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
+ })";
+
+ ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
+ drawQuad(program.get(), "inputAttribute", 0.5f);
+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
+}
+
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(GLSLTest,
ES2_D3D9(),