Commit bbe9fb5e by Olli Etuaho Committed by Commit Bot

Check that implicitly sized array constructors have arguments

Array size must be greater than zero according to the ESSL 3.00.6 spec. BUG=angleproject:1602 TEST=angle_unittests Change-Id: I1fa54b143bc821583822cbc5139464cdd058b6c1 Reviewed-on: https://chromium-review.googlesource.com/407257 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent d9e83787
...@@ -2595,6 +2595,12 @@ TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments, ...@@ -2595,6 +2595,12 @@ TIntermTyped *TParseContext::addConstructor(TIntermNode *arguments,
TType type = fnCall->getReturnType(); TType type = fnCall->getReturnType();
if (type.isUnsizedArray()) if (type.isUnsizedArray())
{ {
if (fnCall->getParamCount() == 0)
{
error(line, "implicitly sized array constructor must have at least one argument", "[]");
type.setArraySize(1u);
return TIntermTyped::CreateZero(type);
}
type.setArraySize(static_cast<unsigned int>(fnCall->getParamCount())); type.setArraySize(static_cast<unsigned int>(fnCall->getParamCount()));
} }
bool constType = true; bool constType = true;
......
...@@ -3056,4 +3056,21 @@ TEST_F(MalformedShaderTest, LogicalOpRHSIsBVec) ...@@ -3056,4 +3056,21 @@ TEST_F(MalformedShaderTest, LogicalOpRHSIsBVec)
{ {
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 when there's an unsized array constructor with no parameters.
// ESSL 3.00.6 section 4.1.9: Array size must be greater than zero.
TEST_F(MalformedShaderTest, UnsizedArrayConstructorNoParameters)
{
const std::string &shaderString =
"#version 300 es\n"
"void main()\n"
"{\n"
" int[]();\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