[hackers] [scc] Add calls to vararg functions || Roberto E. Vargas Caballero
commit f7b3cb04badaa5b42b9f0af83af837ab32b0336b
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Sep 26 10:24:18 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Sep 26 10:24:18 2015 +0200
Add calls to vararg functions
When a vararg is found in a call then the type check is disabled
and float are converted to double, and integer promotion is done.
diff --git a/cc1/expr.c b/cc1/expr.c
index 3d66a41..03490ae 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -535,7 +535,7 @@ arguments(Node *np)
int toomany;;
TINT n;
Node *par = NULL, *arg;
- Type **targs, *tp = np->type;
+ Type *argtype, **targs, *tp = np->type;
if (tp->op == PTR && tp->type->op == FTN) {
np = content(OPTR, np);
_AT_@ -554,18 +554,36 @@ arguments(Node *np)
do {
arg = decay(assign());
+ argtype = *targs;
+ if (argtype == ellipsistype) {
+ n = 0;
+ switch (arg->type->op) {
+ case INT:
+ arg = promote(arg);
+ break;
+ case FLOAT:
+ if (arg->type == floattype)
+ arg = convert(arg, doubletype, 1);
+ break;
+ }
+ if (arg->type->op == INT)
+ arg = promote(arg);
+ par = node(OPAR, arg->type, par, arg);
+ continue;
+ }
if (--n < 0) {
if (!toomany)
errorp("too many arguments in function call");
toomany = 1;
continue;
}
- if ((arg = convert(arg, *targs++, 0)) != NULL) {
+ ++targs;
+ if ((arg = convert(arg, argtype, 0)) != NULL) {
par = node(OPAR, arg->type, par, arg);
continue;
}
errorp("incompatible type for argument %d in function call",
- tp->n.elem - n + 1);
+ tp->n.elem - n + 1);
} while (accept(','));
no_pars:
Received on Sat Sep 26 2015 - 10:25:54 CEST
This archive was generated by hypermail 2.3.0
: Sat Sep 26 2015 - 10:36:11 CEST