public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/52023] New: _Alignof (double) yields wrong value on x86
@ 2012-01-27 20:06 eggert at gnu dot org
  2012-01-27 20:12 ` [Bug target/52023] " pinskia at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: eggert at gnu dot org @ 2012-01-27 20:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52023

             Bug #: 52023
           Summary: _Alignof (double) yields wrong value on x86
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eggert@gnu.org
              Host: x86-64
            Target: x86
             Build: x86-64


Created attachment 26482
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26482
gcc -v output

On x86, alignof (double) should be 4, since that's the alignment
requirement used for 'double' when laying out structures.  But with
GCC alignof incorrectly returns 8.  This causes some gnulib tests to fail
and (more importantly) it may cause problems with programs such as
conservative garbage collectors that use alignof to determine which
addresses might be of valid objects.

The problem also occurs with other fundamental types, such as 'long long'.

Here's a simple test case:

  #include <stddef.h>
  #include <stdalign.h>
  int a = alignof (double);
  int b = offsetof (struct { char c; double d; }, d);
  int main (void) { return a == b; }

Here's the preprocessed output:

  int a = _Alignof (double);
  int b = __builtin_offsetof (struct { char c; double d; }, d);
  int main (void) { return a == b; }

'main' should return 1, but it returns 0 due to the bug, which causes
'a' to be 8 instead of 4 as it should be.

I'm using GCC on the trunk (r183603), built on Fedora 16 x86-64 with
no special flags, and I'm compiling with 'gcc -v -m32 test.c' and
running with './a.out'.  I'm attaching the output of 'gcc -v'.


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

end of thread, other threads:[~2014-01-14 11:50 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-27 20:06 [Bug c/52023] New: _Alignof (double) yields wrong value on x86 eggert at gnu dot org
2012-01-27 20:12 ` [Bug target/52023] " pinskia at gcc dot gnu.org
2012-01-27 21:10 ` bruno at clisp dot org
2012-01-27 21:39 ` pinskia at gcc dot gnu.org
2012-01-27 21:43 ` pinskia at gcc dot gnu.org
2012-01-27 21:44 ` pinskia at gcc dot gnu.org
2012-01-27 21:54 ` pinskia at gcc dot gnu.org
2012-01-27 21:54 ` eggert at gnu dot org
2012-01-27 22:39 ` eggert at gnu dot org
2012-01-27 23:12 ` bruno at clisp dot org
2012-01-27 23:30 ` joseph at codesourcery dot com
2012-01-27 23:37 ` joseph at codesourcery dot com
2012-01-30 11:15 ` [Bug c/52023] [C11] " rguenth at gcc dot gnu.org
2013-12-04 22:57 ` jsm28 at gcc dot gnu.org
2013-12-04 22:59 ` jsm28 at gcc dot gnu.org
2013-12-04 23:00 ` jsm28 at gcc dot gnu.org
2013-12-05  9:56 ` jbglaw@lug-owl.de
2013-12-05 12:08 ` mpolacek at gcc dot gnu.org
2014-01-14 10:31 ` jbglaw@lug-owl.de
2014-01-14 11:50 ` 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).