public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95277] New: error on alignment for a function argument
@ 2020-05-22 19:21 msebor at gcc dot gnu.org
  2020-05-25  7:03 ` [Bug middle-end/95277] " rguenth at gcc dot gnu.org
  2024-04-10 23:45 ` [Bug c/95277] " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-05-22 19:21 UTC (permalink / raw)
  To: gcc-bugs

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");
      |   ^~~~~~~~~~~~~~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug middle-end/95277] error on alignment for a function argument
  2020-05-22 19:21 [Bug middle-end/95277] New: error on alignment for a function argument msebor at gcc dot gnu.org
@ 2020-05-25  7:03 ` rguenth at gcc dot gnu.org
  2024-04-10 23:45 ` [Bug c/95277] " pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-05-25  7:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The question is whether those attributes shall change the ABI or whether it
is enough for GCC to apply this alignment to the incoming variable by
eventually
issueing a callee-copy.  And what happens to C++ type where producing another
copy is not allowed.

Does _Alignas work here?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/95277] error on alignment for a function argument
  2020-05-22 19:21 [Bug middle-end/95277] New: error on alignment for a function argument msebor at gcc dot gnu.org
  2020-05-25  7:03 ` [Bug middle-end/95277] " rguenth at gcc dot gnu.org
@ 2024-04-10 23:45 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-10 23:45 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c
           Keywords|                            |diagnostic

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  else if (! VAR_OR_FUNCTION_DECL_P (decl)
           && TREE_CODE (decl) != FIELD_DECL)
    {
      error ("alignment may not be specified for %q+D", decl);
      *no_add_attrs = true;
    }

Here we have PARM_DECL which is not VAR or FUNCTION DECL.

This is at least a diagnostic issue where we should at least say it is not
allowed for arguments.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-10 23:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-22 19:21 [Bug middle-end/95277] New: error on alignment for a function argument msebor at gcc dot gnu.org
2020-05-25  7:03 ` [Bug middle-end/95277] " rguenth at gcc dot gnu.org
2024-04-10 23:45 ` [Bug c/95277] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).