With optimizations enabled, "f=x; y=*(type*)&f;" reads garbage on 'y' unless 'type'=='char' (problem with memory alias?) "f=x; g(); y=*(type*)&f;" works fine if g() is not inlined. Release: gcc >=2.96 <=3.0.2 How-To-Repeat: Compile with -O0, execute. Compile with -O2, execute. Uncomment the commented line. Test again.
State-Changed-From-To: open->closed State-Changed-Why: Not a bug. See ISO/IEC 9899:1999 Section 6.9 paragraph 7. In summary, you may not access an object with anything other than its proper type.
From: rth@gcc.gnu.org To: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, jfran@clip.dia.fi.upm.es, nobody@gcc.gnu.org Cc: Subject: Re: optimization/4888: incorrect code with -Ox, x >= 2 Date: 27 Nov 2001 04:45:43 -0000 Synopsis: incorrect code with -Ox, x >= 2 State-Changed-From-To: open->closed State-Changed-By: rth State-Changed-When: Mon Nov 26 20:45:42 2001 State-Changed-Why: Not a bug. See ISO/IEC 9899:1999 Section 6.9 paragraph 7. In summary, you may not access an object with anything other than its proper type. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4888&database=gcc
Reopening to ..
Mark as a dup of bug 21920. *** This bug has been marked as a duplicate of 21920 ***