libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / c23-stdarg-9.c
blob068fe3d4c7a5b092737cf42c445e55338a53f8de
1 /* Test C23 variadic functions with no named parameters, or last named
2 parameter with a declaration not allowed in C17. Execution tests. */
3 /* { dg-do run } */
4 /* { dg-options "-O2 -std=c23 -pedantic-errors" } */
6 #include <stdarg.h>
8 #ifdef __AVR__
9 /* AVR doesn't have that much stack... */
10 struct S { int a[500]; };
11 #else
12 struct S { int a[1024]; };
13 #endif
15 int
16 f1 (...)
18 int r = 0;
19 va_list ap;
20 va_start (ap);
21 r += va_arg (ap, int);
22 va_end (ap);
23 return r;
26 int
27 f2 (...)
29 int r = 0;
30 va_list ap;
31 va_start (ap);
32 r += va_arg (ap, int);
33 r += va_arg (ap, int);
34 va_end (ap);
35 return r;
38 int
39 f3 (...)
41 int r = 0;
42 va_list ap;
43 va_start (ap);
44 r += va_arg (ap, int);
45 r += va_arg (ap, int);
46 r += va_arg (ap, int);
47 va_end (ap);
48 return r;
51 int
52 f4 (...)
54 int r = 0;
55 va_list ap;
56 va_start (ap);
57 r += va_arg (ap, int);
58 r += va_arg (ap, int);
59 r += va_arg (ap, int);
60 r += va_arg (ap, int);
61 va_end (ap);
62 return r;
65 int
66 f5 (...)
68 int r = 0;
69 va_list ap;
70 va_start (ap);
71 r += va_arg (ap, int);
72 r += va_arg (ap, int);
73 r += va_arg (ap, int);
74 r += va_arg (ap, int);
75 r += va_arg (ap, int);
76 va_end (ap);
77 return r;
80 int
81 f6 (...)
83 int r = 0;
84 va_list ap;
85 va_start (ap);
86 r += va_arg (ap, int);
87 r += va_arg (ap, int);
88 r += va_arg (ap, int);
89 r += va_arg (ap, int);
90 r += va_arg (ap, int);
91 r += va_arg (ap, int);
92 va_end (ap);
93 return r;
96 int
97 f7 (...)
99 int r = 0;
100 va_list ap;
101 va_start (ap);
102 r += va_arg (ap, int);
103 r += va_arg (ap, int);
104 r += va_arg (ap, int);
105 r += va_arg (ap, int);
106 r += va_arg (ap, int);
107 r += va_arg (ap, int);
108 r += va_arg (ap, int);
109 va_end (ap);
110 return r;
114 f8 (...)
116 int r = 0;
117 va_list ap;
118 va_start (ap);
119 r += va_arg (ap, int);
120 r += va_arg (ap, int);
121 r += va_arg (ap, int);
122 r += va_arg (ap, int);
123 r += va_arg (ap, int);
124 r += va_arg (ap, int);
125 r += va_arg (ap, int);
126 r += va_arg (ap, int);
127 va_end (ap);
128 return r;
131 struct S
132 s1 (...)
134 int r = 0;
135 va_list ap;
136 va_start (ap);
137 r += va_arg (ap, int);
138 va_end (ap);
139 struct S s = {};
140 s.a[0] = r;
141 return s;
144 struct S
145 s2 (...)
147 int r = 0;
148 va_list ap;
149 va_start (ap);
150 r += va_arg (ap, int);
151 r += va_arg (ap, int);
152 va_end (ap);
153 struct S s = {};
154 s.a[0] = r;
155 return s;
158 struct S
159 s3 (...)
161 int r = 0;
162 va_list ap;
163 va_start (ap);
164 r += va_arg (ap, int);
165 r += va_arg (ap, int);
166 r += va_arg (ap, int);
167 va_end (ap);
168 struct S s = {};
169 s.a[0] = r;
170 return s;
173 struct S
174 s4 (...)
176 int r = 0;
177 va_list ap;
178 va_start (ap);
179 r += va_arg (ap, int);
180 r += va_arg (ap, int);
181 r += va_arg (ap, int);
182 r += va_arg (ap, int);
183 va_end (ap);
184 struct S s = {};
185 s.a[0] = r;
186 return s;
189 struct S
190 s5 (...)
192 int r = 0;
193 va_list ap;
194 va_start (ap);
195 r += va_arg (ap, int);
196 r += va_arg (ap, int);
197 r += va_arg (ap, int);
198 r += va_arg (ap, int);
199 r += va_arg (ap, int);
200 va_end (ap);
201 struct S s = {};
202 s.a[0] = r;
203 return s;
206 struct S
207 s6 (...)
209 int r = 0;
210 va_list ap;
211 va_start (ap);
212 r += va_arg (ap, int);
213 r += va_arg (ap, int);
214 r += va_arg (ap, int);
215 r += va_arg (ap, int);
216 r += va_arg (ap, int);
217 r += va_arg (ap, int);
218 va_end (ap);
219 struct S s = {};
220 s.a[0] = r;
221 return s;
224 struct S
225 s7 (...)
227 int r = 0;
228 va_list ap;
229 va_start (ap);
230 r += va_arg (ap, int);
231 r += va_arg (ap, int);
232 r += va_arg (ap, int);
233 r += va_arg (ap, int);
234 r += va_arg (ap, int);
235 r += va_arg (ap, int);
236 r += va_arg (ap, int);
237 va_end (ap);
238 struct S s = {};
239 s.a[0] = r;
240 return s;
243 struct S
244 s8 (...)
246 int r = 0;
247 va_list ap;
248 va_start (ap);
249 r += va_arg (ap, int);
250 r += va_arg (ap, int);
251 r += va_arg (ap, int);
252 r += va_arg (ap, int);
253 r += va_arg (ap, int);
254 r += va_arg (ap, int);
255 r += va_arg (ap, int);
256 r += va_arg (ap, int);
257 va_end (ap);
258 struct S s = {};
259 s.a[0] = r;
260 return s;
264 b1 (void)
266 return f8 (1, 2, 3, 4, 5, 6, 7, 8);
270 b2 (void)
272 return s8 (1, 2, 3, 4, 5, 6, 7, 8).a[0];
276 main ()
278 if (f1 (1) != 1 || f2 (1, 2) != 3 || f3 (1, 2, 3) != 6
279 || f4 (1, 2, 3, 4) != 10 || f5 (1, 2, 3, 4, 5) != 15
280 || f6 (1, 2, 3, 4, 5, 6) != 21 || f7 (1, 2, 3, 4, 5, 6, 7) != 28
281 || f8 (1, 2, 3, 4, 5, 6, 7, 8) != 36)
282 __builtin_abort ();
283 if (s1 (1).a[0] != 1 || s2 (1, 2).a[0] != 3 || s3 (1, 2, 3).a[0] != 6
284 || s4 (1, 2, 3, 4).a[0] != 10 || s5 (1, 2, 3, 4, 5).a[0] != 15
285 || s6 (1, 2, 3, 4, 5, 6).a[0] != 21
286 || s7 (1, 2, 3, 4, 5, 6, 7).a[0] != 28
287 || s8 (1, 2, 3, 4, 5, 6, 7, 8).a[0] != 36)
288 __builtin_abort ();