[LLVMdev] Size of packed struct type <{<3 x i32>, i32}>

Duncan Sands baldrick at free.fr
Wed May 5 09:13:59 PDT 2010


On 05/05/10 17:29, Jan Sjodin wrote:
> I have a packed struct<{<3 x i32>, i32}>  type that LLVM determines to be 20 bytes.
> Is this the expected size for this type?

Yes.  LLVM systematically allocates the same amount of memory for an object of
a given type (here <3 x i32>), whether on the stack, in an array, in a struct,
or a packed struct etc.  The fact that the struct is packed is not relevant [*].

> My guess was that the size should be 16 because I thought there should be no padding between elements.

There is no padding between elements, there is padding inside an element!

Ciao,

Duncan.

[*] This used to be different: when I first rationalized the notion of size in
LLVM, I allocated less memory to types when they are in a packed struct.  But I
later reverted that, since having this exceptional case seemed too confusing.



More information about the llvm-dev mailing list