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

            Bug ID: 88172
           Summary: attribute aligned of zero silently accepted but
                    ignored
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

According to the the latest GCC 9 manual the argument to the aligned variable
attribute is required to be a power of 2:

    The aligned attribute specifies a minimum alignment for the variable or
structure field, measured in bytes. When specified, alignment must be an
integer constant power of 2.

However, GCC silently also accepts and ignores an alignment of zero.  Either
the manual should be updated or GCC should issue a warning noting that that
attribute is ignored.  I lean toward the latter for the GNU attribute, even
though C11 explicitly specifies that in _Alignof, a zero argument is ignored
(not sure why this is so).

$ cat t.c && gcc -S -Wall -Wextra t.c
__attribute__ ((aligned (0))) void f (void);
_Static_assert (__alignof__ (f) == __alignof__ (void ()));

__attribute__ ((aligned (0))) int i;
_Static_assert (__alignof__ (i) == __alignof__ (int));

__attribute__ ((aligned (0))) typedef int Int0;
_Static_assert (__alignof__ (Int0) == __alignof__ (int));

_Alignas (0) int j;
_Static_assert (_Alignof (i) == _Alignof (int));
$

Reply via email to