check the number of function arguments

This commit is contained in:
Rui Ueyama 2020-09-20 21:19:08 +09:00
parent f79e07be82
commit 6a75e3555f
1 changed files with 6 additions and 0 deletions

View File

@ -633,6 +633,9 @@ static Type *func_params(Token **rest, Token *tok, Type *ty) {
cur = cur->next = copy_type(ty2);
}
if (cur == &head)
is_variadic = true;
ty = func_type(ty);
ty->params = head.next;
ty->is_variadic = is_variadic;
@ -2849,6 +2852,9 @@ static Node *funcall(Token **rest, Token *tok, Node *fn) {
Node *arg = assign(&tok, tok);
add_type(arg);
if (!param_ty && !ty->is_variadic)
error_tok(tok, "too many arguments to function call");
if (param_ty) {
if (param_ty->kind != TY_STRUCT && param_ty->kind != TY_UNION)
arg = new_cast(arg, param_ty);