diff --git a/llvm/test/tools/llvm-cxxfilt/prefix-dot.test b/llvm/test/tools/llvm-cxxfilt/prefix-dot.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cxxfilt/prefix-dot.test @@ -0,0 +1,9 @@ +## Show that the llvm-cxxfilt does not consider the prefix dot to be part of the symbol name to be demangled. + +RUN: echo '._Z3Foo ._Z3f.0v' \ +RUN: '._ZL5func0v ._Z5func1i' > %t +RUN: llvm-cxxfilt -n < %t | FileCheck %s + +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 @@ -72,13 +72,21 @@ static std::string demangle(const std::string &Mangled) { const char *DecoratedStr = Mangled.c_str(); + std::string DotPrefix; + + // Do 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; @@ -91,7 +99,7 @@ Undecorated = itaniumDemangle(DecoratedStr + 6, nullptr, nullptr, nullptr); } - Result = Undecorated ? Prefix + Undecorated : Mangled; + Result = Undecorated ? DotPrefix + Prefix + Undecorated : Mangled; free(Undecorated); return Result; }