shithub: scc

Download patch

ref: 3dfdb8b82809ee38faf7a04cc047f48a52bae3dc
parent: d299693e01b086035dec3b88125b526a8263d3cc
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Oct 3 12:11:37 EDT 2016

[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.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -37,6 +37,7 @@
 };
 
 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 @@
 	Type *tp = &sym->type;
 
 	if (tp->flags & FUNF) {
-		curfun = sym;
+		lastfun = sym;
 	} else {
 		switch (sym->kind) {
 		case SEXTRN:
@@ -653,6 +654,7 @@
 static void
 beginfun(void)
 {
+	curfun = lastfun;
 	inpars = 1;
 	pushctx();
 	addstmt(newnode(OBFUN), SETCUR);