[cfe-commits] r148056 - in /cfe/trunk: include/clang/Sema/Sema.h lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/empty-class-layout.cpp

Eli Friedman eli.friedman at gmail.com
Thu Jan 12 14:41:26 PST 2012


Author: efriedma
Date: Thu Jan 12 16:41:25 2012
New Revision: 148056

URL: http://llvm.org/viewvc/llvm-project?rev=148056&view=rev
Log:
Make sure adding a field to a struct never reduces its size.  PR11745.


Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
    cfe/trunk/test/SemaCXX/empty-class-layout.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=148056&r1=148055&r2=148056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 12 16:41:25 2012
@@ -5684,6 +5684,8 @@
   // type.
   ExprResult DefaultLvalueConversion(Expr *E);
 
+  void MarkLValueReferenced(Expr *E);
+
   // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
   // do not have a prototype. Integer promotions are performed on each
   // argument, and arguments that have type float are promoted to double.

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=148056&r1=148055&r2=148056&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Thu Jan 12 16:41:25 2012
@@ -1867,14 +1867,13 @@
                     Context.toBits(UnpackedFieldAlign), FieldPacked, D);
 
   // Reserve space for this field.
-  uint64_t FieldSizeInBits = Context.toBits(FieldSize);
   if (IsUnion)
-    setSize(std::max(getSizeInBits(), FieldSizeInBits));
+    setDataSize(std::max(getDataSize(), FieldSize));
   else
-    setSize(FieldOffset + FieldSize);
+    setDataSize(FieldOffset + FieldSize);
 
-  // Update the data size.
-  setDataSize(getSizeInBits());
+  // Update the size.
+  setSize(std::max(getSize(), getDataSize()));
 
   // Remember max struct/class alignment.
   UpdateAlignment(FieldAlign, UnpackedFieldAlign);

Modified: cfe/trunk/test/SemaCXX/empty-class-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/empty-class-layout.cpp?rev=148056&r1=148055&r2=148056&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/empty-class-layout.cpp (original)
+++ cfe/trunk/test/SemaCXX/empty-class-layout.cpp Thu Jan 12 16:41:25 2012
@@ -144,3 +144,14 @@
 SA(0, sizeof(B) == 16);
 
 }
+
+namespace Test7 {
+  // Make sure we reserve enough space for both bases; PR11745.
+  struct Empty { };
+  struct Base1 : Empty { };
+  struct Base2 : Empty { };
+  struct Test : Base1, Base2 {
+    char c;
+  };
+  SA(0, sizeof(Test) == 2);
+}





More information about the cfe-commits mailing list