shithub: scc

Download patch

ref: 24df403e7e688d13b5c5c29ca5a9fa6c6b2499df
parent: be48e0969a3531f1b4bbd162dde599ca430d599f
author: Michael Forney <mforney@mforney.org>
date: Sun Feb 19 08:58:10 EST 2017

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

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

--- 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 @@
 	if ((sym->flags & SDECLARED) == 0)
 		return;
 	h = hash(sym->name, sym->ns);
+	assert(*h == sym);
 	*h = sym->hash;
 }
 
--- 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 @@
 void
 flushtypes(void)
 {
-	Type *tp, *next;
+	Type *tp, *next, **h;
 
 	for (tp = localtypes; tp; tp = next) {
 		next = tp->next;
@@ -423,7 +424,9 @@
 			 * 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: