Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-va-arg-2.c
blob912769d9d04e0ce96c2464d1742e2ab83dddb980
1 /*
2 va-arg-2.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma disable_warning 85
9 #pragma disable_warning 196
10 #endif
12 #include <string.h>
14 /* The purpose of this test is to catch edge cases when arguments are passed
15 in regs and on the stack. We test 16 cases, trying to catch multiple
16 targets (some use 3 regs for argument passing, some use 12, etc.).
17 We test both the arguments and the `lastarg' (the argument to va_start). */
19 #include <stdarg.h>
21 int
22 to_hex (unsigned int a)
24 static char hex[] = "0123456789abcdef";
26 if (a > 15)
27 ASSERT(0);
28 return hex[a];
31 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
32 void
33 f0 (char* format, ...)
35 va_list ap;
37 va_start (ap, format);
38 if (strlen (format) != 16 - 0)
39 ASSERT(0);
40 while (*format)
41 if (*format++ != to_hex (va_arg (ap, int)))
42 ASSERT(0);
43 va_end(ap);
46 void
47 f1 (int a1, char* format, ...)
49 va_list ap;
51 va_start(ap, format);
52 if (strlen (format) != 16 - 1)
53 ASSERT(0);
54 while (*format)
55 if (*format++ != to_hex (va_arg (ap, int)))
56 ASSERT(0);
57 va_end(ap);
60 void
61 f2 (int a1, int a2, char* format, ...)
63 va_list ap;
65 va_start(ap, format);
66 if (strlen (format) != 16 - 2)
67 ASSERT(0);
68 while (*format)
69 if (*format++ != to_hex (va_arg (ap, int)))
70 ASSERT(0);
71 va_end(ap);
74 void
75 f3 (int a1, int a2, int a3, char* format, ...)
77 va_list ap;
79 va_start(ap, format);
80 if (strlen (format) != 16 - 3)
81 ASSERT(0);
82 while (*format)
83 if (*format++ != to_hex (va_arg (ap, int)))
84 ASSERT(0);
85 va_end(ap);
88 void
89 f4 (int a1, int a2, int a3, int a4, char* format, ...)
91 va_list ap;
93 va_start(ap, format);
94 if (strlen (format) != 16 - 4)
95 ASSERT(0);
96 while (*format)
97 if (*format++ != to_hex (va_arg (ap, int)))
98 ASSERT(0);
99 va_end(ap);
102 void
103 f5 (int a1, int a2, int a3, int a4, int a5,
104 char* format, ...)
106 va_list ap;
108 va_start(ap, format);
109 if (strlen (format) != 16 - 5)
110 ASSERT(0);
111 while (*format)
112 if (*format++ != to_hex (va_arg (ap, int)))
113 ASSERT(0);
114 va_end(ap);
117 void
118 f6 (int a1, int a2, int a3, int a4, int a5,
119 int a6,
120 char* format, ...)
122 va_list ap;
124 va_start(ap, format);
125 if (strlen (format) != 16 - 6)
126 ASSERT(0);
127 while (*format)
128 if (*format++ != to_hex (va_arg (ap, int)))
129 ASSERT(0);
130 va_end(ap);
133 void
134 f7 (int a1, int a2, int a3, int a4, int a5,
135 int a6, int a7,
136 char* format, ...)
138 va_list ap;
140 va_start(ap, format);
141 if (strlen (format) != 16 - 7)
142 ASSERT(0);
143 while (*format)
144 if (*format++ != to_hex (va_arg (ap, int)))
145 ASSERT(0);
146 va_end(ap);
149 void
150 f8 (int a1, int a2, int a3, int a4, int a5,
151 int a6, int a7, int a8,
152 char* format, ...)
154 va_list ap;
156 va_start(ap, format);
157 if (strlen (format) != 16 - 8)
158 ASSERT(0);
159 while (*format)
160 if (*format++ != to_hex (va_arg (ap, int)))
161 ASSERT(0);
162 va_end(ap);
165 void
166 f9 (int a1, int a2, int a3, int a4, int a5,
167 int a6, int a7, int a8, int a9,
168 char* format, ...)
170 va_list ap;
172 va_start(ap, format);
173 if (strlen (format) != 16 - 9)
174 ASSERT(0);
175 while (*format)
176 if (*format++ != to_hex (va_arg (ap, int)))
177 ASSERT(0);
178 va_end(ap);
181 void
182 f10 (int a1, int a2, int a3, int a4, int a5,
183 int a6, int a7, int a8, int a9, int a10,
184 char* format, ...)
186 va_list ap;
188 va_start(ap, format);
189 if (strlen (format) != 16 - 10)
190 ASSERT(0);
191 while (*format)
192 if (*format++ != to_hex (va_arg (ap, int)))
193 ASSERT(0);
194 va_end(ap);
197 void
198 f11 (int a1, int a2, int a3, int a4, int a5,
199 int a6, int a7, int a8, int a9, int a10,
200 int a11,
201 char* format, ...)
203 va_list ap;
205 va_start(ap, format);
206 if (strlen (format) != 16 - 11)
207 ASSERT(0);
208 while (*format)
209 if (*format++ != to_hex (va_arg (ap, int)))
210 ASSERT(0);
211 va_end(ap);
214 void
215 f12 (int a1, int a2, int a3, int a4, int a5,
216 int a6, int a7, int a8, int a9, int a10,
217 int a11, int a12,
218 char* format, ...)
220 va_list ap;
222 va_start(ap, format);
223 if (strlen (format) != 16 - 12)
224 ASSERT(0);
225 while (*format)
226 if (*format++ != to_hex (va_arg (ap, int)))
227 ASSERT(0);
228 va_end(ap);
231 void
232 f13 (int a1, int a2, int a3, int a4, int a5,
233 int a6, int a7, int a8, int a9, int a10,
234 int a11, int a12, int a13,
235 char* format, ...)
237 va_list ap;
239 va_start(ap, format);
240 if (strlen (format) != 16 - 13)
241 ASSERT(0);
242 while (*format)
243 if (*format++ != to_hex (va_arg (ap, int)))
244 ASSERT(0);
245 va_end(ap);
248 void
249 f14 (int a1, int a2, int a3, int a4, int a5,
250 int a6, int a7, int a8, int a9, int a10,
251 int a11, int a12, int a13, int a14,
252 char* format, ...)
254 va_list ap;
256 va_start(ap, format);
257 if (strlen (format) != 16 - 14)
258 ASSERT(0);
259 while (*format)
260 if (*format++ != to_hex (va_arg (ap, int)))
261 ASSERT(0);
262 va_end(ap);
265 void
266 f15 (int a1, int a2, int a3, int a4, int a5,
267 int a6, int a7, int a8, int a9, int a10,
268 int a11, int a12, int a13, int a14, int a15,
269 char* format, ...)
271 va_list ap;
273 va_start(ap, format);
274 if (strlen (format) != 16 - 15)
275 ASSERT(0);
276 while (*format)
277 if (*format++ != to_hex (va_arg (ap, int)))
278 ASSERT(0);
279 va_end(ap);
281 #endif
283 void
284 testTortureExecute (void)
286 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
287 char *f = "0123456789abcdef";
289 f0 (f+0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
290 f1 (0, f+1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
291 f2 (0, 1, f+2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
292 f3 (0, 1, 2, f+3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
293 f4 (0, 1, 2, 3, f+4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
294 f5 (0, 1, 2, 3, 4, f+5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
295 f6 (0, 1, 2, 3, 4, 5, f+6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
296 f7 (0, 1, 2, 3, 4, 5, 6, f+7, 7, 8, 9, 10, 11, 12, 13, 14, 15);
297 f8 (0, 1, 2, 3, 4, 5, 6, 7, f+8, 8, 9, 10, 11, 12, 13, 14, 15);
298 f9 (0, 1, 2, 3, 4, 5, 6, 7, 8, f+9, 9, 10, 11, 12, 13, 14, 15);
299 f10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, f+10, 10, 11, 12, 13, 14, 15);
300 f11 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, f+11, 11, 12, 13, 14, 15);
301 f12 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, f+12, 12, 13, 14, 15);
302 f13 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, f+13, 13, 14, 15);
303 f14 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, f+14, 14, 15);
304 f15 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, f+15, 15);
305 #endif
306 return;