struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-stdarg-3.c
blobabb543459824fc0ac120e4442e16d76d91423b3d
1 /*
2 stdarg-3.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma std_c99
9 #endif
11 #pragma disable_warning 93 // Using float for double.
13 #include <stdarg.h>
15 #if !defined( __SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
16 int foo_arg, bar_arg;
17 long x;
18 double d;
19 va_list gap;
20 struct S1 { int i; double d; int j; double e; } s1;
21 struct S2 { double d; long i; } s2;
22 int y;
24 void
25 bar (int v)
27 bar_arg = v;
30 void
31 f1 (int i, ...)
33 va_list ap;
34 va_start (ap, i);
35 while (i-- > 0)
36 x = va_arg (ap, long);
37 va_end (ap);
40 void
41 f2 (int i, ...)
43 va_list ap;
44 va_start (ap, i);
45 while (i-- > 0)
46 d = va_arg (ap, double);
47 va_end (ap);
50 void
51 f3 (int i, ...)
53 va_list ap;
54 int j = i;
55 while (j-- > 0)
57 va_start (ap, i);
58 x = va_arg (ap, long);
59 va_end (ap);
60 bar (x);
64 void
65 f4 (int i, ...)
67 va_list ap;
68 int j = i;
69 while (j-- > 0)
71 va_start (ap, i);
72 d = va_arg (ap, double);
73 va_end (ap);
74 bar (d + 4.0);
78 #if 0
79 SDCC cannot assign aggregates yet.
80 void
81 f5 (int i, ...)
83 va_list ap;
84 va_start (ap, i);
85 while (i-- > 0)
86 s1 = va_arg (ap, struct S1);
87 va_end (ap);
90 void
91 f6 (int i, ...)
93 va_list ap;
94 va_start (ap, i);
95 while (i-- > 0)
96 s2 = va_arg (ap, struct S2);
97 va_end (ap);
100 void
101 f7 (int i, ...)
103 va_list ap;
104 int j = i;
105 while (j-- > 0)
107 va_start (ap, i);
108 s1 = va_arg (ap, struct S1);
109 va_end (ap);
110 bar (s1.i);
114 void
115 f8 (int i, ...)
117 va_list ap;
118 int j = i;
119 while (j-- > 0)
121 va_start (ap, i);
122 s2 = va_arg (ap, struct S2);
123 y = va_arg (ap, int);
124 va_end (ap);
125 bar (s2.i);
128 #endif
129 #endif
131 void
132 testTortureExecute (void)
134 #if !defined( __SDCC_pdk14) && !defined(__SDCC_pdk15) // Lack of memory
135 // struct S1 a1, a3;
136 // struct S2 a2, a4;
138 f1 (7, 1L, 2L, 3L, 5L, 7L, 9L, 11L, 13L);
139 if (x != 11L)
140 ASSERT (0);
141 f2 (6, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0);
142 if (d != 32.0)
143 ASSERT (0);
144 f3 (2, 1L, 3L);
145 if (bar_arg != 1L || x != 1L)
146 ASSERT (0);
147 f4 (2, 17.0, 19.0);
148 if (bar_arg != 21 || d != 17.0)
149 ASSERT (0);
150 #if 0
151 // SDCC cannot pass structures or assign aggregates yet.
152 a1.i = 131;
153 a1.j = 251;
154 a1.d = 15.0;
155 a1.e = 191.0;
156 a3 = a1;
157 a3.j = 254;
158 a3.e = 178.0;
159 f5 (2, a1, a3, a1);
160 if (s1.i != 131 || s1.j != 254 || s1.d != 15.0 || s1.e != 178.0)
161 ASSERT (0);
162 f5 (3, a1, a3, a1);
163 if (s1.i != 131 || s1.j != 251 || s1.d != 15.0 || s1.e != 191.0)
164 ASSERT (0);
165 a2.i = 138;
166 a2.d = 16.0;
167 a4.i = 257;
168 a4.d = 176.0;
169 f6 (2, a2, a4, a2);
170 if (s2.i != 257 || s2.d != 176.0)
171 ASSERT (0);
172 f6 (3, a2, a4, a2);
173 if (s2.i != 138 || s2.d != 16.0)
174 ASSERT (0);
175 f7 (2, a3, a1, a1);
176 if (s1.i != 131 || s1.j != 254 || s1.d != 15.0 || s1.e != 178.0)
177 ASSERT (0);
178 if (bar_arg != 131)
179 ASSERT (0);
180 f8 (3, a4, a2, a2);
181 if (s2.i != 257 || s2.d != 176.0)
182 ASSERT (0);
183 #endif
184 #endif
185 return;