[PATCH] D104340: [Demangle] Support Rust v0 mangling scheme in llvm::demangle
Tomasz Miąsko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 15 16:38:38 PDT 2021
tmiasko created this revision.
tmiasko added a reviewer: dblaikie.
Herald added subscribers: JDevlieghere, hiraditya.
tmiasko requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The llvm::demangle is currently used by llvm-objdump and llvm-readobj,
so this effectively adds support for Rust v0 mangling to those
applications.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104340
Files:
llvm/lib/Demangle/Demangle.cpp
llvm/unittests/Demangle/DemangleTest.cpp
Index: llvm/unittests/Demangle/DemangleTest.cpp
===================================================================
--- llvm/unittests/Demangle/DemangleTest.cpp
+++ llvm/unittests/Demangle/DemangleTest.cpp
@@ -21,6 +21,7 @@
"invocation function for block in foo(int)");
EXPECT_EQ(demangle("?foo@@YAXH at Z"), "void __cdecl foo(int)");
EXPECT_EQ(demangle("foo"), "foo");
+ EXPECT_EQ(demangle("_RNvC3foo3bar"), "foo::bar");
// Regression test for demangling of optional template-args for vendor
// extended type qualifier (https://bugs.llvm.org/show_bug.cgi?id=48009)
Index: llvm/lib/Demangle/Demangle.cpp
===================================================================
--- llvm/lib/Demangle/Demangle.cpp
+++ llvm/lib/Demangle/Demangle.cpp
@@ -19,10 +19,17 @@
return Pos > 0 && Pos <= 4 && MangledName[Pos] == 'Z';
}
+static bool isRustEncoding(const std::string &MangledName) {
+ return MangledName.size() >= 2 && MangledName[0] == '_' &&
+ MangledName[1] == 'R';
+}
+
std::string llvm::demangle(const std::string &MangledName) {
char *Demangled;
if (isItaniumEncoding(MangledName))
Demangled = itaniumDemangle(MangledName.c_str(), nullptr, nullptr, nullptr);
+ else if (isRustEncoding(MangledName))
+ Demangled = rustDemangle(MangledName.c_str(), nullptr, nullptr, nullptr);
else
Demangled = microsoftDemangle(MangledName.c_str(), nullptr, nullptr,
nullptr, nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104340.352296.patch
Type: text/x-patch
Size: 1471 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210615/6e8bce81/attachment.bin>
More information about the llvm-commits
mailing list