shithub: scc

Download patch

ref: 9e29fc687fadb6d0ef18e986825c1b788ddd7284
parent: 5884598d6118dbbe909880ee6c6a1e38cd602478
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Nov 28 11:12:53 EST 2015

Avoid multiple message errors in Case()

It is anonnying to get a full page of the same error,
so it is a good idea to mark the error like already
printed. There is no problems with the value of nr,
since this field is only used to generate this error.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -242,15 +242,17 @@
 	if ((np = iconstexpr()) == NULL)
 		errorp("case label does not reduce to an integer constant");
 	expect(':');
-	if (lswitch) {
-		pcase = xmalloc(sizeof(*pcase));
-		pcase->expr = np;
-		pcase->next = lswitch->head;
-		emit(OLABEL, pcase->label = newlabel());
-		lswitch->head = pcase;
-		if (++lswitch->nr == NR_SWITCH)
+	if (lswitch && lswitch->nr >= 0) {
+		if (++lswitch->nr == NR_SWITCH) {
 			errorp("too case labels for a switch statement");
-		/* TODO: Avoid repetion of this error for the same switch */
+			lswitch->nr = -1;
+		} else {
+			pcase = xmalloc(sizeof(*pcase));
+			pcase->expr = np;
+			pcase->next = lswitch->head;
+			emit(OLABEL, pcase->label = newlabel());
+			lswitch->head = pcase;
+		}
 	}
 	stmt(lbreak, lcont, lswitch);
 }