Commit f095799b by Olli Etuaho Committed by Commit Bot

Fix accessing the name of a nested struct definition

When generating an error message about the struct nesting limit, the code should make sure that the struct definitions are not nested. While nested struct definitions by themselves are also an error, they're not a syntax error so parsing will continue after encountering them. This fixes a regression from commit: Don't allocate name strings for empty symbols. BUG=chromium:797156 TEST=angle_unittests Change-Id: I4149fbe874c0e7ec90e690aec078ccaf7313eab0 Reviewed-on: https://chromium-review.googlesource.com/842643 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent aaa55bfa
......@@ -3896,10 +3896,19 @@ void TParseContext::checkIsBelowStructNestingLimit(const TSourceLoc &line, const
// one to the field's struct nesting.
if (1 + field.type()->getDeepestStructNesting() > kWebGLMaxStructNesting)
{
ASSERT(field.type()->getStruct()->name() != nullptr);
std::stringstream reasonStream;
reasonStream << "Reference of struct type " << field.type()->getStruct()->name()->c_str()
<< " exceeds maximum allowed nesting level of " << kWebGLMaxStructNesting;
if (field.type()->getStruct()->symbolType() == SymbolType::Empty)
{
// This may happen in case there are nested struct definitions. While they are also
// invalid GLSL, they don't cause a syntax error.
reasonStream << "Struct nesting";
}
else
{
reasonStream << "Reference of struct type "
<< field.type()->getStruct()->name()->c_str();
}
reasonStream << " exceeds maximum allowed nesting level of " << kWebGLMaxStructNesting;
std::string reason = reasonStream.str();
error(line, reason.c_str(), field.name().c_str());
return;
......
......@@ -5620,3 +5620,42 @@ TEST_F(FragmentShaderValidationTest,
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test going past the struct nesting limit while simultaneously using invalid nested struct
// definitions. This makes sure that the code generating an error message about going past the
// struct nesting limit does not access the name of a nameless struct definition.
TEST_F(WebGL1FragmentShaderValidationTest, StructNestingLimitWithNestedStructDefinitions)
{
const std::string &shaderString =
R"(
precision mediump float;
struct
{
struct
{
struct
{
struct
{
struct
{
struct
{
float f;
} s5;
} s4;
} s3;
} s2;
} s1;
} s0;
void main(void)
{
gl_FragColor = vec4(s0.s1.s2.s3.s4.s5.f);
})";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << 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