Skip to content

Commit f535694

Browse files
committed
Add __[_[_]]Z demangling to new common demangle function
This is a follow-up to r351448. It adds support for other _*Z extensions of the Itanium demanling, to the newly available demangle function heuristic. Reviewed by: erik.pilkington, rupprecht, grimar Differential Revision: https://reviews.llvm.org/D56855 llvm-svn: 351551
1 parent 63efa3b commit f535694

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Demangle/Demangle.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313

1414
#include "llvm/Demangle/Demangle.h"
1515

16+
static bool isItaniumEncoding(const std::string &MangledName) {
17+
size_t Pos = MangledName.find_first_not_of('_');
18+
// A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
19+
return Pos > 0 && Pos <= 4 && MangledName[Pos] == 'Z';
20+
}
21+
1622
std::string llvm::demangle(const std::string &MangledName) {
1723
char *Demangled;
18-
if (MangledName.compare(0, 2, "_Z") == 0)
24+
if (isItaniumEncoding(MangledName))
1925
Demangled = itaniumDemangle(MangledName.c_str(), nullptr, nullptr, nullptr);
2026
else
2127
Demangled =

llvm/unittests/Demangle/DemangleTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
using namespace llvm;
1414

1515
TEST(Demangle, demangleTest) {
16+
EXPECT_EQ(demangle("_"), "_");
1617
EXPECT_EQ(demangle("_Z3fooi"), "foo(int)");
18+
EXPECT_EQ(demangle("__Z3fooi"), "foo(int)");
19+
EXPECT_EQ(demangle("___Z3fooi_block_invoke"),
20+
"invocation function for block in foo(int)");
21+
EXPECT_EQ(demangle("____Z3fooi_block_invoke"),
22+
"invocation function for block in foo(int)");
1723
EXPECT_EQ(demangle("?foo@@YAXH@Z"), "void __cdecl foo(int)");
1824
EXPECT_EQ(demangle("foo"), "foo");
1925
}

0 commit comments

Comments
 (0)