Commit d68157fc by Olli Etuaho Committed by Jamie Madill

Fix issues related to modulus operator

Make sure that "scalar %= vector" is not approved by the compiler, and that % and %= are only exposed on GLES3. BUG=angle:854 Change-Id: I3ac7eb607bd86a6caa905d2bef5d397688ad3fd3 Reviewed-on: https://chromium-review.googlesource.com/241410Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGregoire Payen de La Garanderie <Gregory.Payen@imgtec.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5f7a717b
......@@ -584,7 +584,8 @@ bool TIntermBinary::promote(TInfoSink &infoSink)
if (!mRight->isScalar() &&
(mOp == EOpAddAssign ||
mOp == EOpSubAssign ||
mOp == EOpDivAssign))
mOp == EOpDivAssign ||
mOp == EOpModAssign))
return false;
// Operator cannot be of type pure assignment.
......
......@@ -81,6 +81,7 @@ TIntermTyped *TIntermediate::addBinaryMath(
}
break;
case EOpMod:
// Note that this is only for the % operator, not for mod()
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return NULL;
......
......@@ -556,6 +556,7 @@ multiplicative_expression
}
}
| multiplicative_expression PERCENT unary_expression {
ES3_ONLY("%", @2, "integer modulus operator");
$$ = context->intermediate.addBinaryMath(EOpMod, $1, $3, @2);
if ($$ == 0) {
context->binaryOpError(@2, "%", $1->getCompleteString(), $3->getCompleteString());
......@@ -747,7 +748,10 @@ assignment_operator
: EQUAL { $$.op = EOpAssign; }
| MUL_ASSIGN { $$.op = EOpMulAssign; }
| DIV_ASSIGN { $$.op = EOpDivAssign; }
| MOD_ASSIGN { $$.op = EOpModAssign; }
| MOD_ASSIGN {
ES3_ONLY("%=", @$, "integer modulus operator");
$$.op = EOpModAssign;
}
| ADD_ASSIGN { $$.op = EOpAddAssign; }
| SUB_ASSIGN { $$.op = EOpSubAssign; }
;
......
......@@ -691,28 +691,28 @@ static const yytype_uint16 yyrline[] =
256, 262, 265, 268, 271, 274, 284, 297, 305, 422,
425, 433, 436, 442, 446, 453, 459, 468, 476, 479,
489, 492, 502, 512, 534, 535, 536, 541, 542, 550,
558, 569, 570, 578, 589, 593, 594, 604, 614, 624,
637, 638, 648, 661, 665, 669, 673, 674, 687, 688,
701, 702, 715, 716, 733, 734, 747, 748, 749, 750,
751, 752, 756, 759, 770, 778, 786, 813, 819, 830,
834, 838, 842, 849, 905, 908, 915, 923, 944, 965,
975, 1003, 1008, 1018, 1023, 1033, 1036, 1039, 1042, 1048,
1055, 1058, 1062, 1066, 1070, 1077, 1081, 1085, 1092, 1096,
1100, 1107, 1116, 1122, 1125, 1131, 1137, 1144, 1153, 1162,
1170, 1173, 1180, 1184, 1191, 1194, 1198, 1202, 1211, 1220,
1228, 1238, 1250, 1253, 1256, 1262, 1269, 1272, 1278, 1281,
1284, 1290, 1293, 1308, 1312, 1316, 1320, 1324, 1328, 1333,
1338, 1343, 1348, 1353, 1358, 1363, 1368, 1373, 1378, 1383,
1388, 1393, 1398, 1403, 1408, 1413, 1418, 1423, 1428, 1433,
1437, 1441, 1445, 1449, 1453, 1457, 1461, 1465, 1469, 1473,
1477, 1481, 1485, 1489, 1493, 1501, 1509, 1513, 1526, 1526,
1529, 1529, 1535, 1538, 1554, 1557, 1566, 1570, 1576, 1583,
1598, 1602, 1606, 1607, 1613, 1614, 1615, 1616, 1617, 1621,
1622, 1622, 1622, 1632, 1633, 1637, 1637, 1638, 1638, 1643,
1646, 1656, 1659, 1665, 1666, 1670, 1678, 1682, 1692, 1697,
1714, 1714, 1719, 1719, 1726, 1726, 1734, 1737, 1743, 1746,
1752, 1756, 1763, 1770, 1777, 1784, 1795, 1804, 1808, 1815,
1818, 1824, 1824
558, 570, 571, 579, 590, 594, 595, 605, 615, 625,
638, 639, 649, 662, 666, 670, 674, 675, 688, 689,
702, 703, 716, 717, 734, 735, 748, 749, 750, 751,
755, 756, 760, 763, 774, 782, 790, 817, 823, 834,
838, 842, 846, 853, 909, 912, 919, 927, 948, 969,
979, 1007, 1012, 1022, 1027, 1037, 1040, 1043, 1046, 1052,
1059, 1062, 1066, 1070, 1074, 1081, 1085, 1089, 1096, 1100,
1104, 1111, 1120, 1126, 1129, 1135, 1141, 1148, 1157, 1166,
1174, 1177, 1184, 1188, 1195, 1198, 1202, 1206, 1215, 1224,
1232, 1242, 1254, 1257, 1260, 1266, 1273, 1276, 1282, 1285,
1288, 1294, 1297, 1312, 1316, 1320, 1324, 1328, 1332, 1337,
1342, 1347, 1352, 1357, 1362, 1367, 1372, 1377, 1382, 1387,
1392, 1397, 1402, 1407, 1412, 1417, 1422, 1427, 1432, 1437,
1441, 1445, 1449, 1453, 1457, 1461, 1465, 1469, 1473, 1477,
1481, 1485, 1489, 1493, 1497, 1505, 1513, 1517, 1530, 1530,
1533, 1533, 1539, 1542, 1558, 1561, 1570, 1574, 1580, 1587,
1602, 1606, 1610, 1611, 1617, 1618, 1619, 1620, 1621, 1625,
1626, 1626, 1626, 1636, 1637, 1641, 1641, 1642, 1642, 1647,
1650, 1660, 1663, 1669, 1670, 1674, 1682, 1686, 1696, 1701,
1718, 1718, 1723, 1723, 1730, 1730, 1738, 1741, 1747, 1750,
1756, 1760, 1767, 1774, 1781, 1788, 1799, 1808, 1812, 1819,
1822, 1828, 1828
};
#endif
......@@ -2787,6 +2787,7 @@ yyreduce:
case 40:
{
ES3_ONLY("%", (yylsp[-1]), "integer modulus operator");
(yyval.interm.intermTypedNode) = context->intermediate.addBinaryMath(EOpMod, (yyvsp[-2].interm.intermTypedNode), (yyvsp[0].interm.intermTypedNode), (yylsp[-1]));
if ((yyval.interm.intermTypedNode) == 0) {
context->binaryOpError((yylsp[-1]), "%", (yyvsp[-2].interm.intermTypedNode)->getCompleteString(), (yyvsp[0].interm.intermTypedNode)->getCompleteString());
......@@ -3084,7 +3085,10 @@ yyreduce:
case 69:
{ (yyval.interm).op = EOpModAssign; }
{
ES3_ONLY("%=", (yyloc), "integer modulus operator");
(yyval.interm).op = EOpModAssign;
}
break;
......
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