> If %I is not a "POD for the purposes of layout" type, that it's tail > padding MUST be overlapped when inherited from. In this case, we > end up creating two types for %I, %I and %I' and use %I' as the > type when it is inherited from. >But this is the question why two types in this case. if %I = type { i32, i8 }; then %I has 8 bytes if used directly and when used in %J %J = type { %I, i8 } then %I has only 5 bytes. Of course %I' could be %I' = type { i32, i8, i16 }; or %I' = type { i32, i8, i8, i16 }; but I don't see the point of this since %I already does the job or do I miss something? -Jochen
On 24 February 2011 15:13, Jochen Wilhelmy <j.wilhelmy at arcor.de> wrote:> but I don't see the point of this since %I already does the job > or do I miss something?If you're saying that:> %I = type { i32, i8 };has size 5, yes, you're missing the alignment. According to the standard, the alignment of a structure is the alignment of its most-aligned member (and some other cases in the ABI, too). So, %I has an int (align 4) and a char (align 1), so the final alignment is 4, so the size is rounded up to 8. LLVM knows that, and the size of:> %I = type { i32, i8 };is 8, not 5. To get size 5 you need the "packed" keyword (or similar attributes) or transform it to a [5 x i8]. cheers, --renato
> If you're saying that: > > >> %I = type { i32, i8 }; >> > has size 5, yes, you're missing the alignment. >Ah, now I see. But I didn't say that %I = type { i32, i8 }; has 5 bytes (because it has 8) but I thought that it has 5 bytes when being a member of %J, i.e. %J = type { %I, i8 } In this case %I also has 8 bytes right? I was thinking too much in terms of C++ inheritance. Then perhaps the tailpadding should be specified explicitly ;-) %I = type { i32, i8 }; // 5 bytes %I' = type { %I, tailpad}; // 8 bytes %J = type { %I, i8 } // 6 bytes -Jochen