shithub: scc

Download patch

ref: 5248a9060ab850caff27bdefc8faf609ffe4f2c5
parent: 7bef3d1fcbbb59778de9e883f818978696a39617
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Nov 2 12:43:52 EST 2015

Do not recover in arguments()

There was a call to error() when () was used in something
that was not a function, but this error is a semantic error
where it is easy do not recover.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -561,22 +561,26 @@
 static Node *
 arguments(Node *np)
 {
-	int toomany;;
-	TINT n;
+	int toomany, n;
 	Node *par = NULL, *arg;
-	Type *argtype, **targs, *tp = np->type;
+	Type *argtype, **targs, *tp = np->type, *rettype;
 
 	if (tp->op == PTR && tp->type->op == FTN) {
 		np = content(OPTR, np);
 		tp = np->type;
 	}
-	if (tp->op != FTN)
-		error("function or function pointer expected");
-	targs = tp->p.pars;
+	if (tp->op != FTN) {
+		targs = (Type *[]) {ellipsistype};
+		n = 1;
+		rettype = inttype;
+		errorp("function or function pointer expected");
+	} else {
+		targs = tp->p.pars;
+		n = tp->n.elem;
+		rettype = tp->type;
+	}
 
 	expect('(');
-
-	n = tp->n.elem;
 	if (yytoken == ')')
 		goto no_pars;
 	toomany = 0;
@@ -618,7 +622,7 @@
 		errorp("too few arguments in function call");
 
 	expect(')');
-	return node(OCALL, np->type->type, np, par);
+	return node(OCALL, rettype, np, par);
 }
 
 static Node *