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

            Bug ID: 95277
           Summary: error on alignment for a function argument
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Declaring a local variable with attribute aligned is accepted.  Declaring a
function argument with an overligned type is also accepted.

However, specifying attribute aligned on a function argument is rejected.  The
error doesn't say why the attribute may not be specified, and the manual
doesn't say that specifying the attribute on function arguments is not allowed. 

The same code is accepted by Clang.

Either the code should be accepted with the same effect as in Clang, or the
manual (and ideally also the error) should be updated to explain why the
attribute may not be specified this way.

$ cat z.c && gcc -S -Wall -Wextra z.c
void f (void)
{
  __attribute__ ((aligned (256))) char c;          // accepted
  _Static_assert (__alignof__ (c) == 256, "#1");   // passes
}

typedef __attribute__ ((aligned (256))) char C256;

void g (C256 c)                                    // accepted
{
  _Static_assert (__alignof__ (c) == 256, "#2");   // passes
}

void h (__attribute__ ((aligned (256))) char c)    // error
{
  _Static_assert (__alignof__ (c) == 256, "#3");
}
z.c:14:46: error: alignment may not be specified for ‘c’
   14 | void h (__attribute__ ((aligned (256))) char c)    // error
      |                                         ~~~~~^
z.c: In function ‘h’:
z.c:16:3: error: static assertion failed: "#3"
   16 |   _Static_assert (__alignof__ (c) == 256, "#3");
      |   ^~~~~~~~~~~~~~

Reply via email to