]> granicus.if.org Git - clang/commitdiff
Use the right calling convention when mangling names in the Microsoft C++
authorCharles Davis <cdavis@mines.edu>
Tue, 9 Nov 2010 18:04:24 +0000 (18:04 +0000)
committerCharles Davis <cdavis@mines.edu>
Tue, 9 Nov 2010 18:04:24 +0000 (18:04 +0000)
mangler. Now member functions and pointers thereof have their calling
convention mangled as __thiscall if they have the default CC (even though,
they technically still have the __cdecl CC).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118598 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
lib/AST/ASTContext.cpp
lib/CodeGen/MicrosoftCXXABI.cpp
test/CodeGenCXX/mangle-ms.cpp

index 55169c4101026d7fd40fe6b2b3b638db1c5b255f..becafb66e5202a23164bc0b85471afa8d9acea0b 100644 (file)
@@ -1129,6 +1129,10 @@ public:
   NestedNameSpecifier *
   getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS);
 
+  /// \brief Retrieves the default calling convention to use for
+  /// C++ instance methods.
+  CallingConv getDefaultMethodCallConv();
+
   /// \brief Retrieves the canonical representation of the given
   /// calling convention.
   CallingConv getCanonicalCallConv(CallingConv CC) {
index b2451a2d867d10757c949625e671144d3e6fbf66..0f449835412eacff18a2e985c0b51cf075b8ff42 100644 (file)
@@ -5838,4 +5838,9 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   return true;
 }
 
+CallingConv ASTContext::getDefaultMethodCallConv() {
+  // Pass through to the C++ ABI object
+  return ABI->getDefaultMethodCallConv();
+}
+
 CXXABI::~CXXABI() {}
index baa6ed3f82722d4fcb0d8589bce8d9bc55d20347..dd2f1cb1345f7fe1f1069423639429bff576a8db 100644 (file)
@@ -72,7 +72,7 @@ private:
   void mangleType(const ArrayType *T, bool IsGlobal);
   void mangleExtraDimensions(QualType T);
   void mangleFunctionClass(const FunctionDecl *FD);
-  void mangleCallingConvention(const FunctionType *T);
+  void mangleCallingConvention(const FunctionType *T, bool IsInstMethod = false);
   void mangleThrowSpecification(const FunctionProtoType *T);
 
 };
@@ -803,7 +803,7 @@ void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
   if (IsInstMethod)
     mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
 
-  mangleCallingConvention(T);
+  mangleCallingConvention(T, IsInstMethod);
 
   // <return-type> ::= <type>
   //               ::= @ # structors (they have no declared return type)
@@ -898,7 +898,8 @@ void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
   } else
     Out << 'Y';
 }
-void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) {
+void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T,
+                                                      bool IsInstMethod) {
   // <calling-convention> ::= A # __cdecl
   //                      ::= B # __export __cdecl
   //                      ::= C # __pascal
@@ -914,7 +915,10 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) {
   // that keyword. (It didn't actually export them, it just made them so
   // that they could be in a DLL and somebody from another module could call
   // them.)
-  switch (T->getCallConv()) {
+  CallingConv CC = T->getCallConv();
+  if (CC == CC_Default)
+    CC = IsInstMethod ? getASTContext().getDefaultMethodCallConv() : CC_C;
+  switch (CC) {
     case CC_Default:
     case CC_C: Out << 'A'; break;
     case CC_X86Pascal: Out << 'C'; break;
index 61f8a595fc4fc4d9b02f1cd4ffd57972bdfb5c54..d8d75b7d0f0e7ee71bb5bcdff984e8c0b3f209f4 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-apple-darwin10 | FileCheck %s
+// RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
 
 // CHECK: @"\01?a@@3HA"
 // CHECK: @"\01?b@N@@3HA"
@@ -11,7 +11,7 @@
 // CHECK: @"\01?i@@3PAY0BE@HA"
 // CHECK: @"\01?j@@3P6GHCE@ZA"
 // CHECK: @"\01?k@@3PTfoo@@DA"
-// CHECK: @"\01?l@@3P8foo@@AAHH@ZA"
+// CHECK: @"\01?l@@3P8foo@@AEHH@ZA"
 
 int a;
 
@@ -46,10 +46,8 @@ enum quux {
   qthree
 };
 
-// NOTE: The calling convention is supposed to be __thiscall by default,
-// but that needs to be fixed in Sema/AST.
 int foo::operator+(int a) {return a;}
-// CHECK: @"\01??Hfoo@@QAAHH@Z"
+// CHECK: @"\01??Hfoo@@QAEHH@Z"
 
 const short foo::d = 0;
 volatile long foo::e;