1 /* This tests passing of structs. */
2
3 #include "defines.h"
4 #include "args.h"
5 #include <complex.h>
6
7 struct IntegerRegisters iregbits = { ~0, ~0, ~0, ~0, ~0, ~0 };
8 struct IntegerRegisters iregs;
9 unsigned int num_iregs;
10
11 struct int_struct
12 {
13 int i;
14 };
15
16 struct long_struct
17 {
18 long l;
19 };
20
21 struct longlong2_struct
22 {
23 long long ll1, ll2;
24 };
25
26 struct longlong3_struct
27 {
28 long long ll1, ll2, ll3;
29 };
30
31 /* Check that the struct is passed as the individual members in iregs. */
32 void
check_struct_passing1(struct int_struct is ATTRIBUTE_UNUSED)33 check_struct_passing1 (struct int_struct is ATTRIBUTE_UNUSED)
34 {
35 check_int_arguments;
36 }
37
38 void
check_struct_passing2(struct long_struct ls ATTRIBUTE_UNUSED)39 check_struct_passing2 (struct long_struct ls ATTRIBUTE_UNUSED)
40 {
41 check_int_arguments;
42 }
43
44 void
check_struct_passing3(struct longlong2_struct ls ATTRIBUTE_UNUSED)45 check_struct_passing3 (struct longlong2_struct ls ATTRIBUTE_UNUSED)
46 {
47 check_int_arguments;
48 }
49
50 void
check_struct_passing4(struct longlong3_struct ls ATTRIBUTE_UNUSED)51 check_struct_passing4 (struct longlong3_struct ls ATTRIBUTE_UNUSED)
52 {
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);
58 }
59
60 struct flex1_struct
61 {
62 long i;
63 long flex[];
64 };
65
66 struct flex2_struct
67 {
68 long i;
69 long flex[0];
70 };
71
72 void
check_struct_passing7(struct flex1_struct is ATTRIBUTE_UNUSED)73 check_struct_passing7 (struct flex1_struct is ATTRIBUTE_UNUSED)
74 {
75 check_int_arguments;
76 }
77
78 void
check_struct_passing8(struct flex2_struct is ATTRIBUTE_UNUSED)79 check_struct_passing8 (struct flex2_struct is ATTRIBUTE_UNUSED)
80 {
81 check_int_arguments;
82 }
83
84 struct complex1_struct
85 {
86 __complex__ float x;
87 };
88
89 struct complex1a_struct
90 {
91 long l;
92 union
93 {
94 float f;
95 int i;
96 } u;
97 };
98
99 void
check_struct_passing9(struct complex1_struct is ATTRIBUTE_UNUSED)100 check_struct_passing9 (struct complex1_struct is ATTRIBUTE_UNUSED)
101 {
102 check_int_arguments;
103 }
104
105 struct long3_struct
106 {
107 long l1, l2, l3;
108 };
109
110 void
check_struct_passing10(struct long3_struct ls ATTRIBUTE_UNUSED)111 check_struct_passing10 (struct long3_struct ls ATTRIBUTE_UNUSED)
112 {
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);
118 }
119
120 struct char3_struct
121 {
122 char c1, c2, c3;
123 };
124
125 void
check_struct_passing11(struct char3_struct is ATTRIBUTE_UNUSED)126 check_struct_passing11 (struct char3_struct is ATTRIBUTE_UNUSED)
127 {
128 check_int_arguments;
129 }
130
131 struct char7_struct
132 {
133 char c1, c2, c3, c4, c5, c6, c7;
134 };
135
136 void
check_struct_passing12(struct char7_struct is ATTRIBUTE_UNUSED)137 check_struct_passing12 (struct char7_struct is ATTRIBUTE_UNUSED)
138 {
139 check_int_arguments;
140 }
141
142 static struct flex1_struct f1s = { 60, { } };
143 static struct flex2_struct f2s = { 61, { } };
144
145 int
main(void)146 main (void)
147 {
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
157 {
158 struct complex1_struct c;
159 struct complex1a_struct u;
160 } c1u;
161 struct char3_struct c3 = { 0x12, 0x34, 0x56 };
162 union
163 {
164 struct char3_struct c;
165 int i;
166 } c3u;
167 struct char7_struct c7 = { 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56 };
168 union
169 {
170 struct char7_struct c;
171 struct
172 {
173 int i0, i1;
174 } i;
175 } c7u;
176
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);
182
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);
188
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
197
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);
203
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);
209
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);
217
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);
225
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);
235
236 return 0;
237 }
238