* gcc.target/i386/pr70021.c: Add -mtune=skylake.
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / iamcu / test_varargs.c
blob124bef17c621a7a97fffa6a61390eeb4465b0e01
1 /* Test variable number of arguments passed to functions. */
3 #include <stdarg.h>
4 #include "defines.h"
7 #define ARG_INT 1
8 #define ARG_DOUBLE 2
9 #define ARG_POINTER 3
11 union types
13 int ivalue;
14 double dvalue;
15 void *pvalue;
18 struct arg
20 int type;
21 union types value;
24 struct arg *arglist;
26 /* This tests the argumentlist to see if it matches the format string which
27 is printf-like. Nothing will be printed of course. It can handle ints,
28 doubles and void pointers. The given value will be tested against the
29 values given in arglist.
30 This test only assures that the variable argument passing is working.
31 No attempt is made to see if argument passing is done the right way. */
32 void
33 __attribute__ ((noinline))
34 noprintf (char *format, ...)
36 va_list va_arglist;
37 char *c;
39 int ivalue;
40 double dvalue;
41 void *pvalue;
42 struct arg *argp = arglist;
44 va_start (va_arglist, format);
45 for (c = format; *c; c++)
46 if (*c == '%')
48 switch (*++c)
50 case 'd':
51 assert (argp->type == ARG_INT);
52 ivalue = va_arg (va_arglist, int);
53 assert (argp->value.ivalue == ivalue);
54 break;
55 case 'f':
56 assert (argp->type == ARG_DOUBLE);
57 dvalue = va_arg (va_arglist, double);
58 assert (argp->value.dvalue == dvalue);
59 break;
60 case 'p':
61 assert (argp->type == ARG_POINTER);
62 pvalue = va_arg (va_arglist, void *);
63 assert (argp->value.pvalue == pvalue);
64 break;
65 default:
66 abort ();
69 argp++;
73 extern void iamcu_noprintf (char *, ...);
75 int
76 main (void)
78 #ifdef CHECK_VARARGS
79 float f = 258.0;
80 struct arg al[5];
82 al[0].type = ARG_INT;
83 al[0].value.ivalue = 256;
84 al[1].type = ARG_DOUBLE;
85 al[1].value.dvalue = 257.0;
86 al[2].type = ARG_POINTER;
87 al[2].value.pvalue = al;
88 al[3].type = ARG_DOUBLE;
89 al[3].value.dvalue = f;
90 al[4].type = ARG_INT;
91 al[4].value.ivalue = 259;
93 arglist = al;
94 noprintf("%d%f%p%f%d", 256, 257.0, al, f, 259);
96 iamcu_noprintf ((char *) 0xabadbeef, 256, 257.0,
97 (void *) 0xbbadbeef, f, 259);
98 #endif
100 return 0;