shithub: scc

Download patch

ref: 2a651a1e594d8805e6873e45a72aa73ddb6bb505
parent: 2abdf1c09b5cb1217625acdefaa8de44fe1aa15d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jul 10 10:43:40 EDT 2014

Free labels in context()

We know that labels only can be deleted at the end of functions, but
context is also called in compound statements. Ths solution is
check the current context and deleted labels inly in context 0.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -89,9 +89,6 @@
 	struct symbol *hash;
 };
 
-
-extern void freesyms(uint8_t ns);
-
 extern Type *qualifier(Type *tp, uint8_t qlf),
 	*ctype(int8_t type, int8_t sign, int8_t size),
 	*mktype(Type *tp, uint8_t op, uint16_t nelem);
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -477,7 +477,6 @@
 				emitsframe(sym);
 				context(NULL, NULL, NULL);
 				emiteframe();
-				freesyms(NS_LABEL);
 				return;
 			}
 		} while (accept(','));
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -27,7 +27,7 @@
 	return h & NR_SYM_HASH - 1;
 }
 
-void
+static void
 freesyms(uint8_t ns)
 {
 	static struct symtab *tbl;
@@ -66,6 +66,8 @@
 	--curctx;
 	freesyms(NS_IDEN);
 	freesyms(NS_TAG);
+	if (curctx == 0)
+		freesyms(NS_LABEL);
 }
 
 Symbol *
--