[hackers] [scc] [cc2] Minimal fix for type symbols || Quentin Carbonneaux

From: <git_AT_suckless.org>
Date: Mon, 12 Dec 2016 03:20:59 +0100 (CET)

commit 5c3445da52cc656a9c415d1dcb8142ab9beb7400
Author: Quentin Carbonneaux <quentin_AT_c9x.me>
AuthorDate: Sun Dec 11 21:19:37 2016 -0500
Commit: Quentin Carbonneaux <quentin_AT_c9x.me>
CommitDate: Sun Dec 11 21:19:57 2016 -0500

    [cc2] Minimal fix for type symbols
    
    This also fixes a hash removal bug in popctx().

diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index b476973..9c59fdb 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -102,7 +102,7 @@ tmpnode(Node *np, Type *tp)
 
         if (!np)
                 np = newnode(OTMP);
- sym = getsym(TMPSYM);
+ sym = getsym(TMPSYM, 1);
         sym->type = np->type = *tp;
         sym->kind = STMP;
         np->u.sym = sym;
diff --git a/cc2/arch/qbe/optm.c b/cc2/arch/qbe/optm.c
index 8f3eb14..ccb20e3 100644
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
_AT_@ -41,7 +41,7 @@ optm_dep(Node *np)
                 break;
         case OBRANCH:
                 if (!next->label) {
- sym = getsym(TMPSYM);
+ sym = getsym(TMPSYM, 1);
                         sym->kind = SLABEL;
                         next->label = sym;
                 }
diff --git a/cc2/cc2.h b/cc2/cc2.h
index cb0d9c4..d35e432 100644
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
_AT_@ -236,7 +236,7 @@ extern Node *nextstmt(void);
 
 /* symbol.c */
 #define TMPSYM 0
-extern Symbol *getsym(unsigned id);
+extern Symbol *getsym(unsigned id, int islocal);
 extern void popctx(void);
 extern void pushctx(void);
 extern void freesym(Symbol *sym);
diff --git a/cc2/code.c b/cc2/code.c
index 823612b..c37a554 100644
--- a/cc2/code.c
+++ b/cc2/code.c
_AT_@ -61,7 +61,7 @@ addr(Node *np, Addr *addr)
 Symbol *
 newlabel(void)
 {
- Symbol *sym = getsym(TMPSYM);
+ Symbol *sym = getsym(TMPSYM, 1);
 
         sym->kind = SLABEL;
         return sym;
diff --git a/cc2/parser.c b/cc2/parser.c
index 2b8b8e3..f3e2e47 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -178,7 +178,7 @@ composed(char *token, union tokenop u)
 {
         Symbol *sym;
 
- sym = getsym(atoi(token+1));
+ sym = getsym(atoi(token+1), 0);
         push(&sym->type);
 }
 
_AT_@ -192,7 +192,7 @@ static void
 symbol(char *token, union tokenop u)
 {
         Node *np = newnode(u.op & 0xFF);
- Symbol *sym = getsym(atoi(token+1));
+ Symbol *sym = getsym(atoi(token+1), 1);
 
         sclass = u.op >> 8;
         np->u.sym = sym;
diff --git a/cc2/symbol.c b/cc2/symbol.c
index 3d5a342..c42689a 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -33,20 +33,24 @@ pushctx(void)
 void
 popctx(void)
 {
- Symbol *sym, *next;
+ Symbol *sym, *next, **psym;
 
         infunction = 0;
         for (sym = locals; sym; sym = next) {
                 next = sym->next;
- if (sym->id != TMPSYM)
- symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
+ if (sym->id != TMPSYM) {
+ psym = &symtab[sym->id & NR_SYMHASH-1];
+ while (*psym != sym)
+ psym = &(*psym)->next;
+ *psym = sym->h_next;
+ }
                 freesym(sym);
         }
         curlocal = locals = NULL;
 }
 
 Symbol *
-getsym(unsigned id)
+getsym(unsigned id, int islocal)
 {
         Symbol **htab, *sym;
         static unsigned short num;
_AT_@ -64,7 +68,7 @@ getsym(unsigned id)
                 sym->id = id;
                 if ((sym->numid = ++num) == 0)
                         error(EIDOVER);
- if (infunction) {
+ if (infunction && islocal) {
                         if (!locals)
                                 locals = sym;
                         if (curlocal)
Received on Mon Dec 12 2016 - 03:20:59 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 12 2016 - 03:24:22 CET