public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/56576] wrong code for aliased union at -O3
Date: Sat, 09 Mar 2013 08:26:00 -0000	[thread overview]
Message-ID: <bug-56576-4-cxxpEeRhr0@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-56576-4@http.gcc.gnu.org/bugzilla/>


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-03-09 08:25:58 UTC ---
This is IMHO just wrong code.  C99 makes this undefined behavior of course, see
ISO C99, 6.2.6.1/7:
"When a value is stored in a member of an object of union type, the bytes of
the object representation that do not correspond to that member but do
correspond to other members take unspecified values, but the value of the union
object shall not thereby become a trap representation."
Now, while GCC allows some kind of type punning through unions, it doesn't
allow everything, in particular the access has to be done through the union,
not what you did, take pointers of the different union members and just access
everything through the pointers - if GCC wanted to support that, it would
simply has to give up on TBAA.  Also, among the unsupported things are e.g.
structure copies in between union members, consider say:
struct S { long l[256]; };
union U { struct T { int i; struct S s; } t; struct S s; } u;
...
  u.s = u.t.s;
or:
  u.t.s = u.s;
or:
  struct S *p = &u.t.s;
  ...
  *p = u.s;
or:
  struct S *p = &u.s;
  ...
  *p = u.t.s;
will just not work properly (we generate memcpy even when there is overlap),
because generally valid structure copies are either same address or without any
overlap.


  reply	other threads:[~2013-03-09  8:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-09  1:54 [Bug tree-optimization/56576] New: " dhazeghi at yahoo dot com
2013-03-09  8:26 ` jakub at gcc dot gnu.org [this message]
2013-03-10 21:17 ` [Bug tree-optimization/56576] " pinskia at gcc dot gnu.org
2024-06-02 16:10 ` pinskia at gcc dot gnu.org
2024-06-02 16:11 ` pinskia at gcc dot gnu.org
2024-06-02 16:12 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-56576-4-cxxpEeRhr0@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).