[PATCH] D139864: [llvm-cxxfilt] Do not consider the prefix dot as part of the demangled symbol name.

Digger Lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 19:07:29 PDT 2023


DiggerLin updated this revision to Diff 557218.
DiggerLin added a comment.

rebase the code


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/prefix-dot.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
@@ -67,13 +67,19 @@
 static std::string demangle(const std::string &Mangled) {
   using llvm::itanium_demangle::starts_with;
   std::string_view DecoratedStr = Mangled;
-  if (StripUnderscore)
-    if (DecoratedStr[0] == '_')
-      DecoratedStr.remove_prefix(1);
+  std::string DotPrefix;
+
+  if (StripUnderscore && DecoratedStr[0] == '_')
+    DecoratedStr.remove_prefix(1);
+  // Do not consider the prefix dot as part of the demangled symbol name.
+  else if (DecoratedStr[0] == '.') {
+    DecoratedStr.remove_prefix(1);
+    DotPrefix = ".";
+  }
 
   std::string Result;
   if (nonMicrosoftDemangle(DecoratedStr, Result))
-    return Result;
+    return DotPrefix + Result;
 
   std::string Prefix;
   char *Undecorated = nullptr;
@@ -86,7 +92,7 @@
     Undecorated = itaniumDemangle(DecoratedStr.substr(6));
   }
 
-  Result = Undecorated ? Prefix + Undecorated : Mangled;
+  Result = Undecorated ? DotPrefix + Prefix + Undecorated : Mangled;
   free(Undecorated);
   return Result;
 }
Index: llvm/test/tools/llvm-cxxfilt/prefix-dot.test
===================================================================
--- /dev/null
+++ 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)
Index: llvm/test/tools/llvm-cxxfilt/delimiters.test
===================================================================
--- llvm/test/tools/llvm-cxxfilt/delimiters.test
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139864.557218.patch
Type: text/x-patch
Size: 2041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230922/e0d93695/attachment.bin>


More information about the llvm-commits mailing list