Duplicate reused symbol table entries.
BUG=angle:651
Change-Id: Ifce3c19d41a0a5a5ca5ee90ede528adf397d1da5
Reviewed-on: https://chromium-review.googlesource.com/204290
Tested-by: Nicolas Capens <nicolascapens@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shannon Woods <shannonwoods@chromium.org>
diff --git a/src/compiler/translator/Initialize.cpp b/src/compiler/translator/Initialize.cpp
index 27e96f4..e542a3f 100644
--- a/src/compiler/translator/Initialize.cpp
+++ b/src/compiler/translator/Initialize.cpp
@@ -566,10 +566,10 @@
fields->push_back(diff);
TStructure *depthRangeStruct = new TStructure(NewPoolTString("gl_DepthRangeParameters"), fields);
TVariable *depthRangeParameters = new TVariable(&depthRangeStruct->name(), depthRangeStruct, true);
- symbolTable.insert(COMMON_BUILTINS, *depthRangeParameters);
+ symbolTable.insert(COMMON_BUILTINS, depthRangeParameters);
TVariable *depthRange = new TVariable(NewPoolTString("gl_DepthRange"), TType(depthRangeStruct));
depthRange->setQualifier(EvqUniform);
- symbolTable.insert(COMMON_BUILTINS, *depthRange);
+ symbolTable.insert(COMMON_BUILTINS, depthRange);
//
// Implementation dependent built-in constants.
@@ -604,31 +604,31 @@
//
switch(type) {
case SH_FRAGMENT_SHADER:
- symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
- symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
- symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
+ symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FragCoord"), TType(EbtFloat, EbpMedium, EvqFragCoord, 4)));
+ symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_FrontFacing"), TType(EbtBool, EbpUndefined, EvqFrontFacing, 1)));
+ symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointCoord"), TType(EbtFloat, EbpMedium, EvqPointCoord, 2)));
//
// In CSS Shaders, gl_FragColor, gl_FragData, and gl_MaxDrawBuffers are not available.
// Instead, css_MixColor and css_ColorMatrix are available.
//
if (spec != SH_CSS_SHADERS_SPEC) {
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
if (resources.EXT_frag_depth) {
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
symbolTable.relateToExtension(ESSL1_BUILTINS, "gl_FragDepthEXT", "GL_EXT_frag_depth");
}
} else {
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, 4)));
}
break;
case SH_VERTEX_SHADER:
- symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
- symbolTable.insert(COMMON_BUILTINS, *new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
+ symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_Position"), TType(EbtFloat, EbpHigh, EvqPosition, 4)));
+ symbolTable.insert(COMMON_BUILTINS, new TVariable(NewPoolTString("gl_PointSize"), TType(EbtFloat, EbpMedium, EvqPointSize, 1)));
break;
default: assert(false && "Language not supported");
@@ -735,7 +735,7 @@
// Set up gl_FragData. The array size.
TType fragData(EbtFloat, EbpMedium, EvqFragData, 4, 1, true);
fragData.setArraySize(resources.MaxDrawBuffers);
- symbolTable.insert(ESSL1_BUILTINS, *new TVariable(NewPoolTString("gl_FragData"), fragData));
+ symbolTable.insert(ESSL1_BUILTINS, new TVariable(NewPoolTString("gl_FragData"), fragData));
}
break;
default: break;
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index d3df7c8..8b3bfed 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -804,7 +804,7 @@
if (type.arraySize)
variable->getType().setArraySize(type.arraySize);
- if (! symbolTable.declare(*variable)) {
+ if (! symbolTable.declare(variable)) {
delete variable;
error(line, "INTERNAL ERROR inserting new symbol", identifier.c_str());
return true;
@@ -884,7 +884,7 @@
variable = new TVariable(&identifier, TType(type));
- if (! symbolTable.declare(*variable)) {
+ if (! symbolTable.declare(variable)) {
error(line, "redefinition", variable->getName().c_str());
delete variable;
variable = 0;
@@ -1066,7 +1066,7 @@
// add variable to symbol table
//
variable = new TVariable(&identifier, type);
- if (! symbolTable.declare(*variable)) {
+ if (! symbolTable.declare(variable)) {
error(line, "redefinition", variable->getName().c_str());
return true;
// don't delete variable, it's used by error recovery, and the pool
@@ -1774,7 +1774,7 @@
}
TSymbol* blockNameSymbol = new TInterfaceBlockName(&blockName);
- if (!symbolTable.declare(*blockNameSymbol)) {
+ if (!symbolTable.declare(blockNameSymbol)) {
error(nameLine, "redefinition", blockName.c_str(), "interface block name");
recover();
}
@@ -1854,7 +1854,7 @@
TVariable* fieldVariable = new TVariable(&field->name(), *fieldType);
fieldVariable->setQualifier(typeQualifier.qualifier);
- if (!symbolTable.declare(*fieldVariable)) {
+ if (!symbolTable.declare(fieldVariable)) {
error(field->line(), "redefinition", field->name().c_str(), "interface block member name");
recover();
}
@@ -1866,7 +1866,7 @@
TVariable* instanceTypeDef = new TVariable(instanceName, interfaceBlockType, false);
instanceTypeDef->setQualifier(typeQualifier.qualifier);
- if (!symbolTable.declare(*instanceTypeDef)) {
+ if (!symbolTable.declare(instanceTypeDef)) {
error(instanceLine, "redefinition", instanceName->c_str(), "interface block instance name");
recover();
}
@@ -2455,7 +2455,7 @@
recover();
}
TVariable* userTypeDef = new TVariable(structName, *structureType, true);
- if (!symbolTable.declare(*userTypeDef)) {
+ if (!symbolTable.declare(userTypeDef)) {
error(nameLine, "redefinition", structName->c_str(), "struct");
recover();
}
diff --git a/src/compiler/translator/SymbolTable.cpp b/src/compiler/translator/SymbolTable.cpp
index aa5933d..ae4fcaa 100644
--- a/src/compiler/translator/SymbolTable.cpp
+++ b/src/compiler/translator/SymbolTable.cpp
@@ -38,21 +38,16 @@
delete (*it).second;
}
-bool TSymbolTableLevel::insert(const TString &name, TSymbol &symbol)
+bool TSymbolTableLevel::insert(TSymbol *symbol)
{
- symbol.setUniqueId(TSymbolTable::nextUniqueId());
+ symbol->setUniqueId(TSymbolTable::nextUniqueId());
// returning true means symbol was added to the table
- tInsertResult result = level.insert(tLevelPair(name, &symbol));
+ tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol));
return result.second;
}
-bool TSymbolTableLevel::insert(TSymbol &symbol)
-{
- return insert(symbol.getMangledName(), symbol);
-}
-
TSymbol *TSymbolTableLevel::find(const TString &name) const
{
tLevel::const_iterator it = level.find(name);
@@ -212,7 +207,7 @@
}
}
- insert(level, *function);
+ insert(level, function);
}
TPrecision TSymbolTable::getDefaultPrecision(TBasicType type)
diff --git a/src/compiler/translator/SymbolTable.h b/src/compiler/translator/SymbolTable.h
index 078e0be..d3ddf19 100644
--- a/src/compiler/translator/SymbolTable.h
+++ b/src/compiler/translator/SymbolTable.h
@@ -185,7 +185,7 @@
defined(false)
{
}
- TFunction(const TString *name, TType &retType, TOperator tOp = EOpNull)
+ TFunction(const TString *name, const TType &retType, TOperator tOp = EOpNull)
: TSymbol(name),
returnType(retType),
mangledName(TFunction::mangleName(*name)),
@@ -288,8 +288,7 @@
}
~TSymbolTableLevel();
- bool insert(const TString &name, TSymbol &symbol);
- bool insert(TSymbol &symbol);
+ bool insert(TSymbol *symbol);
TSymbol *find(const TString &name) const;
@@ -351,12 +350,12 @@
precisionStack.pop_back();
}
- bool declare(TSymbol &symbol)
+ bool declare(TSymbol *symbol)
{
return insert(currentLevel(), symbol);
}
- bool insert(ESymbolLevel level, TSymbol &symbol)
+ bool insert(ESymbolLevel level, TSymbol *symbol)
{
return table[level]->insert(symbol);
}
@@ -366,7 +365,7 @@
TVariable *constant = new TVariable(
NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
constant->getConstPointer()->setIConst(value);
- return insert(level, *constant);
+ return insert(level, constant);
}
void insertBuiltIn(ESymbolLevel level, TType *rvalue, const char *name,
diff --git a/src/compiler/translator/glslang.y b/src/compiler/translator/glslang.y
index 8ebf2d1..1680f79 100644
--- a/src/compiler/translator/glslang.y
+++ b/src/compiler/translator/glslang.y
@@ -237,7 +237,7 @@
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable($1.string, type);
- context->symbolTable.declare(*fakeVariable);
+ context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
@@ -887,7 +887,8 @@
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
- context->symbolTable.getOuterLevel()->insert($1->getName(), *$1);
+ TFunction *function = new TFunction(NewPoolTString($1->getName().c_str()), $1->getReturnType());
+ context->symbolTable.getOuterLevel()->insert(function);
}
//
@@ -899,7 +900,7 @@
// We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead.
- context->symbolTable.getOuterLevel()->insert(*$$.function);
+ context->symbolTable.getOuterLevel()->insert($$.function);
}
;
@@ -1899,7 +1900,7 @@
//
// Insert the parameters with name in the symbol table.
//
- if (! context->symbolTable.declare(*variable)) {
+ if (! context->symbolTable.declare(variable)) {
context->error(@1, "redefinition", variable->getName().c_str());
context->recover();
delete variable;
diff --git a/src/compiler/translator/glslang_tab.cpp b/src/compiler/translator/glslang_tab.cpp
index 63ec8c7..fc0169e 100644
--- a/src/compiler/translator/glslang_tab.cpp
+++ b/src/compiler/translator/glslang_tab.cpp
@@ -2575,7 +2575,7 @@
{
TType type(EbtFloat, EbpUndefined);
TVariable *fakeVariable = new TVariable((yyvsp[(1) - (1)].lex).string, type);
- context->symbolTable.declare(*fakeVariable);
+ context->symbolTable.declare(fakeVariable);
variable = fakeVariable;
}
@@ -3436,7 +3436,8 @@
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
- context->symbolTable.getOuterLevel()->insert((yyvsp[(1) - (2)].interm.function)->getName(), *(yyvsp[(1) - (2)].interm.function));
+ TFunction *function = new TFunction(NewPoolTString((yyvsp[(1) - (2)].interm.function)->getName().c_str()), (yyvsp[(1) - (2)].interm.function)->getReturnType());
+ context->symbolTable.getOuterLevel()->insert(function);
}
//
@@ -3448,7 +3449,7 @@
// We're at the inner scope level of the function's arguments and body statement.
// Add the function prototype to the surrounding scope instead.
- context->symbolTable.getOuterLevel()->insert(*(yyval.interm).function);
+ context->symbolTable.getOuterLevel()->insert((yyval.interm).function);
}
break;
@@ -4967,7 +4968,7 @@
//
// Insert the parameters with name in the symbol table.
//
- if (! context->symbolTable.declare(*variable)) {
+ if (! context->symbolTable.declare(variable)) {
context->error((yylsp[(1) - (1)]), "redefinition", variable->getName().c_str());
context->recover();
delete variable;