Commit fd643283 by Olli Etuaho Committed by Commit Bot

Disallow case statements nested in blocks

The GLSL ES 3.00.6 spec is a bit unclear on this, but it does disallow case statements "inside control flow". GLSL ES 3.10 clarifies this and disallows any nesting of case or default labels within other statements. BUG=angleproject:2452 TEST=angle_unittests Change-Id: I289bb39abb5227eab7117638af388b0a57dc5dd8 Reviewed-on: https://chromium-review.googlesource.com/995478 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 038dd539
...@@ -26,7 +26,7 @@ class ValidateSwitch : public TIntermTraverser ...@@ -26,7 +26,7 @@ class ValidateSwitch : public TIntermTraverser
void visitSymbol(TIntermSymbol *) override; void visitSymbol(TIntermSymbol *) override;
void visitConstantUnion(TIntermConstantUnion *) override; void visitConstantUnion(TIntermConstantUnion *) override;
bool visitDeclaration(Visit, TIntermDeclaration *) override; bool visitDeclaration(Visit, TIntermDeclaration *) override;
bool visitBlock(Visit, TIntermBlock *) override; bool visitBlock(Visit visit, TIntermBlock *) override;
bool visitBinary(Visit, TIntermBinary *) override; bool visitBinary(Visit, TIntermBinary *) override;
bool visitUnary(Visit, TIntermUnary *) override; bool visitUnary(Visit, TIntermUnary *) override;
bool visitTernary(Visit, TIntermTernary *) override; bool visitTernary(Visit, TIntermTernary *) override;
...@@ -107,13 +107,17 @@ bool ValidateSwitch::visitDeclaration(Visit, TIntermDeclaration *) ...@@ -107,13 +107,17 @@ bool ValidateSwitch::visitDeclaration(Visit, TIntermDeclaration *)
return true; return true;
} }
bool ValidateSwitch::visitBlock(Visit, TIntermBlock *) bool ValidateSwitch::visitBlock(Visit visit, TIntermBlock *)
{ {
if (getParentNode() != nullptr) if (getParentNode() != nullptr)
{ {
if (!mFirstCaseFound) if (!mFirstCaseFound)
mStatementBeforeCase = true; mStatementBeforeCase = true;
mLastStatementWasCase = false; mLastStatementWasCase = false;
if (visit == PreVisit)
++mControlFlowDepth;
if (visit == PostVisit)
--mControlFlowDepth;
} }
return true; return true;
} }
......
...@@ -5939,3 +5939,31 @@ TEST_F(FragmentShaderValidationTest, DeclareBothBuiltInFragmentOutputsInvariant) ...@@ -5939,3 +5939,31 @@ TEST_F(FragmentShaderValidationTest, DeclareBothBuiltInFragmentOutputsInvariant)
FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog; FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
} }
} }
// Test that a case cannot be placed inside a block nested inside a switch statement. GLSL ES 3.10
// section 6.2.
TEST_F(FragmentShaderValidationTest, CaseInsideBlock)
{
const std::string &shaderString =
R"(#version 300 es
precision mediump float;
uniform int u;
out vec4 my_FragColor;
void main()
{
switch (u)
{
case 1:
{
case 0:
my_FragColor = vec4(0.0);
}
default:
my_FragColor = vec4(1.0);
}
})";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment