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/359949
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 34c8aa2..ad5aa13 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -3828,6 +3828,19 @@
                                       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);
 }
 
@@ -4151,6 +4164,15 @@
         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);
 }