Replies: 1 comment
-
Update: as of #767 we disable alignment checks during dereference when the (statically known) dereferencing expression accesses a member of a packed structure. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This discussion is about how to handle packed structs wrt. the alignment checks, sparked by #732.
Assume a
struct S __attribute__((packed)) { char a; short b; };
and an arraystatic struct S x[n];
of those, and now we want one of the.b
members like so:If
i
is a constant (expression), we could figure out whether this particular.b
is aligned or not.When
i
is unknown here, we in most cases have to be conservative and disable the alignment check entirely for this expression.GCC-12.1 and Clang-11.0.1 for example cannot prove that the access to
.b
is always aligned in https://godbolt.org/z/hqPqPz51x, so they generateldrb
instructions on ARMv4 loading one byte at a time. For now. They may in the future be able to prove it, same as us. But there will always be cases when it is not provable; thus the alignment check cannot be guaranteed to be active.It gets worse when pointers to packed structs are involved:
Does
p
as passed to the function point to an aligned array member? We'd again need to be conservative and disable the alignment check (and thus cannot provide any guarantee about the alignment) sinceS
is declared packed.And pointers/references to members of packed structs are not even save to create, cf. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566.
The point of discussion here is: what could be a good strategy for handling alignment checks for packed struct members? Which guarantees can we provide when
--no-align-check
is not specified?Beta Was this translation helpful? Give feedback.
All reactions