r238166 - [MS ABI] Implement restrict qualified references

David Majnemer david.majnemer at gmail.com
Mon May 25 18:30:45 PDT 2015


Author: majnemer
Date: Mon May 25 20:30:45 2015
New Revision: 238166

URL: http://llvm.org/viewvc/llvm-project?rev=238166&view=rev
Log:
[MS ABI] Implement restrict qualified references

MSVC 2015 supports '__restrict' qualified reference types.

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=238166&r1=238165&r2=238166&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon May 25 20:30:45 2015
@@ -277,7 +277,7 @@ private:
   void mangleQualifiers(Qualifiers Quals, bool IsMember);
   void mangleRefQualifier(RefQualifierKind RefQualifier);
   void manglePointerCVQualifiers(Qualifiers Quals);
-  void manglePointerExtQualifiers(Qualifiers Quals, const Type *PointeeType);
+  void manglePointerExtQualifiers(Qualifiers Quals, QualType PointeeType);
 
   void mangleUnscopedTemplateName(const TemplateDecl *ND);
   void
@@ -291,6 +291,7 @@ private:
 #define ABSTRACT_TYPE(CLASS, PARENT)
 #define NON_CANONICAL_TYPE(CLASS, PARENT)
 #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \
+                                            Qualifiers Quals, \
                                             SourceRange Range);
 #include "clang/AST/TypeNodes.def"
 #undef ABSTRACT_TYPE
@@ -461,7 +462,7 @@ void MicrosoftCXXNameMangler::mangleVari
       Ty->isMemberPointerType()) {
     mangleType(Ty, SR, QMM_Drop);
     manglePointerExtQualifiers(
-        Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), nullptr);
+        Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), QualType());
     if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) {
       mangleQualifiers(MPT->getPointeeType().getQualifiers(), true);
       // Member pointers are suffixed with a back reference to the member
@@ -1351,11 +1352,11 @@ MicrosoftCXXNameMangler::mangleRefQualif
   }
 }
 
-void
-MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals,
-                                                    const Type *PointeeType) {
+void MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals,
+                                                         QualType PointeeType) {
   bool HasRestrict = Quals.hasRestrict();
-  if (PointersAre64Bit && (!PointeeType || !PointeeType->isFunctionType()))
+  if (PointersAre64Bit &&
+      (PointeeType.isNull() || !PointeeType->isFunctionType()))
     Out << 'E';
 
   if (HasRestrict)
@@ -1450,7 +1451,7 @@ void MicrosoftCXXNameMangler::mangleType
   }
 
   bool IsPointer = T->isAnyPointerType() || T->isMemberPointerType() ||
-                   T->isBlockPointerType();
+                   T->isReferenceType() || T->isBlockPointerType();
 
   switch (QMM) {
   case QMM_Drop:
@@ -1477,11 +1478,6 @@ void MicrosoftCXXNameMangler::mangleType
     break;
   }
 
-  // We have to mangle these now, while we still have enough information.
-  if (IsPointer) {
-    manglePointerCVQualifiers(Quals);
-    manglePointerExtQualifiers(Quals, T->getPointeeType().getTypePtr());
-  }
   const Type *ty = T.getTypePtr();
 
   switch (ty->getTypeClass()) {
@@ -1492,7 +1488,7 @@ void MicrosoftCXXNameMangler::mangleType
     return;
 #define TYPE(CLASS, PARENT) \
   case Type::CLASS: \
-    mangleType(cast<CLASS##Type>(ty), Range); \
+    mangleType(cast<CLASS##Type>(ty), Quals, Range); \
     break;
 #include "clang/AST/TypeNodes.def"
 #undef ABSTRACT_TYPE
@@ -1501,7 +1497,7 @@ void MicrosoftCXXNameMangler::mangleType
   }
 }
 
-void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T,
+void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
                                          SourceRange Range) {
   //  <type>         ::= <builtin-type>
   //  <builtin-type> ::= X  # void
@@ -1587,7 +1583,7 @@ void MicrosoftCXXNameMangler::mangleType
 }
 
 // <type>          ::= <function-type>
-void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T,
+void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, Qualifiers,
                                          SourceRange) {
   // Structors only appear in decls, so at this point we know it's not a
   // structor type.
@@ -1601,7 +1597,7 @@ void MicrosoftCXXNameMangler::mangleType
   }
 }
 void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T,
-                                         SourceRange) {
+                                         Qualifiers, SourceRange) {
   llvm_unreachable("Can't mangle K&R function prototypes");
 }
 
@@ -1637,7 +1633,7 @@ void MicrosoftCXXNameMangler::mangleFunc
   // this pointer.
   if (HasThisQuals) {
     Qualifiers Quals = Qualifiers::fromCVRMask(Proto->getTypeQuals());
-    manglePointerExtQualifiers(Quals, /*PointeeType=*/nullptr);
+    manglePointerExtQualifiers(Quals, /*PointeeType=*/QualType());
     mangleRefQualifier(Proto->getRefQualifier());
     mangleQualifiers(Quals, /*IsMember=*/false);
   }
