Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp	(revision 142728)
+++ lib/AST/RecordLayoutBuilder.cpp	(working copy)
@@ -788,6 +788,8 @@
   // indirect bases, and record all their primary virtual base classes.
   RD->getIndirectPrimaryBases(IndirectPrimaryBases);
 
+  bool HasNonVirtBases = false;
+
   // If the record has a dynamic base class, attempt to choose a primary base
   // class. It is the first (in direct base class order) non-virtual dynamic
   // base class, if one exists.
@@ -800,6 +802,8 @@
     const CXXRecordDecl *Base =
       cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
 
+    HasNonVirtBases = true;
+
     if (Base->isDynamicClass()) {
       // We found it.
       PrimaryBase = Base;
@@ -811,6 +815,20 @@
   // The Microsoft ABI doesn't have primary virtual bases.
   if (Context.getTargetInfo().getCXXABI() == CXXABI_Microsoft) {
     assert(!PrimaryBase && "Should not get here with a primary base!");
+
+    if (HasNewVirtualFunction(RD)) {
+      CharUnits PtrWidth = 
+       Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerWidth(0));
+
+      VFPtrOffset = getSize();
+      setSize(getSize() + PtrWidth);
+      setDataSize(getSize());
+
+      if (!HasNonVirtBases) {
+        setSize(getSize().RoundUpToAlignment(Alignment));
+        setDataSize(getSize());
+      }
+    }
     return;
   }
 
@@ -1039,13 +1057,6 @@
     CharUnits PtrAlign = 
       Context.toCharUnitsFromBits(Context.getTargetInfo().getPointerAlign(0));
     PtrAlign = std::max(PtrAlign, Alignment);
-    if (HasNewVirtualFunction(RD) &&
-        (!PrimaryBase || !BaseHasVFPtr(PrimaryBase))) {
-      EnsureVTablePointerAlignment(PtrAlign);
-      VFPtrOffset = getSize();
-      setSize(getSize() + PtrWidth);
-      setDataSize(getSize());
-    }
     if (RD->getNumVBases() &&
         (!PrimaryBase || !PrimaryBase->getNumVBases())) {
       EnsureVTablePointerAlignment(PtrAlign);
Index: test/Sema/ms_class_layout.cpp
===================================================================
--- test/Sema/ms_class_layout.cpp	(revision 142728)
+++ test/Sema/ms_class_layout.cpp	(working copy)
@@ -67,6 +67,12 @@
   double q;
 };
 
+struct J : public G, 
+           public virtual D
+{
+	virtual ~J(){}
+};
+
 #pragma pack(pop)
 
 // This needs only for building layouts. 
@@ -79,6 +85,7 @@
   H* g;
   BaseStruct* u;
   I* i;
+  J* j;
   return 0;
 }
 
@@ -227,3 +234,16 @@
 
 // CHECK: %struct.I = type { [16 x i8], double, %class.D }
 // CHECK: %struct.I.base = type { [16 x i8], double }
+
+// CHECK:       0 | struct J
+// CHECK-NEXT:  4 |   struct G (base)
+// CHECK-NEXT:  4 |     int g_field
+// CHECK-NEXT:  0 |   (J vftable pointer)
+// CHECK-NEXT:  8 |   (J vbtable pointer)
+// CHECK-NEXT: 16 |   class D (virtual base)
+// CHECK-NEXT: 16 |     (D vftable pointer)
+// CHECK-NEXT: 24 |     double a
+// CHECK-NEXT: sizeof=32, dsize=32, align=8
+// CHECK-NEXT: nvsize=12, nvalign=4
+
+// CHECK: %struct.J = type { [4 x i8], %struct.G, [8 x i8], %class.D }
