Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!decvax!harpo!seismo!hao!cires!nbires!reb
From: reb@nbires.UUCP
Newsgroups: net.unix-wizards,net.bugs.4bsd
Subject: Structure Parameter Bug
Message-ID: <213@nbires.UUCP>
Date: Fri, 29-Jul-83 16:12:06 EDT
Article-I.D.: nbires.213
Posted: Fri Jul 29 16:12:06 1983
Date-Received: Mon, 1-Aug-83 04:49:36 EDT
Lines: 36

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);