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.

llvm-svn: 148070
This commit is contained in:
Eli Friedman 2012-01-12 23:48:56 +00:00
parent c37917f309
commit 2e108376d5
2 changed files with 15 additions and 4 deletions

View File

@ -1869,12 +1869,12 @@ void RecordLayoutBuilder::LayoutField(const FieldDecl *D) {
// 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);

View File

@ -144,3 +144,14 @@ struct B : Empty, A { };
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);
}