[LLVMdev] Structure Types and ABI sizes

Renato Golin rengolin at systemcall.org
Thu Feb 24 08:08:09 PST 2011


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



More information about the llvm-dev mailing list