[Bug tree-optimization/38405] New: Regression (silent failure) handling bitfield in ternary

gcc-bugzilla at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Dec 4 17:37:00 GMT 2008


        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



More information about the Gcc-bugs mailing list