scc

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

commit 4c2396d344274ea2c415858d89135e5e864e7673
parent 14fdb4eb3b67d5074552c53f695980f837cfd5d9
Author: Michael Forney <mforney@mforney.org>
Date:   Sun, 19 Feb 2017 13:58:10 -0800

[cc1] Add asserts in hash removals so that broken invariants are obvious

It appears that these invariants aren't so invariant after all.

Diffstat:
Mcc1/symbol.c | 2++
Mcc1/types.c | 7+++++--
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc1/symbol.c"; +#include <assert.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -72,6 +73,7 @@ unlinkhash(Symbol *sym) if ((sym->flags & SDECLARED) == 0) return; h = hash(sym->name, sym->ns); + assert(*h == sym); *h = sym->hash; } diff --git a/cc1/types.c b/cc1/types.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ static char sccsid[] = "@(#) ./cc1/types.c"; +#include <assert.h> #include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -410,7 +411,7 @@ eqtype(Type *tp1, Type *tp2, int equiv) void flushtypes(void) { - Type *tp, *next; + Type *tp, *next, **h; for (tp = localtypes; tp; tp = next) { next = tp->next; @@ -423,7 +424,9 @@ flushtypes(void) * we do know that tp is always the head * of the collision list */ - typetab[HASH(tp)] = tp->h_next; + h = &typetab[HASH(tp)]; + assert(*h == tp); + *h = tp->h_next; case STRUCT: case UNION: case ENUM: