From 92ac146bb99ca035a0410e8966249072a31c334c Mon Sep 17 00:00:00 2001 From: "Wang, Pengfei" Date: Wed, 29 Sep 2021 23:05:18 +0800 Subject: [PATCH] [demangle] Add a unittest for _Float16 demangling. NFC --- llvm/unittests/Demangle/ItaniumDemangleTest.cpp | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/llvm/unittests/Demangle/ItaniumDemangleTest.cpp b/llvm/unittests/Demangle/ItaniumDemangleTest.cpp index 11bb784..6d4a9bc 100644 --- a/llvm/unittests/Demangle/ItaniumDemangleTest.cpp +++ b/llvm/unittests/Demangle/ItaniumDemangleTest.cpp @@ -51,3 +51,34 @@ TEST(ItaniumDemangle, MethodOverride) { ASSERT_NE(nullptr, Parser.parse()); EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l')); } + +static std::string toString(OutputStream &OS) { + return {OS.getBuffer(), OS.getCurrentPosition()}; +} + +TEST(ItaniumDemangle, HalfType) { + struct TestParser : AbstractManglingParser { + std::vector Types; + + TestParser(const char *Str) + : AbstractManglingParser(Str, Str + strlen(Str)) {} + + Node *parseType() { + OutputStream OS; + Node *N = AbstractManglingParser::parseType(); + N->printLeft(OS); + StringView Name = N->getBaseName(); + if (!Name.empty()) + Types.push_back(std::string(Name.begin(), Name.end())); + else + Types.push_back(toString(OS)); + std::free(OS.getBuffer()); + return N; + } + }; + + // void f(A<_Float16>, _Float16); + TestParser Parser("_Z1f1AIDF16_EDF16_"); + ASSERT_NE(nullptr, Parser.parse()); + EXPECT_THAT(Parser.Types, testing::ElementsAre("_Float16", "A", "_Float16")); +} -- 2.7.4