Skip to content

Commit 8f38045

Browse files
authored
Support Itanium demangling of the half precision FP type. (#3992)
Encoded as "DF16_" by the Itanium mangler. Signed-off-by: kbobrovs <Konstantin.S.Bobrovsky@intel.com>
1 parent 51c747d commit 8f38045

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/include/llvm/Demangle/ItaniumDemangle.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,6 +3898,17 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
38983898
case 'f':
38993899
First += 2;
39003900
return make<NameType>("decimal32");
3901+
// ::= DF <number> _
3902+
// # ISO/IEC TS 18661 binary floating point type _FloatN (N bits)
3903+
case 'F': {
3904+
First += 2;
3905+
StringView N = parseNumber(false /*disallow negatives*/);
3906+
if (N.size() == 0 || look() != '_')
3907+
return nullptr;
3908+
assert((std::string(N.begin(), N.end()) == "16") && "Unknown FP type");
3909+
First += 1; // consume '_'
3910+
return make<NameType>("_Float16"); // use FE-supoprted spelling
3911+
}
39013912
// ::= Dh # IEEE 754r half-precision floating point (16 bits)
39023913
case 'h':
39033914
First += 2;

llvm/unittests/Demangle/ItaniumDemangleTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,24 @@ TEST(ItaniumDemangle, MethodOverride) {
5151
ASSERT_NE(nullptr, Parser.parse());
5252
EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l'));
5353
}
54+
55+
TEST(ItaniumDemangle, HalfType) {
56+
struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
57+
std::vector<std::string> Types;
58+
59+
TestParser(const char *Str)
60+
: AbstractManglingParser(Str, Str + strlen(Str)) {}
61+
62+
Node *parseType() {
63+
Node *N = AbstractManglingParser<TestParser, TestAllocator>::parseType();
64+
StringView Name = N->getBaseName();
65+
Types.push_back(std::string(Name.begin(), Name.end()));
66+
return N;
67+
}
68+
};
69+
70+
// void f(A<_Float16>, _Float16);
71+
TestParser Parser("_Z1f1AIDF16_EDF16_");
72+
ASSERT_NE(nullptr, Parser.parse());
73+
EXPECT_THAT(Parser.Types, testing::ElementsAre("_Float16", "A", "_Float16"));
74+
}

0 commit comments

Comments
 (0)