scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 70065bd373fba3c7f1a2c601387ce8222197062d
parent 98125f39a3d9975d9c70966aadb935144ebb227f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Mar 2022 16:44:54 +0100

cc2: Fix parameters order after popctx() fix

The commit f124441b fixed a memory corruption problem but it also
introduced an important regression because the order of parameters
was reversed.

Diffstat:
Msrc/cmd/cc/cc2/cc2.h | 2+-
Msrc/cmd/cc/cc2/symbol.c | 18++++++++++++------
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/cmd/cc/cc2/cc2.h b/src/cmd/cc/cc2/cc2.h @@ -168,7 +168,7 @@ struct symbol { Node *stmt; Inst *inst; } u; - Symbol *next; + Symbol *next, *prev; Symbol *h_next; }; diff --git a/src/cmd/cc/cc2/symbol.c b/src/cmd/cc/cc2/symbol.c @@ -10,6 +10,7 @@ #define NR_SYMHASH 64 Symbol *locals; +static Symbol *tail; static Symbol *symtab[NR_SYMHASH]; static int infunction; @@ -31,11 +32,11 @@ pushctx(void) void popctx(void) { - Symbol *sym, *next; + Symbol *sym, *prev; infunction = 0; - for (sym = locals; sym; sym = next) { - next = sym->next; + for (sym = tail; sym; sym = prev) { + prev = sym->prev; /* * Symbols are inserted in the hash in the inverted * order they are found in locals and it is impossible @@ -51,7 +52,7 @@ popctx(void) symtab[sym->id & NR_SYMHASH-1] = sym->h_next; freesym(sym); } - locals = NULL; + locals = tail = NULL; } Symbol * @@ -74,8 +75,13 @@ getsym(unsigned id) sym = xcalloc(1, sizeof(*sym)); sym->id = id; if (infunction) { - sym->next = locals; - locals = sym; + sym->next = NULL; + sym->prev = tail; + if (tail) + tail->next = sym; + tail = sym; + if (!locals) + locals = sym; } if (id != TMPSYM) { sym->h_next = *htab;