Index: lib/Sema/SemaExprCXX.cpp
===================================================================
--- lib/Sema/SemaExprCXX.cpp	(revision 182601)
+++ lib/Sema/SemaExprCXX.cpp	(working copy)
@@ -1554,6 +1554,20 @@
                                /*AllowMissing=*/true, OperatorNew))
       return true;
   }
+
+  if (!OperatorNew && IsArray && Context.getLangOpts().MicrosoftMode) {
+    // MSVC will fall back on the non-array version of operator new if the
+    // array version cannot be found, before attempting to find the global
+    // operator new[].
+    NewName = Context.DeclarationNames.getCXXOperatorName(OO_New);
+    DeleteName = Context.DeclarationNames.getCXXOperatorName(OO_Delete);
+    if (FindAllocationOverload(StartLoc, Range, NewName,
+                           AllocArgs, Context.getTranslationUnitDecl(),
+                           /*AllowMissing=*/true, OperatorNew,
+                           /*Diagnose=*/false))
+      return true;
+  }
+
   if (!OperatorNew) {
     // Didn't find a member overload. Look for a global one.
     DeclareGlobalNewDelete();
Index: test/CodeGenCXX/microsoft-new.cpp
===================================================================
--- test/CodeGenCXX/microsoft-new.cpp	(revision 0)
+++ test/CodeGenCXX/microsoft-new.cpp	(working copy)
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple i686-pc-win32 -fms-compatibility %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-MSVC %s
+
+struct arbitrary_t {} arbitrary;
+void *operator new(unsigned int size, arbitrary_t);
+
+namespace PR13164 {
+  void f() {
+	// MSVC will fall back on the non-array operator new
+    void *a;
+    int *p = new(arbitrary) int[4];
+    // CHECK-MSVC: call i8* @_Znwj11arbitrary_t(i32 16, %struct.arbitrary_t*
+  }
+}
Index: test/SemaCXX/microsoft-new-delete.cpp
===================================================================
--- test/SemaCXX/microsoft-new-delete.cpp	(revision 0)
+++ test/SemaCXX/microsoft-new-delete.cpp	(working copy)
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct arbitrary_t {} arbitrary;
+void *operator new(unsigned int size, arbitrary_t);
+
+void f() {
+  // Expect no error in MSVC compatibility mode
+  int *p = new(arbitrary) int[4];
+}
