[libcxx-commits] [libcxxabi] [llvm] [ItaniumDemangle] Demangle DF16b as bfloat16_t (PR #120109)

Fraser Cormack via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 17 03:22:41 PST 2024


https://github.com/frasercrmck updated https://github.com/llvm/llvm-project/pull/120109

>From 1c6173b7416276c9862d4a22a79e75a13b6ddb06 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 16 Dec 2024 16:36:58 +0000
Subject: [PATCH 1/4] [ItaniumDemangle] Demangle DF16b as bfloat16_t

This mangling is already supported in clang.
---
 libcxxabi/src/demangle/ItaniumDemangle.h     | 14 +++++++++++++-
 libcxxabi/src/demangle/ItaniumNodes.def      |  1 +
 libcxxabi/test/test_demangle.pass.cpp        |  2 ++
 llvm/include/llvm/Demangle/ItaniumDemangle.h | 14 +++++++++++++-
 llvm/include/llvm/Demangle/ItaniumNodes.def  |  1 +
 5 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index e4752bed6da8bb..85e5b2a9f10f67 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1224,6 +1224,15 @@ class BinaryFPType final : public Node {
   }
 };
 
+class BFloat16Type final : public Node {
+public:
+  BFloat16Type() : Node(KBinaryFPType) {}
+
+  template <typename Fn> void match(Fn F) const { F(); }
+
+  void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
+};
+
 enum class TemplateParamKind { Type, NonType, Template };
 
 /// An invented name for a template parameter for which we don't have a
@@ -4330,9 +4339,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'h':
       First += 2;
       return make<NameType>("half");
-    //                ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
+    //       ::= DF16b         # C++23 std::bfloat16_t
+    //       ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
     case 'F': {
       First += 2;
+      if (consumeIf("16b"))
+        return make<BFloat16Type>();
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;
diff --git a/libcxxabi/src/demangle/ItaniumNodes.def b/libcxxabi/src/demangle/ItaniumNodes.def
index 18f5d52b47e911..588dd93e15840c 100644
--- a/libcxxabi/src/demangle/ItaniumNodes.def
+++ b/libcxxabi/src/demangle/ItaniumNodes.def
@@ -100,5 +100,6 @@ NODE(ExprRequirement)
 NODE(TypeRequirement)
 NODE(NestedRequirement)
 NODE(ExplicitObjectParameter)
+NODE(BFloat16Type)
 
 #undef NODE
diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 67b9df212ff3b4..47a83819faf4d1 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -30245,6 +30245,8 @@ const char *cases[][2] = {
     {"_Z1fDSDRj", "f(_Sat unsigned _Fract)"},
     {"_Z1fDSDRl", "f(_Sat long _Fract)"},
     {"_Z1fDSDRm", "f(_Sat unsigned long _Fract)"},
+
+    {"_Z11bfloat16addDF16bDF16b", "bfloat16add(bfloat16_t, bfloat16_t)"},
     // clang-format on
 };
 
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 7fba3fdc1abc9a..591b3ad65f4539 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -1224,6 +1224,15 @@ class BinaryFPType final : public Node {
   }
 };
 
+class BFloat16Type final : public Node {
+public:
+  BFloat16Type() : Node(KBinaryFPType) {}
+
+  template <typename Fn> void match(Fn F) const { F(); }
+
+  void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
+};
+
 enum class TemplateParamKind { Type, NonType, Template };
 
 /// An invented name for a template parameter for which we don't have a
@@ -4330,9 +4339,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'h':
       First += 2;
       return make<NameType>("half");
