edA-qa mort-ora-y
2013-May-12 15:13 UTC
[LLVMdev] structure packing and misaligned members
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? -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130512/a6955951/attachment.sig>
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.
edA-qa mort-ora-y
2013-May-12 16:01 UTC
[LLVMdev] structure packing and misaligned members
On 12/05/13 17:50, Duncan Sands wrote:> 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.Okay, so I will track that on my own. Though I'm a bit confused then by what clang is emitted for packed C structures. It appears an "int*" is always loaded with "align 8" regardless of where it comes from. I know C says you have to be responsible for your own alignment, so is this result from clang correct? -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 261 bytes Desc: OpenPGP digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130512/7e7b7740/attachment.sig>
Maybe Matching Threads
- [LLVMdev] structure packing and misaligned members
- [LLVMdev] structure packing and misaligned members
- A struct {i8,i64} has size == 12, clang says size 16
- [LLVMdev] alignment issue, getting corrupt double values
- [LLVMdev] UNREACHABLE executed at MCJIT.cpp:322!