[cfe-commits] [PATCH] [VCPP] Add __ptr64 qualifier

pravic ehysta at gmail.com
Tue Nov 13 12:42:51 PST 2012


  Add __ptr64 to the pointers and function pointers (including references).

  Is not completed, have an issues with mangling.

  Explicit qualifiers such as __ptr32 is not supported yet.

Hi cdavis5x,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D101?vs=292&id=313#toc

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

Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -45,9 +45,12 @@
 
   ASTContext &getASTContext() const { return Context.getASTContext(); }
 
+  const bool ExtendedPointer;
+
 public:
   MicrosoftCXXNameMangler(MangleContext &C, raw_ostream &Out_)
-  : Context(C), Out(Out_), UseNameBackReferences(true) { }
+  : Context(C), Out(Out_), UseNameBackReferences(true),
+  ExtendedPointer(C.getASTContext().getTargetInfo().getPointerWidth(0) == 64) { }
 
   raw_ostream &getStream() const { return Out; }
 
@@ -68,8 +71,8 @@
   void mangleSourceName(const IdentifierInfo *II);
   void manglePostfix(const DeclContext *DC, bool NoFunction=false);
   void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc);
-  void mangleQualifiers(Qualifiers Quals, bool IsMember);
-  void manglePointerQualifiers(Qualifiers Quals);
+  void mangleQualifiers(Qualifiers Quals, bool IsMember, bool IsPointer = false);
+  void manglePointerQualifiers(Qualifiers Quals, bool AllowExtendedPointer = true);
 
   void mangleUnscopedTemplateName(const TemplateDecl *ND);
   void mangleTemplateInstantiationName(const TemplateDecl *TD,
@@ -276,7 +279,7 @@
   QualType Ty = TL.getType();
   if (Ty->isPointerType() || Ty->isReferenceType()) {
     mangleType(Ty, TL.getSourceRange());
-    mangleQualifiers(Ty->getPointeeType().getQualifiers(), false);
+    mangleQualifiers(Ty->getPointeeType().getQualifiers(), false, true);
   } else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) {
     // Global arrays are funny, too.
     mangleType(AT, true);
@@ -844,7 +847,7 @@
 }
 
 void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
-                                               bool IsMember) {
+                                               bool IsMember, bool IsPointer) {
   // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
   // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
   // 'I' means __restrict (32/64-bit).
@@ -897,6 +900,9 @@
   //         ::= 3 # ?
   //         ::= 4 # ?
   //         ::= 5 # not really based
+  if (IsPointer && ExtendedPointer)
+    Out << 'E';
+
   bool HasConst = Quals.hasConst(),
        HasVolatile = Quals.hasVolatile();
   if (!IsMember) {
@@ -924,7 +930,8 @@
   // FIXME: For now, just drop all extension qualifiers on the floor.
 }
 
-void MicrosoftCXXNameMangler::manglePointerQualifiers(Qualifiers Quals) {
+void MicrosoftCXXNameMangler::manglePointerQualifiers(Qualifiers Quals,
+                                                      bool AllowExtendedPointer) {
   // <pointer-cvr-qualifiers> ::= P  # no qualifiers
   //                          ::= Q  # const
   //                          ::= R  # volatile
@@ -940,6 +947,9 @@
   } else {
     Out << 'P';
   }
+  // mangle pointer with implicit __ptr64 qualifier on x64 mode.
+  if (ExtendedPointer && AllowExtendedPointer)
+    Out << 'E';
 }
 
 void MicrosoftCXXNameMangler::mangleArgumentType(QualType T,
@@ -974,7 +984,8 @@
   // We have to mangle these now, while we still have enough information.
   if (T->isAnyPointerType() || T->isMemberPointerType() ||
       T->isBlockPointerType()) {
-    manglePointerQualifiers(Quals);
+    // pointer to function type isn't extended
+    manglePointerQualifiers(Quals, T->isFunctionPointerType() == false);
   } else if (Quals && MangleQualifiers) {
     mangleQualifiers(Quals, false);
   }
@@ -1219,6 +1230,11 @@
         else
           Out << 'Q';
     }
+    // mangle function with implicit __ptr64 qualifier on x64 mode.
+    if (ExtendedPointer)	{
+      Out << 'E';
+    }
+
   } else
     Out << 'Y';
 }
