[gnu.gcc.bug] Bug report for gcc 1.33

jjm@EDDIE.MIT.EDU (Jim Murray) (02/18/89)

Bug report for gcc version 1.33 configured for i386v.

The following program fragment compiles correctly without -O
bug generates an incorrect code with -O.

-------------------------------------------------------------------------
THE PROGRAM:
--------------------------------- snip here -----------------------------
int	a;
int	b;
main ()
{
	if ( a == b || ((--b < 0) ? a : b))
		++a;
}
--------------------------------- snip here -----------------------------
THE COMPILATION:
-------------------------------------------------------------------------
gcc -O -S -v test.c
gcc version 1.33
 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dunix -Di386 -D__unix__ -D__i386__ -D__OPTIMIZE__ test.c /tmp/cca03535.cpp
GNU CPP version 1.33
 /usr/local/lib/gcc-cc1 /tmp/cca03535.cpp -quiet -dumpbase test.c -O -version -o test.s
GNU C version 1.33 (80386, ATT syntax) compiled by GNU C version 1.33.
----------------------------------------------------------------------------
THE OUTPUT:
----------------------------------------------------------------------------
	.file	"test.c"
gcc_compiled.:
.text
	.align 4
.globl main
main:
	pushl %ebp
	movl %esp,%ebp
	movl b,%eax
	cmpl a,%eax
	je .L3
	decl b
	cmpl $0,b
	jle .L4			<---- incorrect branch
	cmpl $0,a
	jne .L3
	jmp .L2
.L4:
	cmpl $0,b
	je .L2
.L3:
	incl a
.L2:
	leave
	ret
.comm b,4
.comm a,4
-------------------------------------------------------------------------
The output when compiled without -O
-------------------------------------------------------------------------
	.file	"test.c"
gcc_compiled.:
.text
	.align 4
.globl main
main:
	pushl %ebp
	movl %esp,%ebp
	movl b,%eax
	cmpl a,%eax
	je .L3
	decl b
	cmpl $0,b
	jge .L4			<---- correct branch
	cmpl $0,a
	jne .L3
	jmp .L2
.L4:
	cmpl $0,b
	jne .L3
	jmp .L2
.L5:
.L3:
	incl a
.L2:
.L1:
	leave
	ret
.comm b,4
.comm a,4
------------------------------------------------------------------------
---
Jim Murray              encore!cloud9!jjmhome!jjm
2 Mohawk Circle         harvard!m2c!jjmhome!jjm
Westboro Mass 01581     jjm%jjmhome@m2c.m2c.org
USA                     voice (508) 366-2813