This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc for hppa1.1-hp-hpux10.20 doesn't save function arguments correctly


I started looking to see if I could determine why strct-stdarg-1 fails
for the hppa1.1-hp-hpux10.20 target.  In the process, I noticed that
gcc doesn't save arguments correctly when a small struct is passed
as the second argument of a function.

For example, this test code

struct tiny
{
  char c;
  char d;
  char e;
  char f;
  char g;
};

void f (int n, struct tiny a)
{
  if (a.c != 10)
    abort ();
}

yields the following assembly code when compiled with -O0:

	.LEVEL 1.1
	.SPACE $PRIVATE$
	.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
	.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
	.SPACE $TEXT$
	.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
	.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
	.IMPORT $global$,DATA
	.IMPORT $$dyncall,MILLICODE
; gcc_compiled.:
	.IMPORT abort,CODE
	.SPACE $TEXT$
	.SUBSPA $CODE$

	.align 4
	.NSUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
	.EXPORT f,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW2=GR,ARGW3=GR
f
	.PROC
	.CALLINFO FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
	.ENTRY
	stw %r2,-20(%r30)
	copy %r3,%r1
	copy %r30,%r3
	stwm %r1,64(%r30)
	stw %r26,-36(%r3)		<< arg0 is saved
	ldb -48(%r3),%r20		<< load a.c from frame
	extrs %r20,31,8,%r19
	comib,=,n 10,%r19,L$0003
	.CALL 
	bl abort,%r2
	nop
L$0003
L$0002
	ldw -20(%r3),%r2
	ldo 64(%r3),%r30
	ldwm -64(%r30),%r3
	bv,n %r0(%r2)
	.EXIT
	.PROCEND

As far as I can tell, the code only works because gcc saves the struct tiny
to the fixed argument area prior to the call.  The HP compiler doesn't
appear to do this, and it saves r23, r24 and r26 to the fixed argument
area in f before trying to access a.c.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]