[hackers] [scc] [cc1] Add asserts in hash removals so that broken invariants are obvious || Michael Forney
commit 4c2396d344274ea2c415858d89135e5e864e7673
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Sun Feb 19 13:58:10 2017 -0800
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
static char sccsid[] = "_AT_(#) ./cc1/symbol.c";
+#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
_AT_@ -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
_AT_@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
static char sccsid[] = "_AT_(#) ./cc1/types.c";
+#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
_AT_@ -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;
_AT_@ -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:
Received on Mon Feb 20 2017 - 04:41:35 CET
This archive was generated by hypermail 2.3.0
: Mon Feb 20 2017 - 04:48:19 CET