scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 5248a9060ab850caff27bdefc8faf609ffe4f2c5
parent 7bef3d1fcbbb59778de9e883f818978696a39617
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  2 Nov 2015 17:43:52 +0100

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.

Diffstat:
Mcc1/expr.c | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/cc1/expr.c b/cc1/expr.c @@ -561,22 +561,26 @@ static Node *assign(void); 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 @@ no_pars: errorp("too few arguments in function call"); expect(')'); - return node(OCALL, np->type->type, np, par); + return node(OCALL, rettype, np, par); } static Node *