Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP
Path: utzoo!linus!decvax!harpo!seismo!rlgvax!cvl!umcp-cs!chris
From: chris@umcp-cs.UUCP
Newsgroups: net.unix-wizards
Subject: Re: C compiler bug
Message-ID: <920@umcp-cs.UUCP>
Date: Sun, 17-Jul-83 18:35:29 EDT
Article-I.D.: umcp-cs.920
Posted: Sun Jul 17 18:35:29 1983
Date-Received: Mon, 18-Jul-83 01:05:01 EDT
References: <3136@sri-arpa.UUCP>
Organization: Univ. of Maryland, Computer Science Dept.
Lines: 33

The code generated for

	extern foo(bar);
	main (argc) { printf ("%d\n", argc); }

is definitely wrong.  I took a quick look into the pcc code but didn't
find anything useful.  However, for anyone who wants to attempt to fix
pcc, what's wrong is almost certainly that the offsets for function
arguments are calculated during parsing of the argument list.  This
gets reset somewhere, probably after a left brace.  Since the extern
has a single parameter, but no left brace, the offset count is left too
large.  (I checked also "extern foo(bar,baz);" and that makes the
offset count two units too large, instead of one.)  The parser really
ought to reject the arguments in an "extern" declaration, and also
should probably give an error message if you write something like

	foo(bar); main () { ...

(for which it generates the same incorrect code as for the first
example).  Possibly one could check the argument offset after seeing a
function declaration with a right paren followed by a semicolon.  A
better (?) way to fix it would be to change the parser to reject that
syntax in the first place, but I suspect adding one semantic action
would be easier.  (Have you ever *looked* at the pcc parser?  Shudder.)

(Gee, this is an awfully long note for one without a bug fix.)

				- Chris
-- 
In-Real-Life:	Chris Torek, Univ of MD Comp Sci
UUCP:		{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:		chris@umcp-cs
ARPA:		chris.umcp-cs@UDel-Relay