shithub: scc

Download patch

ref: 5a7f4ee3d6a0643520098f73ecb93b4202bb5133
parent: 5b666be8a5986e9d7f82d7877b9678429bfb3d55
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Sep 26 05:49:16 EDT 2015

Fix toomany error control

There are variables called 'toomany' in several places
to avoid repeat the same error a number of times, but
the logic was wrong and they were not only disabling
the error, but the error recovery code to.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -554,8 +554,9 @@
 
 	do {
 		arg = decay(assign());
-		if (--n < 0 && !toomany) {
-			errorp("too many arguments in function call");
+		if (--n < 0) {
+			if (!toomany)
+				errorp("too many arguments in function call");
 			toomany = 1;
 			continue;
 		}
@@ -1071,17 +1072,19 @@
 		}
 		switch (tp->op) {
 		case ARY:
-			if (tp->defined && n >= tp->n.elem && !toomany) {
+			if (tp->defined && n >= tp->n.elem) {
+				if (!toomany)
+					warn("excess elements in array initializer");
 				toomany = 1;
-				warn("excess elements in array initializer");
 				sym = NULL;
 			}
 			newtp = tp->type;
 			break;
 		case STRUCT:
-			if (n >= tp->n.elem && !toomany) {
+			if (n >= tp->n.elem) {
+				if (!toomany)
+					warn("excess elements in struct initializer");
 				toomany = 1;
-				warn("excess elements in struct initializer");
 				sym = NULL;
 			} else {
 				sym = tp->p.fields[n];
@@ -1091,9 +1094,11 @@
 		default:
 			newtp = tp;
 			warn("braces around scalar initializer");
-			if (n > 0 && !toomany) {
+			if (n > 0) {
+				if (!toomany)
+					warn("excess elements in scalar initializer");
 				toomany = 1;
-				warn("excess elements in scalar initializer");
+				sym = NULL;
 			}
 			break;
 		}