Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp	(revision 118407)
+++ test/CodeGenCXX/mangle-ms.cpp	(working copy)
@@ -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 @@
   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;
Index: include/clang/AST/ASTContext.h
===================================================================
--- include/clang/AST/ASTContext.h	(revision 118407)
+++ include/clang/AST/ASTContext.h	(working copy)
@@ -285,13 +285,12 @@
   /// \brief Allocator for partial diagnostics.
   PartialDiagnostic::StorageAllocator DiagAllocator;
 
-  /// \brief The current C++ ABI.
-  llvm::OwningPtr<CXXABI> ABI;
   CXXABI *createCXXABI(const TargetInfo &T);
 
   friend class ASTDeclReader;
 
 public:
+  llvm::OwningPtr<CXXABI> ABI;
   const TargetInfo &Target;
   IdentifierTable &Idents;
   SelectorTable &Selectors;
Index: lib/AST/MicrosoftCXXABI.cpp
===================================================================
--- lib/AST/MicrosoftCXXABI.cpp	(revision 118407)
+++ lib/AST/MicrosoftCXXABI.cpp	(working copy)
@@ -12,7 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CXXABI.h"
+#include "clang/AST/CXXABI.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Type.h"
Index: lib/AST/ItaniumCXXABI.cpp
===================================================================
--- lib/AST/ItaniumCXXABI.cpp	(revision 118407)
+++ lib/AST/ItaniumCXXABI.cpp	(working copy)
@@ -17,7 +17,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "CXXABI.h"
+#include "clang/AST/CXXABI.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Type.h"
 
Index: lib/AST/CXXABI.h
===================================================================
--- lib/AST/CXXABI.h	(revision 118407)
+++ lib/AST/CXXABI.h	(working copy)
@@ -1,44 +0,0 @@
-//===----- CXXABI.h - Interface to C++ ABIs ---------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This provides an abstract class for C++ AST support. Concrete
-// subclasses of this implement AST support for specific C++ ABIs.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_AST_CXXABI_H
-#define LLVM_CLANG_AST_CXXABI_H
-
-#include "clang/AST/Type.h"
-
-namespace clang {
-
-class ASTContext;
-class MemberPointerType;
-
-/// Implements C++ ABI-specific semantic analysis functions.
-class CXXABI {
-public:
-  virtual ~CXXABI();
-
-  /// Returns the size of a member pointer in multiples of the target
-  /// pointer size.
-  virtual unsigned getMemberPointerSize(const MemberPointerType *MPT) const = 0;
-
-  /// Returns the default calling convention for C++ methods.
-  virtual CallingConv getDefaultMethodCallConv() const = 0;
-};
-
-/// Creates an instance of a C++ ABI class.
-CXXABI *CreateARMCXXABI(ASTContext &Ctx);
-CXXABI *CreateItaniumCXXABI(ASTContext &Ctx);
-CXXABI *CreateMicrosoftCXXABI(ASTContext &Ctx);
-}
-
-#endif
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp	(revision 118407)
+++ lib/AST/ASTContext.cpp	(working copy)
@@ -13,6 +13,7 @@
 
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/CharUnits.h"
+#include "clang/AST/CXXABI.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DeclTemplate.h"
@@ -29,7 +30,6 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
-#include "CXXABI.h"
 
 using namespace clang;
 
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- lib/CodeGen/MicrosoftCXXABI.cpp	(revision 118407)
+++ lib/CodeGen/MicrosoftCXXABI.cpp	(working copy)
@@ -18,6 +18,7 @@
 #include "CodeGenModule.h"
 #include "Mangle.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/CXXABI.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
@@ -72,7 +73,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 +804,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 +899,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 +916,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().ABI->getDefaultMethodCallConv() : CC_C;
+  switch (CC) {
     case CC_Default:
     case CC_C: Out << 'A'; break;
     case CC_X86Pascal: Out << 'C'; break;
