Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ struct DEMANGLE_ABI SpecialTableSymbolNode : public SymbolNode {
return N->kind() == NodeKind::SpecialTableSymbol;
}

QualifiedNameNode *TargetName = nullptr;
NodeArrayNode *TargetNames = nullptr;
Qualifiers Quals = Qualifiers::Q_None;
};

Expand Down
50 changes: 36 additions & 14 deletions llvm/lib/Demangle/MicrosoftDemangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "llvm/Demangle/MicrosoftDemangle.h"

#include "llvm/ADT/SmallVector.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot build LLVM with gcc+gnu ld after this patch. It introduces cyclic dependencies (LLVMSupport <-> LLVMDemangle).

FAILED: lib/libLLVMDemangle.so.22.0git 
: && /usr/bin/c++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-dangling-reference -Wno-redundant-move -Wno-pessimizing-move -Wno-array-bounds -Wno-stringop-overread -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O2 -g -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete   -Wl,-rpath-link,/data/zyw/dev/llvm-build/./lib  -Wl,--gc-sections -shared -Wl,-soname,libLLVMDemangle.so.22.0git -o lib/libLLVMDemangle.so.22.0git lib/Demangle/CMakeFiles/LLVMDemangle.dir/Demangle.cpp.o lib/Demangle/CMakeFiles/LLVMDemangle.dir/ItaniumDemangle.cpp.o lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangleNodes.cpp.o lib/Demangle/CMakeFiles/LLVMDemangle.dir/RustDemangle.cpp.o lib/Demangle/CMakeFiles/LLVMDemangle.dir/DLangDemangle.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib:" && :
/usr/bin/ld: lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o: in function `llvm::SmallVectorTemplateCommon<llvm::ms_demangle::Node*, void>::grow_pod(unsigned long, unsigned long)':
/data/zyw/dev/llvm-project/llvm/include/llvm/ADT/SmallVector.h:140:(.text._ZN4llvm11ms_demangle9Demangler30demangleSpecialTableSymbolNodeERSt17basic_string_viewIcSt11char_traitsIcEENS0_20SpecialIntrinsicKindE+0x28c): undefined reference to `llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, opened #166586 to fix this.

#include "llvm/Demangle/Demangle.h"
#include "llvm/Demangle/DemangleConfig.h"
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
Expand Down Expand Up @@ -277,6 +278,28 @@ demanglePointerCVQualifiers(std::string_view &MangledName) {
DEMANGLE_UNREACHABLE;
}

static NodeArrayNode *nodeListToNodeArray(ArenaAllocator &Arena, NodeList *Head,
size_t Count) {
NodeArrayNode *N = Arena.alloc<NodeArrayNode>();
N->Count = Count;
N->Nodes = Arena.allocArray<Node *>(Count);
for (size_t I = 0; I < Count; ++I) {
N->Nodes[I] = Head->N;
Head = Head->Next;
}
return N;
}

template <unsigned N>
static NodeArrayNode *smallVecToNodeArray(ArenaAllocator &Arena,
const SmallVector<Node *, N> &Vec) {
NodeArrayNode *Arr = Arena.alloc<NodeArrayNode>();
Arr->Count = Vec.size();
Arr->Nodes = Arena.allocArray<Node *>(Vec.size());
std::memcpy(Arr->Nodes, Vec.data(), Vec.size() * sizeof(Node *));
return Arr;
}

std::string_view Demangler::copyString(std::string_view Borrowed) {
char *Stable = Arena.allocUnalignedBuffer(Borrowed.size());
// This is not a micro-optimization, it avoids UB, should Borrowed be an null
Expand Down Expand Up @@ -323,8 +346,19 @@ Demangler::demangleSpecialTableSymbolNode(std::string_view &MangledName,
}

std::tie(STSN->Quals, IsMember) = demangleQualifiers(MangledName);
if (!consumeFront(MangledName, '@'))
STSN->TargetName = demangleFullyQualifiedTypeName(MangledName);

SmallVector<Node *, 1> TargetNames;
while (!consumeFront(MangledName, '@')) {
QualifiedNameNode *QN = demangleFullyQualifiedTypeName(MangledName);
if (Error)
return nullptr;
assert(QN);
TargetNames.push_back(QN);
}

if (!TargetNames.empty())
STSN->TargetNames = smallVecToNodeArray(Arena, TargetNames);

return STSN;
}

Expand Down Expand Up @@ -1605,18 +1639,6 @@ Demangler::demangleNameScopePiece(std::string_view &MangledName) {
return demangleSimpleName(MangledName, /*Memorize=*/true);
}

static NodeArrayNode *nodeListToNodeArray(ArenaAllocator &Arena, NodeList *Head,
size_t Count) {
NodeArrayNode *N = Arena.alloc<NodeArrayNode>();
N->Count = Count;
N->Nodes = Arena.allocArray<Node *>(Count);
for (size_t I = 0; I < Count; ++I) {
N->Nodes[I] = Head->N;
Head = Head->Next;
}
return N;
}

QualifiedNameNode *
Demangler::demangleNameScopeChain(std::string_view &MangledName,
IdentifierNode *UnqualifiedName) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,9 @@ void VcallThunkIdentifierNode::output(OutputBuffer &OB,
void SpecialTableSymbolNode::output(OutputBuffer &OB, OutputFlags Flags) const {
outputQualifiers(OB, Quals, false, true);
Name->output(OB, Flags);
if (TargetName) {
if (TargetNames) {
OB << "{for `";
TargetName->output(OB, Flags);
TargetNames->output(OB, Flags, "'s `");
OB << "'}";
}
}
15 changes: 15 additions & 0 deletions llvm/test/Demangle/ms-operators.test
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,24 @@
??_7A@B@@6BC@D@@@
; CHECK: const B::A::`vftable'{for `D::C'}

??_7A@B@@6BC@D@@E@F@@@
; CHECK: const B::A::`vftable'{for `D::C's `F::E'}

??_7A@B@@6BC@D@@E@F@@G@H@@@
; CHECK: const B::A::`vftable'{for `D::C's `F::E's `H::G'}

??_8Middle2@@7B@
; CHECK: const Middle2::`vbtable'

??_7A@@6BB@@@
; CHECK: const A::`vftable'{for `B'}

??_7A@@6BB@@C@@@
; CHECK: const A::`vftable'{for `B's `C'}

??_7A@@6BB@@C@@D@@@
; CHECK: const A::`vftable'{for `B's `C's `D'}

??_9Base@@$B7AA
; CHECK: [thunk]: __cdecl Base::`vcall'{8, {flat}}

Expand Down
Loading