forked from OSchip/llvm-project
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:
parent
c37917f309
commit
2e108376d5
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue