[llvm] 4bc4d51 - [Demangle] demangle builtin type transformations (#65902)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 23:24:04 PDT 2023


Author: Congcong Cai
Date: 2023-09-21T14:23:58+08:00
New Revision: 4bc4d51c18d5c087dfbdad1753c84bba8dbf3be0

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

LOG: [Demangle] demangle builtin type transformations (#65902)

Fixed: https://github.com/llvm/llvm-project/issues/62127
https://reviews.llvm.org/D116203 introduced several compiler builtin
equivalents of the unary type traits. In some cases (e.g. template)
those builtin will be dependent and need to be mangle.
This patch add the check for `u{builtin}I{type}E` to demangle it.

Reviewed By: rjmccall

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

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 6fdfe38bd0f1f87..2336b84da293bcc 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -534,6 +534,23 @@ class ElaboratedTypeSpefType : public Node {
   }
 };
 
+class TransformedType : public Node {
+  std::string_view Transform;
+  Node *BaseType;
+public:
+  TransformedType(std::string_view Transform_, Node *BaseType_)
+      : Node(KTransformedType), Transform(Transform_), BaseType(BaseType_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Transform, BaseType); }
+
+  void printLeft(OutputBuffer &OB) const override {
+    OB += Transform;
+    OB += '(';
+    BaseType->print(OB);
+    OB += ')';
+  }
+};
+
 struct AbiTagAttr : Node {
   Node *Base;
   std::string_view Tag;
@@ -4125,7 +4142,15 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     // Typically, <builtin-type>s are not considered substitution candidates,
     // but the exception to that exception is vendor extended types (Itanium C++
     // ABI 5.9.1).
-    Result = make<NameType>(Res);
+    if (consumeIf('I')) {
+      Node *BaseType = parseType();
+      if (BaseType == nullptr)
+        return nullptr;
+      if (!consumeIf('E'))
+        return nullptr;
+      Result = make<TransformedType>(Res, BaseType);
+    } else
+      Result = make<NameType>(Res);
     break;
   }
   case 'D':

diff  --git a/libcxxabi/src/demangle/ItaniumNodes.def b/libcxxabi/src/demangle/ItaniumNodes.def
index 74dc7097c1b30aa..e27c111de3389c5 100644
--- a/libcxxabi/src/demangle/ItaniumNodes.def
+++ b/libcxxabi/src/demangle/ItaniumNodes.def
@@ -19,6 +19,7 @@ NODE(QualType)
 NODE(ConversionOperatorType)
 NODE(PostfixQualifiedType)
 NODE(ElaboratedTypeSpefType)
+NODE(TransformedType)
 NODE(NameType)
 NODE(AbiTagAttr)
 NODE(EnableIfAttr)

diff  --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp
index 47cc29b2430e72b..df7bedc73c289ba 100644
--- a/libcxxabi/test/test_demangle.pass.cpp
+++ b/libcxxabi/test/test_demangle.pass.cpp
@@ -30161,6 +30161,15 @@ const char* cases[][2] =
      " std::allocator<char>>::basic_string()"},
     {"_ZN1SB8ctor_tagC2Ev", "S[abi:ctor_tag]::S()"},
     {"_ZN1SB8ctor_tagD2Ev", "S[abi:ctor_tag]::~S()"},
+
+    // clang builtin type transform
+    {"_Z2f5IiEvu22__add_lvalue_referenceIT_E", "void f5<int>(__add_lvalue_reference(int))"},
+    {"_Z2f5IiEvu13__add_pointerIT_E", "void f5<int>(__add_pointer(int))"},
+    {"_Z2f5IiEvu7__decayIT_E", "void f5<int>(__decay(int))"},
+    {"_Z2f5IjEvu13__make_signedIT_E", "void f5<unsigned int>(__make_signed(unsigned int))"},
+    {"_Z2f5IKiEvu14__remove_constIT_E", "void f5<int const>(__remove_const(int const))"},
+    {"_Z2f5IPiEvu16__remove_pointerIT_E", "void f5<int*>(__remove_pointer(int*))"},
+    {"_Z2f5IiEvu14__remove_cvrefIT_E", "void f5<int>(__remove_cvref(int))"},
 };
 
 const unsigned N = sizeof(cases) / sizeof(cases[0]);

diff  --git a/llvm/include/llvm/Demangle/ItaniumDemangle.h b/llvm/include/llvm/Demangle/ItaniumDemangle.h
index 52105bfeca5b737..f68c37258ce0992 100644
--- a/llvm/include/llvm/Demangle/ItaniumDemangle.h
+++ b/llvm/include/llvm/Demangle/ItaniumDemangle.h
@@ -533,6 +533,23 @@ class ElaboratedTypeSpefType : public Node {
   }
 };
 
+class TransformedType : public Node {
+  std::string_view Transform;
+  Node *BaseType;
+public:
+  TransformedType(std::string_view Transform_, Node *BaseType_)
+      : Node(KTransformedType), Transform(Transform_), BaseType(BaseType_) {}
+
+  template<typename Fn> void match(Fn F) const { F(Transform, BaseType); }
+
+  void printLeft(OutputBuffer &OB) const override {
+    OB += Transform;
+    OB += '(';
+    BaseType->print(OB);
+    OB += ')';
+  }
+};
+
 struct AbiTagAttr : Node {
   Node *Base;
   std::string_view Tag;
@@ -4124,7 +4141,15 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() {
     // Typically, <builtin-type>s are not considered substitution candidates,
     // but the exception to that exception is vendor extended types (Itanium C++
     // ABI 5.9.1).
-    Result = make<NameType>(Res);
+    if (consumeIf('I')) {
+      Node *BaseType = parseType();
+      if (BaseType == nullptr)
+        return nullptr;
+      if (!consumeIf('E'))
+        return nullptr;
+      Result = make<TransformedType>(Res, BaseType);
+    } else
+      Result = make<NameType>(Res);
     break;
   }
   case 'D':

diff  --git a/llvm/include/llvm/Demangle/ItaniumNodes.def b/llvm/include/llvm/Demangle/ItaniumNodes.def
index 12cfa70f93e6308..30a93eccaee37e9 100644
--- a/llvm/include/llvm/Demangle/ItaniumNodes.def
+++ b/llvm/include/llvm/Demangle/ItaniumNodes.def
@@ -19,6 +19,7 @@ NODE(QualType)
 NODE(ConversionOperatorType)
 NODE(PostfixQualifiedType)
 NODE(ElaboratedTypeSpefType)
+NODE(TransformedType)
 NODE(NameType)
 NODE(AbiTagAttr)
 NODE(EnableIfAttr)


        


More information about the llvm-commits mailing list