-    //                ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
+    //       ::= DF16b         # C++23 std::bfloat16_t
+    //       ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
     case 'F': {
       First += 2;
+      if (consumeIf("16b"))
+        return make<BFloat16Type>();
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;
diff --git a/llvm/include/llvm/Demangle/ItaniumNodes.def b/llvm/include/llvm/Demangle/ItaniumNodes.def
index 330552663ee658..88d59ea76ae48b 100644
--- a/llvm/include/llvm/Demangle/ItaniumNodes.def
+++ b/llvm/include/llvm/Demangle/ItaniumNodes.def
@@ -100,5 +100,6 @@ NODE(ExprRequirement)
 NODE(TypeRequirement)
 NODE(NestedRequirement)
 NODE(ExplicitObjectParameter)
+NODE(BFloat16Type)
 
 #undef NODE

>From 3373767a4dd5c26354307522b13d6c018f0abcb8 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 16 Dec 2024 16:44:53 +0000
Subject: [PATCH 2/4] fix formatting

---
 libcxxabi/test/test_demangle.pass.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 47a83819faf4d1..2513b36654684b 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -33,7 +33,7 @@
 // Is long double fp128?
 #define LDBL_FP128 (__LDBL_MANT_DIG__ == 113)
 
-const char *cases[][2] = {
+const char* cases[][2] = {
     // clang-format off
     {"_Z1A", "A"},
     {"_Z1Av", "A()"},

>From 214def3d086b8fec70813412b1211b331465363c Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Mon, 16 Dec 2024 17:14:14 +0000
Subject: [PATCH 3/4] use nametype

---
 libcxxabi/src/demangle/ItaniumDemangle.h     | 11 +----------
 libcxxabi/src/demangle/ItaniumNodes.def      |  1 -
 llvm/include/llvm/Demangle/ItaniumDemangle.h | 11 +----------
 llvm/include/llvm/Demangle/ItaniumNodes.def  |  1 -
 4 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 85e5b2a9f10f67..ebb63dee55f3ed 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -1224,15 +1224,6 @@ class BinaryFPType final : public Node {
   }
 };
 
-class BFloat16Type final : public Node {
-public:
-  BFloat16Type() : Node(KBinaryFPType) {}
-
-  template <typename Fn> void match(Fn F) const { F(); }
-
-  void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
-};
-
 enum class TemplateParamKind { Type, NonType, Template };
 
 /// An invented name for a template parameter for which we don't have a
@@ -4344,7 +4335,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'F': {
       First += 2;
       if (consumeIf("16b"))
-        return make<BFloat16Type>();
+        return make<NameType>("bfloat16_t");
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;
diff --git a/libcxxabi/src/demangle/ItaniumNodes.def b/libcxxabi/src/demangle/ItaniumNodes.def
index 588dd93e15840c..18f5d52b47e911 100644
--- a/libcxxabi/src/demangle/ItaniumNodes.def
+++ b/libcxxabi/src/demangle/ItaniumNodes.def
@@ -100,6 +100,5 @@ NODE(ExprRequirement)
 NODE(TypeRequirement)
 NODE(NestedRequirement)
 NODE(ExplicitObjectParameter)
-NODE(BFloat16Type)
 
 #undef NODE
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 591b3ad65f4539..7997c9b6bf3e78 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -1224,15 +1224,6 @@ class BinaryFPType final : public Node {
   }
 };
 
-class BFloat16Type final : public Node {
-public:
-  BFloat16Type() : Node(KBinaryFPType) {}
-
-  template <typename Fn> void match(Fn F) const { F(); }
-
-  void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
-};
-
 enum class TemplateParamKind { Type, NonType, Template };
 
 /// An invented name for a template parameter for which we don't have a
@@ -4344,7 +4335,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'F': {
       First += 2;
       if (consumeIf("16b"))
-        return make<BFloat16Type>();
+        return make<NameType>("bfloat16_t");
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;
diff --git a/llvm/include/llvm/Demangle/ItaniumNodes.def b/llvm/include/llvm/Demangle/ItaniumNodes.def
index 88d59ea76ae48b..330552663ee658 100644
--- a/llvm/include/llvm/Demangle/ItaniumNodes.def
+++ b/llvm/include/llvm/Demangle/ItaniumNodes.def
@@ -100,6 +100,5 @@ NODE(ExprRequirement)
 NODE(TypeRequirement)
 NODE(NestedRequirement)
 NODE(ExplicitObjectParameter)
-NODE(BFloat16Type)
 
 #undef NODE

>From f3c30f8b78d4581f1e88a848d9513e24472fff9b Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Tue, 17 Dec 2024 11:22:18 +0000
Subject: [PATCH 4/4] change mangling to std::

---
 libcxxabi/src/demangle/ItaniumDemangle.h     | 2 +-
 libcxxabi/test/test_demangle.pass.cpp        | 2 +-
 llvm/include/llvm/Demangle/ItaniumDemangle.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index ebb63dee55f3ed..3df41b5f4d7d07 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -4335,7 +4335,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'F': {
       First += 2;
       if (consumeIf("16b"))
-        return make<NameType>("bfloat16_t");
+        return make<NameType>("std::bfloat16_t");
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;
diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 2513b36654684b..e9c74f70a094b5 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -30246,7 +30246,7 @@ const char* cases[][2] = {
     {"_Z1fDSDRl", "f(_Sat long _Fract)"},
     {"_Z1fDSDRm", "f(_Sat unsigned long _Fract)"},
 
-    {"_Z11bfloat16addDF16bDF16b", "bfloat16add(bfloat16_t, bfloat16_t)"},
+    {"_Z11bfloat16addDF16bDF16b", "bfloat16add(std::bfloat16_t, std::bfloat16_t)"},
     // clang-format on
 };
 
diff --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 7997c9b6bf3e78..b0363c1a7a7863 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -4335,7 +4335,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     case 'F': {
       First += 2;
       if (consumeIf("16b"))
-        return make<NameType>("bfloat16_t");
+        return make<NameType>("std::bfloat16_t");
       Node *DimensionNumber = make<NameType>(parseNumber());
       if (!DimensionNumber)
         return nullptr;



More information about the libcxx-commits mailing list