[libcxx-commits] [libcxxabi] a23652f - [demangler] Support C23 _BitInt type

Senran Zhang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 7 21:20:53 PDT 2022


Author: Senran Zhang
Date: 2022-04-08T12:20:45+08:00
New Revision: a23652f6f9d8bcdeb7eee81c45eaf3ae65cfb3c5

URL: https://github.com/llvm/llvm-project/commit/a23652f6f9d8bcdeb7eee81c45eaf3ae65cfb3c5
DIFF: https://github.com/llvm/llvm-project/commit/a23652f6f9d8bcdeb7eee81c45eaf3ae65cfb3c5.diff

LOG: [demangler] Support C23 _BitInt type

Reviewed By: #libc_abi, aaron.ballman, urnathan

Differential Revision: https://reviews.llvm.org/D122530

Added: 
    

Modified: 
    libcxxabi/src/demangle/ItaniumDemangle.h
    libcxxabi/src/demangle/ItaniumNodes.def
    libcxxabi/test/test_demangle.pass.cpp
    llvm/include/llvm/Demangle/ItaniumDemangle.h
    llvm/include/llvm/Demangle/ItaniumNodes.def

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index 36fe26b44620c..90f62bab0bd9f 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -482,6 +482,26 @@ class NameType final : public Node {
   void printLeft(OutputBuffer &OB) const override { OB += Name; }
 };
 
+class BitIntType final : public Node {
+  const Node *Size;
+  bool Signed;
+
+public:
+  BitIntType(const Node *Size_, bool Signed_)
+      : Node(KBitIntType), Size(Size_), Signed(Signed_) {}
+
+  template <typename Fn> void match(Fn F) const { F(Size, Signed); }
+
+  void printLeft(OutputBuffer &OB) const override {
+    if (!Signed)
+      OB += "unsigned ";
+    OB += "_BitInt";
+    OB.printOpen();
+    Size->printAsOperand(OB);
+    OB.printClose();
+  }
+};
+
 class ElaboratedTypeSpefType : public Node {
   StringView Kind;
   Node *Child;
@@ -3924,6 +3944,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       return make<BinaryFPType>(DimensionNumber);
     }
+    //                ::= DB <number> _                             # C23 signed _BitInt(N)
+    //                ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
+    //                ::= DU <number> _                             # C23 unsigned _BitInt(N)
+    //                ::= DU <instantiation-dependent expression> _ # C23 unsigned _BitInt(N)
+    case 'B':
+    case 'U': {
+      bool Signed = look(1) == 'B';
+      First += 2;
+      Node *Size = std::isdigit(look()) ? make<NameType>(parseNumber())
+                                        : getDerived().parseExpr();
+      if (!Size)
+        return nullptr;
+      if (!consumeIf('_'))
+        return nullptr;
+      return make<BitIntType>(Size, Signed);
+    }
     //                ::= Di   # char32_t
     case 'i':
       First += 2;

diff  --git a/libcxxabi/src/demangle/ItaniumNodes.def b/libcxxabi/src/demangle/ItaniumNodes.def
index 1d71c5de8e9d4..f615cb9fadb05 100644
--- a/libcxxabi/src/demangle/ItaniumNodes.def
+++ b/libcxxabi/src/demangle/ItaniumNodes.def
@@ -42,6 +42,7 @@ NODE(ModuleEntity)
 NODE(VectorType)
 NODE(PixelVectorType)
 NODE(BinaryFPType)
+NODE(BitIntType)
 NODE(SyntheticTemplateParamName)
 NODE(TypeTemplateParamDecl)
 NODE(NonTypeTemplateParamDecl)

diff  --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 5282b0161fe64..a450f36e20d9a 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -32,6 +32,10 @@ const char* cases[][2] =
     {"_Z1A", "A"},
     {"_Z1Av", "A()"},
     {"_Z1A1B1C", "A(B, C)"},
+    {"_Z1fDB3_", "f(_BitInt(3))"},
+    {"_Z1fDU10_", "f(unsigned _BitInt(10))"},
+    {"_Z1fIfEvDUstPT__", "void f<float>(unsigned _BitInt(sizeof (float*)))"},
+    {"_Z1fIiEvDBstPT__", "void f<int>(_BitInt(sizeof (int*)))"},
     {"_Z4testI1A1BE1Cv", "C test<A, B>()"},
     {"_Z4testI1A1BET0_T_S3_", "B test<A, B>(A, A)"},
     {"_ZN1SgtEi", "S::operator>(int)"},

diff  --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 10e13571fab3d..40a99bfe6d57c 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -482,6 +482,26 @@ class NameType final : public Node {
   void printLeft(OutputBuffer &OB) const override { OB += Name; }
 };
 
+class BitIntType final : public Node {
+  const Node *Size;
+  bool Signed;
+
+public:
+  BitIntType(const Node *Size_, bool Signed_)
+      : Node(KBitIntType), Size(Size_), Signed(Signed_) {}
+
+  template <typename Fn> void match(Fn F) const { F(Size, Signed); }
+
+  void printLeft(OutputBuffer &OB) const override {
+    if (!Signed)
+      OB += "unsigned ";
+    OB += "_BitInt";
+    OB.printOpen();
+    Size->printAsOperand(OB);
+    OB.printClose();
+  }
+};
+
 class ElaboratedTypeSpefType : public Node {
   StringView Kind;
   Node *Child;
@@ -3924,6 +3944,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
         return nullptr;
       return make<BinaryFPType>(DimensionNumber);
     }
+    //                ::= DB <number> _                             # C23 signed _BitInt(N)
+    //                ::= DB <instantiation-dependent expression> _ # C23 signed _BitInt(N)
+    //                ::= DU <number> _                             # C23 unsigned _BitInt(N)
+    //                ::= DU <instantiation-dependent expression> _ # C23 unsigned _BitInt(N)
+    case 'B':
+    case 'U': {
+      bool Signed = look(1) == 'B';
+      First += 2;
+      Node *Size = std::isdigit(look()) ? make<NameType>(parseNumber())
+                                        : getDerived().parseExpr();
+      if (!Size)
+        return nullptr;
+      if (!consumeIf('_'))
+        return nullptr;
+      return make<BitIntType>(Size, Signed);
+    }
     //                ::= Di   # char32_t
     case 'i':
       First += 2;

diff  --git a/llvm/include/llvm/Demangle/ItaniumNodes.def b/llvm/include/llvm/Demangle/ItaniumNodes.def
index dc6535c5271b5..c0e277d554ccf 100644
--- a/llvm/include/llvm/Demangle/ItaniumNodes.def
+++ b/llvm/include/llvm/Demangle/ItaniumNodes.def
@@ -42,6 +42,7 @@ NODE(ModuleEntity)
 NODE(VectorType)
 NODE(PixelVectorType)
 NODE(BinaryFPType)
+NODE(BitIntType)
 NODE(SyntheticTemplateParamName)
 NODE(TypeTemplateParamDecl)
 NODE(NonTypeTemplateParamDecl)


        


More information about the libcxx-commits mailing list