Commit 02bd82cd by Olli Etuaho Committed by Commit Bot

Fix handling unsized arrays with incorrect initializer

In case the initializer of an unsized array is not an array, the array size still needs to be set to some value > 0 in order to not hit asserts in the code that parses accessing the array. An error was already being generated in the case an unsized array has a non-array initializer, but the variable will still have an array type in the symbol table. BUG=chromium:661592 TEST=angle_unittests Change-Id: I4a11527eab0404ba9e59ebb7227faef13dbea62c Reviewed-on: https://chromium-review.googlesource.com/407256Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent b526f541
...@@ -1484,7 +1484,17 @@ bool TParseContext::executeInitializer(const TSourceLoc &line, ...@@ -1484,7 +1484,17 @@ bool TParseContext::executeInitializer(const TSourceLoc &line,
TVariable *variable = nullptr; TVariable *variable = nullptr;
if (type.isUnsizedArray()) if (type.isUnsizedArray())
{ {
type.setArraySize(initializer->getArraySize()); // We have not checked yet whether the initializer actually is an array or not.
if (initializer->isArray())
{
type.setArraySize(initializer->getArraySize());
}
else
{
// Having a non-array initializer for an unsized array will result in an error later,
// so we don't generate an error message here.
type.setArraySize(1u);
}
} }
if (!declareVariable(line, identifier, type, &variable)) if (!declareVariable(line, identifier, type, &variable))
{ {
......
...@@ -3017,4 +3017,24 @@ TEST_F(MalformedShaderTest, FloatDeclarationNoQualifiersNoPrecision) ...@@ -3017,4 +3017,24 @@ TEST_F(MalformedShaderTest, FloatDeclarationNoQualifiersNoPrecision)
{ {
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
\ No newline at end of file
// Check compiler doesn't crash on incorrect unsized array declarations.
TEST_F(MalformedShaderTest, IncorrectUnsizedArray)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"float foo[] = 0.0;\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\n"
" foo[0] = 1.0;\n"
" my_FragColor = vec4(foo[0]);\n"
"}\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