shithub: scc

Download patch

ref: 59eb8445113a831ac3edd6a42bc39438536db5da
parent: 83156e58cac626a74cbb47ae94300355a6b89813
author: Quentin Rameau <[email protected]>
date: Thu Feb 16 14:18:00 EST 2017

[cc1] Fix multiple void function parameter check

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -166,11 +166,7 @@
 
 	switch (tp->op) {
 	case VOID:
-		if (n != 0 || (funtp->prop & TK_R)) {
-			errorp("incorrect void parameter");
-			return NULL;
-		}
-		funtp->n.elem = -1;
+		funtp->n.elem = 1;
 		if (dcl->sclass)
 			errorp("void as unique parameter may not be qualified");
 		return NULL;
@@ -246,41 +242,30 @@
 {
 	int npars = 0;
 	Symbol *sym;
-	int toomany = 0, toovoid = 0;
+	int toomany = 0, voidparam = 0;
 
 	do {
-		if (npars == -1 && !toovoid) {
-			errorp("'void' must be the only parameter");
-			toovoid = 1;
-		}
+		++npars;
 		if (accept(ELLIPSIS)) {
-			if (npars == 0)
+			if (npars < 2)
 				errorp("a named argument is requiered before '...'");
-			++npars;
 			*syms = NULL;
 			*types++ = ellipsistype;
-			break;
-		}
-		if ((sym = dodcl(NOREP, parameter, NS_IDEN, tp)) == NULL)
-			continue;
-		if (tp->n.elem == -1) {
-			npars = -1;
-			continue;
-		}
-		if (npars < NR_FUNPARAM) {
+		} else if ((sym = dodcl(NOREP, parameter, NS_IDEN, tp)) == NULL) {
+			if (tp->n.elem == 1)
+				voidparam = 1;
+		} else if (npars < NR_FUNPARAM) {
 			*syms++ = sym;
 			*types++ = sym->type;
-			++npars;
-			continue;
-		}
-		if (!toomany) {
+		} else if (!toomany) {
 			errorp("too many parameters in function definition");
 			toomany = 1;
 		}
+		if (npars == 2 && voidparam)
+			errorp("'void' must be the only parameter");
 	} while (accept(','));
 
-	*nsyms = npars;
-	*ntypes = npars;
+	*nsyms = *ntypes = voidparam ? 0 : npars;
 }
 
 static void