scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 4c6c01a90ba930f89907cc16efc1a3b2d2f2db6c
parent d9b9cf2c66cd52605ddbac816cd204daf3f4a4cf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  3 Oct 2016 16:11:37 +0200

[cc2] Assign curfun only in functions

Curfun was changed in every prototype, and it meant
that the current function could be changed when a
prototype was declared in the body of a function.

Diffstat:
Mcc2/parser.c | 4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cc2/parser.c b/cc2/parser.c @@ -37,6 +37,7 @@ struct swtch { }; static struct swtch swtbl[NR_BLOCK], *swp = swtbl; +static Symbol *lastfun; typedef void parsefun(char *, union tokenop); static parsefun type, symbol, getname, unary, binary, ternary, call, @@ -543,7 +544,7 @@ decl(Symbol *sym) Type *tp = &sym->type; if (tp->flags & FUNF) { - curfun = sym; + lastfun = sym; } else { switch (sym->kind) { case SEXTRN: @@ -653,6 +654,7 @@ stmt(void) static void beginfun(void) { + curfun = lastfun; inpars = 1; pushctx(); addstmt(newnode(OBFUN), SETCUR);