>> %I = type { i32, i8 }; // 5 bytes >> %I' = type { %I, tailpad}; // 8 bytes >> %J = type { %I, i8 } // 6 bytes >> > That would break C code (and whatever else relies on alignment). >why would it break C code? of course a C frontend should generate only tailpadded types.> I don't see a way of specifying two structures, but I like the idea of > using a packed structure for inheritance and the "normal" one for > types. >or something like %J = type { inherit %I, i8 } the inherit keyword before %I removes the tailpadding -Jochen
On 4 March 2011 12:51, Jochen Wilhelmy <j.wilhelmy at arcor.de> wrote:> why would it break C code? of course a C frontend should generate only > tailpadded types.It's not about the size, but the offset. If you had a char field in the inherited class: %I' = type { %I, i8, tailpad}; The offset of that i8 has to be 8, not 5. If all structures are packed, that would be 5, which is correct for non-POD in C++ but wrong for everything else.> %J = type { inherit %I, i8 } > > the inherit keyword before %I removes the tailpaddingThat's what the packed is for. %Base = type { i32, i8 }; // size = 8 %POSDerived = type { %Base, i8 }; // i8 offset = 8, size 12 %Basep = packed type { i32, i8 }; // size = 5 %nonPOSDerived = type { %Basep, i8 }; // i8 offset = 5, size 8 cheers, --renato
>> why would it break C code? of course a C frontend should generate only >> tailpadded types. >> > It's not about the size, but the offset. If you had a char field in > the inherited class: > > %I' = type { %I, i8, tailpad}; > > The offset of that i8 has to be 8, not 5. If all structures are > packed, that would be 5, which is correct for non-POD in C++ but wrong > for everything else. >I know therefore in this case %I has to tailpadded. but packing and tailpadding are different things, aren't they? in a packet type {i8, i32} the i32 type has offset 1 while in a non-tailpadded type it still has offset 4.>> %J = type { inherit %I, i8 } >> >> the inherit keyword before %I removes the tailpadding >> > That's what the packed is for. >I don't think so because packing removes alignment constraints of all members. -Jochen