[LLVMdev] struct alignment question
Caldarale, Charles R
Chuck.Caldarale at unisys.com
Mon Nov 18 23:03:27 PST 2013
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu]
> On Behalf Of edA-qa mort-ora-y
> Subject: [LLVMdev] struct alignment question
> Is a series of fields in a structure guaranteed to have the same layout
> as those fields in a structure on their own? That is, can I cast a
> pointer within a main structure to an equivalent type?
> X = { a, b, c, d, e }
> Y = { c, d, e }
> y = BitCast( StructGEP( some_x, 2 ), Y* )
> Is that a valid cast?
In general, no. If a, b, and c were char, and d was an int, using typical C alignments, there would be one slack byte between c and d in X, whereas there would be three in Y. You could probably force what you want with packed structures or by playing with the data layout setting.
- Chuck
More information about the llvm-dev
mailing list