Don't query names of empty symbols
This makes it possible to return a reference from TSymbol::name()
instead of a pointer. This is safer since it completely avoids the
possibility of a nullptr dereference. An assert is making sure that
the function is not being called for empty symbols.
BUG=angleproject:2267
TEST=angle_unittests
Change-Id: I44279f65989dbb828322843fc0216ba84d91dedf
Reviewed-on: https://chromium-review.googlesource.com/836894
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 9df5186..571b018 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -341,9 +341,8 @@
{
TInterfaceBlock *interfaceBlock =
mappedStruct.blockDeclarator->getType().getInterfaceBlock();
- const TString &interfaceBlockName = *interfaceBlock->name();
const TName &instanceName = mappedStruct.blockDeclarator->getName();
- if (mReferencedUniformBlocks.count(interfaceBlockName) == 0)
+ if (mReferencedUniformBlocks.count(interfaceBlock->name()) == 0)
{
continue;
}
@@ -380,7 +379,7 @@
TType *structType = mappedStruct.field->type();
mappedStructs +=
- "static " + Decorate(*structType->getStruct()->name()) + " " + mappedName;
+ "static " + Decorate(structType->getStruct()->name()) + " " + mappedName;
if (structType->isArray())
{
@@ -889,7 +888,7 @@
if (interfaceBlock)
{
- mReferencedUniformBlocks[*interfaceBlock->name()] = node;
+ mReferencedUniformBlocks[interfaceBlock->name()] = node;
}
else
{
@@ -1237,7 +1236,7 @@
{
TInterfaceBlock *interfaceBlock = leftType.getInterfaceBlock();
TIntermSymbol *instanceArraySymbol = node->getLeft()->getAsSymbolNode();
- mReferencedUniformBlocks[*interfaceBlock->name()] = instanceArraySymbol;
+ mReferencedUniformBlocks[interfaceBlock->name()] = instanceArraySymbol;
const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0);
out << mUniformHLSL->UniformBlockInstanceString(
instanceArraySymbol->getSymbol(), arrayIndex);
@@ -1925,16 +1924,16 @@
}
else if (node->getFunction()->isImageFunction())
{
- const TString *name = node->getFunction()->name();
+ const TString &name = node->getFunction()->name();
TType type = (*arguments)[0]->getAsTyped()->getType();
TString imageFunctionName = mImageFunctionHLSL->useImageFunction(
- *name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
+ name, type.getBasicType(), type.getLayoutQualifier().imageInternalFormat,
type.getMemoryQualifier().readonly);
out << imageFunctionName << "(";
}
else
{
- const TString *name = node->getFunction()->name();
+ const TString &name = node->getFunction()->name();
TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType();
int coords = 0; // textureSize(gsampler2DMS) doesn't have a second argument.
if (arguments->size() > 1)
@@ -1942,7 +1941,7 @@
coords = (*arguments)[1]->getAsTyped()->getNominalSize();
}
TString textureFunctionName = mTextureFunctionHLSL->useTextureFunction(
- *name, samplerType, coords, arguments->size(), lod0, mShaderType);
+ name, samplerType, coords, arguments->size(), lod0, mShaderType);
out << textureFunctionName << "(";
}