[libcxxabi] [llvm] [demangler] Enhance demangling in llvm-cxxfilt for fixed-point types. (PR #114257)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 09:03:28 PDT 2024


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/114257

This patch adds support for fixed-point type in demanger.

Closes #114090.

>From d10084c116fc6012a9713cc481b65f37a5814b23 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Wed, 30 Oct 2024 23:57:23 +0800
Subject: [PATCH 1/2] demangle

---
 libcxxabi/src/demangle/ItaniumDemangle.h      |  99 ++++++++++++++++-
 llvm/include/llvm/Demangle/ItaniumDemangle.h  |  95 ++++++++++++++++
 .../Demangle/PartialDemangleTest.cpp          | 103 +++++++++++-------
 3 files changed, 256 insertions(+), 41 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 501d0b6fdfcd16..3dfe838bf5fd2d 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1,5 +1,5 @@
-//===------------------------- ItaniumDemangle.h ----------------*- C++ -*-===//
-//
+//===--- ItaniumDemangle.h -----------*- mode:c++;eval:(read-only-mode) -*-===//
+//       Do not edit! See README.txt.
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
@@ -4331,6 +4331,101 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       return make<BinaryFPType>(DimensionNumber);
     }
+    //                ::= [DS] DA  # N1169 fixed-point [_Sat] T _Accum
+    //                ::= [DS] DR  # N1169 fixed-point [_Sat] T _Frac
+    // <fixed-point-size>
+    //                ::= s # short
+    //                ::= t # unsigned short
+    //                ::= i # plain
+    //                ::= j # unsigned
+    //                ::= l # long
+    //                ::= m # unsigned long
+    case 'A': {
+      char c = look(2);
+      First += 3;
+      switch (c) {
+      case 's':
+        return make<NameType>("short _Accum");
+      case 't':
+        return make<NameType>("unsigned short _Accum");
+      case 'i':
+        return make<NameType>("_Accum");
+      case 'j':
+        return make<NameType>("unsigned _Accum");
+      case 'l':
+        return make<NameType>("long _Accum");
+      case 'm':
+        return make<NameType>("unsigned long _Accum");
+      default:
+        return nullptr;
+      }
+    }
+    case 'R': {
+      char c = look(2);
+      First += 3;
+      switch (c) {
+      case 's':
+        return make<NameType>("short _Fract");
+      case 't':
+        return make<NameType>("unsigned short _Fract");
+      case 'i':
+        return make<NameType>("_Fract");
+      case 'j':
+        return make<NameType>("unsigned _Fract");
+      case 'l':
+        return make<NameType>("long _Fract");
+      case 'm':
+        return make<NameType>("unsigned long _Fract");
+      default:
+        return nullptr;
+      }
+    }
+    case 'S': {
+      First += 2;
+      if (look() != 'D')
+        return nullptr;
+      if (look(1) == 'A') {
+        char c = look(2);
+        First += 3;
+        switch (c) {
+        case 's':
+          return make<NameType>("_Sat short _Accum");
+        case 't':
+          return make<NameType>("_Sat unsigned short _Accum");
+        case 'i':
+          return make<NameType>("_Sat _Accum");
+        case 'j':
+          return make<NameType>("_Sat unsigned _Accum");
+        case 'l':
+          return make<NameType>("_Sat long _Accum");
+        case 'm':
+          return make<NameType>("_Sat unsigned long _Accum");
+        default:
+          return nullptr;
+        }
+      }
+      if (look(1) == 'R') {
+        char c = look(2);
+        First += 3;
+        switch (c) {
+        case 's':
+          return make<NameType>("_Sat short _Fract");
+        case 't':
+          return make<NameType>("_Sat unsigned short _Fract");
+        case 'i':
+          return make<NameType>("_Sat _Fract");
+        case 'j':
+          return make<NameType>("_Sat unsigned _Fract");
+        case 'l':
+          return make<NameType>("_Sat long _Fract");
+        case 'm':
+          return make<NameType>("_Sat unsigned long _Fract");
+        default:
+          return nullptr;
+        }
+      }
+      return nullptr;
+    }
     //                ::= DB <number> _                             # C23 signed _BitInt(N)
     //                ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
     //                ::= DU <number> _                             # C23 unsigned _BitInt(N)
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 56ff3cfb148f09..3dfe838bf5fd2d 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -4331,6 +4331,101 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       return make<BinaryFPType>(DimensionNumber);
     }
