struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-stdarg-2.c
blob4a0bba924f2f9a87b2ba0fc8431cb494be2a8a5d
1 /*
2 stdarg-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma disable_warning 93
9 #endif
11 #include <stdarg.h>
13 int foo_arg, bar_arg;
14 long x;
15 double d;
16 va_list gap;
17 #if 0 // TODO: Enable when SDCC supports long double!
18 void
19 foo (int v, va_list ap)
21 switch (v)
23 case 5:
24 foo_arg = va_arg (ap, int);
25 foo_arg += va_arg (ap, double);
26 foo_arg += va_arg (ap, long long);
27 break;
28 case 8:
29 foo_arg = va_arg (ap, long long);
30 foo_arg += va_arg (ap, double);
31 break;
32 case 11:
33 foo_arg = va_arg (ap, int);
34 foo_arg += va_arg (ap, long double);
35 break;
36 default:
37 abort ();
41 void
42 bar (int v)
44 if (v == 0x4002)
46 if (va_arg (gap, int) != 13 || va_arg (gap, double) != -14.0)
47 abort ();
49 bar_arg = v;
52 void
53 f1 (int i, ...)
55 va_start (gap, i);
56 x = va_arg (gap, long);
57 va_end (gap);
60 void
61 f2 (int i, ...)
63 va_start (gap, i);
64 bar (i);
65 va_end (gap);
68 void
69 f3 (int i, ...)
71 va_list aps[10];
72 va_start (aps[4], i);
73 x = va_arg (aps[4], long);
74 va_end (aps[4]);
77 void
78 f4 (int i, ...)
80 va_list aps[10];
81 va_start (aps[4], i);
82 bar (i);
83 va_end (aps[4]);
86 void
87 f5 (int i, ...)
89 va_list aps[10];
90 va_start (aps[4], i);
91 foo (i, aps[4]);
92 va_end (aps[4]);
95 struct A { int i; va_list g; va_list h[2]; };
97 void
98 f6 (int i, ...)
100 struct A a;
101 va_start (a.g, i);
102 x = va_arg (a.g, long);
103 va_end (a.g);
106 void
107 f7 (int i, ...)
109 struct A a;
110 va_start (a.g, i);
111 bar (i);
112 va_end (a.g);
115 void
116 f8 (int i, ...)
118 struct A a;
119 va_start (a.g, i);
120 foo (i, a.g);
121 va_end (a.g);
124 void
125 f10 (int i, ...)
127 struct A a;
128 va_start (a.h[1], i);
129 x = va_arg (a.h[1], long);
130 va_end (a.h[1]);
133 void
134 f11 (int i, ...)
136 struct A a;
137 va_start (a.h[1], i);
138 bar (i);
139 va_end (a.h[1]);
142 void
143 f12 (int i, ...)
145 struct A a;
146 va_start (a.h[1], i);
147 foo (i, a.h[1]);
148 va_end (a.h[1]);
150 #endif
151 void
152 testTortureExecute (void)
154 #if 0
155 f1 (1, 79L);
156 if (x != 79L)
157 abort ();
158 f2 (0x4002, 13, -14.0);
159 if (bar_arg != 0x4002)
160 abort ();
161 f3 (3, 2031L);
162 if (x != 2031)
163 abort ();
164 f4 (4, 18);
165 if (bar_arg != 4)
166 abort ();
167 f5 (5, 1, 19.0, 18LL);
168 if (foo_arg != 38)
169 abort ();
170 f6 (6, 18L);
171 if (x != 18L)
172 abort ();
173 f7 (7);
174 if (bar_arg != 7)
175 abort ();
176 f8 (8, 2031LL, 13.0);
177 if (foo_arg != 2044)
178 abort ();
179 f10 (9, 180L);
180 if (x != 180L)
181 abort ();
182 f11 (10);
183 if (bar_arg != 10)
184 abort ();
185 f12 (11, 2030, 12.0L);
186 if (foo_arg != 2042)
187 abort ();
188 #endif
189 return;