public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/6609: gcc 3.0.3 (and other versions) generate bogus code with -O2
@ 2002-05-08 15:09 rth
  0 siblings, 0 replies; 2+ messages in thread
From: rth @ 2002-05-08 15:09 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, solomon

Synopsis: gcc 3.0.3 (and other versions) generate bogus code with -O2

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed May  8 15:09:33 2002
State-Changed-Why:
    Not a bug.  This violates ICO C aliasing rules.
    Use a union instead.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6609


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

* c/6609: gcc 3.0.3 (and other versions) generate bogus code with -O2
@ 2002-05-08 14:56 solomon
  0 siblings, 0 replies; 2+ messages in thread
From: solomon @ 2002-05-08 14:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         6609
>Category:       c
>Synopsis:       gcc 3.0.3 (and other versions) generate bogus code with -O2
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed May 08 14:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Marvin Solomon
>Release:        3.0.3
>Organization:
Concept Shopping, Inc. and University of Wisconsin
>Environment:
System: SunOS lisle 5.7 Generic_106541-08 sun4u sparc SUNW,Ultra-5_10
Architecture: sun4

	
host: sparc-sun-solaris2.7
build: sparc-sun-solaris2.7
target: sparc-sun-solaris2.7
configured with: ../configure 
Also seen with other versions and platforms (see below).
>Description:
Compile the following program with "gcc -O2" and run it.
    #include <stdio.h>

    void bug(long long upc) {
        unsigned long *p = (unsigned long *)(&upc);
        printf("%08lx %08lx\n", p[0], p[1]);
        printf("%08lx %08lx\n", p[0], p[1]);
    }

    int main() {
        long long u = 0x0123456789abcdefll;
        bug(u);
        return 0;
    }

The result on the indicated platform is
    00000000 89abcdef
    01234567 89abcdef

Note that the two printfs print different things, and the first one is wrong.
It prints the correct results without out optimication, and with -O1 and
(curiously) -O3.

I've tried this on a variety of platforms with a variety of gcc releases,
including
    Linux solomon-csi 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
    gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)

    Linux gjetost.cs.wisc.edu 2.4.18-csl2smp #1 SMP Thu Apr 11 09:20:41 CDT
    2002 i686 unknown
    Configured with: /s/gcc-3.0.3/src/gcc-3.0.3/configure
    --prefix=/s/gcc-3.0.3/i386_rh72 --enable-shared --enable-threads
    Thread model: posix
    gcc version 3.0.3

In all cases, -O2 gives incorrect (and different) results for the first
printf and correct results for the second printf.  Usually -O3 also
generates incorrect code.  In fact the only version I've found that compiles
this code correctly is

    gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)

>How-To-Repeat:
	See above.
>Fix:
	No known fix or work-around.
>Release-Note:
>Audit-Trail:
>Unformatted:
 Also seen with other versions and platforms (see below).


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

end of thread, other threads:[~2002-05-08 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-08 15:09 c/6609: gcc 3.0.3 (and other versions) generate bogus code with -O2 rth
  -- strict thread matches above, loose matches on Subject: below --
2002-05-08 14:56 solomon

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