public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86
@ 2014-10-09  6:13 eggert at gnu dot org
  2014-10-09  7:58 ` [Bug c/63495] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: eggert at gnu dot org @ 2014-10-09  6:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 63495
           Summary: struct __attribute__ ((aligned (8))) broken on x86
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at gnu dot org

Compile and run the following two-line program with an x86 target:

struct __attribute__ ((aligned (8))) s { char c; };
_Static_assert (_Alignof (struct s) >= 8, "wrong alignment");

This should compile, but here are the symptoms I observe with GCC 4.9.1:

$ gcc -m32 t.c
t.c:2:1: error: static assertion failed: "wrong alignment"
 _Static_assert (_Alignof (struct s) >= 8, "wrong alignment");
 ^

On the buggy platform the structure's alignment is 4; it should be 8.

The program compiles fine with GCC 4.8.3, so there is a regression here.  The
program also compiles fine on x86-64.

The alignment bug breaks the trunk version of GNU Emacs when built on a 32-bit
platform; see
<http://lists.gnu.org/archive/html/emacs-devel/2014-10/msg00261.html>.  I'll
try to fix Emacs to work around the bug, but the GCC bug really should get
fixed.


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
@ 2014-10-09  7:58 ` jakub at gcc dot gnu.org
  2014-10-09  8:04 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-09  7:58 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-10-09
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This started with r205685.

The problem is in the x86 32-bit ABI, which decreases alignment of fields to 32
bits if the field has integral mode, or DFmode/DCmode or complex integral mode.

