2002-05-10 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.c-torture / execute / va-arg-2.c
blob7675b3f760357f8069e402431c0273ca3afa8992
1 /* The purpose of this test is to catch edge cases when arguments are passed
2 in regs and on the stack. We test 16 cases, trying to catch multiple
3 targets (some use 3 regs for argument passing, some use 12, etc.).
4 We test both the arguments and the `lastarg' (the argument to va_start). */
6 #include <stdarg.h>
8 extern __SIZE_TYPE__ strlen ();
10 int
11 to_hex (unsigned int a)
13 static char hex[] = "0123456789abcdef";
15 if (a > 15)
16 abort ();
17 return hex[a];
20 void
21 f0 (char* format, ...)
23 va_list ap;
25 va_start (ap, format);
26 if (strlen (format) != 16 - 0)
27 abort ();
28 while (*format)
29 if (*format++ != to_hex (va_arg (ap, int)))
30 abort ();
31 va_end(ap);
34 void
35 f1 (int a1, char* format, ...)
37 va_list ap;
39 va_start(ap, format);
40 if (strlen (format) != 16 - 1)
41 abort ();
42 while (*format)
43 if (*format++ != to_hex (va_arg (ap, int)))
44 abort ();
45 va_end(ap);
48 void
49 f2 (int a1, int a2, char* format, ...)
51 va_list ap;
53 va_start(ap, format);
54 if (strlen (format) != 16 - 2)
55 abort ();
56 while (*format)
57 if (*format++ != to_hex (va_arg (ap, int)))
58 abort ();
59 va_end(ap);
62 void
63 f3 (int a1, int a2, int a3, char* format, ...)
65 va_list ap;
67 va_start(ap, format);
68 if (strlen (format) != 16 - 3)
69 abort ();
70 while (*format)
71 if (*format++ != to_hex (va_arg (ap, int)))
72 abort ();
73 va_end(ap);
76 void
77 f4 (int a1, int a2, int a3, int a4, char* format, ...)
79 va_list ap;
81 va_start(ap, format);
82 if (strlen (format) != 16 - 4)
83 abort ();
84 while (*format)
85 if (*format++ != to_hex (va_arg (ap, int)))
86 abort ();
87 va_end(ap);
90 void
91 f5 (int a1, int a2, int a3, int a4, int a5,
92 char* format, ...)
94 va_list ap;
96 va_start(ap, format);
97 if (strlen (format) != 16 - 5)
98 abort ();
99 while (*format)
100 if (*format++ != to_hex (va_arg (ap, int)))
101 abort ();
102 va_end(ap);
105 void
106 f6 (int a1, int a2, int a3, int a4, int a5,
107 int a6,
108 char* format, ...)
110 va_list ap;
112 va_start(ap, format);
113 if (strlen (format) != 16 - 6)
114 abort ();
115 while (*format)
116 if (*format++ != to_hex (va_arg (ap, int)))
117 abort ();
118 va_end(ap);
121 void
122 f7 (int a1, int a2, int a3, int a4, int a5,
123 int a6, int a7,
124 char* format, ...)
126 va_list ap;
128 va_start(ap, format);
129 if (strlen (format) != 16 - 7)
130 abort ();
131 while (*format)
132 if (*format++ != to_hex (va_arg (ap, int)))
133 abort ();
134 va_end(ap);
137 void
138 f8 (int a1, int a2, int a3, int a4, int a5,
139 int a6, int a7, int a8,
140 char* format, ...)
142 va_list ap;
144 va_start(ap, format);
145 if (strlen (format) != 16 - 8)
146 abort ();
147 while (*format)
148 if (*format++ != to_hex (va_arg (ap, int)))
149 abort ();
150 va_end(ap);
153 void
154 f9 (int a1, int a2, int a3, int a4, int a5,
155 int a6, int a7, int a8, int a9,
156 char* format, ...)
158 va_list ap;
160 va_start(ap, format);
161 if (strlen (format) != 16 - 9)
162 abort ();
163 while (*format)
164 if (*format++ != to_hex (va_arg (ap, int)))
165 abort ();
166 va_end(ap);
169 void
170 f10 (int a1, int a2, int a3, int a4, int a5,
171 int a6, int a7, int a8, int a9, int a10,
172 char* format, ...)
174 va_list ap;
176 va_start(ap, format);
177 if (strlen (format) != 16 - 10)
178 abort ();
179 while (*format)
180 if (*format++ != to_hex (va_arg (ap, int)))
181 abort ();
182 va_end(ap);
185 void
186 f11 (int a1, int a2, int a3, int a4, int a5,
187 int a6, int a7, int a8, int a9, int a10,
188 int a11,
189 char* format, ...)
191 va_list ap;
193 va_start(ap, format);
194 if (strlen (format) != 16 - 11)
195 abort ();
196 while (*format)
197 if (*format++ != to_hex (va_arg (ap, int)))
198 abort ();
199 va_end(ap);
202 void
203 f12 (int a1, int a2, int a3, int a4, int a5,
204 int a6, int a7, int a8, int a9, int a10,
205 int a11, int a12,
206 char* format, ...)
208 va_list ap;
210 va_start(ap, format);
211 if (strlen (format) != 16 - 12)
212 abort ();
213 while (*format)
214 if (*format++ != to_hex (va_arg (ap, int)))
215 abort ();
216 va_end(ap);
219 void
220 f13 (int a1, int a2, int a3, int a4, int a5,
221 int a6, int a7, int a8, int a9, int a10,
222 int a11, int a12, int a13,
223 char* format, ...)
225 va_list ap;
227 va_start(ap, format);
228 if (strlen (format) != 16 - 13)
229 abort ();
230 while (*format)
231 if (*format++ != to_hex (va_arg (ap, int)))
232 abort ();
233 va_end(ap);
236 void
237 f14 (int a1, int a2, int a3, int a4, int a5,
238 int a6, int a7, int a8, int a9, int a10,
239 int a11, int a12, int a13, int a14,
240 char* format, ...)
242 va_list ap;
244 va_start(ap, format);
245 if (strlen (format) != 16 - 14)
246 abort ();
247 while (*format)
248 if (*format++ != to_hex (va_arg (ap, int)))
249 abort ();
250 va_end(ap);
253 void
254 f15 (int a1, int a2, int a3, int a4, int a5,
255 int a6, int a7, int a8, int a9, int a10,
256 int a11, int a12, int a13, int a14, int a15,
257 char* format, ...)
259 va_list ap;
261 va_start(ap, format);
262 if (strlen (format) != 16 - 15)
263 abort ();
264 while (*format)
265 if (*format++ != to_hex (va_arg (ap, int)))
266 abort ();
267 va_end(ap);
270 main ()
272 char *f = "0123456789abcdef";
274 f0 (f+0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
275 f1 (0, f+1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
276 f2 (0, 1, f+2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
277 f3 (0, 1, 2, f+3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
278 f4 (0, 1, 2, 3, f+4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
279 f5 (0, 1, 2, 3, 4, f+5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
280 f6 (0, 1, 2, 3, 4, 5, f+6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
281 f7 (0, 1, 2, 3, 4, 5, 6, f+7, 7, 8, 9, 10, 11, 12, 13, 14, 15);
282 f8 (0, 1, 2, 3, 4, 5, 6, 7, f+8, 8, 9, 10, 11, 12, 13, 14, 15);
283 f9 (0, 1, 2, 3, 4, 5, 6, 7, 8, f+9, 9, 10, 11, 12, 13, 14, 15);
284 f10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, f+10, 10, 11, 12, 13, 14, 15);
285 f11 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, f+11, 11, 12, 13, 14, 15);
286 f12 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, f+12, 12, 13, 14, 15);
287 f13 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, f+13, 13, 14, 15);
288 f14 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, f+14, 14, 15);
289 f15 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, f+15, 15);
291 exit (0);