https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122227

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Zack Buhman from comment #7)
> This behavior is undesirable.

Which one? -O0 or -O2? Both are valid based on what how C treats alignment of
types.


> GCC does not know and can not prove the (un)alignment of `data`.

Yes that is why at -O2 get the loads/stores via byte.

For -O0 as I said the alignment is based on the type which is alignment of 4
bytes.

If you want unaligned stores there then you need to use an type which has an
aligned of 1.

Like doing:
        typedef unsigned int unaligned_uint __attribute__((aligned(1)));

        void test_write_a(void)
        {
         *(volatile unaligned_uint*)data = 0;
        }



If you want to always do an aligned stores then mark the data as an aligned
like:
        extern volatile unsigned char data[8] __attribute__((aligned(4)));



The behavior of GCC here might seen inconsistent but it is not because you are
invoking undefined behavior anyways due to alignment requirements of types and
such.

Reply via email to