[cfe-commits] r118598 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/CodeGen/MicrosoftCXXABI.cpp test/CodeGenCXX/mangle-ms.cpp

Charles Davis cdavis at mines.edu
Tue Nov 9 10:04:24 PST 2010


Author: cdavis
Date: Tue Nov  9 12:04:24 2010
New Revision: 118598

URL: http://llvm.org/viewvc/llvm-project?rev=118598&view=rev
Log:
Use the right calling convention when mangling names in the Microsoft C++
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).

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

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=118598&r1=118597&r2=118598&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Nov  9 12:04:24 2010
@@ -1129,6 +1129,10 @@
   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) {

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=118598&r1=118597&r2=118598&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov  9 12:04:24 2010
@@ -5838,4 +5838,9 @@
   return true;
 }
 
+CallingConv ASTContext::getDefaultMethodCallConv() {
+  // Pass through to the C++ ABI object
+  return ABI->getDefaultMethodCallConv();
+}
+
 CXXABI::~CXXABI() {}

Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=118598&r1=118597&r2=118598&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Tue Nov  9 12:04:24 2010
@@ -72,7 +72,7 @@
   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 @@
   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 @@
   } 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 @@
   // 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;

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms.cpp?rev=118598&r1=118597&r2=118598&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms.cpp Tue Nov  9 12:04:24 2010
@@ -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 at N@@3HA"
@@ -11,7 +11,7 @@
 // CHECK: @"\01?i@@3PAY0BE at HA"
 // CHECK: @"\01?j@@3P6GHCE at ZA"
 // CHECK: @"\01?k@@3PTfoo@@DA"
-// CHECK: @"\01?l@@3P8foo@@AAHH at ZA"
+// CHECK: @"\01?l@@3P8foo@@AEHH at ZA"
 
 int a;
 
@@ -46,10 +46,8 @@
   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 at Z"
+// CHECK: @"\01??Hfoo@@QAEHH at Z"
 
 const short foo::d = 0;
 volatile long foo::e;





More information about the cfe-commits mailing list