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.y b/src/compiler/preprocessor/ExpressionParser.y
index a98638a..4dbc9e8 100644
--- a/src/compiler/preprocessor/ExpressionParser.y
+++ b/src/compiler/preprocessor/ExpressionParser.y
@@ -264,6 +264,12 @@
}
$$ = static_cast<YYSTYPE>(0);
}
+ else if (($1 == std::numeric_limits<YYSTYPE>::min()) && ($3 == -1))
+ {
+ // Check for the special case where the minimum representable number is
+ // divided by -1. If left alone this has undefined results.
+ $$ = 0;
+ }
else
{
$$ = $1 % $3;
@@ -284,7 +290,7 @@
}
$$ = static_cast<YYSTYPE>(0);
}
- else if ($1 == std::numeric_limits<YYSTYPE>::min() && $3 == -1)
+ else if (($1 == std::numeric_limits<YYSTYPE>::min()) && ($3 == -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