diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2015-06-09 20:41:08 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2015-06-09 20:41:08 +0000 |
| commit | 6d17edc534265ccd1c06ed9c22f68876ed2c00de (patch) | |
| tree | 5c4aed770dd4a33115aaa56b6b57c9ff0f53701a /llvm | |
| parent | a9ecddbbe5dbb1f463065b38e37fbc0d3022bcc8 (diff) | |
| download | bcm5719-llvm-6d17edc534265ccd1c06ed9c22f68876ed2c00de.tar.gz bcm5719-llvm-6d17edc534265ccd1c06ed9c22f68876ed2c00de.zip | |
Reduce duplication in MCSymbol Name handling. NFC>
Based on feedback to r239428 by David Blaikie, use const_cast to reduce
duplication of the const and non-const versions of getNameEntryPtr.
Also have that method return the pointer to the name directly instead
of users having to then get the name from the union.
Finally, add a FIXME that we should use a static_assert once available in
the new operator.
llvm-svn: 239429
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/MC/MCSymbol.h | 14 | ||||
| -rw-r--r-- | llvm/lib/MC/MCSymbol.cpp | 1 |
2 files changed, 7 insertions, 8 deletions
diff --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h index 544cf8abe60..78b7c516e83 100644 --- a/llvm/include/llvm/MC/MCSymbol.h +++ b/llvm/include/llvm/MC/MCSymbol.h @@ -136,7 +136,7 @@ protected: // MCContext creates and uniques these. Kind(Kind) { Offset = 0; if (Name) - getNameEntryPtr().NameEntry = Name; + getNameEntryPtr() = Name; } // Provide custom new/delete as we will only allocate space for a name @@ -169,15 +169,13 @@ private: } /// \brief Get a reference to the name field. Requires that we have a name - NameEntryStorageTy &getNameEntryPtr() { + const StringMapEntry<bool> *&getNameEntryPtr() { assert(HasName && "Name is required"); NameEntryStorageTy *Name = reinterpret_cast<NameEntryStorageTy *>(this); - return *(Name - 1); + return (*(Name - 1)).NameEntry; } - const NameEntryStorageTy &getNameEntryPtr() const { - assert(HasName && "Name is required"); - const auto *Name = reinterpret_cast<const NameEntryStorageTy *>(this); - return *(Name - 1); + const StringMapEntry<bool> *&getNameEntryPtr() const { + return const_cast<MCSymbol*>(this)->getNameEntryPtr(); } public: @@ -186,7 +184,7 @@ public: if (!HasName) return StringRef(); - return getNameEntryPtr().NameEntry->first(); + return getNameEntryPtr()->first(); } bool isRegistered() const { return IsRegistered; } diff --git a/llvm/lib/MC/MCSymbol.cpp b/llvm/lib/MC/MCSymbol.cpp index a5097bc90f6..f0f35f7b29e 100644 --- a/llvm/lib/MC/MCSymbol.cpp +++ b/llvm/lib/MC/MCSymbol.cpp @@ -28,6 +28,7 @@ void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name, // For safety, ensure that the alignment of a pointer is enough for an // MCSymbol. This also ensures we don't need padding between the name and // symbol. + // FIXME: Use static_assert when constexpr is supported. assert(alignOf<MCSymbol>() <= alignOf<NameEntryStorageTy>() && "Bad alignment of MCSymbol"); void *Storage = Ctx.allocate(Size, alignOf<NameEntryStorageTy>()); |

