Hash :
568caaa0
Author :
Date :
2024-07-23T15:07:59
Prune switch(constant) with no matching case Bug: chromium:350528343 Change-Id: Iabb475b230f22086de482bbdcf2fa00b0d986622 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5735815 Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PruneNoOps_test.cpp:
// Tests for pruning no-op statements.
//
#include "GLSLANG/ShaderLang.h"
#include "angle_gl.h"
#include "gtest/gtest.h"
#include "tests/test_utils/compiler_test.h"
using namespace sh;
namespace
{
class PruneNoOpsTest : public MatchOutputCodeTest
{
public:
PruneNoOpsTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, SH_GLSL_COMPATIBILITY_OUTPUT) {}
};
// Test that a switch statement with a constant expression without a matching case is pruned.
TEST_F(PruneNoOpsTest, SwitchStatementWithConstantExpressionNoMatchingCase)
{
const std::string shaderString = R"(#version 300 es
precision mediump float;
out vec4 color;
void main(void)
{
switch (10)
{
case 0:
color = vec4(0);
break;
case 1:
color = vec4(1);
break;
}
})";
compile(shaderString);
ASSERT_TRUE(notFoundInCode("switch"));
ASSERT_TRUE(notFoundInCode("case"));
}
// Test that a switch statement with a constant expression with a default is not pruned.
TEST_F(PruneNoOpsTest, SwitchStatementWithConstantExpressionWithDefault)
{
const std::string shaderString = R"(#version 300 es
precision mediump float;
out vec4 color;
void main(void)
{
switch (10)
{
case 0:
color = vec4(0);
break;
case 1:
color = vec4(1);
break;
default:
color = vec4(0.5);
break;
}
})";
compile(shaderString);
ASSERT_TRUE(foundInCode("switch"));
ASSERT_TRUE(foundInCode("case"));
}
// Test that a switch statement with a constant expression with a matching case is not pruned.
TEST_F(PruneNoOpsTest, SwitchStatementWithConstantExpressionWithMatchingCase)
{
const std::string shaderString = R"(#version 300 es
precision mediump float;
out vec4 color;
void main(void)
{
switch (10)
{
case 0:
color = vec4(0);
break;
case 10:
color = vec4(1);
break;
}
})";
compile(shaderString);
ASSERT_TRUE(foundInCode("switch"));
ASSERT_TRUE(foundInCode("case"));
}
} // namespace