Structure Parameter Bug

reb at nbires.UUCP reb at nbires.UUCP
Sat Jul 30 06:12:06 AEST 1983


Running 4.1c BSD on a VAX 750, we found the following bug in the C compiler
(/lib/ccom):
	If you pass as a parameter a structure that 1) contains only shorts
	or chars, 2) is not of a mod 4 length, 3) is greater than 4 bytes
	long, and 4) is not the last parameter, the compiler aborts with
	a "compiler error: bad argument" message.

The problem is that dclargs (in pftn.c) and bfcode (in code.c) both
allocate the parameter offsets, but not in quite the same manner.
bfcode realigns the stack after a structure/union parameter and
dclargs (incorrectly) does not. The allocation routine checks for such
inconsistencies which causes the abort in due time.

The fix is to routine dclargs() in file pftn.c.  The following diff shows
the two lines added to properly realign the stack offset.

*** pftn.c.old	Fri Jul 29 13:04:33 1983
--- pftn.c	Fri Jul 29 11:12:04 1983
***************
*** 429,434
  			}
  		FIXARG(p); /* local arg hook, eg. for sym. debugger */
  		oalloc( p, &argoff );  /* always set aside space, even for register arguments */
  		}
  	cendarg();
  	locctr(PROG);

--- 429,436 -----
  			}
  		FIXARG(p); /* local arg hook, eg. for sym. debugger */
  		oalloc( p, &argoff );  /* always set aside space, even for register arguments */
+ 		if( p->stype==STRTY || p->stype==UNIONTY )
+ 			SETOFF( argoff, ALSTACK );	/* restore alignment */
  		}
  	cendarg();
  	locctr(PROG);



More information about the Comp.unix.wizards mailing list