https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122227
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is no bug here. IN the case of -O0, the alignment is based on the type
being accessed which you marked as 4 byte aligned. at -O2, the alignment is
based on what is know about &data[0] which is 1 (which is unaligned) as that
used when expanding from gimple to rtl (from a high level IR to the lower level
IR).
unaligned volatile stores is a load followed by a store aka &=.
clang has a similar behavior except it produces the similar code gen at -O0 and
-O2. In that test_write_a is based on the known alignment of &data[0] while
test_write_b is based on __builtin_assume_aligned. test_write_a is always
implemented as `&=0` and always unaligned.
There is no bug here. If you want aligned load you need to align the variable.