Commit 0d959258 by Corentin Wallez Committed by Commit Bot

ParseContext: validate additional restriction for the ? and , operators

WebGL2 shaders have added restriction to improve portability for some OpenGL compilers that do not support arbitrary ternary and sequence operators. It disallows these operators for arrays, structs containing arrays and the void type. BUG=612066 Change-Id: Id11042051bce25a91e57deaa9591d4d813fed7aa Reviewed-on: https://chromium-review.googlesource.com/359949Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 1b2f1629
...@@ -3828,6 +3828,19 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left, ...@@ -3828,6 +3828,19 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left,
TIntermTyped *right, TIntermTyped *right,
const TSourceLoc &loc) const TSourceLoc &loc)
{ {
// WebGL2 section 5.26, the following results in an error:
// "Sequence operator applied to void, arrays, or structs containing arrays"
if (mShaderSpec == SH_WEBGL2_SPEC && (left->isArray() || left->getBasicType() == EbtVoid ||
left->getType().isStructureContainingArrays() ||
right->isArray() || right->getBasicType() == EbtVoid ||
right->getType().isStructureContainingArrays()))
{
error(loc,
"sequence operator is not allowed for void, arrays, or structs containing arrays",
",");
recover();
}
return intermediate.addComma(left, right, loc, mShaderVersion); return intermediate.addComma(left, right, loc, mShaderVersion);
} }
...@@ -4151,6 +4164,15 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, ...@@ -4151,6 +4164,15 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
recover(); recover();
return falseBlock; return falseBlock;
} }
// WebGL2 section 5.26, the following results in an error:
// "Ternary operator applied to void, arrays, or structs containing arrays"
if (mShaderSpec == SH_WEBGL2_SPEC && trueBlock->getBasicType() == EbtVoid)
{
error(loc, "ternary operator is not allowed for void", ":");
recover();
return falseBlock;
}
return intermediate.addSelection(cond, trueBlock, falseBlock, loc); return intermediate.addSelection(cond, trueBlock, falseBlock, loc);
} }
......
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