From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6993 invoked by alias); 4 Dec 2008 17:37:40 -0000 Received: (qmail 5156 invoked by alias); 4 Dec 2008 17:36:20 -0000 Date: Thu, 04 Dec 2008 17:37:00 -0000 Subject: [Bug tree-optimization/38405] New: Regression (silent failure) handling bitfield in ternary X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "gcc-bugzilla at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-12/txt/msg00420.txt.bz2 In the context of a function returning int, and rfp->signed is a one-bit field, return rfp->signed_flag ? 1 : 0; yields -1. This is an optimization problem, seen with -O2 but not -O1. Isolated to -ftree-vrp. Not seen in gcc-4.3 or earlier. Environment: System: Linux recycle 2.6.26-1-amd64 #1 SMP Sat Oct 18 15:27:18 UTC 2008 x86_64 GNU/Linux host: x86_64-pc-linux-gnu build: x86_64-pc-linux-gnu target: x86_64-pc-linux-gnu configured with: ../src/configure -v --with-pkgversion='Debian 20081130-1' --with-bugurl=file:///usr/share/doc/gcc-snapshot/README.Bugs --enable-languages=c,c++,java,fortran,objc,obj-c++,ada --prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --disable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo --disable-plugin --with-java-home=/usr/lib/gcc-snapshot/java-1.5.0-gcj-4.4-1.5.0.0/jre --enable-java-home --with-jvm-root-dir=/usr/lib/gcc-snapshot/jvm --with-jvm-jar-dir=/usr/lib/gcc-snapshot/jvm-exports --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-mpfr --enable-cld --disable-werror --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu How-To-Repeat: Short way: $ gcc -Wall -O1 -ftree-vrp ternbug.c -o ternbug && ./ternbug Hello world: -1 FAIL $ Long way: $ /usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/4.4.0/cc1 -fpreprocessed ternbug.i -quiet -dumpbase ternbug.c -mtune=generic -auxbase ternbug -O1 -ftree-vrp -version -o ternbug.s GNU C (Debian 20081130-1) version 4.4.0 20081130 (experimental) [trunk revision 142292] (x86_64-linux-gnu) compiled by GNU C version 4.4.0 20081130 (experimental) [trunk revision 142292], GMP version 4.2.2, MPFR version 2.3.2. GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: ef8facef55b835d47393957737fa78a4 $ as -V -Qy -o ternbug.o ternbug.s GNU assembler version 2.18.0 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.18.0.20080103 $ /usr/lib/gcc-snapshot/libexec/gcc/x86_64-linux-gnu/4.4.0/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o ternbug /usr/lib/../lib/crt1.o /usr/lib/../lib/crti.o /usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.4.0/crtbegin.o -L/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.4.0 -L/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.4.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.4.0/../../.. ternbug.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/4.4.0/crtend.o /usr/lib/../lib/crtn.o $ ./ternbug Hello world: -1 FAIL $ Minimal test case, ternbug.{c,i}: extern int printf (__const char *__restrict __format, ...); struct vpiBinaryConst { int signed_flag :1; int sized_flag :1; }; int binary_get(int code, struct vpiBinaryConst *rfp) { switch (code) { case 1: return rfp->signed_flag ? 1 : 0; default: printf("error: %d not supported\n", code); return 0; } } ------- Comment #1 from ldoolitt at recycle dot lbl dot gov 2008-12-04 17:36 ------- Fix: Work around by reducing optimization, e.g., from -O2 to -O1 -- Summary: Regression (silent failure) handling bitfield in ternary Product: gcc Version: 4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ldoolitt at recycle dot lbl dot gov GCC build triplet: x86_64-pc-linux-gnu GCC host triplet: x86_64-pc-linux-gnu GCC target triplet: x86_64-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38405