[PATCH] D105048: Support Itanium demangling of the half precision FP type.

Konstantin Bobrovsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 10:30:44 PDT 2021


kbobrovs updated this revision to Diff 355934.
kbobrovs added a comment.

Remove usage of std::string (also fixes debug build of the unittests/Demangle/ItaniumDemangleTest.cpp)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105048/new/

https://reviews.llvm.org/D105048

Files:
  llvm/include/llvm/Demangle/ItaniumDemangle.h
  llvm/unittests/Demangle/ItaniumDemangleTest.cpp


Index: llvm/unittests/Demangle/ItaniumDemangleTest.cpp
===================================================================
--- llvm/unittests/Demangle/ItaniumDemangleTest.cpp
+++ llvm/unittests/Demangle/ItaniumDemangleTest.cpp
@@ -51,3 +51,24 @@
   ASSERT_NE(nullptr, Parser.parse());
   EXPECT_THAT(Parser.Types, testing::ElementsAre('i', 'j', 'l'));
 }
+
+TEST(ItaniumDemangle, HalfType) {
+  struct TestParser : AbstractManglingParser<TestParser, TestAllocator> {
+    std::vector<std::string> Types;
+
+    TestParser(const char *Str)
+        : AbstractManglingParser(Str, Str + strlen(Str)) {}
+
+    Node *parseType() {
+      Node *N = AbstractManglingParser<TestParser, TestAllocator>::parseType();
+      StringView Name = N->getBaseName();
+      Types.push_back(std::string(Name.begin(), Name.end()));
+      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"));
+}
Index: llvm/include/llvm/Demangle/ItaniumDemangle.h
===================================================================
--- llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -3880,6 +3880,17 @@
     case 'f':
       First += 2;
       return make<NameType>("decimal32");
+    //                ::= DF <number> _
+    //            # ISO/IEC TS 18661 binary floating point type _FloatN (N bits)
+    case 'F': {
+      First += 2;
+      StringView N = parseNumber(false /*disallow negatives*/);
+      if (N.size() == 0 || look() != '_')
+        return nullptr;
+      assert((N == "16") && "Unknown FP type");
+      First += 1;                        // consume '_'
+      return make<NameType>("_Float16"); // use FE-supoprted spelling
+    }
     //                ::= Dh   # IEEE 754r half-precision floating point (16 bits)
     case 'h':
       First += 2;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105048.355934.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210701/3ed4a8cc/attachment.bin>


More information about the llvm-commits mailing list