This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
if statement incorrectly optimized to 0 with recent CVS
- To: gcc-bugs at gcc dot gnu dot org
- Subject: if statement incorrectly optimized to 0 with recent CVS
- From: Peter Osterlund <peter dot osterlund at mailbox dot swipnet dot se>
- Date: 19 Feb 2000 13:32:14 +0100
Appearently there is some optimization in gcc trying to combine tests
of adjacent bytes into a single 16 bit test. This optimization
produces incorrect code for the following source. The compiler also
generates a bogus "comparison is always 0" warning during compilation.
I bootstrapped with CFLAGS="-O2 -Wall -march=pentiumpro -mpentiumpro"
gcc2.95 compiles this code correctly.
bash$ cat test.c
struct t {
signed char b[2];
int x;
};
enum { v = 1 };
int f(struct t* t)
{
if (((t->b[0]) == 2) && ((t->b[1]) == -v))
return 1;
return 0;
}
bash$ PATH=/home/petero/gcc/bin:$PATH gcc -v -O -S test.c
Reading specs from /home/petero/gcc/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000218 (experimental)
/home/petero/gcc/lib/gcc-lib/i686-pc-linux-gnu/2.96/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTIMIZE__ -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_pentiumpro__ test.c /tmp/ccxoGXRr.i
GNU CPP version 2.96 20000218 (experimental) (cpplib)
(i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/home/petero/gcc/i686-pc-linux-gnu/include
/home/petero/gcc/lib/gcc-lib/i686-pc-linux-gnu/2.96/include
/usr/include
End of search list.
/home/petero/gcc/lib/gcc-lib/i686-pc-linux-gnu/2.96/cc1 /tmp/ccxoGXRr.i -quiet -dumpbase test.c -O -version -o test.s
GNU C version 2.96 20000218 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 2.96 20000218 (experimental).
test.c: In function `f':
test.c:10: warning: comparison is always 0
bash$ cat test.s
.file "test.c"
.version "01.01"
gcc2_compiled.:
.text
.align 16
.globl f
.type f,@function
f:
pushl %ebp
movl %esp, %ebp
movl $0, %eax
popl %ebp
ret
.Lfe1:
.size f,.Lfe1-f
.ident "GCC: (GNU) 2.96 20000218 (experimental)"
bash$
--
Peter Österlund Email: peter.osterlund@mailbox.swipnet.se
Sköndalsvägen 35 f90-pos@nada.kth.se
S-128 66 Sköndal Home page: http://home1.swipnet.se/~w-15919
Sweden Phone: +46 8 942647