@@ -1818,7 +1814,7 @@ void MicrosoftCXXNameMangler::mangleThro
 }
 
 void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T,
-                                         SourceRange Range) {
+                                         Qualifiers, SourceRange Range) {
   // Probably should be mangled as a template instantiation; need to see what
   // VC does first.
   DiagnosticsEngine &Diags = Context.getDiags();
@@ -1833,10 +1829,12 @@ void MicrosoftCXXNameMangler::mangleType
 // <struct-type> ::= U <name>
 // <class-type>  ::= V <name>
 // <enum-type>   ::= W4 <name>
-void MicrosoftCXXNameMangler::mangleType(const EnumType *T, SourceRange) {
+void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers,
+                                         SourceRange) {
   mangleType(cast<TagType>(T)->getDecl());
 }
-void MicrosoftCXXNameMangler::mangleType(const RecordType *T, SourceRange) {
+void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers,
+                                         SourceRange) {
   mangleType(cast<TagType>(T)->getDecl());
 }
 void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) {
@@ -1871,20 +1869,20 @@ void MicrosoftCXXNameMangler::mangleDeca
   manglePointerCVQualifiers(T->getElementType().getQualifiers());
   mangleType(T->getElementType(), SourceRange());
 }
-void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T,
+void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T, Qualifiers,
                                          SourceRange) {
   llvm_unreachable("Should have been special cased");
 }
-void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T,
+void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T, Qualifiers,
                                          SourceRange) {
   llvm_unreachable("Should have been special cased");
 }
 void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T,
-                                         SourceRange) {
+                                         Qualifiers, SourceRange) {
   llvm_unreachable("Should have been special cased");
 }
 void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T,
-                                         SourceRange) {
+                                         Qualifiers, SourceRange) {
   llvm_unreachable("Should have been special cased");
 }
 void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
@@ -1931,9 +1929,11 @@ void MicrosoftCXXNameMangler::mangleArra
 // <type>                   ::= <pointer-to-member-type>
 // <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
 //                                                          <class name> <type>
-void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T,
+void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T, Qualifiers Quals,
                                          SourceRange Range) {
   QualType PointeeType = T->getPointeeType();
+  manglePointerCVQualifiers(Quals);
+  manglePointerExtQualifiers(Quals, PointeeType);
   if (const FunctionProtoType *FPT = PointeeType->getAs<FunctionProtoType>()) {
     Out << '8';
     mangleName(T->getClass()->castAs<RecordType>()->getDecl());
@@ -1946,7 +1946,7 @@ void MicrosoftCXXNameMangler::mangleType
 }
 
 void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T,
-                                         SourceRange Range) {
+                                         Qualifiers, SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this template type parameter type yet");
@@ -1954,9 +1954,8 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(
-                                       const SubstTemplateTypeParmPackType *T,
-                                       SourceRange Range) {
+void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T,
+                                         Qualifiers, SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this substituted parameter pack yet");
@@ -1967,40 +1966,46 @@ void MicrosoftCXXNameMangler::mangleType
 // <type> ::= <pointer-type>
 // <pointer-type> ::= E? <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
 //                       # the E is required for 64-bit non-static pointers
-void MicrosoftCXXNameMangler::mangleType(const PointerType *T,
+void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals,
                                          SourceRange Range) {
-  QualType PointeeTy = T->getPointeeType();
-  mangleType(PointeeTy, Range);
+  QualType PointeeType = T->getPointeeType();
+  manglePointerCVQualifiers(Quals);
+  manglePointerExtQualifiers(Quals, PointeeType);
+  mangleType(PointeeType, Range);
 }
 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T,
-                                         SourceRange Range) {
+                                         Qualifiers Quals, SourceRange Range) {
+  QualType PointeeType = T->getPointeeType();
+  manglePointerCVQualifiers(Quals);
+  manglePointerExtQualifiers(Quals, PointeeType);
   // Object pointers never have qualifiers.
   Out << 'A';
-  manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
-  mangleType(T->getPointeeType(), Range);
+  mangleType(PointeeType, Range);
 }
 
 // <type> ::= <reference-type>
 // <reference-type> ::= A E? <cvr-qualifiers> <type>
 //                 # the E is required for 64-bit non-static lvalue references
 void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T,
-                                         SourceRange Range) {
-  Out << 'A';
-  manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
-  mangleType(T->getPointeeType(), Range);
+                                         Qualifiers Quals, SourceRange Range) {
+  QualType PointeeType = T->getPointeeType();
+  Out << (Quals.hasVolatile() ? 'B' : 'A');
+  manglePointerExtQualifiers(Quals, PointeeType);
+  mangleType(PointeeType, Range);
 }
 
 // <type> ::= <r-value-reference-type>
 // <r-value-reference-type> ::= $$Q E? <cvr-qualifiers> <type>
 //                 # the E is required for 64-bit non-static rvalue references
 void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T,
