C compiler bug

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Mon Jul 18 08:35:29 AEST 1983


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 at umcp-cs
ARPA:		chris.umcp-cs at UDel-Relay



More information about the Comp.unix.wizards mailing list