On 28/11/2011 22:56, Eli Friedman wrote:
On Mon, Nov 28, 2011 at 10:01 AM, r4start<[email protected]>  wrote:
Hi, all.

This patch fix problem with empty struct/class for MS mode.
Please review and if it's ok please commit.
Patch looks fine, but please include a testcase.

-Eli
Sorry, I forgot it.
Now I include test.

 - Dmitry.
Index: lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- lib/AST/RecordLayoutBuilder.cpp     (revision 145395)
+++ lib/AST/RecordLayoutBuilder.cpp     (working copy)
@@ -1399,10 +1399,8 @@
   }
 
   // Finally, round the size of the total struct up to the alignment
-  // of the struct itself.  Amazingly, this does not occur in the MS
-  // ABI after virtual base layout.
-  if (!isMicrosoftCXXABI() || RD->getNumVBases())
-    FinishLayout(RD);
+  // of the struct itself.
+  FinishLayout(RD);
 
 #ifndef NDEBUG
   // Check that we have base offsets for all bases.
@@ -1882,6 +1880,13 @@
     else
       setSize(CharUnits::One());
   }
+
+  // MSVC doesn't round up to alignment class with virtual bases.
+  if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D)) {
+    if (isMicrosoftCXXABI() && RD->getNumVBases())
+      return;
+  }
+
   // Finally, round the size of the record up to the alignment of the
   // record itself.
   uint64_t UnpaddedSize = getSizeInBits() - UnfilledBitsInLastByte;
Index: test/Sema/ms_class_layout.cpp
===================================================================
--- test/Sema/ms_class_layout.cpp       (revision 145395)
+++ test/Sema/ms_class_layout.cpp       (working copy)
@@ -95,6 +95,7 @@
   int p;
 };
 
+struct R {};
 
 #pragma pack(pop)
 
@@ -111,6 +112,7 @@
   N* n;
   O* o;
   P* p;
+  R* r;
   return 0;
 }
 
@@ -325,3 +327,9 @@
 // CHECK-NEXT: nvsize=12, nvalign=4
 
 //CHECK: %struct.P = type { %struct.M.base, i32, %struct.K, %struct.L }
+
+// CHECK:       0 | struct R (empty)
+// CHECK-NEXT:  sizeof=1, dsize=0, align=1
+// CHECK-NEXT:  nvsize=0, nvalign=1
+
+//CHECK: %struct.R = type { i8 }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to