ref: 5cad501434c35dfe386f5e57d2e2b9c3ff6838a0
parent: cb118e78c3160f7a01f7de644caee2bff41fa659
author: Quentin Carbonneaux <quentin@c9x.me>
date: Sun Dec 11 16:19:37 EST 2016
[cc2] Minimal fix for type symbols This also fixes a hash removal bug in popctx().
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -102,7 +102,7 @@
if (!np)
np = newnode(OTMP);
- sym = getsym(TMPSYM);
+ sym = getsym(TMPSYM, 1);
sym->type = np->type = *tp;
sym->kind = STMP;
np->u.sym = sym;
--- a/cc2/arch/qbe/optm.c
+++ b/cc2/arch/qbe/optm.c
@@ -41,7 +41,7 @@
break;
case OBRANCH:
if (!next->label) {
- sym = getsym(TMPSYM);
+ sym = getsym(TMPSYM, 1);
sym->kind = SLABEL;
next->label = sym;
}
--- a/cc2/cc2.h
+++ b/cc2/cc2.h
@@ -236,7 +236,7 @@
/* 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);
--- a/cc2/code.c
+++ b/cc2/code.c
@@ -61,7 +61,7 @@
Symbol *
newlabel(void)
{
- Symbol *sym = getsym(TMPSYM);
+ Symbol *sym = getsym(TMPSYM, 1);
sym->kind = SLABEL;
return sym;
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -178,7 +178,7 @@
{
Symbol *sym;
- sym = getsym(atoi(token+1));
+ sym = getsym(atoi(token+1), 0);
push(&sym->type);
}
@@ -192,7 +192,7 @@
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;
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -33,13 +33,17 @@
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;
@@ -46,7 +50,7 @@
}
Symbol *
-getsym(unsigned id)
+getsym(unsigned id, int islocal)
{
Symbol **htab, *sym;
static unsigned short num;
@@ -64,7 +68,7 @@
sym->id = id;
if ((sym->numid = ++num) == 0)
error(EIDOVER);
- if (infunction) {
+ if (infunction && islocal) {
if (!locals)
locals = sym;
if (curlocal)