[cfe-commits] r148070 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/SemaCXX/empty-class-layout.cpp
Eli Friedman
eli.friedman at gmail.com
Thu Jan 12 15:48:56 PST 2012
Author: efriedma
Date: Thu Jan 12 17:48:56 2012
New Revision: 148070
URL: http://llvm.org/viewvc/llvm-project?rev=148070&view=rev
Log:
Recommit r148056 with fixes to deal with weirdness with bitfields in unions.
Original message: Make sure adding a field to a struct never reduces its size. PR11745.
Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/SemaCXX/empty-class-layout.cpp
Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=148070&r1=148069&r2=148070&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Thu Jan 12 17:48:56 2012
@@ -1869,12 +1869,12 @@
// Reserve space for this field.
uint64_t FieldSizeInBits = Context.toBits(FieldSize);
if (IsUnion)
- setSize(std::max(getSizeInBits(), FieldSizeInBits));
+ setDataSize(std::max(getDataSizeInBits(), FieldSizeInBits));
else
- setSize(FieldOffset + FieldSize);
+ setDataSize(FieldOffset + FieldSize);
- // Update the data size.
- setDataSize(getSizeInBits());
+ // Update the size.
+ setSize(std::max(getSizeInBits(), getDataSizeInBits()));
// 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=148070&r1=148069&r2=148070&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/empty-class-layout.cpp (original)
+++ cfe/trunk/test/SemaCXX/empty-class-layout.cpp Thu Jan 12 17:48:56 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