Check precision qualification for all declarations

Precision qualification is now checked properly also for declarations
that don't have qualifiers.

BUG=angleproject:1574
TEST=angle_unittests

Change-Id: I3d186df0763e071614c1da9a355a6f6fefdc8091
Reviewed-on: https://chromium-review.googlesource.com/403949
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 2e2c27e..b0d291e 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -1581,6 +1581,18 @@
     return false;
 }
 
+void TParseContext::addFullySpecifiedType(TPublicType *typeSpecifier)
+{
+    checkPrecisionSpecified(typeSpecifier->getLine(), typeSpecifier->precision,
+                            typeSpecifier->getBasicType());
+
+    if (mShaderVersion < 300 && typeSpecifier->array)
+    {
+        error(typeSpecifier->getLine(), "not supported", "first-class array");
+        typeSpecifier->clearArrayness();
+    }
+}
+
 TPublicType TParseContext::addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
                                                  const TPublicType &typeSpecifier)
 {
diff --git a/src/compiler/translator/ParseContext.h b/src/compiler/translator/ParseContext.h
index 4b1c6ae..68fda25 100644
--- a/src/compiler/translator/ParseContext.h
+++ b/src/compiler/translator/ParseContext.h
@@ -204,6 +204,7 @@
                             TIntermTyped *initializer,
                             TIntermBinary **initNode);
 
+    void addFullySpecifiedType(TPublicType *typeSpecifier);
     TPublicType addFullySpecifiedType(const TTypeQualifierBuilder &typeQualifierBuilder,
                                       const TPublicType &typeSpecifier);
 
diff --git a/src/compiler/translator/glslang.y b/src/compiler/translator/glslang.y
index 0aa15ec..cbce715 100644
--- a/src/compiler/translator/glslang.y
+++ b/src/compiler/translator/glslang.y
@@ -813,14 +813,8 @@
 
 fully_specified_type
     : type_specifier {
+        context->addFullySpecifiedType(&$1);
         $$ = $1;
-
-        if ($1.array) {
-            ES3_OR_NEWER("[]", @1, "first-class-array");
-            if (context->getShaderVersion() != 300) {
-                $1.clearArrayness();
-            }
-        }
     }
     | type_qualifier type_specifier {
         $$ = context->addFullySpecifiedType(*$1, $2);
@@ -959,10 +953,7 @@
 type_specifier
     : type_specifier_no_prec {
         $$ = $1;
-
-        if ($$.precision == EbpUndefined) {
-            $$.precision = context->symbolTable.getDefaultPrecision($1.getBasicType());
-        }
+        $$.precision = context->symbolTable.getDefaultPrecision($1.getBasicType());
     }
     ;
 
diff --git a/src/compiler/translator/glslang_tab.cpp b/src/compiler/translator/glslang_tab.cpp
index aa62e48..f51283a 100644
--- a/src/compiler/translator/glslang_tab.cpp
+++ b/src/compiler/translator/glslang_tab.cpp
@@ -742,23 +742,23 @@
      612,   621,   625,   629,   633,   637,   644,   651,   654,   661,
      669,   689,   699,   707,   732,   736,   740,   744,   751,   758,
      761,   765,   769,   774,   779,   786,   790,   794,   798,   803,
-     808,   815,   825,   831,   834,   840,   844,   851,   857,   861,
-     865,   868,   871,   880,   886,   894,   897,   917,   936,   943,
-     947,   951,   954,   960,   970,   973,   976,   982,   989,   992,
-     998,  1001,  1004,  1010,  1013,  1018,  1029,  1032,  1035,  1038,
-    1041,  1044,  1048,  1052,  1056,  1060,  1064,  1068,  1072,  1076,
-    1080,  1084,  1088,  1092,  1096,  1100,  1104,  1108,  1112,  1116,
-    1120,  1124,  1128,  1131,  1134,  1137,  1140,  1143,  1146,  1149,
-    1152,  1155,  1158,  1161,  1164,  1167,  1170,  1173,  1180,  1186,
-    1189,  1192,  1195,  1198,  1201,  1204,  1207,  1210,  1213,  1216,
-    1219,  1222,  1225,  1237,  1237,  1240,  1240,  1246,  1249,  1264,
-    1267,  1274,  1278,  1284,  1290,  1302,  1306,  1310,  1311,  1317,
-    1318,  1319,  1320,  1321,  1322,  1323,  1327,  1328,  1328,  1328,
-    1337,  1338,  1342,  1342,  1343,  1343,  1348,  1351,  1360,  1365,
-    1372,  1373,  1377,  1384,  1388,  1395,  1395,  1402,  1405,  1412,
-    1416,  1429,  1429,  1434,  1434,  1440,  1440,  1448,  1451,  1457,
-    1460,  1466,  1470,  1477,  1480,  1483,  1486,  1489,  1498,  1504,
-    1510,  1513,  1519,  1519
+     808,   815,   819,   825,   828,   834,   838,   845,   851,   855,
+     859,   862,   865,   874,   880,   888,   891,   911,   930,   937,
+     941,   945,   948,   954,   961,   964,   967,   973,   980,   983,
+     989,   992,   995,  1001,  1004,  1009,  1020,  1023,  1026,  1029,
+    1032,  1035,  1039,  1043,  1047,  1051,  1055,  1059,  1063,  1067,
+    1071,  1075,  1079,  1083,  1087,  1091,  1095,  1099,  1103,  1107,
+    1111,  1115,  1119,  1122,  1125,  1128,  1131,  1134,  1137,  1140,
+    1143,  1146,  1149,  1152,  1155,  1158,  1161,  1164,  1171,  1177,
+    1180,  1183,  1186,  1189,  1192,  1195,  1198,  1201,  1204,  1207,
+    1210,  1213,  1216,  1228,  1228,  1231,  1231,  1237,  1240,  1255,
+    1258,  1265,  1269,  1275,  1281,  1293,  1297,  1301,  1302,  1308,
+    1309,  1310,  1311,  1312,  1313,  1314,  1318,  1319,  1319,  1319,
+    1328,  1329,  1333,  1333,  1334,  1334,  1339,  1342,  1351,  1356,
+    1363,  1364,  1368,  1375,  1379,  1386,  1386,  1393,  1396,  1403,
+    1407,  1420,  1420,  1425,  1425,  1431,  1431,  1439,  1442,  1448,
+    1451,  1457,  1461,  1468,  1471,  1474,  1477,  1480,  1489,  1495,
+    1501,  1504,  1510,  1510
 };
 #endif
 
