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,7 @@ 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$' > %t RUN: llvm-cxxfilt -n < %t | FileCheck %s CHECK: ,,Foo! @@ -66,4 +66,4 @@ CHECK: Foo~,, CHECK: Foo⦙Bar CHECK: Foo,,Bar::Baz Foo,Bar:Baz -CHECK: _Z3Foo$ ._Z3Foo +CHECK: _Z3Foo$ diff --git a/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-aix.test b/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-aix.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-aix.test @@ -0,0 +1,8 @@ +## Show the behaviour of demangling name with '.' prefix on AIX OS. + +REQUIRES: system-aix + +RUN: llvm-cxxfilt ._ZL5func0v ._Z5func1i | FileCheck %s -check-prefix CHECK + +CHECK: .func0() +CHECK: .func1(int) diff --git a/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-non-aix.test b/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-non-aix.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-cxxfilt/with-dot-prefix-non-aix.test @@ -0,0 +1,7 @@ +## Show the behaviour of demangling name with '.' prefix on Non-AIX os. +REQUIRES: !system-aix + +RUN: llvm-cxxfilt ._ZL5func0v ._Z5func1i | FileCheck %s -check-prefix CHECK + +CHECK: ._ZL5func0v +CHECK: ._Z5func1i 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 @@ -55,6 +55,7 @@ } // namespace static bool StripUnderscore; +static bool DecodePrefixWithDot; static bool Types; static StringRef ToolName; @@ -66,13 +67,21 @@ static std::string demangle(const std::string &Mangled) { const char *DecoratedStr = Mangled.c_str(); + std::string DotPrefix; + + // In XCOFF, Function entry lable begin with '.'. + if (DecodePrefixWithDot && 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 +94,7 @@ Undecorated = itaniumDemangle(DecoratedStr + 6, nullptr, nullptr, nullptr); } - Result = Undecorated ? Prefix + Undecorated : Mangled; + Result = Undecorated ? DotPrefix + Prefix + Undecorated : Mangled; free(Undecorated); return Result; } @@ -170,6 +179,9 @@ else StripUnderscore = Triple(sys::getProcessTriple()).isOSBinFormatMachO(); + DecodePrefixWithDot = + Triple(sys::getProcessTriple()).isOSBinFormatXCOFF() ? true : false; + Types = Args.hasArg(OPT_types); std::vector Decorated = Args.getAllArgValues(OPT_INPUT);