mirror of https://github.com/rui314/chibicc
check the number of function arguments
This commit is contained in:
parent
f79e07be82
commit
6a75e3555f
6
parse.c
6
parse.c
|
@ -633,6 +633,9 @@ static Type *func_params(Token **rest, Token *tok, Type *ty) {
|
||||||
cur = cur->next = copy_type(ty2);
|
cur = cur->next = copy_type(ty2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cur == &head)
|
||||||
|
is_variadic = true;
|
||||||
|
|
||||||
ty = func_type(ty);
|
ty = func_type(ty);
|
||||||
ty->params = head.next;
|
ty->params = head.next;
|
||||||
ty->is_variadic = is_variadic;
|
ty->is_variadic = is_variadic;
|
||||||
|
@ -2849,6 +2852,9 @@ static Node *funcall(Token **rest, Token *tok, Node *fn) {
|
||||||
Node *arg = assign(&tok, tok);
|
Node *arg = assign(&tok, tok);
|
||||||
add_type(arg);
|
add_type(arg);
|
||||||
|
|
||||||
|
if (!param_ty && !ty->is_variadic)
|
||||||
|
error_tok(tok, "too many arguments to function call");
|
||||||
|
|
||||||
if (param_ty) {
|
if (param_ty) {
|
||||||
if (param_ty->kind != TY_STRUCT && param_ty->kind != TY_UNION)
|
if (param_ty->kind != TY_STRUCT && param_ty->kind != TY_UNION)
|
||||||
arg = new_cast(arg, param_ty);
|
arg = new_cast(arg, param_ty);
|
||||||
|
|
Loading…
Reference in New Issue