[PATCH] D139864: [AIX] Demangle the name prefix with '.' in AIX OS for llvm-cxxfilt

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 10:45:19 PST 2023


DiggerLin updated this revision to Diff 498080.
DiggerLin marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139864/new/

https://reviews.llvm.org/D139864

Files:
  llvm/test/tools/llvm-cxxfilt/delimiters.test
  llvm/test/tools/llvm-cxxfilt/with-dot-prefix-aix.test
  llvm/test/tools/llvm-cxxfilt/with-dot-prefix-non-aix.test
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp


Index: llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
===================================================================
--- llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
+++ 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<std::string> Decorated = Args.getAllArgValues(OPT_INPUT);
Index: llvm/test/tools/llvm-cxxfilt/with-dot-prefix-non-aix.test
===================================================================
--- /dev/null
+++ 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
Index: llvm/test/tools/llvm-cxxfilt/with-dot-prefix-aix.test
===================================================================
--- /dev/null
+++ 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)
Index: llvm/test/tools/llvm-cxxfilt/delimiters.test
===================================================================
--- llvm/test/tools/llvm-cxxfilt/delimiters.test
+++ 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$


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139864.498080.patch
Type: text/x-patch
Size: 3064 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230216/1d12b0b6/attachment.bin>


More information about the llvm-commits mailing list