public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65892] New: gcc fails to implement N685 aliasing of union members
@ 2015-04-25 23:59 msebor at gcc dot gnu.org
  2015-04-26  0:11 ` [Bug c/65892] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-04-25 23:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65892
           Summary: gcc fails to implement N685 aliasing of union members
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

As the following program derived from the snippet in WG14 paper N685
(http://www.open-std.org/jtc1/sc22/wg14/www/docs/n685.htm) shows, GCC fails to
take into account the C99 and C11 permission for struct members of unions that
declare initial members of compatible types to alias one another.

$ cat n685.c && /build/gcc-65479/gcc/xgcc -B/build/gcc-65479/gcc -O2
-fstrict-aliasing n685.c && ./a.out
#include <assert.h>

union U {
    struct t1 { int m; } s1;
    struct t2 { int m; } s2;
};

int f (struct t1 *p1, struct t2 *p2)
{
    // union U visible here, p1->m and p2->m may alias

    if (p1->m < 0)
        p2->m = -p2->m;

    return p1->m;
}

int main (void)
{
    union U u = { .s1 = { -1 } };

    int n = f (&u.s1, &u.s2);

    assert (1 == n);

    return 0;
}
a.out: n685.c:21: main: Assertion `1 == n' failed.
Aborted (core dumped)


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

end of thread, other threads:[~2018-04-23 14:27 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-25 23:59 [Bug c/65892] New: gcc fails to implement N685 aliasing of union members msebor at gcc dot gnu.org
2015-04-26  0:11 ` [Bug c/65892] " pinskia at gcc dot gnu.org
2015-04-26  0:15 ` pinskia at gcc dot gnu.org
2015-04-26  0:17 ` pinskia at gcc dot gnu.org
2015-04-26 17:50 ` pinskia at gcc dot gnu.org
2015-04-26 18:00 ` msebor at gcc dot gnu.org
2015-04-27  9:00 ` rguenth at gcc dot gnu.org
2015-04-27 14:57 ` msebor at gcc dot gnu.org
2015-04-28 17:08 ` joseph at codesourcery dot com
2015-05-13 16:02 ` msebor at gcc dot gnu.org
2015-05-21 11:41 ` mpolacek at gcc dot gnu.org
2015-09-09  0:39 ` myriachan at gmail dot com
2015-09-09  0:43 ` myriachan at gmail dot com
2015-09-09 13:44 ` joseph at codesourcery dot com
2015-09-09 14:25 ` redi at gcc dot gnu.org
2015-09-09 14:42 ` redi at gcc dot gnu.org
2015-09-09 15:59 ` msebor at gcc dot gnu.org
2018-04-23 14:27 ` joseph at codesourcery dot com

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).