From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8289 invoked by alias); 9 Aug 2002 16:16:01 -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 8263 invoked by uid 71); 9 Aug 2002 16:16:00 -0000 Resent-Date: 9 Aug 2002 16:16:00 -0000 Resent-Message-ID: <20020809161600.8262.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, Johannes Stezenbach Received: (qmail 674 invoked from network); 9 Aug 2002 16:06:33 -0000 Received: from unknown (HELO hell) (212.84.236.66) by sources.redhat.com with SMTP; 9 Aug 2002 16:06:33 -0000 Received: from js by hell with local (Exim 3.35 #1 (Debian)) id 17dCGd-0003Qi-00; Fri, 09 Aug 2002 18:05:35 +0200 Message-Id: Date: Fri, 09 Aug 2002 09:26:00 -0000 From: Johannes Stezenbach To: gcc-gnats@gcc.gnu.org, debian-gcc@lists.debian.org X-Send-Pr-Version: 3.113 Subject: optimization/7557: gcc-3.1.1 (debian/i386): wrong code with -O2 / bitfields / pointer aliasing X-SW-Source: 2002-08/txt/msg00192.txt.bz2 List-Id: >Number: 7557 >Category: optimization >Synopsis: gcc-3.1.1 (debian/i386): wrong code with -O2 / bitfields / pointer aliasing >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Fri Aug 09 09:16:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Johannes Stezenbach >Release: 3.1.1 (Debian testing/unstable) >Organization: >Environment: System: Linux hell 2.4.19pre1 #3 Sun May 12 19:15:17 CEST 2002 i686 unknown unknown GNU/Linux Architecture: i686 host: i386-pc-linux-gnu build: i386-pc-linux-gnu target: i386-pc-linux-gnu configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds3/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux >Description: The attached sample program produces wrong output when compiled with -O2. Output produced when compiled with-O is correct. I'm attaching the C source as well as compressed preprcessor output. $ gcc-3.1 -Wall -O2 bug.c -o bug $ ./bug 8 8 0xbeaddeef 0x34127856 0xa307401c 0x12345678 $ gcc-3.1 -Wall -O bug.c -o bug $ ./bug 8 8 0xbeaddeef 0x34127856 0xdeadbeef 0x12345678 $ gcc-3.1 -v -Wall -O2 bug.c -o bug Reading specs from /usr/lib/gcc-lib/i386-linux/3.1.1/specs Configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds3/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux Thread model: posix gcc version 3.1.1 /usr/lib/gcc-lib/i386-linux/3.1.1/cc1 -lang-c -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i386__ bug.c -quiet -dumpbase bug.c -O2 -Wall -version -o /home/js/tmp/ccA9puym.s GNU CPP version 3.1.1 (cpplib) (i386 Linux/ELF) GNU C version 3.1.1 (i386-linux) compiled by GNU C version 3.1.1. ignoring nonexistent directory "/usr/i386-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc-lib/i386-linux/3.1.1/include /usr/include End of search list. as -V -Qy -o /home/js/tmp/ccA3HBCF.o /home/js/tmp/ccA9puym.s GNU assembler version 2.12.90.0.15 (i386-linux) using BFD version 2.12.90.0.15 20020717 Debian GNU/Linux /usr/lib/gcc-lib/i386-linux/3.1.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o bug /usr/lib/gcc-lib/i386-linux/3.1.1/../../../crt1.o /usr/lib/gcc-lib/i386-linux/3.1.1/../../../crti.o /usr/lib/gcc-lib/i386-linux/3.1.1/crtbegin.o -L/usr/lib/gcc-lib/i386-linux/3.1.1 -L/usr/lib/gcc-lib/i386-linux/3.1.1/../../.. /home/js/tmp/ccA3HBCF.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc-lib/i386-linux/3.1.1/crtend.o /usr/lib/gcc-lib/i386-linux/3.1.1/../../../crtn.o >How-To-Repeat: /* gcc-3.1.1 bug: wrong results with -O2 */ #include #include struct foo { unsigned int a: 8, b:24; unsigned int c:16, d:16; }; struct foo_swabbed { unsigned int b:24, a: 8; unsigned int d:16, c:16; }; static void swab_foo(struct foo *f) { struct foo_swabbed fs = *(struct foo_swabbed *) f; unsigned int *p = (unsigned int *)&fs; p[0] = __swab32(p[0]); p[1] = __swab32(p[1]); f->a = fs.a; f->b = fs.b; f->c = fs.c; f->d = fs.d; } int main(void) { struct foo f = { 0xef, 0xbeadde, 0x7856, 0x3412 }; unsigned int *p = (unsigned int *)&f; printf("%u %u\n", sizeof(struct foo), sizeof(struct foo_swabbed)); printf("%#010x %#010x\n", p[0], p[1]); swab_foo(&f); printf("%#010x %#010x\n", p[0], p[1]); return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: