Commit 635671dc by Olli Etuaho Committed by Commit Bot

Fix pruning empty declarations from loop headers

Empty declarations are possible in loop init expressions. Make PruneEmptyDeclarations take this into account. BUG=angleproject:1550 TEST=angle_unittests Change-Id: If407babf9b6f7a26dfcf73ff345493d3e2af3f9a Reviewed-on: https://chromium-review.googlesource.com/401147Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 14ac0d77
......@@ -63,9 +63,17 @@ bool PruneEmptyDeclarationsTraverser::visitAggregate(Visit, TIntermAggregate *no
// float;
TIntermSequence emptyReplacement;
TIntermBlock *parentAsBlock = getParentNode()->getAsBlock();
ASSERT(parentAsBlock != nullptr);
mMultiReplacements.push_back(
NodeReplaceWithMultipleEntry(parentAsBlock, node, emptyReplacement));
// The declaration may be inside a block or in a loop init expression.
ASSERT(parentAsBlock != nullptr || getParentNode()->getAsLoopNode() != nullptr);
if (parentAsBlock)
{
mMultiReplacements.push_back(
NodeReplaceWithMultipleEntry(parentAsBlock, node, emptyReplacement));
}
else
{
queueReplacement(node, nullptr, OriginalNode::IS_DROPPED);
}
}
else if (sym->getType().getQualifier() != EvqGlobal &&
sym->getType().getQualifier() != EvqTemporary)
......
......@@ -2563,3 +2563,24 @@ TEST_F(MalformedShaderTest, DeferGlobalVariableInitWithEmptyMain)
FAIL() << "Shader compilation failed, expecting success " << mInfoLog;
}
}
// Test that pruning empty declarations from loop init expression works.
TEST_F(MalformedShaderTest, EmptyDeclarationAsLoopInit)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\n"
" int i = 0;\n"
" for (int; i < 3; i++)\n"
" {\n"
" my_FragColor = vec4(i);\n"
" }\n"
"}\n";
if (!compile(shaderString))
{
FAIL() << "Shader compilation failed, expecting success " << 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