commit 4c2396d344274ea2c415858d89135e5e864e7673
Author:     Michael Forney <[email protected]>
AuthorDate: Sun Feb 19 13:58:10 2017 -0800
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Mon Feb 20 04:40:24 2017 +0100

    [cc1] Add asserts in hash removals so that broken invariants are obvious
    
    It appears that these invariants aren't so invariant after all.

diff --git a/cc1/symbol.c b/cc1/symbol.c
index bdd26d6..1126279 100644
--- 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
index f9d6391..7abb58e 100644
--- 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:

Reply via email to