Commit 2c43325d by Jamie Madill

Fix double delete with invariant varyings.

The compiler would leave some TString variables lying around after the pool gets released, leading to a potential crash. BUG=angle:846 Change-Id: I484ed9b14bba9bf653f6ed4001ae79f87791b0dd Reviewed-on: https://chromium-review.googlesource.com/232780Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org>
parent 68439854
......@@ -1390,7 +1390,7 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
recover();
return NULL;
}
symbolTable.addInvariantVarying(*identifier);
symbolTable.addInvariantVarying(std::string(identifier->c_str()));
const TVariable *variable = getNamedVariable(identifierLoc, identifier, symbol);
ASSERT(variable);
const TType &type = variable->getType();
......
......@@ -413,7 +413,7 @@ class TSymbolTable
// This records invariant varyings declared through
// "invariant varying_name;".
void addInvariantVarying(const TString &originalName)
void addInvariantVarying(const std::string &originalName)
{
mInvariantVaryings.insert(originalName);
}
......@@ -421,7 +421,7 @@ class TSymbolTable
// if it is set as invariant during the varying variable
// declaration - this piece of information is stored in the
// variable's type, not here.
bool isVaryingInvariant(const TString &originalName) const
bool isVaryingInvariant(const std::string &originalName) const
{
return (mGlobalInvariant ||
mInvariantVaryings.count(originalName) > 0);
......@@ -445,7 +445,7 @@ class TSymbolTable
typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
std::vector< PrecisionStackLevel *> precisionStack;
std::set<TString> mInvariantVaryings;
std::set<std::string> mInvariantVaryings;
bool mGlobalInvariant;
static int uniqueIdCounter;
......
......@@ -307,7 +307,7 @@ void GetVariableTraverser::setTypeSpecificInfo(
break;
case EvqVaryingIn:
case EvqVaryingOut:
if (mSymbolTable.isVaryingInvariant(name))
if (mSymbolTable.isVaryingInvariant(std::string(name.c_str())))
{
variable->isInvariant = true;
}
......
......@@ -218,4 +218,29 @@ TEST(ShaderVariableTest, IsSameVaryingWithDifferentInvariance)
EXPECT_TRUE(vx.isSameVaryingAtLinkTime(fx));
}
// Test that using invariant varyings doesn't trigger a double delete.
TEST(ShaderVariableTest, InvariantDoubleDeleteBug)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC, SH_GLSL_OUTPUT, &resources);
EXPECT_NE(static_cast<ShHandle>(0), compiler);
const char *program[] =
{
"attribute vec4 position;\n"
"varying float v;\n"
"invariant v;\n"
"void main() {\n"
" v = 1.0;\n"
" gl_Position = position;\n"
"}"
};
EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE));
EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE));
ShDestruct(compiler);
}
} // namespace sh
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