diff --git a/llvm/include/llvm/Demangle/Demangle.h b/llvm/include/llvm/Demangle/Demangle.h --- a/llvm/include/llvm/Demangle/Demangle.h +++ b/llvm/include/llvm/Demangle/Demangle.h @@ -67,7 +67,8 @@ /// demangling occurred. std::string demangle(std::string_view MangledName); -bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result); +bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result, + bool StripDot = true); /// "Partial" demangler. This supports demangling a string into an AST /// (typically an intermediate stage in itaniumDemangle) and querying certain diff --git a/llvm/lib/Demangle/Demangle.cpp b/llvm/lib/Demangle/Demangle.cpp --- a/llvm/lib/Demangle/Demangle.cpp +++ b/llvm/lib/Demangle/Demangle.cpp @@ -24,7 +24,7 @@ return Result; if (starts_with(MangledName, '_') && - nonMicrosoftDemangle(MangledName.substr(1), Result)) + nonMicrosoftDemangle(MangledName.substr(1), Result, false)) return Result; if (char *Demangled = microsoftDemangle(MangledName, nullptr, nullptr)) { @@ -46,8 +46,15 @@ static bool isDLangEncoding(std::string_view S) { return starts_with(S, "_D"); } bool llvm::nonMicrosoftDemangle(std::string_view MangledName, - std::string &Result) { + std::string &Result, bool StripDot) { char *Demangled = nullptr; + + // Do not consider the prefix dot as part of the demangled symbol name. + if (StripDot && MangledName.size() > 0 && MangledName[0] == '.') { + MangledName.remove_prefix(1); + Result = "."; + } + if (isItaniumEncoding(MangledName)) Demangled = itaniumDemangle(MangledName); else if (isRustEncoding(MangledName)) @@ -58,7 +65,7 @@ if (!Demangled) return false; - Result = Demangled; + Result += Demangled; std::free(Demangled); return true; } diff --git a/llvm/test/tools/llvm-cxxfilt/delimiters.test b/llvm/test/tools/llvm-cxxfilt/delimiters.test --- a/llvm/test/tools/llvm-cxxfilt/delimiters.test +++ b/llvm/test/tools/llvm-cxxfilt/delimiters.test @@ -66,4 +66,4 @@ CHECK: Foo~,, CHECK: Foo⦙Bar CHECK: Foo,,Bar::Baz Foo,Bar:Baz -CHECK: _Z3Foo$ ._Z3Foo +CHECK: _Z3Foo$ .Foo diff --git a/llvm/test/tools/llvm-cxxfilt/dot-prefix.test b/llvm/test/tools/llvm-cxxfilt/dot-prefix.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cxxfilt/dot-prefix.test @@ -0,0 +1,4 @@ +## Show that the llvm-cxxfilt does not consider the dot prefix to be part of the symbol name to be demangled. +RUN: llvm-cxxfilt -n ._ZL5func0v | FileCheck %s + +CHECK: .func0() diff --git a/llvm/test/tools/llvm-cxxfilt/strip-underscore.test b/llvm/test/tools/llvm-cxxfilt/strip-underscore.test --- a/llvm/test/tools/llvm-cxxfilt/strip-underscore.test +++ b/llvm/test/tools/llvm-cxxfilt/strip-underscore.test @@ -1,15 +1,17 @@ ## Show the behaviour of --[no-]strip-underscore. This test does not test ## the platform-specific default behaviour. This is tested elsewhere. -RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED -RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-STRIPPED -RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED -RUN: llvm-cxxfilt --no-strip-underscore __ZN2ns1fE _ZSt1f _f | FileCheck %s -check-prefix CHECK-UNSTRIPPED +RUN: llvm-cxxfilt -_ __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED +RUN: llvm-cxxfilt --strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-STRIPPED +RUN: llvm-cxxfilt -n __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED +RUN: llvm-cxxfilt --no-strip-underscore __ZN2ns1fE _ZSt1f _f _._Z3f.0v | FileCheck %s -check-prefix CHECK-UNSTRIPPED CHECK-STRIPPED: ns::f CHECK-STRIPPED: _ZSt1f CHECK-STRIPPED: _f +CHECK-STRIPPED: ._Z3f.0v CHECK-UNSTRIPPED: __ZN2ns1fE CHECK-UNSTRIPPED: std::f CHECK-UNSTRIPPED: _f +CHECK-UNSTRIPPED: _._Z3f.0v diff --git a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp --- a/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp +++ b/llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp @@ -67,12 +67,15 @@ static std::string demangle(const std::string &Mangled) { using llvm::itanium_demangle::starts_with; std::string_view DecoratedStr = Mangled; + bool StripDot = true; if (StripUnderscore) - if (DecoratedStr[0] == '_') + if (DecoratedStr[0] == '_') { DecoratedStr.remove_prefix(1); + StripDot = false; + } std::string Result; - if (nonMicrosoftDemangle(DecoratedStr, Result)) + if (nonMicrosoftDemangle(DecoratedStr, Result, StripDot)) return Result; std::string Prefix;