public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/61447] New: _Alignof returns incorrect results for some types/archs
@ 2014-06-08 14:30 bugdal at aerifal dot cx
  2014-06-08 15:19 ` [Bug c/61447] " joseph at codesourcery dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2014-06-08 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 61447
           Summary: _Alignof returns incorrect results for some
                    types/archs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugdal at aerifal dot cx

_Alignof is defined per C11 as the "alignment requirement of its operand type".
This is different from GCC's result for __alignof__ (and sometimes for
_Alignof) where it returns the "preferred alignment for optimization" or the
"actual alignment applied".

On i386, _Alignof(long long) returns 8, despite the correct value being 4. With
recent enough gcc (tested on 4.9.0), -std=c11 fixes _Alignof when applied to
the type name, but not when applied to an object: long long x; _Alignof(x)
still gives 8. In order to be correct:

1. _Alignof(object) should always be the same as _Alignof(__typeof__(object))

2. _Alignof(x) should always be the same as (sizeof(struct{char __a;
__typeof__(x) __b;}) - sizeof(x))

Failure of condition 2 results in observably incorrect behavior: a program can
observe the existence of a structure containing members a and b of the same
type where (char*)&foo.a-(char*)&foo.b is not a multiple of _Alignof(foo.a).


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

end of thread, other threads:[~2014-06-23  5:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
2014-06-08 15:19 ` [Bug c/61447] " joseph at codesourcery dot com
2014-06-08 15:28 ` bugdal at aerifal dot cx
2014-06-08 15:34 ` joseph at codesourcery dot com
2014-06-08 15:47 ` bugdal at aerifal dot cx
2014-06-08 16:00 ` schwab@linux-m68k.org
2014-06-09  6:27 ` mpolacek at gcc dot gnu.org
2014-06-09 15:14 ` joseph at codesourcery dot com
2014-06-09 16:21 ` bugdal at aerifal dot cx
2014-06-23  1:02 ` bugdal at aerifal dot cx
2014-06-23  5:37 ` mpolacek 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).