@@ -1458,9 +1474,12 @@
                                          SourceRange Range) {
   Out << 'A';
   QualType PointeeTy = T->getPointeeType();
-  if (!PointeeTy.hasQualifiers())
+  if (!PointeeTy.hasQualifiers()){
+    if (ExtendedPointer)
+      Out << 'E';
     // Lack of qualifiers is mangled as 'A'.
     Out << 'A';
+  }
   mangleType(PointeeTy, Range);
 }
 
@@ -1470,9 +1489,12 @@
                                          SourceRange Range) {
   Out << "$$Q";
   QualType PointeeTy = T->getPointeeType();
-  if (!PointeeTy.hasQualifiers())
+  if (!PointeeTy.hasQualifiers()){
+    if (ExtendedPointer)
+      Out << 'E';
     // Lack of qualifiers is mangled as 'A'.
     Out << 'A';
+  }
   mangleType(PointeeTy, Range);
 }
 
Index: test/CodeGenCXX/mangle-ms-ptr64.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/mangle-ms-ptr64.cpp
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -fms-extensions -triple=i386-pc-win32   | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -fms-extensions -triple=x86_64-pc-win32 | FileCheck -check-prefix=CHK64 %s
+// expected-no-diagnostics
+
+// pointer qualifications mangling
+
+// CHECK: @"\01?VS_p_@@3PAHA" = global i32* null
+// CHK64: @"\01?VS_p_@@3PEAHEA" = global i32* null
+int * VS_p_;
+
+// CHECK: @"\01?VS_func_@@3P6AXH at ZA" = global void (i32)* null
+// CHK64: @"\01?VS_func_@@3P6AXH at ZEA" = global void (i32)* null
+typedef void VS_func_t(int arg);
+VS_func_t* VS_func_;
+
+// Struct mangling
+template<class T>
+struct VS_1 {	VS_1(T); };
+
+struct VS_0	{	
+	VS_0( );
+	
+	virtual int check();
+};
+
+void test_vs() {
+	// 'QAE':  __thiscall (x86)
+	// 'QAA':  __cdecl (x86)
+	// 'QEAA': __cdecl __ptr64 (x64)
+	// CHECK: @"\01??0VS_0@@QAE at XZ"(%struct.VS_0* %vs0)
+	// CHK64: @"\01??0VS_0@@QEAA at XZ"(%struct.VS_0* %vs0)
+	VS_0 vs0;
+	
+	// CHECK: @"\01?check at VS_0@@UAEHXZ"(%struct.VS_0* %vs0)
+	// CHK64: @"\01?check at VS_0@@UEAAHXZ"(%struct.VS_0* %vs0)
+	vs0.check();
+	
+	// CHECK: @"\01??0?$VS_1 at H@@QAE at H@Z"(%struct.VS_1* %vs1, i32 1)
+	// CHK64: @"\01??0?$VS_1 at H@@QEAA at H@Z"(%struct.VS_1* %vs1, i32 1)
+	VS_1<int> vs1(1);
+}
+
+
+
+class cls {
+  void priv( int * p) {}
+public:
+void* pub( int * p) { priv( p ); return 0; }
+};
+// CHECK: @"\01?pub at cls@@QAEPAXPAH at Z"
+// CHK64: @"\01?pub at cls@@QEAAPEAXPEAH at Z"
+
+// CHECK: @"\01?priv at cls@@AAEXPAH at Z"
+// CHK64: @"\01?priv at cls@@AEAAXPEAH at Z"
+
+void use_cls() {
+  cls().pub(0);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101.5.patch
Type: text/x-patch
Size: 6230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121113/30f1f3c6/attachment.bin>


More information about the cfe-commits mailing list