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

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amonakov at gcc dot gnu.org

--- Comment #1 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
(In reply to Johannes Vetter from comment #0)
> since version gcc version>=5 there seems to be a bug if pragma pack(1) is
> used. gcc thinks test.cmd is missaligned, but it isn't.
> 
> The code is ok in gcc version 4. The code with AND without pack(1) should be
> identical in this example.

No, it was a bug in version 4: since 'test' does not have an initializer, it
ends up as a common definition, which could be preempted at link time with a
normal definition with less-than-int alignment. Compiling with -fno-common
leads to desired code generation, as does providing an initializer:

test_t test = { 0 };

You can also add __attribute__((aligned(4))) on the struct type to make it
aligned (while still packed).

> It would be nice, if there is a compiler switch, which leeds into an error,
> if a volatile variable can't be read/write in one single access.

I think this makes sense.

Reply via email to