[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 06:02:38 PST 2019
This revision was automatically updated to reflect the committed changes.
jhenderson marked 2 inline comments as done.
Closed by commit rL351551: Add __[_[_]]Z demangling to new common demangle function (authored by jhenderson, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D56855?vs=182495&id=182503#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D56855/new/
https://reviews.llvm.org/D56855
Files:
llvm/trunk/lib/Demangle/Demangle.cpp
llvm/trunk/unittests/Demangle/DemangleTest.cpp
Index: llvm/trunk/lib/Demangle/Demangle.cpp
===================================================================
--- llvm/trunk/lib/Demangle/Demangle.cpp
+++ llvm/trunk/lib/Demangle/Demangle.cpp
@@ -13,9 +13,15 @@
#include "llvm/Demangle/Demangle.h"
+static bool isItaniumEncoding(const std::string &MangledName) {
+ size_t Pos = MangledName.find_first_not_of('_');
+ // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'.
+ return Pos > 0 && Pos <= 4 && MangledName[Pos] == '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 =
Index: llvm/trunk/unittests/Demangle/DemangleTest.cpp
===================================================================
--- llvm/trunk/unittests/Demangle/DemangleTest.cpp
+++ llvm/trunk/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");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56855.182503.patch
Type: text/x-patch
Size: 1541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190118/e6e31376/attachment.bin>
More information about the llvm-commits
mailing list