diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2021-06-17 10:30:04 +0200 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2021-06-17 10:37:26 +0200 |
commit | 9b1085604ecf3d2d1a416ee658bca981af133128 (patch) | |
tree | 716b86ffedd61e8b668df106d5979dfb9b22295a | |
parent | 80a403348b0f4f5429c40816bf02ae37bd2e85a1 (diff) | |
download | llvm-9b1085604ecf3d2d1a416ee658bca981af133128.zip llvm-9b1085604ecf3d2d1a416ee658bca981af133128.tar.gz llvm-9b1085604ecf3d2d1a416ee658bca981af133128.tar.bz2 |
[Demangle] Support Rust v0 mangling scheme in llvm::demangle
The llvm::demangle is currently used by llvm-objdump and llvm-readobj,
so this effectively adds support for Rust v0 mangling to those
applications.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D104340
-rw-r--r-- | llvm/lib/Demangle/Demangle.cpp | 7 | ||||
-rw-r--r-- | llvm/unittests/Demangle/DemangleTest.cpp | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp index 000f75b..1851fb7 100644 --- a/llvm/lib/Demangle/Demangle.cpp +++ b/llvm/lib/Demangle/Demangle.cpp @@ -19,10 +19,17 @@ static bool isItaniumEncoding(const std::string &MangledName) { 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); diff --git a/llvm/unittests/Demangle/DemangleTest.cpp b/llvm/unittests/Demangle/DemangleTest.cpp index 1216d2c..b7b31f9 100644 --- a/llvm/unittests/Demangle/DemangleTest.cpp +++ b/llvm/unittests/Demangle/DemangleTest.cpp @@ -21,6 +21,7 @@ TEST(Demangle, demangleTest) { "invocation function for block in foo(int)"); EXPECT_EQ(demangle("?foo@@YAXH@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) |