From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26525 invoked by alias); 8 May 2002 21:56:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 26505 invoked by uid 71); 8 May 2002 21:56:01 -0000 Resent-Date: 8 May 2002 21:56:01 -0000 Resent-Message-ID: <20020508215601.26504.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, solomon@conceptshopping.com Received:(qmail 23075 invoked from network); 8 May 2002 21:52:15 -0000 Received: from unknown (HELO lisle.conceptshopping.com) (63.141.143.82) by sources.redhat.com with SMTP; 8 May 2002 21:52:15 -0000 Received: from lisle.conceptshopping.com (localhost [127.0.0.1]) by localhost.conceptshopping.com (Postfix) with ESMTP id 436571278B for ; Wed, 8 May 2002 16:52:02 -0500 (CDT) Received: by lisle.conceptshopping.com (Postfix, from userid 1005) id D8DBA1278A; Wed, 8 May 2002 16:52:01 -0500 (CDT) Message-Id:<20020508215201.D8DBA1278A@lisle.conceptshopping.com> Date: Wed, 08 May 2002 14:56:00 -0000 From: solomon@conceptshopping.com To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:3.113 Subject: c/6609: gcc 3.0.3 (and other versions) generate bogus code with -O2 X-SW-Source: 2002-05/txt/msg00250.txt.bz2 List-Id: >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 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).