[gnu.gcc.bug] sparc struct passing, version 1.36

mccanne@HELIOS.EE.LBL.GOV (Steven McCanne) (01/02/90)

Here is a bug in gcc version 1.36, running on a Sun sparcstation.
The structure below is being passed in only a single register.
Note that the structure is both passed and received in a single register.


struct triple { short a, b, c; };

void
p (e)
	struct triple e;
{
	printf ("%d %d %d\n", e.a, e.b, e.c);
}

q ()
{
	struct triple r = { 1, 2, 3 };

	p (r);
}

Output from 'gcc -S':

gcc_compiled.:
.text
LC0:
	.ascii "%d %d %d\12\0"
	.align 4
.global _p
	.proc 1
_p:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	! Here is the problem.
	! The struct is passed in only 1 register.  
	st %i0,[%fp+68]
	ldsh [%fp+68],%o1
	ldsh [%fp+70],%o2
	! This is garbage, but should be 'e.c'.
	ldsh [%fp+72],%o3
	sethi %hi(LC0),%o0
	or %lo(LC0),%o0,%o0
	mov %o1,%o1
	mov %o2,%o2
	mov %o3,%o3
	call _printf,0
	nop
L1:
	ret
	restore
	.align 2
LC1:
	.half 1
	.half 2
	.half 3
	.align 4
.global _q
	.proc 1
_q:
	!#PROLOGUE# 0
	save %sp,-120,%sp
	!#PROLOGUE# 1
	add %fp,-24,%o0
	sethi %hi(LC1),%o2
	or %lo(LC1),%o2,%o2
	lduh [%o2+4],%g1
	sth %g1,[%o0+4]
	lduh [%o2+2],%g1
	sth %g1,[%o0+2]
	lduh [%o2+0],%g1
	sth %g1,[%o0+0]
	! Also, P is called with only one reg argument.
	ld [%fp-24],%o0
	call _p,0
	nop
L2:
	ret
	restore


-------------------------
Steven McCanne
mccanne@helios.ee.lbl.gov
-------------------------