@@ -3469,14 +3469,8 @@
   case 121:
 
     {
+        context->addFullySpecifiedType(&(yyvsp[0].interm.type));
         (yyval.interm.type) = (yyvsp[0].interm.type);
-
-        if ((yyvsp[0].interm.type).array) {
-            ES3_OR_NEWER("[]", (yylsp[0]), "first-class-array");
-            if (context->getShaderVersion() != 300) {
-                (yyvsp[0].interm.type).clearArrayness();
-            }
-        }
     }
 
     break;
@@ -3705,10 +3699,7 @@
 
     {
         (yyval.interm.type) = (yyvsp[0].interm.type);
-
-        if ((yyval.interm.type).precision == EbpUndefined) {
-            (yyval.interm.type).precision = context->symbolTable.getDefaultPrecision((yyvsp[0].interm.type).getBasicType());
-        }
+        (yyval.interm.type).precision = context->symbolTable.getDefaultPrecision((yyvsp[0].interm.type).getBasicType());
     }
 
     break;
diff --git a/src/tests/compiler_tests/MalformedShader_test.cpp b/src/tests/compiler_tests/MalformedShader_test.cpp
index c4a6ad4..66d3023 100644
--- a/src/tests/compiler_tests/MalformedShader_test.cpp
+++ b/src/tests/compiler_tests/MalformedShader_test.cpp
@@ -3000,3 +3000,21 @@
         FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
     }
 }
+
+// ESSL 1.00.17 section 4.5.2.
+// ESSL 3.00.6 section 4.5.3.
+// Precision must be specified for floats. Test this with a declaration with no qualifiers.
+TEST_F(MalformedShaderTest, FloatDeclarationNoQualifiersNoPrecision)
+{
+    const std::string &shaderString =
+        "vec4 foo = vec4(0.0);\n"
+        "void main()\n"
+        "{\n"
+        "    gl_FragColor = foo;\n"
+        "}\n";
+
+    if (compile(shaderString))
+    {
+        FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
+    }
+}
\ No newline at end of file