[gnu.gcc.bug] Bug in gcc-1.35, sparc version

lynch@EAST.SUN.COM (Brendan Lynch - Sun East Coast Software) (05/20/89)

I think I have found a bug in the builtin function calling sequence
for the sparc in gcc-1.35.  The following program:

main()
{
	int i;

	i = 3;

	printf("one is %d\n", i/3);
}

produces the following assembler code when compiled with "gcc -S":

gcc_compiled.:
.text
LC0:
	.ascii "one is %d\12\0"
	.align 4
.global _main
	.proc 1
_main:
	!#PROLOGUE# 0
	save %sp,-120,%sp
	!#PROLOGUE# 1
	mov 3,%o2
	st %o2,[%fp-20]
	call .div,0
	nop
	mov %o0,%o1
	sethi %hi(LC0),%o0
	or %lo(LC0),%o0,%o0
	mov %o1,%o1
	call _printf,0
	nop
L1:
	ret
	restore

and when run, produces the output:

one is 0

The problem seems to be that the arguments to the builtin function
".div" are never put in the output registers, therefore the ".div"
function returns 0.

Using Version 1.34 of gcc, the following code is produced:

gcc_compiled.:
.text
LC0:
	.ascii "one is %d\12\0"
	.align 4
.global _main
	.proc 1
_main:
	!#PROLOGUE# 0
	save %sp,-120,%sp
	!#PROLOGUE# 1
	mov 3,%o2
	st %o2,[%fp-20]
	ld [%fp-20],%o0
	mov 3,%o1
	call .div,0
	nop
	mov %o0,%o1
	sethi %hi(LC0),%o0
	or %lo(LC0),%o0,%o0
	mov %o1,%o1
	call _printf,0
	nop
L1:
	ret
	restore


which produces the correct result.

This seems only to be a problem for the sparc version; the 386 and
68020 versions seem to work fine.

----------------------------------------------------------------------
              /\
             \\ \	Brendan Lynch
            \ \\ /	Sun Microsystems - Entry Systems Software
           / \/ / / 	2 Federal Street,
          / /   \//\ 	Billerica, Massachusetts 01821
          \//\   / / 	
           / / /\ /  	Phone:  (508) 671 0247
            / \\ \	EMail:	lynch@east.sun.com
             \ \\ 		..!sun!east!lynch
              \/

lynch@EAST.SUN.COM (Brendan Lynch - Sun East Coast Software) (05/22/89)

Some further info that may be of help:  I had compiled gcc-1.35 with the
the value "CFLAGS=-O" (no -g: yes, I know this is stupid, but...).  This
version of gcc forgot to push the parameters to the builtin ".div".

Compiling gcc with "CFLAGS=-g -O" produces a compiler that generates correct
code fo the call to ".div".  In both cases, the sample program I mentioned
in my last mail was compiled without -g or -O flags: simply "gcc -S".

So the "-g" flag affects the compiled code of the compiler, and compiling
without it causes the stage1 compiler to generate incorrect code for the
stage2 compiler.

Hope this helps troubleshoot the bug.

Brendan Lynch
lynch@east.sun.com