[cfe-commits] r145544 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/Sema/ms_class_layout.cpp

Eli Friedman eli.friedman at gmail.com
Wed Nov 30 16:37:01 PST 2011


Author: efriedma
Date: Wed Nov 30 18:37:01 2011
New Revision: 145544

URL: http://llvm.org/viewvc/llvm-project?rev=145544&view=rev
Log:
Fix MSVC class layout for empty classes.  Patch by Dmitry Sokolov.


Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/Sema/ms_class_layout.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=145544&r1=145543&r2=145544&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Wed Nov 30 18:37:01 2011
@@ -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 the alignment of the record 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;

Modified: cfe/trunk/test/Sema/ms_class_layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms_class_layout.cpp?rev=145544&r1=145543&r2=145544&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ms_class_layout.cpp (original)
+++ cfe/trunk/test/Sema/ms_class_layout.cpp Wed Nov 30 18:37:01 2011
@@ -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 }





More information about the cfe-commits mailing list