[PATCH] D56855: Add ___Z demangling to new common demangle function
James Henderson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 18 04:36:35 PST 2019
jhenderson updated this revision to Diff 182495.
jhenderson added a comment.
Handle `__Z` and `____Z` too.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56855/new/
https://reviews.llvm.org/D56855
Files:
lib/Demangle/Demangle.cpp
unittests/Demangle/DemangleTest.cpp
Index: unittests/Demangle/DemangleTest.cpp
===================================================================
--- unittests/Demangle/DemangleTest.cpp
+++ unittests/Demangle/DemangleTest.cpp
@@ -13,7 +13,13 @@
using namespace llvm;
TEST(Demangle, demangleTest) {
+ EXPECT_EQ(demangle("_"), "_");
EXPECT_EQ(demangle("_Z3fooi"), "foo(int)");
+ EXPECT_EQ(demangle("__Z3fooi"), "foo(int)");
+ EXPECT_EQ(demangle("___Z3fooi_block_invoke"),
+ "invocation function for block in foo(int)");
+ EXPECT_EQ(demangle("____Z3fooi_block_invoke"),
+ "invocation function for block in foo(int)");
EXPECT_EQ(demangle("?foo@@YAXH at Z"), "void __cdecl foo(int)");
EXPECT_EQ(demangle("foo"), "foo");
}
Index: lib/Demangle/Demangle.cpp
===================================================================
--- lib/Demangle/Demangle.cpp
+++ lib/Demangle/Demangle.cpp
@@ -13,9 +13,16 @@
#include "llvm/Demangle/Demangle.h"
+static bool isItaniumEncoding(const std::string &MangledName) {
+ std::size_t FirstNonUnderscore = MangledName.find_first_not_of('_');
+ // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
+ return FirstNonUnderscore > 0 && FirstNonUnderscore <= 4 &&
+ MangledName[FirstNonUnderscore] == 'Z';
+}
+
std::string llvm::demangle(const std::string &MangledName) {
char *Demangled;
- if (MangledName.compare(0, 2, "_Z") == 0)
+ if (isItaniumEncoding(MangledName))
Demangled = itaniumDemangle(MangledName.c_str(), nullptr, nullptr, nullptr);
else
Demangled =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56855.182495.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190118/fecb8c27/attachment.bin>
More information about the llvm-commits
mailing list