+    //                ::= [DS] DA  # N1169 fixed-point [_Sat] T _Accum
+    //                ::= [DS] DR  # N1169 fixed-point [_Sat] T _Frac
+    // <fixed-point-size>
+    //                ::= s # short
+    //                ::= t # unsigned short
+    //                ::= i # plain
+    //                ::= j # unsigned
+    //                ::= l # long
+    //                ::= m # unsigned long
+    case 'A': {
+      char c = look(2);
+      First += 3;
+      switch (c) {
+      case 's':
+        return make<NameType>("short _Accum");
+      case 't':
+        return make<NameType>("unsigned short _Accum");
+      case 'i':
+        return make<NameType>("_Accum");
+      case 'j':
+        return make<NameType>("unsigned _Accum");
+      case 'l':
+        return make<NameType>("long _Accum");
+      case 'm':
+        return make<NameType>("unsigned long _Accum");
+      default:
+        return nullptr;
+      }
+    }
+    case 'R': {
+      char c = look(2);
+      First += 3;
+      switch (c) {
+      case 's':
+        return make<NameType>("short _Fract");
+      case 't':
+        return make<NameType>("unsigned short _Fract");
+      case 'i':
+        return make<NameType>("_Fract");
+      case 'j':
+        return make<NameType>("unsigned _Fract");
+      case 'l':
+        return make<NameType>("long _Fract");
+      case 'm':
+        return make<NameType>("unsigned long _Fract");
+      default:
+        return nullptr;
+      }
+    }
+    case 'S': {
+      First += 2;
+      if (look() != 'D')
+        return nullptr;
+      if (look(1) == 'A') {
+        char c = look(2);
+        First += 3;
+        switch (c) {
+        case 's':
+          return make<NameType>("_Sat short _Accum");
+        case 't':
+          return make<NameType>("_Sat unsigned short _Accum");
+        case 'i':
+          return make<NameType>("_Sat _Accum");
+        case 'j':
+          return make<NameType>("_Sat unsigned _Accum");
+        case 'l':
+          return make<NameType>("_Sat long _Accum");
+        case 'm':
+          return make<NameType>("_Sat unsigned long _Accum");
+        default:
+          return nullptr;
+        }
+      }
+      if (look(1) == 'R') {
+        char c = look(2);
+        First += 3;
+        switch (c) {
+        case 's':
+          return make<NameType>("_Sat short _Fract");
+        case 't':
+          return make<NameType>("_Sat unsigned short _Fract");
+        case 'i':
+          return make<NameType>("_Sat _Fract");
+        case 'j':
+          return make<NameType>("_Sat unsigned _Fract");
+        case 'l':
+          return make<NameType>("_Sat long _Fract");
+        case 'm':
+          return make<NameType>("_Sat unsigned long _Fract");
+        default:
+          return nullptr;
+        }
+      }
+      return nullptr;
+    }
     //                ::= DB <number> _                             # C23 signed _BitInt(N)
     //                ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
     //                ::= DU <number> _                             # C23 unsigned _BitInt(N)