-                                         SourceRange Range) {
-  Out << "$$Q";
-  manglePointerExtQualifiers(Qualifiers(), T->getPointeeType().getTypePtr());
-  mangleType(T->getPointeeType(), Range);
+                                         Qualifiers Quals, SourceRange Range) {
+  QualType PointeeType = T->getPointeeType();
+  Out << (Quals.hasVolatile() ? "$$R" : "$$Q");
+  manglePointerExtQualifiers(Quals, PointeeType);
+  mangleType(PointeeType, Range);
 }
 
-void MicrosoftCXXNameMangler::mangleType(const ComplexType *T,
+void MicrosoftCXXNameMangler::mangleType(const ComplexType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2009,7 +2014,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const VectorType *T,
+void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals,
                                          SourceRange Range) {
   const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>();
   assert(ET && "vectors with non-builtin elements are unsupported");
@@ -2037,13 +2042,13 @@ void MicrosoftCXXNameMangler::mangleType
     // our own mangling to handle uses of __vector_size__ on user-specified
     // types, and for extensions like __v4sf.
     Out << "T__clang_vec" << T->getNumElements() << '_';
-    mangleType(ET, Range);
+    mangleType(ET, Quals, Range);
   }
 
   Out << "@@";
 }
 
-void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T,
+void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2052,7 +2057,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T,
-                                         SourceRange Range) {
+                                         Qualifiers, SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this dependent-sized extended vector type yet");
@@ -2060,14 +2065,14 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T,
+void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers,
                                          SourceRange) {
   // ObjC interfaces have structs underlying them.
   Out << 'U';
   mangleName(T->getDecl());
 }
 
-void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T,
+void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
                                          SourceRange Range) {
   // We don't allow overloading by different protocol qualification,
   // so mangling them isn't necessary.
@@ -2075,20 +2080,23 @@ void MicrosoftCXXNameMangler::mangleType
 }
 
 void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,
-                                         SourceRange Range) {
+                                         Qualifiers Quals, SourceRange Range) {
+  QualType PointeeType = T->getPointeeType();
+  manglePointerCVQualifiers(Quals);
+  manglePointerExtQualifiers(Quals, PointeeType);
+
   Out << "_E";
 
-  QualType pointee = T->getPointeeType();
-  mangleFunctionType(pointee->castAs<FunctionProtoType>());
+  mangleFunctionType(PointeeType->castAs<FunctionProtoType>());
 }
 
 void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *,
-                                         SourceRange) {
+                                         Qualifiers, SourceRange) {
   llvm_unreachable("Cannot mangle injected class name type.");
 }
 
 void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T,
-                                         SourceRange Range) {
+                                         Qualifiers, SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this template specialization type yet");
@@ -2096,7 +2104,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T,
+void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2106,8 +2114,8 @@ void MicrosoftCXXNameMangler::mangleType
 }
 
 void MicrosoftCXXNameMangler::mangleType(
-                                 const DependentTemplateSpecializationType *T,
-                                 SourceRange Range) {
+    const DependentTemplateSpecializationType *T, Qualifiers,
+    SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this dependent template specialization type yet");
@@ -2115,7 +2123,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T,
+void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2124,7 +2132,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T,
+void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2133,7 +2141,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T,
+void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2142,7 +2150,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T,
+void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
@@ -2152,7 +2160,7 @@ void MicrosoftCXXNameMangler::mangleType
 }
 
 void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T,
-                                         SourceRange Range) {
+                                         Qualifiers, SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
     "cannot mangle this unary transform type yet");
@@ -2160,7 +2168,8 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const AutoType *T, SourceRange Range) {
+void MicrosoftCXXNameMangler::mangleType(const AutoType *T, Qualifiers,
+                                         SourceRange Range) {
   assert(T->getDeducedType().isNull() && "expecting a dependent type!");
 
   DiagnosticsEngine &Diags = Context.getDiags();
@@ -2170,7 +2179,7 @@ void MicrosoftCXXNameMangler::mangleType
     << Range;
 }
 
-void MicrosoftCXXNameMangler::mangleType(const AtomicType *T,
+void MicrosoftCXXNameMangler::mangleType(const AtomicType *T, Qualifiers,
                                          SourceRange Range) {
   DiagnosticsEngine &Diags = Context.getDiags();
   unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp?rev=238166&r1=238165&r2=238166&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-return-qualifiers.cpp Mon May 25 20:30:45 2015
@@ -183,3 +183,7 @@ function_pointer* g3() { return 0; }
 
 const function_pointer* g4() { return 0; }
 // CHECK: "\01?g4@@YAPBQ6AHH at ZXZ"
+
+extern int &z;
+int & __restrict h1() { return z; }
+// CHECK: "\01?h1@@YAAIAHXZ"





More information about the cfe-commits mailing list