Fix setting const qualifier on indexing expression
Resubmitting now that separate fix for updating mangled names of types
has been merged. A unit test is added to make sure that the same
regression doesn't happen again.
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: Ie9b6aaee8185b945c03657b13d9513cc55cd2a9f
Reviewed-on: https://chromium-review.googlesource.com/303601
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 8eaa111..04e88da 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -2872,51 +2872,36 @@
}
else if (baseExpression->isArray())
{
- const TType &baseType = baseExpression->getType();
- if (baseType.getStruct())
- {
- 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);
- }
+ TType indexedType = baseExpression->getType();
+ indexedType.clearArrayness();
+ indexedExpression->setType(indexedType);
}
else if (baseExpression->isMatrix())
{
- TQualifier qualifier =
- baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
indexedExpression->setType(TType(baseExpression->getBasicType(),
- baseExpression->getPrecision(), qualifier,
+ baseExpression->getPrecision(), EvqTemporary,
static_cast<unsigned char>(baseExpression->getRows())));
}
else if (baseExpression->isVector())
{
- TQualifier qualifier =
- baseExpression->getType().getQualifier() == EvqConst ? EvqConst : EvqTemporary;
indexedExpression->setType(
- TType(baseExpression->getBasicType(), baseExpression->getPrecision(), qualifier));
+ TType(baseExpression->getBasicType(), baseExpression->getPrecision(), EvqTemporary));
}
else
{
indexedExpression->setType(baseExpression->getType());
}
+ if (baseExpression->getType().getQualifier() == EvqConst &&
+ indexExpression->getType().getQualifier() == EvqConst)
+ {
+ indexedExpression->getTypePointer()->setQualifier(EvqConst);
+ }
+ else
+ {
+ indexedExpression->getTypePointer()->setQualifier(EvqTemporary);
+ }
+
return indexedExpression;
}