struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-stdarg-1.c
blob516d4071e113035cef4bda17f59e84a2173ba86f
1 /*
2 stdarg-1.c from the execute part of the gcc torture tests.
3 */
5 #include <testfwk.h>
7 #ifdef __SDCC
8 #pragma disable_warning 93
9 #pragma disable_warning 85
10 #endif
12 #include <stdarg.h>
14 int foo_arg, bar_arg;
15 long x;
16 double d;
17 va_list gap;
18 va_list *pap;
20 void
21 foo (int v, va_list ap)
23 switch (v)
25 case 5: foo_arg = va_arg (ap, int); break;
26 default: ASSERT (0);
30 #if 0 // TODO: Enable when SDCC support long double!
31 void
32 bar (int v)
34 if (v == 0x4006)
36 if (va_arg (gap, double) != 17.0
37 || va_arg (gap, long) != 129L)
38 ASSERT (0);
40 else if (v == 0x4008)
42 if (va_arg (*pap, long long) != 14LL
43 || va_arg (*pap, long double) != 131.0L
44 || va_arg (*pap, int) != 17)
45 ASSERT (0);
47 bar_arg = v;
49 #endif
51 void
52 f0 (int i, ...)
56 void
57 f1 (int i, ...)
59 va_list ap;
60 va_start (ap, i);
61 va_end (ap);
63 #if 0 // TODO: Enable when SDCC support long double!
64 void
65 f2 (int i, ...)
67 va_list ap;
68 va_start (ap, i);
69 bar (d);
70 x = va_arg (ap, long);
71 bar (x);
72 va_end (ap);
75 void
76 f3 (int i, ...)
78 va_list ap;
79 va_start (ap, i);
80 d = va_arg (ap, double);
81 va_end (ap);
84 void
85 f4 (int i, ...)
87 va_list ap;
88 va_start (ap, i);
89 x = va_arg (ap, double);
90 foo (i, ap);
91 va_end (ap);
94 void
95 f5 (int i, ...)
97 va_list ap;
98 va_start (ap, i);
99 va_copy (gap, ap);
100 bar (i);
101 va_end (ap);
102 va_end (gap);
105 void
106 f6 (int i, ...)
108 va_list ap;
109 va_start (ap, i);
110 bar (d);
111 va_arg (ap, long);
112 va_arg (ap, long);
113 x = va_arg (ap, long);
114 bar (x);
115 va_end (ap);
118 void
119 f7 (int i, ...)
121 va_list ap;
122 va_start (ap, i);
123 pap = &ap;
124 bar (i);
125 va_end (ap);
128 void
129 f8 (int i, ...)
131 va_list ap;
132 va_start (ap, i);
133 pap = &ap;
134 bar (i);
135 d = va_arg (ap, double);
136 va_end (ap);
138 #endif
139 void
140 testTortureExecute (void)
142 f0 (1);
143 f1 (2);
144 d = 31.0;
145 #if 0 // TODO: Enable when SDCC support long double!
146 f2 (3, 28L);
147 if (bar_arg != 28 || x != 28)
148 ASSERT (0);
149 f3 (4, 131.0);
150 if (d != 131.0)
151 ASSERT (0);
152 f4 (5, 16.0, 128);
153 if (x != 16 || foo_arg != 128)
154 ASSERT (0);
155 f5 (0x4006, 17.0, 129L);
156 if (bar_arg != 0x4006)
158 f6 (7, 12L, 14L, -31L);
159 if (bar_arg != -31)
160 ASSERT (0);
161 f7 (0x4008, 14LL, 131.0L, 17, 26.0);
162 if (bar_arg != 0x4008)
163 ASSERT (0);
164 f8 (0x4008, 14LL, 131.0L, 17, 27.0);
165 if (bar_arg != 0x4008 || d != 27.0)
166 ASSERT (0);
167 #endif
168 return;