Commit bd163f6a by Olli Etuaho

Fix parsing structure definitions in place of constructors

The shader parser used to accept structure definitions in place of constructors, which is invalid GLSL. This patch fixes that. BUG=angleproject:939 TEST=angle_unittests Change-Id: Ibcf502160e91c19e693e9427b548a399d83e2a71 Reviewed-on: https://chromium-review.googlesource.com/312032Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 40d9edf1
...@@ -2093,6 +2093,13 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF ...@@ -2093,6 +2093,13 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
TFunction *TParseContext::addConstructorFunc(const TPublicType &publicTypeIn) TFunction *TParseContext::addConstructorFunc(const TPublicType &publicTypeIn)
{ {
TPublicType publicType = publicTypeIn; TPublicType publicType = publicTypeIn;
if (publicType.isStructSpecifier)
{
error(publicType.line, "constructor can't be a structure definition",
getBasicString(publicType.type));
recover();
}
TOperator op = EOpNull; TOperator op = EOpNull;
if (publicType.userDef) if (publicType.userDef)
{ {
...@@ -3281,6 +3288,7 @@ TPublicType TParseContext::addStructure(const TSourceLoc &structLine, ...@@ -3281,6 +3288,7 @@ TPublicType TParseContext::addStructure(const TSourceLoc &structLine,
TPublicType publicType; TPublicType publicType;
publicType.setBasic(EbtStruct, EvqTemporary, structLine); publicType.setBasic(EbtStruct, EvqTemporary, structLine);
publicType.userDef = structureType; publicType.userDef = structureType;
publicType.isStructSpecifier = true;
exitStructDeclaration(); exitStructDeclaration();
return publicType; return publicType;
......
...@@ -582,6 +582,9 @@ struct TPublicType ...@@ -582,6 +582,9 @@ struct TPublicType
TType *userDef; TType *userDef;
TSourceLoc line; TSourceLoc line;
// true if the type was defined by a struct specifier rather than a reference to a type name.
bool isStructSpecifier;
void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln) void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln)
{ {
type = bt; type = bt;
...@@ -595,6 +598,7 @@ struct TPublicType ...@@ -595,6 +598,7 @@ struct TPublicType
arraySize = 0; arraySize = 0;
userDef = 0; userDef = 0;
line = ln; line = ln;
isStructSpecifier = false;
} }
void setAggregate(unsigned char size) void setAggregate(unsigned char size)
......
...@@ -1201,3 +1201,20 @@ TEST_F(MalformedShaderTest, DynamicallyIndexedInterfaceBlock) ...@@ -1201,3 +1201,20 @@ TEST_F(MalformedShaderTest, DynamicallyIndexedInterfaceBlock)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// Test that a shader that uses a struct definition in place of a struct constructor does not
// compile. See GLSL ES 1.00 section 5.4.3.
TEST_F(MalformedShaderTest, StructConstructorWithStructDefinition)
{
const std::string &shaderString =
"precision mediump float;\n"
"void main()\n"
"{\n"
" struct s { float f; } (0.0);\n"
" gl_FragColor = vec4(0.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