[LLVMdev] structure packing and misaligned members

Duncan Sands baldrick at free.fr
Sun May 12 08:50:07 PDT 2013

Hi edA-qa mort-ora-y,

On 12/05/13 17:13, edA-qa mort-ora-y wrote:
> I'm trying to determine how to do my packed structure compilation and am
> a bit unclear about how packed structures are handled. Consider this
> structure:
> %struct.packed = type <{ i8, i32 }>
> Now if I get a pointer to the i32 element the pointer will not be
> properly aligned for a typical i32. On my current machine (x86_64) the
> cpu doesn't seem to care, but I suspect this isn't true on all platforms
> (not is true on this platform if I do atomic operations). Yet the
> pointer for this i32 which I get is the same as a normal i32 pointer.
> Is there supposed to be a special marker for possibly misaligned
> pointers? Or how I am supposed to track such misaligned pointers and
> ensure they aren't used incorrectly?

in LLVM, pointer types don't have an alignment associated with them.
Instead it is pointer operations that have an alignment (when relevant),
for example load and store instructions have an optional alignment.  So
you need to put the alignment information onto the loads and stores that
you generate in your front-end.

Ciao, Duncan.

More information about the llvm-dev mailing list