int
x86_field_alignment (tree field, int computed)
{
  enum machine_mode mode;
  tree type = TREE_TYPE (field);

  if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
    return computed;
  mode = TYPE_MODE (strip_array_types (type));
  if (mode == DFmode || mode == DCmode
      || GET_MODE_CLASS (mode) == MODE_INT
      || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
    return MIN (32, computed);
  return computed;
}

When the struct has only a single field, it is QImode, therefore despite the
user forced alignment the alignment is lowered to 32 bits.

Now, when actually laying out struct s fields, such as:
struct T { char a; struct s s; } t = { 1, { 2 } };
it actually is given 64-bit alignment, because ADJUST_FIELD_ALIGN is not used
in that case:
      if (! packed_p && ! DECL_USER_ALIGN (decl))
        {
          /* Some targets (i.e. i386, VMS) limit struct field alignment
             to a lower boundary than alignment of variables unless
             it was overridden by attribute aligned.  */
#ifdef BIGGEST_FIELD_ALIGNMENT
          DECL_ALIGN (decl)
            = MIN (DECL_ALIGN (decl), (unsigned) BIGGEST_FIELD_ALIGNMENT);
#endif
#ifdef ADJUST_FIELD_ALIGN
          DECL_ALIGN (decl) = ADJUST_FIELD_ALIGN (decl, DECL_ALIGN (decl));
#endif
        }

As do_type_align for FIELD_DECLs sets DECL_USER_ALIGN:
static inline void
do_type_align (tree type, tree decl)
{
  if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
    {
      DECL_ALIGN (decl) = TYPE_ALIGN (type);
      if (TREE_CODE (decl) == FIELD_DECL)
        DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
    }
}

if TYPE_USER_ALIGN is set, IMHO ADJUST_FIELD_ALIGN and corresponding 
BIGGEST_FIELD_ALIGNMENT will never be used.


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
  2014-10-09  7:58 ` [Bug c/63495] " jakub at gcc dot gnu.org
@ 2014-10-09  8:04 ` jakub at gcc dot gnu.org
  2014-10-10 17:43 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-09  8:04 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 33670
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33670&action=edit
gcc5-pr63495.patch

Untested fix.


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
  2014-10-09  7:58 ` [Bug c/63495] " jakub at gcc dot gnu.org
  2014-10-09  8:04 ` jakub at gcc dot gnu.org
@ 2014-10-10 17:43 ` jakub at gcc dot gnu.org
  2014-10-10 17:51 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-10 17:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Oct 10 17:43:21 2014
New Revision: 216101

URL: https://gcc.gnu.org/viewcvs?rev=216101&root=gcc&view=rev
Log:
    PR c/63495
    * stor-layout.c (min_align_of_type): Don't decrease alignment
    through BIGGEST_FIELD_ALIGNMENT or ADJUST_FIELD_ALIGN if
    TYPE_USER_ALIGN is set.

    * gcc.target/i386/pr63495.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr63495.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/stor-layout.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
                   ` (2 preceding siblings ...)
  2014-10-10 17:43 ` jakub at gcc dot gnu.org
@ 2014-10-10 17:51 ` jakub at gcc dot gnu.org
  2014-10-10 17:54 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-10 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Fri Oct 10 17:51:14 2014
New Revision: 216102

URL: https://gcc.gnu.org/viewcvs?rev=216102&root=gcc&view=rev
Log:
    PR c/63495
    * c-common.c (min_align_of_type): Don't decrease alignment
    through BIGGEST_FIELD_ALIGNMENT or ADJUST_FIELD_ALIGN if
    TYPE_USER_ALIGN is set.

    * gcc.target/i386/pr63495.c: New test.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.target/i386/pr63495.c
Modified:
    branches/gcc-4_9-branch/gcc/c-family/ChangeLog
    branches/gcc-4_9-branch/gcc/c-family/c-common.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
                   ` (3 preceding siblings ...)
  2014-10-10 17:51 ` jakub at gcc dot gnu.org
@ 2014-10-10 17:54 ` jakub at gcc dot gnu.org
  2014-10-10 18:05 ` eggert at gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-10-10 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.9.2

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed now.


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
                   ` (4 preceding siblings ...)
  2014-10-10 17:54 ` jakub at gcc dot gnu.org
@ 2014-10-10 18:05 ` eggert at gnu dot org
  2023-04-06  6:33 ` zhonghao at pku dot org.cn
  2023-04-06  7:00 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: eggert at gnu dot org @ 2014-10-10 18:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paul Eggert <eggert at gnu dot org> ---
That was fast!  Thank you.


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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
                   ` (5 preceding siblings ...)
  2014-10-10 18:05 ` eggert at gnu dot org
@ 2023-04-06  6:33 ` zhonghao at pku dot org.cn
  2023-04-06  7:00 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: zhonghao at pku dot org.cn @ 2023-04-06  6:33 UTC (permalink / raw)
  To: gcc-bugs

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

zhonghao at pku dot org.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zhonghao at pku dot org.cn

--- Comment #7 from zhonghao at pku dot org.cn ---
I tried to compile the sample code with the latest gcc.

struct __attribute__ ((aligned (8))) s { char c; };
_Static_assert (_Alignof (struct s) >= 8, "wrong alignment");

However, it does not compile. Is this a regression?

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

* [Bug c/63495] struct __attribute__ ((aligned (8))) broken on x86
  2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
                   ` (6 preceding siblings ...)
  2023-04-06  6:33 ` zhonghao at pku dot org.cn
@ 2023-04-06  7:00 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-04-06  7:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
No, works just fine.  Perhaps you are compiling with C++ when this is C?

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

end of thread, other threads:[~2023-04-06  7:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-09  6:13 [Bug c/63495] New: struct __attribute__ ((aligned (8))) broken on x86 eggert at gnu dot org
2014-10-09  7:58 ` [Bug c/63495] " jakub at gcc dot gnu.org
2014-10-09  8:04 ` jakub at gcc dot gnu.org
2014-10-10 17:43 ` jakub at gcc dot gnu.org
2014-10-10 17:51 ` jakub at gcc dot gnu.org
2014-10-10 17:54 ` jakub at gcc dot gnu.org
2014-10-10 18:05 ` eggert at gnu dot org
2023-04-06  6:33 ` zhonghao at pku dot org.cn
2023-04-06  7:00 ` jakub 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).