This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimizer bug in egcs-1.0.3a
- To: egcs-bugs at cygnus dot com
- Subject: optimizer bug in egcs-1.0.3a
- From: Bruno Haible <haible at ilog dot fr>
- Date: Tue, 16 Jun 1998 14:06:22 +0200 (MET DST)
Hi,
Here gcc simplifies two comparisons of the same term against adjacent
values into a single range check, but forgets that the range check is
to be done on a byte, not an int.
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-pc-linux-gnulibc1/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
$ gcc foo32.c
$ ./a.out
$ gcc -O foo32.c
$ ./a.out
IOT trap/Abort (core dumped)
=============================== foo32.c ================================
void bar () {}
void baz () { abort(); }
void foo (unsigned int * p)
{
if ((signed char)(*p & 0xFF) == 17 || (signed char)(*p & 0xFF) == 18)
bar();
else
baz();
}
int main ()
{
int i = 0x30011;
foo(&i);
return 0;
}
=========================== gcc -O -S foo32.c ==========================
.file "foo32.c"
.version "01.01"
/ GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release) (i486-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.29 980515 (egcs-1.0.3 release).
/ options passed: -O
/ options enabled: -fdefer-pop -fthread-jumps -fpeephole -ffunction-cse
/ -finline -fkeep-static-consts -fpcc-struct-return -fcommon -fverbose-asm
/ -fgnu-linker -falias-check -fargument-alias -m80387 -mhard-float
/ -mno-soft-float -mieee-fp -mfp-ret-in-387 -mschedule-prologue -mcpu=i486
/ -march=pentium
gcc2_compiled.:
.text
.align 16
.globl bar
.type bar,@function
bar:
pushl %ebp
movl %esp,%ebp
movl %ebp,%esp
popl %ebp
ret
.Lfe1:
.size bar,.Lfe1-bar
.align 16
.globl baz
.type baz,@function
baz:
pushl %ebp
movl %esp,%ebp
call abort
.align 16
.Lfe2:
.size baz,.Lfe2-baz
.align 16
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl (%eax),%eax ; <=== These three instructions
addl $-17,%eax ; <=== ignore the "& 0xFF"
cmpl $1,%eax ; <=== present in the source
ja .L4
call bar
jmp .L5
.align 16
.L4:
call baz
.L5:
movl %ebp,%esp
popl %ebp
ret
.Lfe3:
.size foo,.Lfe3-foo
.align 16
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
subl $4,%esp
movl $196625,-4(%ebp)
leal -4(%ebp),%eax
pushl %eax
call foo
xorl %eax,%eax
movl %ebp,%esp
popl %ebp
ret
.Lfe4:
.size main,.Lfe4-main
.ident "GCC: (GNU) egcs-2.90.29 980515 (egcs-1.0.3 release)"
========================================================================