Fix undefined modulus in ExpressionParser
In constant folding of integer expressions this case is already being
handled.
BUG=angleproject:1599
Change-Id: Ifb3ea0279467f216e1c93909647b79fca24fcaf2
Reviewed-on: https://chromium-review.googlesource.com/406868
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/preprocessor/ExpressionParser.cpp b/src/compiler/preprocessor/ExpressionParser.cpp
index f737a2e..ee20a6f 100644
--- a/src/compiler/preprocessor/ExpressionParser.cpp
+++ b/src/compiler/preprocessor/ExpressionParser.cpp
@@ -500,7 +500,7 @@
{
0, 108, 108, 115, 116, 127, 127, 148, 148, 169,
172, 175, 178, 181, 184, 187, 190, 193, 196, 221,
- 246, 249, 252, 272, 299, 302, 305, 308, 320, 323
+ 246, 249, 252, 278, 305, 308, 311, 314, 326, 329
};
#endif
@@ -1583,6 +1583,12 @@
}
(yyval) = static_cast<YYSTYPE>(0);
}
+ else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
+ {
+ // Check for the special case where the minimum representable number is
+ // divided by -1. If left alone this has undefined results.
+ (yyval) = 0;
+ }
else
{
(yyval) = (yyvsp[-2]) % (yyvsp[0]);
@@ -1608,7 +1614,7 @@
}
(yyval) = static_cast<YYSTYPE>(0);
}
- else if ((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min() && (yyvsp[0]) == -1)
+ else if (((yyvsp[-2]) == std::numeric_limits<YYSTYPE>::min()) && ((yyvsp[0]) == -1))
{
// Check for the special case where the minimum representable number is
// divided by -1. If left alone this leads to integer overflow in C++, which