Commit 44ebf6b4 by Jamie Madill Committed by Commit Bot

ConstantUnion: Error on undefined shift.

BUG=chromium:648135 Change-Id: I41581f63af650564a0f61c1baeeb38017c8513ed Reviewed-on: https://chromium-review.googlesource.com/387470 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 1db8a26b
...@@ -380,11 +380,21 @@ TConstantUnion TConstantUnion::rshift(const TConstantUnion &lhs, ...@@ -380,11 +380,21 @@ TConstantUnion TConstantUnion::rshift(const TConstantUnion &lhs,
switch (lhs.type) switch (lhs.type)
{ {
case EbtInt: case EbtInt:
returnValue.setIConst(lhs.iConst >> rhs.iConst); if (lhs.iConst < 0 || rhs.iConst < 0)
{
diag->error(line, "Undefined shift", ">>", "");
returnValue.setIConst(0);
}
else
{
returnValue.setIConst(lhs.iConst >> rhs.iConst);
}
break; break;
case EbtUInt: case EbtUInt:
returnValue.setUConst(lhs.uConst >> rhs.uConst); returnValue.setUConst(lhs.uConst >> rhs.uConst);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -406,11 +416,21 @@ TConstantUnion TConstantUnion::lshift(const TConstantUnion &lhs, ...@@ -406,11 +416,21 @@ TConstantUnion TConstantUnion::lshift(const TConstantUnion &lhs,
switch (lhs.type) switch (lhs.type)
{ {
case EbtInt: case EbtInt:
returnValue.setIConst(lhs.iConst << rhs.iConst); if (lhs.iConst < 0 || rhs.iConst < 0)
{
diag->error(line, "Undefined shift", "<<", "");
returnValue.setIConst(0);
}
else
{
returnValue.setIConst(lhs.iConst << rhs.iConst);
}
break; break;
case EbtUInt: case EbtUInt:
returnValue.setUConst(lhs.uConst << rhs.uConst); returnValue.setUConst(lhs.uConst << rhs.uConst);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
......
...@@ -2433,6 +2433,42 @@ TEST_P(GLSLTest, FoldedIntDifferenceOutOfBounds) ...@@ -2433,6 +2433,42 @@ TEST_P(GLSLTest, FoldedIntDifferenceOutOfBounds)
glDeleteProgram(program); glDeleteProgram(program);
} }
// Test that using an invalid constant right-shift produces an error.
TEST_P(GLSLTest_ES3, FoldedInvalidRightShift)
{
const std::string &fragmentShader =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 color;\n"
"void main(void)\n"
"{\n"
" int diff = -100 >> -100;\n"
" color = vec4(float(diff));\n"
"}\n";
GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
EXPECT_EQ(0u, program);
glDeleteProgram(program);
}
// Test that using an invalid constant left-shift produces an error.
TEST_P(GLSLTest_ES3, FoldedInvalidLeftShift)
{
const std::string &fragmentShader =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 color;\n"
"void main(void)\n"
"{\n"
" int diff = -100 << -100;\n"
" color = vec4(float(diff));\n"
"}\n";
GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
EXPECT_EQ(0u, program);
glDeleteProgram(program);
}
} // anonymous namespace } // anonymous namespace
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
......
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