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 @@ -32,7 +32,10 @@ COM: Piping the echo output causes '⦙' to be converted to '?' in some COM: builds/environments. Redirect echo output to and from %t to work COM: around this. See D111072. -RUN: '_Z3Foo$ ._Z3Foo' > %t +RUN: '_Z3Foo$ _Z3f.0v' \ +## Show that the llvm-cxxfilt does not consider the prefix dot as part of the demangled symbol name. +RUN: '._Z3Foo ._Z3f.0v' \ +RUN: '._ZL5func0v ._Z5func1i' > %t RUN: llvm-cxxfilt -n < %t | FileCheck %s CHECK: ,,Foo! @@ -66,4 +69,7 @@ CHECK: Foo~,, CHECK: Foo⦙Bar CHECK: Foo,,Bar::Baz Foo,Bar:Baz -CHECK: _Z3Foo$ ._Z3Foo +CHECK: _Z3Foo$ f.0() +CHECK: .Foo .f.0() +CHECK: .func0() +CHECK: .func1(int) 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 @@ -66,13 +66,21 @@ static std::string demangle(const std::string &Mangled) { const char *DecoratedStr = Mangled.c_str(); + std::string DotPrefix; + + // Not consider the prefix dot as part of the demangled symbol name. + if (DecoratedStr[0] == '.') { + ++DecoratedStr; + DotPrefix = "."; + } + if (StripUnderscore) if (DecoratedStr[0] == '_') ++DecoratedStr; std::string Result; if (nonMicrosoftDemangle(DecoratedStr, Result)) - return Result; + return DotPrefix + Result; std::string Prefix; char *Undecorated = nullptr; @@ -85,7 +93,7 @@ Undecorated = itaniumDemangle(DecoratedStr + 6, nullptr, nullptr, nullptr); } - Result = Undecorated ? Prefix + Undecorated : Mangled; + Result = Undecorated ? DotPrefix + Prefix + Undecorated : Mangled; free(Undecorated); return Result; }