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

            Bug ID: 61447
           Summary: _Alignof returns incorrect results for some
                    types/archs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx

_Alignof is defined per C11 as the "alignment requirement of its operand type".
This is different from GCC's result for __alignof__ (and sometimes for
_Alignof) where it returns the "preferred alignment for optimization" or the
"actual alignment applied".

On i386, _Alignof(long long) returns 8, despite the correct value being 4. With
recent enough gcc (tested on 4.9.0), -std=c11 fixes _Alignof when applied to
the type name, but not when applied to an object: long long x; _Alignof(x)
still gives 8. In order to be correct:

1. _Alignof(object) should always be the same as _Alignof(__typeof__(object))

2. _Alignof(x) should always be the same as (sizeof(struct{char __a;
__typeof__(x) __b;}) - sizeof(x))

Failure of condition 2 results in observably incorrect behavior: a program can
observe the existence of a structure containing members a and b of the same
type where (char*)&foo.a-(char*)&foo.b is not a multiple of _Alignof(foo.a).

Reply via email to