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

via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 16 08:39:36 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxxabi

Author: Fraser Cormack (frasercrmck)

<details>
<summary>Changes</summary>

This mangling is already supported in clang.

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


5 Files Affected:

- (modified) libcxxabi/src/demangle/ItaniumDemangle.h (+13-1) 
- (modified) libcxxabi/src/demangle/ItaniumNodes.def (+1) 
- (modified) libcxxabi/test/test_demangle.pass.cpp (+2) 
- (modified) llvm/include/llvm/Demangle/ItaniumDemangle.h (+13-1) 
- (modified) llvm/include/llvm/Demangle/ItaniumNodes.def (+1) 


``````````diff
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

``````````

</details>


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


More information about the libcxx-commits mailing list