1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

[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
This commit is contained in:
Tomasz Miąsko 2021-06-17 10:30:04 +02:00
parent 9585730a05
commit a8b1d6117d
2 changed files with 8 additions and 0 deletions

View File

@ -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);

View File

@ -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)