[PATCH] [-cxx-abi microsoft] Mangle member pointers better

David Majnemer david.majnemer at gmail.com
Sat Aug 10 00:30:29 PDT 2013


Hi rnk, whunt,

There were several things going wrong:
- We mangled in useless qualifiers like "volatile void" return types.
- We didn't propagate 64-bit pointer markers sufficiently.
- We mangled qualifiers belonging to the pointee incorrectly.

This fixes PR16844 and PR16848.

http://llvm-reviews.chandlerc.com/D1353

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-ms.cpp

Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -317,9 +317,18 @@
   // mangled as 'QAHA' instead of 'PAHB', for example.
   TypeLoc TL = VD->getTypeSourceInfo()->getTypeLoc();
   QualType Ty = TL.getType();
-  if (Ty->isPointerType() || Ty->isReferenceType()) {
+  if (Ty->isPointerType() || Ty->isReferenceType() ||
+      Ty->isMemberPointerType()) {
     mangleType(Ty, TL.getSourceRange(), QMM_Drop);
-    mangleQualifiers(Ty->getPointeeType().getQualifiers(), false);
+    if (PointersAre64Bit)
+      Out << 'E';
+    if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) {
+      mangleQualifiers(MPT->getPointeeType().getQualifiers(), true);
+      // Member pointers are suffixed with a back reference to the member
+      // pointer's class name.
+      mangleName(MPT->getClass()->getAsCXXRecordDecl());
+    } else
+      mangleQualifiers(Ty->getPointeeType().getQualifiers(), false);
   } else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) {
     // Global arrays are funny, too.
     mangleDecayedArrayType(AT, true);
@@ -329,11 +338,7 @@
       mangleQualifiers(Ty.getQualifiers(), false);
   } else {
     mangleType(Ty, TL.getSourceRange(), QMM_Drop);
-    mangleQualifiers(Ty.getLocalQualifiers(), Ty->isMemberPointerType());
-    // Member pointers are suffixed with a back reference to the member
-    // pointer's class name.
-    if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>())
-      mangleName(MPT->getClass()->getAsCXXRecordDecl());
+    mangleQualifiers(Ty.getLocalQualifiers(), false);
   }
 }
 
@@ -994,9 +999,6 @@
       Out << 'A';
     }
   } else {
-    if (PointersAre64Bit)
-      Out << 'E';
-
     if (HasConst && HasVolatile) {
       Out << 'T';
     } else if (HasVolatile) {
@@ -1245,8 +1247,11 @@
 
   // If this is a C++ instance method, mangle the CVR qualifiers for the
   // this pointer.
-  if (IsInstMethod)
+  if (IsInstMethod) {
+    if (PointersAre64Bit)
+      Out << 'E';
     mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
+  }
 
   mangleCallingConvention(T, IsInstMethod);
 
@@ -1264,6 +1269,9 @@
     }
     Out << '@';
   } else {
+    QualType ResultType = Proto->getResultType();
+    if (ResultType->isVoidType())
+      ResultType = ResultType.getUnqualifiedType();
     mangleType(Proto->getResultType(), Range, QMM_Result);
   }
 
@@ -1346,8 +1354,6 @@
         else
           Out << 'Q';
     }
-    if (PointersAre64Bit && !MD->isStatic())
-      Out << 'E';
   } else
     Out << 'Y';
 }
@@ -1535,6 +1541,8 @@
     mangleName(T->getClass()->castAs<RecordType>()->getDecl());
     mangleFunctionType(FPT, NULL, false, true);
   } else {
+    if (PointersAre64Bit && !T->getPointeeType()->isFunctionType())
+      Out << 'E';
     mangleQualifiers(PointeeType.getQualifiers(), true);
     mangleName(T->getClass()->castAs<RecordType>()->getDecl());
     mangleType(PointeeType, Range, QMM_Drop);
@@ -1574,6 +1582,8 @@
                                          SourceRange Range) {
   // Object pointers never have qualifiers.
   Out << 'A';
+  if (PointersAre64Bit && !T->getPointeeType()->isFunctionType())
+    Out << 'E';
   mangleType(T->getPointeeType(), Range);
 }
 
Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp
+++ test/CodeGenCXX/mangle-ms.cpp
@@ -13,12 +13,28 @@
 // CHECK: @"\01?h2@@3QBHB"
 // CHECK: @"\01?i@@3PAY0BE at HA"
 // CHECK: @"\01?j@@3P6GHCE at ZA"
-// CHECK: @"\01?k@@3PTfoo@@DQ1@"
+// WIN32: @"\01?k@@3PTfoo@@DT1@"
+// WIN64: @"\01?k@@3PETfoo@@DET1@"
 // CHECK: @"\01?l@@3P8foo@@AEHH at ZQ1@"
 // CHECK: @"\01?color1@@3PANA"
 // CHECK: @"\01?color2@@3QBNB"
 // CHECK: @"\01?color3@@3QAY02$$CBNA"
 // CHECK: @"\01?color4@@3QAY02$$CBNA"
+// WIN64: @"\01?funmemptr1@@3RESB@@R6AHXZES1@"
+// WIN64: @"\01?funmemptr2@@3PESB@@R6AHXZES1@"
+// WIN64: @"\01?funmemptr3@@3REQB@@P6AHXZEQ1@"
+// WIN64: @"\01?memptr1@@3RESB@@HES1@"
+// WIN64: @"\01?memptr2@@3PESB@@HES1@"
+// WIN64: @"\01?memptr3@@3REQB@@HEQ1@"
+// WIN64: @"\01?memptrtofun1@@3R8B@@EAAXXZEQ1@"
+// WIN64: @"\01?memptrtofun2@@3P8B@@EAAXXZEQ1@"
+// WIN64: @"\01?memptrtofun3@@3P8B@@EAAXXZEQ1@"
+// WIN64: @"\01?memptrtofun4@@3R8B@@EAAHXZEQ1@"
+// WIN64: @"\01?memptrtofun5@@3P8B@@EAA?CHXZEQ1@"
+// WIN64: @"\01?memptrtofun6@@3P8B@@EAA?BHXZEQ1@"
+// WIN64: @"\01?memptrtofun7@@3R8B@@EAAP6AHXZXZEQ1@"
+// WIN64: @"\01?memptrtofun8@@3P8B@@EAAR6AHXZXZEQ1@"
+// WIN64: @"\01?memptrtofun9@@3P8B@@EAAQ6AHXZXZEQ1@"
 
 int a;
 
@@ -180,6 +196,24 @@
 extern RGB const color3[5] = {};
 extern RGB const ((color4)[5]) = {};
 
+struct B;
+extern volatile int B::* volatile memptr1;
+extern volatile int B::* memptr2;
+extern int B::* volatile memptr3;
+typedef int (*fun)();
+extern volatile fun B::* volatile funmemptr1;
+extern volatile fun B::* funmemptr2;
+extern fun B::* volatile funmemptr3;
+extern void (B::* volatile memptrtofun1)();
+extern const void (B::* memptrtofun2)();
+extern volatile void (B::* memptrtofun3)();
+extern int (B::* volatile memptrtofun4)();
+extern volatile int (B::* memptrtofun5)();
+extern const int (B::* memptrtofun6)();
+extern fun (B::* volatile memptrtofun7)();
+extern volatile fun (B::* memptrtofun8)();
+extern const fun (B::* memptrtofun9)();
+
 // PR12603
 enum E {};
 // CHECK: "\01?fooE@@YA?AW4E@@XZ"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1353.1.patch
Type: text/x-patch
Size: 5458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130810/e47ad17b/attachment.bin>


More information about the cfe-commits mailing list