-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libcxxabi][ItaniumDemangle] Demangle DF16b as std::bfloat16_t #120109
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
Conversation
This mangling is already supported in clang.
@llvm/pr-subscribers-libcxxabi Author: Fraser Cormack (frasercrmck) ChangesThis mangling is already supported in clang. Full diff: https://github.com/llvm/llvm-project/pull/120109.diff 5 Files Affected:
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
|
Sorry, wasn't sure about the exact difference between libcxx and llvm with regards to demangling, and why they seem to have duplicated code - I've probably made some mistakes in that regard. |
✅ With the latest revision this PR passed the C/C++ code formatter. |
ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
About the duplicate code situation, https://github.com/llvm/llvm-project/blob/e9de53875b9005233f07a68d80e144af8607893b/libcxxabi/src/demangle/README.txt explains:
Why are there multiple copies of the this library in the source tree?
The canonical sources are in libcxxabi/src/demangle and some of the
files are copied to llvm/include/llvm/Demangle. The simple reason for
this comes from before the monorepo, and both [sub]projects need to
demangle symbols, but neither can depend on each other.
libcxxabi needs the demangler to implement __cxa_demangle, which is
part of the itanium ABI spec.LLVM needs a copy for a bunch of places, and cannot rely on the
system's __cxa_demangle because it a) might not be available (i.e.,
on Windows), and b) may not be up-to-date on the latest language
features.The copy of the demangler in LLVM has some extra stuff that aren't
needed in libcxxabi (ie, the MSVC demangler, ItaniumPartialDemangler),
which depend on the shared generic components. Despite these
differences, we want to keep the "core" generic demangling library
identical between both copies to simplify development and testing.If you're working on the generic library, then do the work first in
libcxxabi, then run libcxxabi/src/demangle/cp-to-llvm.sh. This
script takes as an optional argument the path to llvm, and copies the
changes you made to libcxxabi over. Note that this script just
blindly overwrites all changes to the generic library in llvm, so be
careful.
etc...
The test failure doesn't look related to the change, merging. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/11633 Here is the relevant piece of the build log for the reference
|
This mangling is official in the Itanium C++ ABI specification and is already supported by clang.