public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joseph at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/38297] O2 causes invalid code
Date: Sun, 30 Nov 2008 15:38:00 -0000	[thread overview]
Message-ID: <20081130153719.31990.qmail@sourceware.org> (raw)
In-Reply-To: <bug-38297-17012@http.gcc.gnu.org/bugzilla/>



------- Comment #14 from joseph at codesourcery dot com  2008-11-30 15:37 -------
Subject: Re:  O2 causes invalid code

On Sun, 30 Nov 2008, rguenth at gcc dot gnu dot org wrote:

> Note that the C standard forbids type-punning through a union.  
> Basically it says that you may only read from a union member if you have 
> previously written to it. It also says that all other bits apart from 
> the ones you have written to contain undefined values after the write.  
> So
> 
>  union { int i; float f; } u;
>  u.i = 1;
>  x = u.f;
> 
> invokes undefined behavior in C (but not in GNU C because of the language
> extension).

Note that C99 TC3 adds a footnote: "*) If the member used to access the 
contents of a union object is not the same as the member last used to 
store a value in the object, the appropriate part of the object 
representation of the value is reinterpreted as an object representation 
in the new type as described in 6.2.6 (a process sometimes called "type 
punning"). This might be a trap representation."


-- 


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


      parent reply	other threads:[~2008-11-30 15:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-28  0:30 [Bug c++/38297] New: " andrew at warnux dot com
2008-11-28  0:33 ` [Bug c++/38297] " andrew at warnux dot com
2008-11-28  1:39 ` pinskia at gcc dot gnu dot org
2008-11-28  2:00 ` andrew at warnux dot com
2008-11-28  2:22 ` pinskia at gcc dot gnu dot org
2008-11-28  2:35 ` andrew at warnux dot com
2008-11-28 16:40 ` andrew at warnux dot com
2008-11-28 16:54 ` pinskia at gcc dot gnu dot org
2008-11-28 19:26 ` cdfrey at netdirect dot ca
2008-11-28 22:03 ` andrew at warnux dot com
2008-11-28 22:04 ` andrew at warnux dot com
2008-11-28 23:33 ` pinskia at gcc dot gnu dot org
2008-11-28 23:37 ` cdfrey at netdirect dot ca
2008-11-30 11:44 ` rguenth at gcc dot gnu dot org
2008-11-30 15:38 ` joseph at codesourcery dot com [this message]

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=20081130153719.31990.qmail@sourceware.org \
    --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).