Commit 34bf2d93 by Jamie Madill Committed by Commit Bot

translator: Fix ASSERT in array init corner case.

This ASSERT was benign and can be turned into an error check. The pattern in question is to initialize an array with another array as the first argument, but dereferencing the array with "." instead of "[]". This would trip up our error handling. BUG=chromium:662702 Change-Id: Ie0e44af7b9d1a66cad03cefae9bf931f8e216cd9 Reviewed-on: https://chromium-review.googlesource.com/437599 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 70ee0f61
...@@ -686,8 +686,12 @@ bool TParseContext::checkConstructorArguments(const TSourceLoc &line, ...@@ -686,8 +686,12 @@ bool TParseContext::checkConstructorArguments(const TSourceLoc &line,
for (TIntermNode *const &argNode : *arguments) for (TIntermNode *const &argNode : *arguments)
{ {
const TType &argType = argNode->getAsTyped()->getType(); const TType &argType = argNode->getAsTyped()->getType();
// It has already been checked that the argument is not an array. // It has already been checked that the argument is not an array, but we can arrive
ASSERT(!argType.isArray()); // here due to prior error conditions.
if (argType.isArray())
{
return false;
}
if (!argType.sameElementType(type)) if (!argType.sameElementType(type))
{ {
error(line, "Array constructor argument has an incorrect type", "constructor"); error(line, "Array constructor argument has an incorrect type", "constructor");
......
...@@ -3447,3 +3447,20 @@ TEST_F(FragmentShaderValidationTest, SamplerFieldStructUnsizedArrayEmptyConstruc ...@@ -3447,3 +3447,20 @@ TEST_F(FragmentShaderValidationTest, SamplerFieldStructUnsizedArrayEmptyConstruc
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// Checks that odd array initialization syntax is an error, and does not produce
// an ASSERT failure.
TEST_F(VertexShaderValidationTest, InvalidArrayConstruction)
{
const std::string &shaderString =
"struct S { mediump float i; mediump int ggb; };\n"
"void main() {\n"
" S s[2];\n"
" s = S[](s.x, 0.0);\n"
" gl_Position = vec4(1, 0, 0, 1);\n"
"}";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << 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