IA MCU psABI support: testsuite
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / iamcu / test_passing_structs.c
blob1660a4d430b8b8603ca36d943e23c17f433c0253
1 /* This tests passing of structs. */
3 #include "defines.h"
4 #include "args.h"
5 #include <complex.h>
7 struct IntegerRegisters iregbits = { ~0, ~0, ~0, ~0, ~0, ~0 };
8 struct IntegerRegisters iregs;
9 unsigned int num_iregs;
11 struct int_struct
13 int i;
16 struct long_struct
18 long l;
21 struct longlong2_struct
23 long long ll1, ll2;
26 struct longlong3_struct
28 long long ll1, ll2, ll3;
31 /* Check that the struct is passed as the individual members in iregs. */
32 void
33 check_struct_passing1 (struct int_struct is ATTRIBUTE_UNUSED)
35 check_int_arguments;
38 void
39 check_struct_passing2 (struct long_struct ls ATTRIBUTE_UNUSED)
41 check_int_arguments;
44 void
45 check_struct_passing3 (struct longlong2_struct ls ATTRIBUTE_UNUSED)
47 check_int_arguments;
50 void
51 check_struct_passing4 (struct longlong3_struct ls ATTRIBUTE_UNUSED)
53 /* Check the passing on the stack by comparing the address of the
54 stack elements to the expected place on the stack. */
55 assert ((unsigned long)&ls.ll1 == esp+4);
56 assert ((unsigned long)&ls.ll2 == esp+12);
57 assert ((unsigned long)&ls.ll3 == esp+20);
60 struct flex1_struct
62 long i;
63 long flex[];
66 struct flex2_struct
68 long i;
69 long flex[0];
72 void
73 check_struct_passing7 (struct flex1_struct is ATTRIBUTE_UNUSED)
75 check_int_arguments;
78 void
79 check_struct_passing8 (struct flex2_struct is ATTRIBUTE_UNUSED)
81 check_int_arguments;
84 struct complex1_struct
86 __complex__ float x;
89 struct complex1a_struct
91 long l;
92 union
94 float f;
95 int i;
96 } u;
99 void
100 check_struct_passing9 (struct complex1_struct is ATTRIBUTE_UNUSED)
102 check_int_arguments;
105 struct long3_struct
107 long l1, l2, l3;
110 void
111 check_struct_passing10 (struct long3_struct ls ATTRIBUTE_UNUSED)
113 /* Check the passing on the stack by comparing the address of the
114 stack elements to the expected place on the stack. */
115 assert ((unsigned long)&ls.l1 == esp+4);
116 assert ((unsigned long)&ls.l2 == esp+8);
117 assert ((unsigned long)&ls.l3 == esp+12);
120 struct char3_struct
122 char c1, c2, c3;
125 void
126 check_struct_passing11 (struct char3_struct is ATTRIBUTE_UNUSED)
128 check_int_arguments;
131 struct char7_struct
133 char c1, c2, c3, c4, c5, c6, c7;
136 void
137 check_struct_passing12 (struct char7_struct is ATTRIBUTE_UNUSED)
139 check_int_arguments;
142 static struct flex1_struct f1s = { 60, { } };
143 static struct flex2_struct f2s = { 61, { } };
146 main (void)
148 struct int_struct is = { 48 };
149 struct long_struct ls = { 49 };
150 #ifdef CHECK_LARGER_STRUCTS
151 struct longlong2_struct ll2s = { 50, 51 };
152 struct longlong3_struct ll3s = { 52, 53, 54 };
153 struct long3_struct l3s = { 60, 61, 62 };
154 #endif
155 struct complex1_struct c1s = { ( -13.4 + 3.5*I ) };
156 union
158 struct complex1_struct c;
159 struct complex1a_struct u;
160 } c1u;
161 struct char3_struct c3 = { 0x12, 0x34, 0x56 };
162 union
164 struct char3_struct c;
165 int i;
166 } c3u;
167 struct char7_struct c7 = { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56 };
168 union
170 struct char7_struct c;
171 struct
173 int i0, i1;
174 } i;
175 } c7u;
177 clear_struct_registers;
178 iregs.I0 = is.i;
179 num_iregs = 1;
180 clear_int_hardware_registers;
181 WRAP_CALL (check_struct_passing1)(is);
183 clear_struct_registers;
184 iregs.I0 = ls.l;
185 num_iregs = 1;
186 clear_int_hardware_registers;
187 WRAP_CALL (check_struct_passing2)(ls);
189 #ifdef CHECK_LARGER_STRUCTS
190 clear_struct_registers;
191 num_iregs = 0;
192 clear_int_hardware_registers;
193 WRAP_CALL (check_struct_passing3)(ll2s);
194 WRAP_CALL (check_struct_passing4)(ll3s);
195 WRAP_CALL (check_struct_passing10)(l3s);
196 #endif
198 clear_struct_registers;
199 iregs.I0 = f1s.i;
200 num_iregs = 1;
201 clear_int_hardware_registers;
202 WRAP_CALL (check_struct_passing7)(f1s);
204 clear_struct_registers;
205 iregs.I0 = f2s.i;
206 num_iregs = 1;
207 clear_int_hardware_registers;
208 WRAP_CALL (check_struct_passing8)(f2s);
210 clear_struct_registers;
211 c1u.c = c1s;
212 iregs.I0 = c1u.u.l;
213 iregs.I1 = c1u.u.u.i;
214 num_iregs = 2;
215 clear_int_hardware_registers;
216 WRAP_CALL (check_struct_passing9)(c1s);
218 clear_struct_registers;
219 c3u.c = c3;
220 iregs.I0 = c3u.i;
221 iregbits.I0 = 0xffffff;
222 num_iregs = 1;
223 clear_int_hardware_registers;
224 WRAP_CALL (check_struct_passing11)(c3);
226 clear_struct_registers;
227 c7u.c = c7;
228 iregs.I0 = c7u.i.i0;
229 iregs.I1 = c7u.i.i1;
230 iregbits.I0 = 0xffffffff;
231 iregbits.I1 = 0xffffff;
232 num_iregs = 2;
233 clear_int_hardware_registers;
234 WRAP_CALL (check_struct_passing12)(c7);
236 return 0;