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?

Hi edA-qa mort-ora-y,

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?

Hi,

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?

Yes. The various packed-struct extensions aren't specified very well
since they're not in the standard, but in general I think you only get
(guaranteed) sane behaviour if you access their members through an
lvalue whose type is related to that packed struct. So given:

struct __attribute__((packed)) Mine { char a; int b; };

the following works:

int foo(struct Mine *m) {
  return m->b;
}

but this won't necessarily work:

int foo(struct Mine *m) {
  int *b_pointer = &m->b
  return *b_pointer;
}

Tim.