Commit c7965001 by Jamie Madill

Revert "Make TType store a const char * for mangled name."

This reverts commit dc7bffd0. Reason for revert: Causes a memory leak, detected by ASAN bot: https://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_asan_rel_ng/builds/494713 Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x847aa2 in operator new(unsigned long) /b/build/slave/linux_upload_clang/build/src/third_party/llvm/compiler-rt/lib/asan/asan_new_delete.cc:92:3 #1 0x193a833 in sh::TType::buildMangledName() const third_party/angle/src/compiler/translator/Types.cpp:545:21 #2 0x193d2e8 in getMangledName third_party/angle/src/compiler/translator/Types.cpp:751:24 #3 0x193d2e8 in sh::TType::realize() third_party/angle/src/compiler/translator/Types.cpp:759 #4 0x1834474 in sh::TCache::getType(sh::TBasicType, sh::TPrecision, sh::TQualifier, unsigned char, unsigned char) third_party/angle/src/compiler/translator/Cache.cpp:89:11 #5 0x1859ac7 in getType third_party/angle/src/compiler/translator/Cache.h:36:16 #6 0x1859ac7 in sh::InsertBuiltInFunctions(unsigned int, ShShaderSpec, ShBuiltInResources const&, sh::TSymbolTable&) third_party/angle/src/compiler/translator/Initialize.cpp:28 Bug: angleproject:1432 Original change's description: > Make TType store a const char * for mangled name. > > We would only ever use the c_str value from the mangled name. This > makes it easier to make constexpr TTypes. > > Bug: angleproject:1432 > Change-Id: I147b3a85f9b8b2453e2d7f4a713d767b22036cc9 > Reviewed-on: https://chromium-review.googlesource.com/776277 > Commit-Queue: Jamie Madill <jmadill@chromium.org> > Reviewed-by: Kai Ninomiya <kainino@chromium.org> TBR=jmadill@chromium.org,kainino@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: angleproject:1432 Change-Id: Ib112a2ce9871a4f4afc53101ac1a3ddd166008cf Reviewed-on: https://chromium-review.googlesource.com/780420Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 85c93c41
...@@ -66,7 +66,7 @@ const TString *TFunction::buildMangledName() const ...@@ -66,7 +66,7 @@ const TString *TFunction::buildMangledName() const
for (const auto &p : parameters) for (const auto &p : parameters)
{ {
newName += p.type->getMangledName(); newName += p.type->getMangledName().c_str();
} }
return NewPoolTString(newName.c_str()); return NewPoolTString(newName.c_str());
} }
...@@ -79,7 +79,7 @@ const TString &TFunction::GetMangledNameFromCall(const TString &functionName, ...@@ -79,7 +79,7 @@ const TString &TFunction::GetMangledNameFromCall(const TString &functionName,
for (TIntermNode *argument : arguments) for (TIntermNode *argument : arguments)
{ {
newName += argument->getAsTyped()->getType().getMangledName(); newName += argument->getAsTyped()->getType().getMangledName().c_str();
} }
return *NewPoolTString(newName.c_str()); return *NewPoolTString(newName.c_str());
} }
......
...@@ -125,8 +125,7 @@ TType::TType() ...@@ -125,8 +125,7 @@ TType::TType()
secondarySize(0), secondarySize(0),
mInterfaceBlock(nullptr), mInterfaceBlock(nullptr),
mStructure(nullptr), mStructure(nullptr),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
} }
...@@ -141,8 +140,7 @@ TType::TType(TBasicType t, unsigned char ps, unsigned char ss) ...@@ -141,8 +140,7 @@ TType::TType(TBasicType t, unsigned char ps, unsigned char ss)
secondarySize(ss), secondarySize(ss),
mInterfaceBlock(0), mInterfaceBlock(0),
mStructure(0), mStructure(0),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
} }
...@@ -157,8 +155,7 @@ TType::TType(TBasicType t, TPrecision p, TQualifier q, unsigned char ps, unsigne ...@@ -157,8 +155,7 @@ TType::TType(TBasicType t, TPrecision p, TQualifier q, unsigned char ps, unsigne
secondarySize(ss), secondarySize(ss),
mInterfaceBlock(0), mInterfaceBlock(0),
mStructure(0), mStructure(0),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
} }
...@@ -173,8 +170,7 @@ TType::TType(const TPublicType &p) ...@@ -173,8 +170,7 @@ TType::TType(const TPublicType &p)
secondarySize(p.getSecondarySize()), secondarySize(p.getSecondarySize()),
mInterfaceBlock(nullptr), mInterfaceBlock(nullptr),
mStructure(nullptr), mStructure(nullptr),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
ASSERT(primarySize <= 4); ASSERT(primarySize <= 4);
ASSERT(secondarySize <= 4); ASSERT(secondarySize <= 4);
...@@ -200,8 +196,7 @@ TType::TType(TStructure *userDef) ...@@ -200,8 +196,7 @@ TType::TType(TStructure *userDef)
secondarySize(1), secondarySize(1),
mInterfaceBlock(nullptr), mInterfaceBlock(nullptr),
mStructure(userDef), mStructure(userDef),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
} }
...@@ -218,8 +213,7 @@ TType::TType(TInterfaceBlock *interfaceBlockIn, ...@@ -218,8 +213,7 @@ TType::TType(TInterfaceBlock *interfaceBlockIn,
secondarySize(1), secondarySize(1),
mInterfaceBlock(interfaceBlockIn), mInterfaceBlock(interfaceBlockIn),
mStructure(0), mStructure(0),
mIsStructSpecifier(false), mIsStructSpecifier(false)
mMangledName(nullptr)
{ {
} }
...@@ -381,7 +375,7 @@ TString TType::getCompleteString() const ...@@ -381,7 +375,7 @@ TString TType::getCompleteString() const
// //
// Recursively generate mangled names. // Recursively generate mangled names.
// //
const char *TType::buildMangledName() const TString TType::buildMangledName() const
{ {
TString mangledName; TString mangledName;
if (isMatrix()) if (isMatrix())
...@@ -538,12 +532,7 @@ const char *TType::buildMangledName() const ...@@ -538,12 +532,7 @@ const char *TType::buildMangledName() const
mangledName += buf; mangledName += buf;
mangledName += ']'; mangledName += ']';
} }
return mangledName;
mangledName += ';';
// We allocate with the pool allocator, so it's fine that the TString goes out of scope.
TString *temp = new TString(mangledName);
return temp->c_str();
} }
size_t TType::getObjectSize() const size_t TType::getObjectSize() const
...@@ -744,11 +733,12 @@ void TType::setStruct(TStructure *s) ...@@ -744,11 +733,12 @@ void TType::setStruct(TStructure *s)
} }
} }
const char *TType::getMangledName() const const TString &TType::getMangledName() const
{ {
if (mMangledName == nullptr) if (mMangledName.empty())
{ {
mMangledName = buildMangledName(); mMangledName = buildMangledName();
mMangledName += ';';
} }
return mMangledName; return mMangledName;
...@@ -761,7 +751,7 @@ void TType::realize() ...@@ -761,7 +751,7 @@ void TType::realize()
void TType::invalidateMangledName() void TType::invalidateMangledName()
{ {
mMangledName = nullptr; mMangledName = "";
} }
// TStructure implementation. // TStructure implementation.
......
...@@ -279,7 +279,7 @@ class TType ...@@ -279,7 +279,7 @@ class TType
const TStructure *getStruct() const { return mStructure; } const TStructure *getStruct() const { return mStructure; }
void setStruct(TStructure *s); void setStruct(TStructure *s);
const char *getMangledName() const; const TString &getMangledName() const;
bool sameNonArrayType(const TType &right) const; bool sameNonArrayType(const TType &right) const;
...@@ -368,7 +368,7 @@ class TType ...@@ -368,7 +368,7 @@ class TType
private: private:
void invalidateMangledName(); void invalidateMangledName();
const char *buildMangledName() const; TString buildMangledName() const;
TBasicType type; TBasicType type;
TPrecision precision; TPrecision precision;
...@@ -393,7 +393,7 @@ class TType ...@@ -393,7 +393,7 @@ class TType
TStructure *mStructure; TStructure *mStructure;
bool mIsStructSpecifier; bool mIsStructSpecifier;
mutable const char *mMangledName; mutable TString mMangledName;
}; };
// TTypeSpecifierNonArray stores all of the necessary fields for type_specifier_nonarray from the // TTypeSpecifierNonArray stores all of the necessary fields for type_specifier_nonarray from the
......
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