Commit 21c1e456 by Jamie Madill

Fix a translator crash with index expressions.

This crash happened with certain bad shaders which used temporary values as array (or other) index expresisons. Fixes the crash covered in the WebGL test "conformance/bugs/undefined-index-should-not-crash" BUG=angle:857 Change-Id: I13e2ba6d5f1ab0846ac902021bc0b57cbb37d759 Reviewed-on: https://chromium-review.googlesource.com/237460Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 97399235
......@@ -2051,9 +2051,11 @@ TIntermTyped* TParseContext::addIndexExpression(TIntermTyped *baseExpression, co
recover();
}
if (indexExpression->getQualifier() == EvqConst)
TIntermConstantUnion *indexConstantUnion = indexExpression->getAsConstantUnion();
if (indexExpression->getQualifier() == EvqConst && indexConstantUnion)
{
int index = indexExpression->getAsConstantUnion()->getIConst(0);
int index = indexConstantUnion->getIConst(0);
if (index < 0)
{
std::stringstream infoStream;
......@@ -2114,7 +2116,7 @@ TIntermTyped* TParseContext::addIndexExpression(TIntermTyped *baseExpression, co
index = baseExpression->getType().getNominalSize() - 1;
}
indexExpression->getAsConstantUnion()->getUnionArrayPointer()->setIConst(index);
indexConstantUnion->getUnionArrayPointer()->setIConst(index);
indexedExpression = intermediate.addIndex(EOpIndexDirect, baseExpression, indexExpression, location);
}
}
......
......@@ -821,3 +821,56 @@ TYPED_TEST(GLSLTest, ZeroShaderLength)
glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
EXPECT_NE(compileResult, 0);
}
// Tests that bad index expressions don't crash ANGLE's translator.
// https://code.google.com/p/angleproject/issues/detail?id=857
TYPED_TEST(GLSLTest, BadIndexBug)
{
const std::string &fragmentShaderSourceVec =
"precision mediump float;\n"
"uniform vec4 uniformVec;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(uniformVec[int()]);\n"
"}";
GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec);
EXPECT_EQ(0u, shader);
if (shader != 0)
{
glDeleteShader(shader);
}
const std::string &fragmentShaderSourceMat =
"precision mediump float;\n"
"uniform mat4 uniformMat;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(uniformMat[int()]);\n"
"}";
shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat);
EXPECT_EQ(0u, shader);
if (shader != 0)
{
glDeleteShader(shader);
}
const std::string &fragmentShaderSourceArray =
"precision mediump float;\n"
"uniform vec4 uniformArray;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(uniformArray[int()]);\n"
"}";
shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray);
EXPECT_EQ(0u, shader);
if (shader != 0)
{
glDeleteShader(shader);
}
}
\ No newline at end of file
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