Commit c2128ff5 by Jamie Madill Committed by Commit Bot

translator: Fix two bugs that trigger ASSERTs.

The first bug was a result of constant-folding a vector swizzle that was out-of-bounds. The second bug was a result of using a semicolon in a preprocessor define. BUG=angleproject:1425 Change-Id: Id6643b1f3e3b13cc021bd721ef2572487fe3c8d3 Reviewed-on: https://chromium-review.googlesource.com/357864Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 474a08c0
......@@ -1899,7 +1899,14 @@ void TParseContext::parseGlobalLayoutQualifier(const TPublicType &typeQualifier)
}
const TLayoutQualifier layoutQualifier = typeQualifier.layoutQualifier;
ASSERT(!layoutQualifier.isEmpty());
// It should never be the case, but some strange parser errors can send us here.
if (layoutQualifier.isEmpty())
{
error(typeQualifier.line, "Error during layout qualifier parsing.", "?");
recover();
return;
}
if (mShaderVersion < 300)
{
......@@ -2469,21 +2476,22 @@ TIntermTyped *TParseContext::addConstVectorNode(TVectorFields &fields,
ASSERT(unionArray);
TConstantUnion *constArray = new TConstantUnion[fields.num];
const auto &type = node->getType();
for (int i = 0; i < fields.num; i++)
{
if (fields.offsets[i] >= node->getType().getNominalSize())
if (fields.offsets[i] >= type.getNominalSize())
{
std::stringstream extraInfoStream;
extraInfoStream << "vector field selection out of range '" << fields.offsets[i] << "'";
std::string extraInfo = extraInfoStream.str();
outOfRangeError(outOfRangeIndexIsError, line, "", "[", extraInfo.c_str());
fields.offsets[i] = node->getType().getNominalSize() - 1;
fields.offsets[i] = type.getNominalSize() - 1;
}
constArray[i] = unionArray[fields.offsets[i]];
}
return intermediate.addConstantUnion(constArray, node->getType(), line);
return intermediate.addConstantUnion(constArray, type, line);
}
//
......@@ -3056,7 +3064,7 @@ TIntermTyped *TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre
// Note that the qualifier set here will be corrected later.
indexedExpression->setType(TType(baseExpression->getBasicType(),
baseExpression->getPrecision(), EvqTemporary,
(unsigned char)(fieldString).size()));
static_cast<unsigned char>(fields.num)));
}
}
else if (baseExpression->getBasicType() == EbtStruct)
......
......@@ -1610,3 +1610,28 @@ TEST_F(MalformedShaderTest, CompoundMultiplyMatrixValidNonSquareDimensions)
FAIL() << "Shader compilation failed, expecting success " << mInfoLog;
}
}
// Covers a bug where we would set the incorrect result size on an out-of-bounds vector sizzle.
TEST_F(MalformedShaderTest, OutOfBoundsVectorSwizzle)
{
const std::string &shaderString =
"void main() {\n"
" vec2(0).qq * a(b);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Covers a bug where strange preprocessor defines could trigger asserts.
TEST_F(MalformedShaderTest, DefineWithSemicolon)
{
const std::string &shaderString =
"#define Def; highp\n"
"uniform Def vec2 a;\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
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