1 // Some convenient things to return:
2 static char *g_first_pointer = "I am the first";
3 static char *g_second_pointer = "I am the second";
4 
5 // First we have some simple functions that return standard types, ints, floats and doubles.
6 // We have a function calling a function in a few cases to test that if you stop in the
7 // inner function then do "up/fin" you get the return value from the outer-most frame.
8 
9 int
inner_sint(int value)10 inner_sint (int value)
11 {
12   return value;
13 }
14 
15 int
outer_sint(int value)16 outer_sint (int value)
17 {
18   int outer_value = 2 * inner_sint (value);
19   return outer_value;
20 }
21 
22 float
inner_float(float value)23 inner_float (float value)
24 {
25   return value;
26 }
27 
28 float
outer_float(float value)29 outer_float (float value)
30 {
31   float outer_value = 2 * inner_float(value);
32   return outer_value;
33 }
34 
35 double
return_double(double value)36 return_double (double value)
37 {
38   return value;
39 }
40 
41 long double
return_long_double(long double value)42 return_long_double (long double value)
43 {
44   return value;
45 }
46 
47 char *
return_pointer(char * value)48 return_pointer (char *value)
49 {
50   return value;
51 }
52 
53 struct one_int
54 {
55   int one_field;
56 };
57 
58 struct one_int
return_one_int(struct one_int value)59 return_one_int (struct one_int value)
60 {
61   return value;
62 }
63 
64 struct two_int
65 {
66   int first_field;
67   int second_field;
68 };
69 
70 struct two_int
return_two_int(struct two_int value)71 return_two_int (struct two_int value)
72 {
73   return value;
74 }
75 
76 struct three_int
77 {
78   int first_field;
79   int second_field;
80   int third_field;
81 };
82 
83 struct three_int
return_three_int(struct three_int value)84 return_three_int (struct three_int value)
85 {
86   return value;
87 }
88 
89 struct four_int
90 {
91   int first_field;
92   int second_field;
93   int third_field;
94   int fourth_field;
95 };
96 
97 struct four_int
return_four_int(struct four_int value)98 return_four_int (struct four_int value)
99 {
100   return value;
101 }
102 
103 struct five_int
104 {
105   int first_field;
106   int second_field;
107   int third_field;
108   int fourth_field;
109   int fifth_field;
110 };
111 
112 struct five_int
return_five_int(struct five_int value)113 return_five_int (struct five_int value)
114 {
115   return value;
116 }
117 
118 struct one_int_one_double
119 {
120   int first_field;
121   double second_field;
122 };
123 
124 struct one_int_one_double
return_one_int_one_double(struct one_int_one_double value)125 return_one_int_one_double (struct one_int_one_double value)
126 {
127   return value;
128 }
129 
130 struct one_int_one_double_one_int
131 {
132   int one_field;
133   double second_field;
134   int third_field;
135 };
136 
137 struct one_int_one_double_one_int
return_one_int_one_double_one_int(struct one_int_one_double_one_int value)138 return_one_int_one_double_one_int (struct one_int_one_double_one_int value)
139 {
140   return value;
141 }
142 
143 struct one_short_one_double_one_short
144 {
145   int one_field;
146   double second_field;
147   int third_field;
148 };
149 
150 struct one_short_one_double_one_short
return_one_short_one_double_one_short(struct one_short_one_double_one_short value)151 return_one_short_one_double_one_short (struct one_short_one_double_one_short value)
152 {
153   return value;
154 }
155 
156 struct three_short_one_float
157 {
158   short one_field;
159   short second_field;
160   short third_field;
161   float fourth_field;
162 };
163 
164 struct three_short_one_float
return_three_short_one_float(struct three_short_one_float value)165 return_three_short_one_float (struct three_short_one_float value)
166 {
167   return value;
168 }
169 
170 struct one_int_one_float_one_int
171 {
172   int one_field;
173   float second_field;
174   int third_field;
175 };
176 
177 struct one_int_one_float_one_int
return_one_int_one_float_one_int(struct one_int_one_float_one_int value)178 return_one_int_one_float_one_int (struct one_int_one_float_one_int value)
179 {
180   return value;
181 }
182 
183 struct one_float_one_int_one_float
184 {
185   float one_field;
186   int second_field;
187   float third_field;
188 };
189 
190 struct one_float_one_int_one_float
return_one_float_one_int_one_float(struct one_float_one_int_one_float value)191 return_one_float_one_int_one_float (struct one_float_one_int_one_float value)
192 {
193   return value;
194 }
195 
196 struct one_double_two_float
197 {
198   double one_field;
199   float second_field;
200   float third_field;
201 };
202 
203 struct one_double_two_float
return_one_double_two_float(struct one_double_two_float value)204 return_one_double_two_float (struct one_double_two_float value)
205 {
206   return value;
207 }
208 
209 struct two_double
210 {
211   double first_field;
212   double second_field;
213 };
214 
215 struct two_double
return_two_double(struct two_double value)216 return_two_double (struct two_double value)
217 {
218   return value;
219 }
220 
221 struct two_float
222 {
223   float first_field;
224   float second_field;
225 };
226 
227 struct two_float
return_two_float(struct two_float value)228 return_two_float (struct two_float value)
229 {
230   return value;
231 }
232 
233 struct one_int_one_double_packed
234 {
235   int first_field;
236   double second_field;
237 } __attribute__((__packed__));
238 
239 struct one_int_one_double_packed
return_one_int_one_double_packed(struct one_int_one_double_packed value)240 return_one_int_one_double_packed (struct one_int_one_double_packed value)
241 {
242   return value;
243 }
244 
245 struct one_int_one_long
246 {
247   int first_field;
248   long second_field;
249 };
250 
251 struct one_int_one_long
return_one_int_one_long(struct one_int_one_long value)252 return_one_int_one_long (struct one_int_one_long value)
253 {
254   return value;
255 }
256 
257 struct one_pointer
258 {
259   char *first_field;
260 };
261 
262 struct one_pointer
return_one_pointer(struct one_pointer value)263 return_one_pointer (struct one_pointer value)
264 {
265   return value;
266 }
267 
268 struct two_pointer
269 {
270   char *first_field;
271   char *second_field;
272 };
273 
274 struct two_pointer
return_two_pointer(struct two_pointer value)275 return_two_pointer (struct two_pointer value)
276 {
277   return value;
278 }
279 
280 struct one_float_one_pointer
281 {
282   float first_field;
283   char *second_field;
284 };
285 
286 struct one_float_one_pointer
return_one_float_one_pointer(struct one_float_one_pointer value)287 return_one_float_one_pointer (struct one_float_one_pointer value)
288 {
289   return value;
290 }
291 
292 struct one_int_one_pointer
293 {
294   int first_field;
295   char *second_field;
296 };
297 
298 struct one_int_one_pointer
return_one_int_one_pointer(struct one_int_one_pointer value)299 return_one_int_one_pointer (struct one_int_one_pointer value)
300 {
301   return value;
302 }
303 
304 typedef float vector_size_float32 __attribute__((__vector_size__(16)));
305 typedef float ext_vector_size_float32 __attribute__((ext_vector_type(4)));
306 
307 vector_size_float32
return_vector_size_float32(vector_size_float32 value)308 return_vector_size_float32 (vector_size_float32 value)
309 {
310     return value;
311 }
312 
313 ext_vector_size_float32
return_ext_vector_size_float32(ext_vector_size_float32 value)314 return_ext_vector_size_float32 (ext_vector_size_float32 value)
315 {
316     return value;
317 }
318 
319 int
main()320 main ()
321 {
322   int first_int = 123456;
323   int second_int = 234567;
324 
325   outer_sint (first_int);
326   outer_sint (second_int);
327 
328   float first_float_value = 12.34;
329   float second_float_value = 23.45;
330 
331   outer_float (first_float_value);
332   outer_float (second_float_value);
333 
334   double double_value = -23.45;
335 
336   return_double (double_value);
337 
338   return_pointer(g_first_pointer);
339 
340   long double long_double_value = -3456789.987654321;
341 
342   return_long_double (long_double_value);
343 
344   // Okay, now the structures:
345   return_one_int ((struct one_int) {10});
346   return_two_int ((struct two_int) {10, 20});
347   return_three_int ((struct three_int) {10, 20, 30});
348   return_four_int ((struct four_int) {10, 20, 30, 40});
349   return_five_int ((struct five_int) {10, 20, 30, 40, 50});
350 
351   return_two_double ((struct two_double) {10.0, 20.0});
352   return_one_double_two_float ((struct one_double_two_float) {10.0, 20.0, 30.0});
353   return_one_int_one_float_one_int ((struct one_int_one_float_one_int) {10, 20.0, 30});
354 
355   return_one_pointer ((struct one_pointer) {g_first_pointer});
356   return_two_pointer ((struct two_pointer) {g_first_pointer, g_second_pointer});
357   return_one_float_one_pointer ((struct one_float_one_pointer) {10.0, g_first_pointer});
358   return_one_int_one_pointer ((struct one_int_one_pointer) {10, g_first_pointer});
359   return_three_short_one_float ((struct three_short_one_float) {10, 20, 30, 40.0});
360 
361   return_one_int_one_double ((struct one_int_one_double) {10, 20.0});
362   return_one_int_one_double_one_int ((struct one_int_one_double_one_int) {10, 20.0, 30});
363   return_one_short_one_double_one_short ((struct one_short_one_double_one_short) {10, 20.0, 30});
364   return_one_float_one_int_one_float ((struct one_float_one_int_one_float) {10.0, 20, 30.0});
365   return_two_float ((struct two_float) { 10.0, 20.0});
366   return_one_int_one_double_packed ((struct one_int_one_double_packed) {10, 20.0});
367   return_one_int_one_long ((struct one_int_one_long) {10, 20});
368 
369   return_vector_size_float32 (( vector_size_float32 ){1.5, 2.25, 4.125, 8.0625});
370   return_ext_vector_size_float32 ((ext_vector_size_float32){ 16.5, 32.25, 64.125, 128.0625});
371 
372   return 0;
373 
374 }
375