Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp	(revision 163328)
+++ lib/AST/MicrosoftMangle.cpp	(working copy)
@@ -1232,7 +1232,14 @@
     } else {
       CC = CC_C;
     }
+  } else if (CC == CC_X86StdCall &&
+             getASTContext().getLangOpts().MicrosoftMode &&
+             getASTContext().getTargetInfo().getTriple().isArch64Bit()) {
+    // Microsoft silently ignores the __stdcall calling convention when 
+    // specified for an x64 target.
+    CC = CC_C;
   }
+
   switch (CC) {
     default:
       llvm_unreachable("Unsupported CC for mangling");
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp	(revision 163328)
+++ lib/CodeGen/CGCall.cpp	(working copy)
@@ -402,6 +402,13 @@
 
   unsigned CC = ClangCallConvToLLVMCallConv(info.getCC());
 
+  // If we're compiling in Microsoft mode for x64 and the calling convention is
+  // stdcall, we need to silently treat that as cdecl instead.
+  if (CGM.getLangOpts().MicrosoftMode && 
+      CGM.getTarget().getTriple().isArch64Bit() &&
+      CC == llvm::CallingConv::X86_StdCall)
+    CC = llvm::CallingConv::C;
+
   // Lookup or create unique function info.
   llvm::FoldingSetNodeID ID;
   CGFunctionInfo::Profile(ID, info, required, resultType, argTypes);
Index: test/CodeGen/microsoft-call-conv.c
===================================================================
--- test/CodeGen/microsoft-call-conv.c	(revision 163328)
+++ test/CodeGen/microsoft-call-conv.c	(working copy)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fms-compatibility -emit-llvm < %s | FileCheck -check-prefix X64 %s
 
 void __fastcall f1(void);
 void __stdcall f2(void);
@@ -10,8 +11,10 @@
 }
 void __stdcall f5(void) {
 // CHECK: define x86_stdcallcc void @f5()
+// X64: define void @f5()
   f2();
 // CHECK: call x86_stdcallcc void @f2()
+// X64: call void @f2()
 }
 void __thiscall f6(void) {
 // CHECK: define x86_thiscallcc void @f6()
@@ -32,6 +35,7 @@
     // CHECK: call x86_fastcallcc void @f4()
     // CHECK: call x86_stdcallcc void @f5()
     // CHECK: call x86_thiscallcc void @f6()
+    // X64: call void @f5()
     pf1(); pf2(); pf3(); pf4(); pf5(); pf6();
     // CHECK: call x86_fastcallcc void %{{.*}}()
     // CHECK: call x86_stdcallcc void %{{.*}}()
Index: test/CodeGenCXX/mangle-ms.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms.cpp	(revision 163328)
+++ test/CodeGenCXX/mangle-ms.cpp	(working copy)
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fms-extensions -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
+// RUN: %clang_cc1 -fms-compatibility -fblocks -emit-llvm %s -o - -cxx-abi microsoft -triple=x86_64-pc-win32 | FileCheck -check-prefix X64 %s
 
 // CHECK: @"\01?a@@3HA"
 // CHECK: @"\01?b@N@@3HA"
@@ -109,6 +110,7 @@
 }
 
 // CHECK: @"\01?alpha@@YGXMN@Z"
+// X64: @"\01?alpha@@YAXMN@Z"
 
 // Make sure tag-type mangling works.
 void gamma(class foo, struct bar, union baz, enum quux) {}
