[libcxx-commits] [libcxxabi] [llvm] [ItaniumDemangle] Demangle DF16b as bfloat16_t (PR #120109)
Fraser Cormack via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 16 08:45:06 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/2] [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/2] 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()"},
More information about the libcxx-commits
mailing list