Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

c8ef
Copy link
Contributor

@c8ef c8ef commented Oct 30, 2024

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

Closes #114090.

@c8ef c8ef requested a review from a team as a code owner October 30, 2024 16:03
@llvmbot llvmbot added the libc++abi libc++abi C++ Runtime Library. Not libc++. label Oct 30, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Oct 30, 2024

@llvm/pr-subscribers-libcxxabi

Author: None (c8ef)

Changes

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

Closes #114090.


Full diff: https://github.com/llvm/llvm-project/pull/114257.diff

3 Files Affected:

  • (modified) libcxxabi/src/demangle/ItaniumDemangle.h (+95)
  • (modified) llvm/include/llvm/Demangle/ItaniumDemangle.h (+95)
  • (modified) llvm/unittests/Demangle/PartialDemangleTest.cpp (+64-39)
diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 501d0b6fdfcd16..52755e6f851032 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/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/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) {

@c8ef c8ef requested a review from PiJoules October 30, 2024 16:04
Copy link
Contributor

@PiJoules PiJoules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this. LGTM for the llvm/ changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++abi libc++abi C++ Runtime Library. Not libc++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support demangling in llvm-cxxfilt for fixed point types
3 participants