Commit 16a79cd1 by Olli Etuaho

Fix setting const qualifier on indexing expression

Previously, constness of indexing expressions did not take the index expression into account. Now constness correctly takes into account both the base expression and the index expression. Setting the type of expressions that index arrays is also simplified. BUG=angleproject:1170 TEST=angle_unittests Change-Id: Ie2d122020cc252655ab0eea96886b9f85931b80a Reviewed-on: https://chromium-review.googlesource.com/303350Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent d4b5054d
...@@ -2872,51 +2872,36 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression, ...@@ -2872,51 +2872,36 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression,
} }
else if (baseExpression->isArray()) else if (baseExpression->isArray())
{ {
const TType &baseType = baseExpression->getType(); TType indexedType = baseExpression->getType();
if (baseType.getStruct()) indexedType.clearArrayness();
{ indexedExpression->setType(indexedType);
TType copyOfType(baseType.getStruct());
indexedExpression->setType(copyOfType);
}
else if (baseType.isInterfaceBlock())
{
TType copyOfType(baseType.getInterfaceBlock(), baseType.getQualifier(),
baseType.getLayoutQualifier(), 0);
indexedExpression->setType(copyOfType);
}
else
{
indexedExpression->setType(
TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary,
static_cast<unsigned char>(baseExpression->getNominalSize()),
static_cast<unsigned char>(baseExpression->getSecondarySize())));
}
if (baseExpression->getType().getQualifier() == EvqConst)
{
indexedExpression->getTypePointer()->setQualifier(EvqConst);
}
} }
else if (baseExpression->isMatrix()) else if (baseExpression->isMatrix())
{ {
TQualifier qualifier =
baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
indexedExpression->setType(TType(baseExpression->getBasicType(), indexedExpression->setType(TType(baseExpression->getBasicType(),
baseExpression->getPrecision(), qualifier, baseExpression->getPrecision(), EvqTemporary,
static_cast<unsigned char>(baseExpression->getRows()))); static_cast<unsigned char>(baseExpression->getRows())));
} }
else if (baseExpression->isVector()) else if (baseExpression->isVector())
{ {
TQualifier qualifier =
baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
indexedExpression->setType( indexedExpression->setType(
TType(baseExpression->getBasicType(), baseExpression->getPrecision(), qualifier)); TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary));
} }
else else
{ {
indexedExpression->setType(baseExpression->getType()); indexedExpression->setType(baseExpression->getType());
} }
if (baseExpression->getType().getQualifier() == EvqConst &&
indexExpression->getType().getQualifier() == EvqConst)
{
indexedExpression->getTypePointer()->setQualifier(EvqConst);
}
else
{
indexedExpression->getTypePointer()->setQualifier(EvqTemporary);
}
return indexedExpression; return indexedExpression;
} }
......
...@@ -872,3 +872,21 @@ TEST_F(MalformedShaderTest, FragmentShaderInputStructWithInt) ...@@ -872,3 +872,21 @@ TEST_F(MalformedShaderTest, FragmentShaderInputStructWithInt)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// Selecting a field of a vector that's the result of dynamic indexing a constant array should work.
TEST_F(MalformedShaderTest, ShaderSelectingFieldOfVectorIndexedFromArray)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"uniform int i;\n"
"void main() {\n"
" float f = vec2[1](vec2(0.0, 0.1))[i].x;\n"
" my_FragColor = vec4(f);\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