Skip to content

Commit

Permalink
ParseContext: validate additional restriction for the ? and , operators
Browse files Browse the repository at this point in the history
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/359949
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
  • Loading branch information
Kangz authored and Commit Bot committed Jul 18, 2016
1 parent 1b2f162 commit 0d95925
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/compiler/translator/ParseContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3828,6 +3828,19 @@ TIntermTyped *TParseContext::addComma(TIntermTyped *left,
TIntermTyped *right,
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);
}

Expand Down Expand Up @@ -4151,6 +4164,15 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
recover();
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);
}

Expand Down

0 comments on commit 0d95925

Please sign in to comment.