Skip to content

Commit 1c6173b

Browse files
committed
[ItaniumDemangle] Demangle DF16b as bfloat16_t
This mangling is already supported in clang.
1 parent 39c9dda commit 1c6173b

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,15 @@ class BinaryFPType final : public Node {
12241224
}
12251225
};
12261226

1227+
class BFloat16Type final : public Node {
1228+
public:
1229+
BFloat16Type() : Node(KBinaryFPType) {}
1230+
1231+
template <typename Fn> void match(Fn F) const { F(); }
1232+
1233+
void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
1234+
};
1235+
12271236
enum class TemplateParamKind { Type, NonType, Template };
12281237

12291238
/// An invented name for a template parameter for which we don't have a
@@ -4330,9 +4339,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
43304339
case 'h':
43314340
First += 2;
43324341
return make<NameType>("half");
4333-
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
4342+
// ::= DF16b # C++23 std::bfloat16_t
4343+
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
43344344
case 'F': {
43354345
First += 2;
4346+
if (consumeIf("16b"))
4347+
return make<BFloat16Type>();
43364348
Node *DimensionNumber = make<NameType>(parseNumber());
43374349
if (!DimensionNumber)
43384350
return nullptr;

libcxxabi/src/demangle/ItaniumNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ NODE(ExprRequirement)
100100
NODE(TypeRequirement)
101101
NODE(NestedRequirement)
102102
NODE(ExplicitObjectParameter)
103+
NODE(BFloat16Type)
103104

104105
#undef NODE

libcxxabi/test/test_demangle.pass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30245,6 +30245,8 @@ const char *cases[][2] = {
3024530245
{"_Z1fDSDRj", "f(_Sat unsigned _Fract)"},
3024630246
{"_Z1fDSDRl", "f(_Sat long _Fract)"},
3024730247
{"_Z1fDSDRm", "f(_Sat unsigned long _Fract)"},
30248+
30249+
{"_Z11bfloat16addDF16bDF16b", "bfloat16add(bfloat16_t, bfloat16_t)"},
3024830250
// clang-format on
3024930251
};
3025030252

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,15 @@ class BinaryFPType final : public Node {
12241224
}
12251225
};
12261226

1227+
class BFloat16Type final : public Node {
1228+
public:
1229+
BFloat16Type() : Node(KBinaryFPType) {}
1230+
1231+
template <typename Fn> void match(Fn F) const { F(); }
1232+
1233+
void printLeft(OutputBuffer &OB) const override { OB += "bfloat16_t"; }
1234+
};
1235+
12271236
enum class TemplateParamKind { Type, NonType, Template };
12281237

12291238
/// An invented name for a template parameter for which we don't have a
@@ -4330,9 +4339,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
43304339
case 'h':
43314340
First += 2;
43324341
return make<NameType>("half");
4333-
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
4342+
// ::= DF16b # C++23 std::bfloat16_t
4343+
// ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits)
43344344
case 'F': {
43354345
First += 2;
4346+
if (consumeIf("16b"))
4347+
return make<BFloat16Type>();
43364348
Node *DimensionNumber = make<NameType>(parseNumber());
43374349
if (!DimensionNumber)
43384350
return nullptr;

llvm/include/llvm/Demangle/ItaniumNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ NODE(ExprRequirement)
100100
NODE(TypeRequirement)
101101
NODE(NestedRequirement)
102102
NODE(ExplicitObjectParameter)
103+
NODE(BFloat16Type)
103104

104105
#undef NODE

0 commit comments

Comments
 (0)