[LLVMdev] Structure Types and ABI sizes

Jochen Wilhelmy j.wilhelmy at arcor.de
Tue Feb 22 14:39:07 PST 2011


>> What I really wonder is why it isn't
>>
>> %I = type { i32, i8 }
>> %J = type { %I, i16, i8 }
>>
>> because llvm at least knows alignment rules by
>>
>> target  datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16...
>>
>> Therefore llvm has no other choice than assigning %I a size of 8
>> since an array may consist of %I elements and size of 5 would violate
>> the aligment of the i32 member.
> I can't quite parse this.  %I doesn't get "assigned" a size by anyone.
> Do you meant the size of struct I is eight bytes?  Yes, that's true.
Yes I mean that

%I = type { i32, i8 }
is 8 bytes given the alignment rules (i.e. llvm "assigns" a size of
8 bytes to this struct after parsing it)


> Yes, the padding is required.  I believe %J = type { %I, i16, i8 } would
> work just as well as long as %I = type { i32, i8 } as in your example.
Yes but given the ABI requires the last member to be at offset 5, which 
may happen
(i.e. no tail padding if I is derived from), then your solution

%I = type { i32, i8, i16 }
is problematic or do you switch struct generation dependent on the ABI?
The question arises to me since I would use an "always working" solution
(with no case distinction) but of course I'm not deep enough in the matter.

-Jochen





More information about the llvm-dev mailing list