commit 4c6c01a90ba930f89907cc16efc1a3b2d2f2db6c
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Mon Oct 3 16:11:37 2016 +0200
Commit:     Roberto E. Vargas Caballero <k...@shike2.com>
CommitDate: Mon Oct 3 16:11:37 2016 +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.

diff --git a/cc2/parser.c b/cc2/parser.c
index 496b900..34f35c3 100644
--- 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);

Reply via email to