r215464 - MS ABI: Mangle this qualifiers on function types

David Majnemer david.majnemer at gmail.com
Tue Aug 12 10:53:10 PDT 2014


Author: majnemer
Date: Tue Aug 12 12:53:10 2014
New Revision: 215464

URL: http://llvm.org/viewvc/llvm-project?rev=215464&view=rev
Log:
MS ABI: Mangle this qualifiers on function types

C++11 allows this qualifiers to exist on function types when used in
template arguments.  Previously, I believed it wasn't possible because
MSVC rejected declarations like: S<int () const &> s;

However, it turns out MSVC properly allows them in using declarations;
updated clang to be compatible with this mangling.

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

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=215464&r1=215463&r2=215464&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Tue Aug 12 12:53:10 2014
@@ -234,7 +234,7 @@ public:
                   QualifierMangleMode QMM = QMM_Mangle);
   void mangleFunctionType(const FunctionType *T,
                           const FunctionDecl *D = nullptr,
-                          bool ForceInstMethod = false);
+                          bool ForceThisQuals = false);
   void mangleNestedName(const NamedDecl *ND);
 
 private:
@@ -1538,8 +1538,13 @@ void MicrosoftCXXNameMangler::mangleType
   // Structors only appear in decls, so at this point we know it's not a
   // structor type.
   // FIXME: This may not be lambda-friendly.
-  Out << "$$A6";
-  mangleFunctionType(T);
+  if (T->getTypeQuals() || T->getRefQualifier() != RQ_None) {
+    Out << "$$A8@@";
+    mangleFunctionType(T, /*D=*/nullptr, /*ForceThisQuals=*/true);
+  } else {
+    Out << "$$A6";
+    mangleFunctionType(T);
+  }
 }
 void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T,
                                          SourceRange) {
@@ -1548,7 +1553,7 @@ void MicrosoftCXXNameMangler::mangleType
 
 void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
                                                  const FunctionDecl *D,
-                                                 bool ForceInstMethod) {
+                                                 bool ForceThisQuals) {
   // <function-type> ::= <this-cvr-qualifiers> <calling-convention>
   //                     <return-type> <argument-list> <throw-spec>
   const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
@@ -1556,21 +1561,21 @@ void MicrosoftCXXNameMangler::mangleFunc
   SourceRange Range;
   if (D) Range = D->getSourceRange();
 
-  bool IsStructor = false, IsInstMethod = ForceInstMethod;
+  bool IsStructor = false, HasThisQuals = ForceThisQuals;
   if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(D)) {
     if (MD->isInstance())
-      IsInstMethod = true;
+      HasThisQuals = true;
     if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD))
       IsStructor = true;
   }
 
   // If this is a C++ instance method, mangle the CVR qualifiers for the
   // this pointer.
-  if (IsInstMethod) {
+  if (HasThisQuals) {
     Qualifiers Quals = Qualifiers::fromCVRMask(Proto->getTypeQuals());
-    manglePointerExtQualifiers(Quals, nullptr);
+    manglePointerExtQualifiers(Quals, /*PointeeType=*/nullptr);
     mangleRefQualifier(Proto->getRefQualifier());
-    mangleQualifiers(Quals, false);
+    mangleQualifiers(Quals, /*IsMember=*/false);
   }
 
   mangleCallingConvention(T);

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp?rev=215464&r1=215463&r2=215464&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx11.cpp Tue Aug 12 12:53:10 2014
@@ -1,5 +1,58 @@
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
 
+namespace FTypeWithQuals {
+template <typename T>
+struct S {};
+
+using A = int () const;
+S<A> a;
+// CHECK-DAG: @"\01?a at FTypeWithQuals@@3U?$S@$$A8@@BAHXZ at 1@A"
+
+using B = int () volatile;
+S<B> b;
+// CHECK-DAG: @"\01?b at FTypeWithQuals@@3U?$S@$$A8@@CAHXZ at 1@A"
+
+using C = int () __restrict;
+S<C> c;
+// CHECK-DAG: @"\01?c at FTypeWithQuals@@3U?$S@$$A8@@IAAHXZ at 1@A"
+
+using D = int () const &;
+S<D> d;
+// CHECK-DAG: @"\01?d at FTypeWithQuals@@3U?$S@$$A8@@GBAHXZ at 1@A"
+
+using E = int () volatile &;
+S<E> e;
+// CHECK-DAG: @"\01?e at FTypeWithQuals@@3U?$S@$$A8@@GCAHXZ at 1@A"
+
+using F = int () __restrict &;
+S<F> f;
+// CHECK-DAG: @"\01?f at FTypeWithQuals@@3U?$S@$$A8@@IGAAHXZ at 1@A"
+
+using G = int () const &&;
+S<G> g;
+// CHECK-DAG: @"\01?g at FTypeWithQuals@@3U?$S@$$A8@@HBAHXZ at 1@A"
+
+using H = int () volatile &&;
+S<H> h;
+// CHECK-DAG: @"\01?h at FTypeWithQuals@@3U?$S@$$A8@@HCAHXZ at 1@A"
+
+using I = int () __restrict &&;
+S<I> i;
+// CHECK-DAG: @"\01?i at FTypeWithQuals@@3U?$S@$$A8@@IHAAHXZ at 1@A"
+
+using J = int ();
+S<J> j;
+// CHECK-DAG: @"\01?j at FTypeWithQuals@@3U?$S@$$A6AHXZ at 1@A"
+
+using K = int () &;
+S<K> k;
+// CHECK-DAG: @"\01?k at FTypeWithQuals@@3U?$S@$$A8@@GAAHXZ at 1@A"
+
+using L = int () &&;
+S<L> l;
+// CHECK-DAG: @"\01?l at FTypeWithQuals@@3U?$S@$$A8@@HAAHXZ at 1@A"
+}
+
 // CHECK: "\01?DeducedType@@3HA"
 auto DeducedType = 30;
 





More information about the cfe-commits mailing list