struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / gcc-torture-execute-stdarg-5.c.in
blob9d48376d3f4c291e30c2b2e8debc2f9fbd1a20d5
1 /*
2 stdarg-4.c from the execute part of the gcc torture tests.
3 inlined: yes, no
4 */
6 #include <testfwk.h>
8 #ifdef __SDCC
9 #pragma std_c99
10 #endif
12 #pragma disable_warning 93 // Using float for double.
14 #include <stdarg.h>
16 long x, y;
18 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Bug #2874
20 #define INLINED_{inlined}
22 #ifdef INLINED_yes
23 static inline
24 #endif
25 void
26 f1i (va_list ap)
28 x = va_arg (ap, double);
29 x += va_arg (ap, long);
30 x += va_arg (ap, double);
33 void
34 f1 (int i, ...)
36 va_list ap;
37 va_start (ap, i);
38 f1i (ap);
39 va_end (ap);
42 #ifdef INLINED_yes
43 static inline
44 #endif
45 void
46 f2i (va_list ap)
48 y = va_arg (ap, int);
49 y += va_arg (ap, long);
50 y += va_arg (ap, double);
51 f1i (ap);
54 void
55 f2 (int i, ...)
57 va_list ap;
58 va_start (ap, i);
59 f2i (ap);
60 va_end (ap);
63 long
64 f3h (int i, long arg0, long arg1, long arg2, long arg3)
66 return i + arg0 + arg1 + arg2 + arg3;
69 long
70 f3 (int i, ...)
72 long t, arg0, arg1, arg2, arg3;
73 va_list ap;
75 va_start (ap, i);
76 switch (i)
78 case 0:
79 t = f3h (i, 0, 0, 0, 0);
80 break;
81 case 1:
82 arg0 = va_arg (ap, long);
83 t = f3h (i, arg0, 0, 0, 0);
84 break;
85 case 2:
86 arg0 = va_arg (ap, long);
87 arg1 = va_arg (ap, long);
88 t = f3h (i, arg0, arg1, 0, 0);
89 break;
90 case 3:
91 arg0 = va_arg (ap, long);
92 arg1 = va_arg (ap, long);
93 arg2 = va_arg (ap, long);
94 t = f3h (i, arg0, arg1, arg2, 0);
95 break;
96 case 4:
97 arg0 = va_arg (ap, long);
98 arg1 = va_arg (ap, long);
99 arg2 = va_arg (ap, long);
100 arg3 = va_arg (ap, long);
101 t = f3h (i, arg0, arg1, arg2, arg3);
102 break;
103 default:
104 t = 0;
105 ASSERT (0);
107 va_end (ap);
109 return t;
112 void
113 f4 (int i, ...)
115 va_list ap;
117 va_start (ap, i);
118 switch (i)
120 case 4:
121 y = va_arg (ap, double);
122 break;
123 case 5:
124 y = va_arg (ap, double);
125 y += va_arg (ap, double);
126 break;
127 default:
128 ASSERT (0);
130 f1i (ap);
131 va_end (ap);
133 #endif
135 void
136 testTortureExecute (void)
138 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Bug #2874
139 #if defined(__SDCC_pic16)
140 //broken, skip
141 #elif defined(__SDCC_mcs51) && defined(__SDCC_STACK_AUTO) && !defined(__SDCC_USE_XSTACK) && defined(INLINED_yes)
142 //broken, skip
143 #else
144 f1 (3, 16.0, 128L, 32.0);
145 ASSERT (x == 176L);
146 f2 (6, 5, 7L, 18.0, 19.0, 17L, 64.0);
147 ASSERT (x == 100L);
148 ASSERT (y == 30L);
149 ASSERT (f3 (0) == 0);
150 ASSERT (f3 (1, 18L) == 19L);
151 ASSERT (f3 (2, 18L, 100L) == 120L);
152 ASSERT (f3 (3, 18L, 100L, 300L) == 421L);
153 ASSERT (f3 (4, 18L, 71L, 64L, 86L) == 243L);
154 f4 (4, 6.0, 9.0, 16L, 18.0);
155 ASSERT (x == 43L);
156 ASSERT (y == 6L);
157 f4 (5, 7.0, 21.0, 1.0, 17L, 126.0);
159 // Failed on z80 and related
160 ASSERT (x == 144L);
161 ASSERT (y == 28L);
162 #endif
163 #endif
164 return;