Commit 67d2cd07 by Olli Etuaho Committed by Commit Bot

Issue a clearer warning about negative modulus operands

This also adds unit tests for negative modulus operands. BUG=chromium:839468 TEST=angle_unittests Change-Id: I6ab5959ba4f7045d2bde71d246695ef0983c5608 Reviewed-on: https://chromium-review.googlesource.com/1046055Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent e95a7f07
...@@ -1926,11 +1926,11 @@ const TConstantUnion *TIntermConstantUnion::FoldBinary(TOperator op, ...@@ -1926,11 +1926,11 @@ const TConstantUnion *TIntermConstantUnion::FoldBinary(TOperator op,
if (lhs < 0 || divisor < 0) if (lhs < 0 || divisor < 0)
{ {
// ESSL 3.00.6 section 5.9: Results of modulus are undefined // ESSL 3.00.6 section 5.9: Results of modulus are undefined
// when // when either one of the operands is negative.
// either one of the operands is negative.
diagnostics->warning(line, diagnostics->warning(line,
"Negative modulus operator operand " "Negative modulus operator operand "
"encountered during constant folding", "encountered during constant folding. "
"Results are undefined.",
"%"); "%");
resultArray[i].setIConst(0); resultArray[i].setIConst(0);
} }
......
...@@ -1645,3 +1645,19 @@ TEST_F(ConstantFoldingExpressionTest, LargeFloatToUint) ...@@ -1645,3 +1645,19 @@ TEST_F(ConstantFoldingExpressionTest, LargeFloatToUint)
ASSERT_TRUE(constantFoundInAST(3221225472u)); ASSERT_TRUE(constantFoundInAST(3221225472u));
ASSERT_FALSE(hasWarning()); ASSERT_FALSE(hasWarning());
} }
// Test that folding % with a negative dividend generates a warning.
TEST_F(ConstantFoldingExpressionTest, IntegerModulusNegativeDividend)
{
const std::string &intString = "(-5) % 3";
evaluateInt(intString);
ASSERT_TRUE(hasWarning());
}
// Test that folding % with a negative divisor generates a warning.
TEST_F(ConstantFoldingExpressionTest, IntegerModulusNegativeDivisor)
{
const std::string &intString = "5 % (-3)";
evaluateInt(intString);
ASSERT_TRUE(hasWarning());
}
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