shithub: scc

Download patch

ref: da310fbe77b3276fa9554b91c3e28dd53399fe22
parent: d092be22d3220430733d7fb532d72d6a2348e9d1
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 11 08:41:43 EDT 2015

Do not link cpp and label symbols in the block list

Cpp symbols have file storage, and labels have
function storage, so it is not very useful put
them in the block list.
disturb in popctx().

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -4,6 +4,8 @@
 #define PREFIX "/usr/"
 #endif
 
+#define GLOBALCTX 0
+
 /*
  * Definition of structures
  */
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -9,7 +9,6 @@
 #include "../inc/cc.h"
 #include "cc1.h"
 
-#define GLOBALCTX 0
 #define NOSCLASS  0
 
 struct dcldata {
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -14,7 +14,7 @@
 static short localcnt;
 static short globalcnt;
 
-static Symbol *head;
+static Symbol *head, *labels;
 static Symbol *htab[NR_SYM_HASH];
 
 #ifndef NDEBUG
@@ -102,36 +102,28 @@
 popctx(void)
 {
 	Symbol *next, *sym;
-	Symbol dummy = {.next = NULL}, *hp = &dummy;
+	short f;
 
-	if (--curctx == 0)
+	if (--curctx == GLOBALCTX) {
 		localcnt = 0;
+		for (sym = labels; sym; sym = next) {
+			next = sym->next;
+			if ((f & (ISUSED|ISDECLARED)) == ISDECLARED)
+				warn("'%s' defined but not used", sym->name);
+			if ((sym->flags & ISDECLARED) == 0)
+				printerr("label '%s' is not defined", sym->name);
+			free(sym->name);
+			free(sym);
+		}
+		labels = NULL;
+	}
 
 	for (sym = head; sym && sym->ctx > curctx; sym = next) {
 		next = sym->next;
-		switch (sym->ns) {
-		case NS_LABEL:
-			if (curctx != 0)
-				goto save_symbol;
-			if (sym->flags & ISDECLARED)
-				break;
-			printerr("label '%s' is not defined", sym->name);
-			break;
-		case NS_CPP:
-		save_symbol:
-			/*
-			 * CPP symbols have file scope
-			 * Labels have function scope
-			 */
-			hp->next = sym;
-			hp = sym;
-			continue;
-		case NS_TAG:
+		if (sym->ns == NS_TAG)
 			sym->type->defined = 0;
-			break;
-		}
 		if (sym->name) {
-			short f = sym->flags;
+			f = sym->flags;
 			unlinkhash(sym);
 			if ((f & (ISUSED|ISGLOBAL|ISDECLARED)) == ISDECLARED)
 				warn("'%s' defined but not used", sym->name);
@@ -140,8 +132,7 @@
 		// TODO: Fix this memory leak free(sym->u.pars);
 		free(sym);
 	}
-	hp->next = sym;
-	head = dummy.next;
+	head = sym;
 }
 
 Type *
@@ -171,6 +162,10 @@
 
 	if (ns == NS_CPP)
 		return sym;
+	if (ns == NS_LABEL) {
+		sym->next = labels;
+		return labels = sym;
+	}
 
 	for (prev = p = head; p; prev = p, p = p->next) {
 		if (p->ctx <= sym->ctx)