diff --git a/llvm/unittests/Demangle/PartialDemangleTest.cpp b/llvm/unittests/Demangle/PartialDemangleTest.cpp
index 60193cdf9e1ace..9cb26c47d8f243 100644
--- a/llvm/unittests/Demangle/PartialDemangleTest.cpp
+++ b/llvm/unittests/Demangle/PartialDemangleTest.cpp
@@ -16,45 +16,70 @@ struct ChoppedName {
 };
 
 static ChoppedName NamesToTest[] = {
-  {"_Z1fv", "", "f", "", "()"},
-  {"_ZN1a1b1cIiiiEEvm", "a::b", "c", "void", "(unsigned long)"},
-  {"_ZZ5OuterIiEivEN5Inner12inner_memberEv",
-   "int Outer<int>()::Inner", "inner_member", "", "()"},
-  {"_Z1fIiEPFvvEv", "", "f", "void (*)()", "()"},
-  {"_ZN1S1fIiEEvv", "S", "f", "void", "()"},
-
-  // Call operator for a lambda in f().
-  {"_ZZ1fvENK3$_0clEi", "f()::$_0", "operator()", "", "(int)"},
-
-  // A call operator for a lambda in a lambda in f().
-  {"_ZZZ1fvENK3$_0clEvENKUlvE_clEv",
-   "f()::$_0::operator()() const::'lambda'()", "operator()", "", "()"},
-
-  {"_ZZN1S1fEiiEd0_NKUlvE_clEv",
-   "S::f(int, int)::'lambda'()", "operator()", "", "()"},
-
-  {"_ZN1Scv7MuncherIJDpPT_EEIJFivEA_iEEEv",
-   "S", "operator Muncher<int (*)(), int (*) []>", "", "()"},
-
-  // Attributes.
-  {"_ZN5test4IdE1fEUa9enable_ifIXeqfL0p_Li1EEXeqfL0p0_Li2EEEi",
-   "test4<double>", "f", "", "(int)"},
-  {"_ZN1SC2B8ctor_tagEv", "S", "S", "", "()"},
-  {"_ZN1S1fB4MERPIiEEvv", "S", "f", "void", "()"},
-
-  {"_ZNSsC1EmcRKSaIcE",
-   "std::basic_string<char, std::char_traits<char>, std::allocator<char>>",
-   "basic_string", "", "(unsigned long, char, std::allocator<char> const&)"},
-  {"_ZNSsixEm", "std::string", "operator[]", "", "(unsigned long)"},
-  {"_ZSt17__throw_bad_allocv", "std", "__throw_bad_alloc", "", "()"},
-
-  {"_ZN1AI1BEC2Ev", "A<B>", "A", "", "()"},
-  {"_ZN1AI1BED2Ev", "A<B>", "~A", "", "()"},
-  {"_ZN1AI1BECI24BaseEi", "A<B>", "A", "", "(int)"},
-  {"_ZNKR1AI1BE1fIiEEiv", "A<B>", "f", "int", "()"},
-
-  {"_ZN1SIJicfEE3mfnIJjcdEEEvicfDpT_", "S<int, char, float>",
-   "mfn", "void", "(int, char, float, unsigned int, char, double)"},
+    {"_Z1fv", "", "f", "", "()"},
+    {"_ZN1a1b1cIiiiEEvm", "a::b", "c", "void", "(unsigned long)"},
+    {"_ZZ5OuterIiEivEN5Inner12inner_memberEv", "int Outer<int>()::Inner",
+     "inner_member", "", "()"},
+    {"_Z1fIiEPFvvEv", "", "f", "void (*)()", "()"},
+    {"_ZN1S1fIiEEvv", "S", "f", "void", "()"},
+
+    // Call operator for a lambda in f().
+    {"_ZZ1fvENK3$_0clEi", "f()::$_0", "operator()", "", "(int)"},
+
+    // A call operator for a lambda in a lambda in f().
+    {"_ZZZ1fvENK3$_0clEvENKUlvE_clEv",
+     "f()::$_0::operator()() const::'lambda'()", "operator()", "", "()"},
+
+    {"_ZZN1S1fEiiEd0_NKUlvE_clEv", "S::f(int, int)::'lambda'()", "operator()",
+     "", "()"},
+
+    {"_ZN1Scv7MuncherIJDpPT_EEIJFivEA_iEEEv", "S",
+     "operator Muncher<int (*)(), int (*) []>", "", "()"},
+
+    // Attributes.
+    {"_ZN5test4IdE1fEUa9enable_ifIXeqfL0p_Li1EEXeqfL0p0_Li2EEEi",
+     "test4<double>", "f", "", "(int)"},
+    {"_ZN1SC2B8ctor_tagEv", "S", "S", "", "()"},
+    {"_ZN1S1fB4MERPIiEEvv", "S", "f", "void", "()"},
+
+    {"_ZNSsC1EmcRKSaIcE",
+     "std::basic_string<char, std::char_traits<char>, std::allocator<char>>",
+     "basic_string", "", "(unsigned long, char, std::allocator<char> const&)"},
+    {"_ZNSsixEm", "std::string", "operator[]", "", "(unsigned long)"},
+    {"_ZSt17__throw_bad_allocv", "std", "__throw_bad_alloc", "", "()"},
+
+    {"_ZN1AI1BEC2Ev", "A<B>", "A", "", "()"},
+    {"_ZN1AI1BED2Ev", "A<B>", "~A", "", "()"},
+    {"_ZN1AI1BECI24BaseEi", "A<B>", "A", "", "(int)"},
+    {"_ZNKR1AI1BE1fIiEEiv", "A<B>", "f", "int", "()"},
+
+    {"_ZN1SIJicfEE3mfnIJjcdEEEvicfDpT_", "S<int, char, float>", "mfn", "void",
+     "(int, char, float, unsigned int, char, double)"},
+
+    {"_Z1fDAs", "", "f", "", "(short _Accum)"},
+    {"_Z1fDAt", "", "f", "", "(unsigned short _Accum)"},
+    {"_Z1fDAi", "", "f", "", "(_Accum)"},
+    {"_Z1fDAj", "", "f", "", "(unsigned _Accum)"},
+    {"_Z1fDAl", "", "f", "", "(long _Accum)"},
+    {"_Z1fDAm", "", "f", "", "(unsigned long _Accum)"},
+    {"_Z1fDRs", "", "f", "", "(short _Fract)"},
+    {"_Z1fDRt", "", "f", "", "(unsigned short _Fract)"},
+    {"_Z1fDRi", "", "f", "", "(_Fract)"},
+    {"_Z1fDRj", "", "f", "", "(unsigned _Fract)"},
+    {"_Z1fDRl", "", "f", "", "(long _Fract)"},
+    {"_Z1fDRm", "", "f", "", "(unsigned long _Fract)"},
+    {"_Z1fDSDAs", "", "f", "", "(_Sat short _Accum)"},
+    {"_Z1fDSDAt", "", "f", "", "(_Sat unsigned short _Accum)"},
+    {"_Z1fDSDAi", "", "f", "", "(_Sat _Accum)"},
+    {"_Z1fDSDAj", "", "f", "", "(_Sat unsigned _Accum)"},
+    {"_Z1fDSDAl", "", "f", "", "(_Sat long _Accum)"},
+    {"_Z1fDSDAm", "", "f", "", "(_Sat unsigned long _Accum)"},
+    {"_Z1fDSDRs", "", "f", "", "(_Sat short _Fract)"},
+    {"_Z1fDSDRt", "", "f", "", "(_Sat unsigned short _Fract)"},
+    {"_Z1fDSDRi", "", "f", "", "(_Sat _Fract)"},
+    {"_Z1fDSDRj", "", "f", "", "(_Sat unsigned _Fract)"},
+    {"_Z1fDSDRl", "", "f", "", "(_Sat long _Fract)"},
+    {"_Z1fDSDRm", "", "f", "", "(_Sat unsigned long _Fract)"},
 };
 
 TEST(PartialDemanglerTest, TestNameChopping) {

>From bf8575d5b162e1e096e3c75d04e62409b3eed883 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Thu, 31 Oct 2024 00:00:04 +0800
Subject: [PATCH 2/2] Update ItaniumDemangle.h

---
 libcxxabi/src/demangle/ItaniumDemangle.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 3dfe838bf5fd2d..52755e6f851032 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1,5 +1,5 @@
-//===--- ItaniumDemangle.h -----------*- mode:c++;eval:(read-only-mode) -*-===//
-//       Do not edit! See README.txt.
+//===------------------------- ItaniumDemangle.h ----------------*- C++ -*-===//
+//
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception



More information about the llvm-commits mailing list