]>
Commit | Line | Data |
---|---|---|
ef44eed1 SS |
1 | /* Test passing of arguments to functions. Use various sorts of arguments, |
2 | including basic types, pointers to those types, structures, lots of | |
3 | args, etc, in various combinations. */ | |
4 | ||
5 | /* AIX requires this to be the first thing in the file. */ | |
6 | #ifdef __GNUC__ | |
7 | # define alloca __builtin_alloca | |
8 | # define HAVE_STACK_ALLOCA 1 | |
9 | #else /* not __GNUC__ */ | |
10 | # ifdef _AIX | |
11 | #pragma alloca | |
12 | # define HAVE_STACK_ALLOCA 1 | |
13 | # else /* Not AIX */ | |
14 | # ifdef sparc | |
15 | # include <alloca.h> | |
16 | # define HAVE_STACK_ALLOCA 1 | |
17 | char *alloca (); | |
18 | # endif /* sparc */ | |
19 | # endif /* Not AIX */ | |
20 | #endif /* not __GNUC__ */ | |
21 | ||
22 | char c = 'a'; | |
23 | char *cp = &c; | |
24 | ||
25 | unsigned char uc = 'b'; | |
26 | unsigned char *ucp = &uc; | |
27 | ||
28 | short s = 1; | |
29 | short *sp = &s; | |
30 | ||
31 | unsigned short us = 6; | |
32 | unsigned short *usp = &us; | |
33 | ||
34 | int i = 2; | |
35 | int *ip = &i; | |
36 | ||
37 | unsigned int ui = 7; | |
38 | unsigned int *uip = &ui; | |
39 | ||
40 | long l = 3; | |
41 | long *lp = &l; | |
42 | ||
43 | unsigned long ul = 8; | |
44 | unsigned long *ulp = &ul; | |
45 | ||
46 | float f = 4.0; | |
47 | float *fp = &f; | |
48 | ||
49 | double d = 5.0; | |
50 | double *dp = &d; | |
51 | ||
52 | struct stag { | |
53 | int s1; | |
54 | int s2; | |
55 | } st = { 101, 102 }; | |
56 | struct stag *stp = &st; | |
57 | ||
58 | union utag { | |
59 | int u1; | |
60 | long u2; | |
61 | } un; | |
62 | union utag *unp = &un; | |
63 | ||
64 | char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'}; | |
65 | ||
66 | ||
67 | /* Test various permutations and interleaving of integral arguments */ | |
68 | ||
69 | ||
70 | call0a (c, s, i, l) | |
71 | char c; short s; int i; long l; | |
72 | { | |
73 | c = 'a'; | |
74 | s = 5; | |
75 | i = 6; | |
76 | l = 7; | |
77 | } | |
78 | ||
79 | call0b (s, i, l, c) | |
80 | short s; int i; long l; char c; | |
81 | { | |
82 | s = 6; i = 7; l = 8; c = 'j'; | |
83 | } | |
84 | ||
85 | call0c (i, l, c, s) | |
86 | int i; long l; char c; short s; | |
87 | { | |
88 | i = 3; l = 4; c = 'k'; s = 5; | |
89 | } | |
90 | ||
91 | call0d (l, c, s, i) | |
92 | long l; char c; short s; int i; | |
93 | { | |
94 | l = 7; c = 'z'; s = 8; i = 9; | |
95 | } | |
96 | ||
97 | call0e (c1, l, c2, i, c3, s, c4, c5) | |
98 | char c1; long l; char c2; int i; char c3; short s; char c4; char c5; | |
99 | { | |
100 | c1 = 'a'; l = 5; c2 = 'b'; i = 7; c3 = 'c'; s = 7; c4 = 'f'; c5 = 'g'; | |
101 | } | |
102 | ||
103 | ||
104 | /* Test various permutations and interleaving of unsigned integral arguments */ | |
105 | ||
106 | ||
107 | call1a (uc, us, ui, ul) | |
108 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
109 | { | |
110 | uc = 5; us = 6; ui = 7; ul = 8; | |
111 | } | |
112 | ||
113 | call1b (us, ui, ul, uc) | |
114 | unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc; | |
115 | { | |
116 | uc = 5; us = 6; ui = 7; ul = 8; | |
117 | } | |
118 | ||
119 | call1c (ui, ul, uc, us) | |
120 | unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us; | |
121 | { | |
122 | uc = 5; us = 6; ui = 7; ul = 8; | |
123 | } | |
124 | ||
125 | call1d (ul, uc, us, ui) | |
126 | unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui; | |
127 | { | |
128 | uc = 5; us = 6; ui = 7; ul = 8; | |
129 | } | |
130 | ||
131 | call1e (uc1, ul, uc2, ui, uc3, us, uc4, uc5) | |
132 | unsigned char uc1; unsigned long ul; unsigned char uc2; unsigned int ui; | |
133 | unsigned char uc3; unsigned short us; unsigned char uc4; unsigned char uc5; | |
134 | { | |
135 | uc1 = 5; ul = 7; uc2 = 8; ui = 9; uc3 = 10; us = 11; uc4 = 12; uc5 = 55; | |
136 | } | |
137 | ||
138 | /* Test various permutations and interleaving of integral arguments with | |
139 | floating point arguments. */ | |
140 | ||
141 | ||
142 | call2a (c, f1, s, d1, i, f2, l, d2) | |
143 | char c; float f1; short s; double d1; int i; float f2; long l; double d2; | |
144 | { | |
145 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
146 | } | |
147 | ||
148 | call2b (f1, s, d1, i, f2, l, d2, c) | |
149 | float f1; short s; double d1; int i; float f2; long l; double d2; char c; | |
150 | { | |
151 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
152 | } | |
153 | ||
154 | call2c (s, d1, i, f2, l, d2, c, f1) | |
155 | short s; double d1; int i; float f2; long l; double d2; char c; float f1; | |
156 | { | |
157 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
158 | } | |
159 | ||
160 | call2d (d1, i, f2, l, d2, c, f1, s) | |
161 | double d1; int i; float f2; long l; double d2; char c; float f1; short s; | |
162 | { | |
163 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
164 | } | |
165 | ||
166 | call2e (i, f2, l, d2, c, f1, s, d1) | |
167 | int i; float f2; long l; double d2; char c; float f1; short s; double d1; | |
168 | { | |
169 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
170 | } | |
171 | ||
172 | call2f (f2, l, d2, c, f1, s, d1, i) | |
173 | float f2; long l; double d2; char c; float f1; short s; double d1; int i; | |
174 | { | |
175 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
176 | } | |
177 | ||
178 | call2g (l, d2, c, f1, s, d1, i, f2) | |
179 | long l; double d2; char c; float f1; short s; double d1; int i; float f2; | |
180 | { | |
181 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
182 | } | |
183 | ||
184 | call2h (d2, c, f1, s, d1, i, f2, l) | |
185 | double d2; char c; float f1; short s; double d1; int i; float f2; long l; | |
186 | { | |
187 | c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2; | |
188 | } | |
189 | ||
190 | call2i (c1, f1, c2, c3, d1, c4, c5, c6, f2, s, c7, d2) | |
191 | char c1; float f1; char c2; char c3; double d1; char c4; char c5; char c6; | |
192 | float f2; short s; char c7; double d2; | |
193 | { | |
194 | c1 = 'a'; f1 = 0.0; c2 = 5; d1 = 0.0; c3 = 6; f2 = 0.1; c4 = 7; d2 = 0.2; | |
195 | c5 = 's'; c6 = 'f'; c7 = 'z'; s = 77; | |
196 | } | |
197 | ||
198 | ||
199 | /* Test pointers to various integral and floating types. */ | |
200 | ||
201 | ||
202 | call3a (cp, sp, ip, lp) | |
203 | char *cp; short *sp; int *ip; long *lp; | |
204 | { | |
205 | cp = 0; sp = 0; ip = 0; lp = 0; | |
206 | } | |
207 | ||
208 | call3b (ucp, usp, uip, ulp) | |
209 | unsigned char *ucp; unsigned short *usp; unsigned int *uip; | |
210 | unsigned long *ulp; | |
211 | { | |
212 | ucp = 0; usp = 0; uip = 0; ulp = 0; | |
213 | } | |
214 | ||
215 | call3c (fp, dp) | |
216 | float *fp; double *dp; | |
217 | { | |
218 | fp = 0; dp = 0; | |
219 | } | |
220 | ||
221 | ||
222 | /* Test passing structures and unions by reference. */ | |
223 | ||
224 | ||
225 | call4a (stp) | |
226 | struct stag *stp; { | |
227 | stp = 0;} | |
228 | ||
229 | call4b (unp) | |
230 | union utag *unp; | |
231 | { | |
232 | unp = 0; | |
233 | } | |
234 | ||
235 | ||
236 | /* Test passing structures and unions by value. */ | |
237 | ||
238 | ||
239 | call5a (st) | |
240 | struct stag st; {st.s1 = 5;} | |
241 | ||
242 | call5b (un) | |
243 | union utag un; {un.u1 = 7;} | |
244 | ||
245 | ||
246 | /* Test shuffling of args */ | |
247 | ||
248 | ||
249 | call6a (c, s, i, l, f, d, uc, us, ui, ul) | |
250 | char c; short s; int i; long l; float f; double d; | |
251 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
252 | { | |
253 | c = c; | |
254 | call6b (s, i, l, f, d, uc, us, ui, ul); | |
255 | } | |
256 | ||
257 | call6b (s, i, l, f, d, uc, us, ui, ul) | |
258 | short s; int i; long l; float f; double d; | |
259 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
260 | { | |
261 | s = s; | |
262 | call6c (i, l, f, d, uc, us, ui, ul); | |
263 | } | |
264 | ||
265 | call6c (i, l, f, d, uc, us, ui, ul) | |
266 | int i; long l; float f; double d; | |
267 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
268 | { | |
269 | i = i; | |
270 | call6d (l, f, d, uc, us, ui, ul); | |
271 | } | |
272 | ||
273 | call6d (l, f, d, uc, us, ui, ul) | |
274 | long l; float f; double d; | |
275 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
276 | { | |
277 | l = l; | |
278 | call6e (f, d, uc, us, ui, ul); | |
279 | } | |
280 | ||
281 | call6e (f, d, uc, us, ui, ul) | |
282 | float f; double d; | |
283 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
284 | { | |
285 | f = f; | |
286 | call6f (d, uc, us, ui, ul); | |
287 | } | |
288 | ||
289 | call6f (d, uc, us, ui, ul) | |
290 | double d; | |
291 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
292 | { | |
293 | d = d; | |
294 | call6g (uc, us, ui, ul); | |
295 | } | |
296 | ||
297 | call6g (uc, us, ui, ul) | |
298 | unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; | |
299 | { | |
300 | uc = uc; | |
301 | call6h (us, ui, ul); | |
302 | } | |
303 | ||
304 | call6h (us, ui, ul) | |
305 | unsigned short us; unsigned int ui; unsigned long ul; | |
306 | { | |
307 | us = us; | |
308 | call6i (ui, ul); | |
309 | } | |
310 | ||
311 | call6i (ui, ul) | |
312 | unsigned int ui; unsigned long ul; | |
313 | { | |
314 | ui = ui; | |
315 | call6j (ul); | |
316 | } | |
317 | ||
318 | call6j (ul) | |
319 | unsigned long ul; | |
320 | { | |
321 | ul = ul; | |
322 | call6k (); | |
323 | } | |
324 | ||
325 | call6k () | |
326 | { | |
327 | } | |
328 | ||
329 | ||
330 | /* Test shuffling of args, round robin */ | |
331 | ||
332 | ||
333 | call7a (c, i, s, l, f, uc, d, us, ul, ui) | |
334 | char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; | |
335 | { | |
336 | call7b (i, s, l, f, uc, d, us, ul, ui, c); | |
337 | } | |
338 | ||
339 | call7b (i, s, l, f, uc, d, us, ul, ui, c) | |
340 | int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; | |
341 | { | |
342 | call7c (s, l, f, uc, d, us, ul, ui, c, i); | |
343 | } | |
344 | ||
345 | call7c (s, l, f, uc, d, us, ul, ui, c, i) | |
346 | short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; | |
347 | { | |
348 | call7d (l, f, uc, d, us, ul, ui, c, i, s); | |
349 | } | |
350 | ||
351 | call7d (l, f, uc, d, us, ul, ui, c, i, s) | |
352 | long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; | |
353 | { | |
354 | call7e (f, uc, d, us, ul, ui, c, i, s, l); | |
355 | } | |
356 | ||
357 | call7e (f, uc, d, us, ul, ui, c, i, s, l) | |
358 | float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; | |
359 | { | |
360 | call7f (uc, d, us, ul, ui, c, i, s, l, f); | |
361 | } | |
362 | ||
363 | call7f (uc, d, us, ul, ui, c, i, s, l, f) | |
364 | unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; | |
365 | { | |
366 | call7g (d, us, ul, ui, c, i, s, l, f, uc); | |
367 | } | |
368 | ||
369 | call7g (d, us, ul, ui, c, i, s, l, f, uc) | |
370 | double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; | |
371 | { | |
372 | call7h (us, ul, ui, c, i, s, l, f, uc, d); | |
373 | } | |
374 | ||
375 | call7h (us, ul, ui, c, i, s, l, f, uc, d) | |
376 | unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; | |
377 | { | |
378 | call7i (ul, ui, c, i, s, l, f, uc, d, us); | |
379 | } | |
380 | ||
381 | call7i (ul, ui, c, i, s, l, f, uc, d, us) | |
382 | unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; | |
383 | { | |
384 | call7j (ui, c, i, s, l, f, uc, d, us, ul); | |
385 | } | |
386 | ||
387 | call7j (ui, c, i, s, l, f, uc, d, us, ul) | |
388 | unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; | |
389 | { | |
390 | call7k (c, i, s, l, f, uc, d, us, ul, ui); | |
391 | } | |
392 | ||
393 | call7k (c, i, s, l, f, uc, d, us, ul, ui) | |
394 | char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; | |
395 | { | |
396 | c = 'a'; i = 7; s = 8; l = 7; f = 0.3; uc = 44; d = 0.44; us = 77; | |
397 | ul = 43; ui = 33; | |
398 | } | |
399 | ||
400 | ||
401 | /* Test printing of structures passed as arguments to recursive functions. */ | |
402 | ||
403 | ||
404 | typedef struct s | |
405 | { | |
406 | short s; | |
407 | int i; | |
408 | long l; | |
409 | } SVAL; | |
410 | ||
411 | hitbottom () | |
412 | { | |
413 | } | |
414 | ||
415 | void recurse (a, depth) | |
416 | SVAL a; | |
417 | int depth; | |
418 | { | |
419 | a.s = a.i = a.l = --depth; | |
420 | if (depth == 0) | |
421 | hitbottom (); | |
422 | else | |
423 | recurse (a, depth); | |
424 | } | |
425 | ||
426 | test_struct_args () | |
427 | { | |
428 | SVAL s; s.s = 5; s.i = 5; s.l = 5; | |
429 | ||
430 | recurse (s, 5); | |
431 | } | |
432 | ||
433 | /* On various machines (pa, 29k, and rs/6000, at least), a function which | |
434 | calls alloca may do things differently with respect to frames. So give | |
435 | it a try. */ | |
436 | ||
437 | int | |
438 | localvars_after_alloca (c, s, i, l) | |
439 | char c; | |
440 | short s; | |
441 | int i; | |
442 | long l; | |
443 | { | |
444 | #ifdef HAVE_STACK_ALLOCA | |
445 | /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't | |
446 | test what we are looking for, so if we don't have an alloca which | |
447 | allocates on the stack, just don't bother to call alloca at all. */ | |
448 | ||
449 | char *z = alloca (s + 50); | |
450 | #endif | |
451 | c = 'a'; | |
452 | s = 5; | |
453 | i = 6; | |
454 | l = 7; | |
455 | } | |
456 | \f | |
457 | ||
458 | /* The point behind this test is the PA will call this indirectly | |
459 | through dyncall. Unlike the indirect calls to call0a, this test | |
460 | will require a trampoline between dyncall and this function on the | |
461 | call path, then another trampoline on between this function and main | |
462 | on the return path. */ | |
463 | double | |
464 | call_with_trampolines (d1) | |
465 | double d1; | |
466 | { | |
467 | return d1; | |
468 | } /* End of call_with_trampolines, this comment is needed by funcargs.exp */ | |
469 | ||
470 | /* Dummy functions which the testsuite can use to run to, etc. */ | |
471 | ||
472 | void | |
473 | marker_indirect_call () {} | |
474 | ||
475 | void | |
476 | marker_call_with_trampolines () {} | |
477 | \f | |
478 | main () | |
479 | { | |
480 | int (*pointer_to_call0a) () = call0a; | |
481 | double (*pointer_to_call_with_trampolines) () = call_with_trampolines; | |
482 | ||
483 | /* Test calling with basic integer types */ | |
484 | call0a (c, s, i, l); | |
485 | call0b (s, i, l, c); | |
486 | call0c (i, l, c, s); | |
487 | call0d (l, c, s, i); | |
488 | call0e (c, l, c, i, c, s, c, c); | |
489 | ||
490 | /* Test calling with unsigned integer types */ | |
491 | call1a (uc, us, ui, ul); | |
492 | call1b (us, ui, ul, uc); | |
493 | call1c (ui, ul, uc, us); | |
494 | call1d (ul, uc, us, ui); | |
495 | call1e (uc, ul, uc, ui, uc, us, uc, uc); | |
496 | ||
497 | /* Test calling with integral types mixed with floating point types */ | |
498 | call2a (c, f, s, d, i, f, l, d); | |
499 | call2b (f, s, d, i, f, l, d, c); | |
500 | call2c (s, d, i, f, l, d, c, f); | |
501 | call2d (d, i, f, l, d, c, f, s); | |
502 | call2e (i, f, l, d, c, f, s, d); | |
503 | call2f (f, l, d, c, f, s, d, i); | |
504 | call2g (l, d, c, f, s, d, i, f); | |
505 | call2h (d, c, f, s, d, i, f, l); | |
506 | call2i (c, f, c, c, d, c, c, c, f, s, c, d);; | |
507 | ||
508 | /* Test dereferencing pointers to various integral and floating types */ | |
509 | ||
510 | call3a (cp, sp, ip, lp); | |
511 | call3b (ucp, usp, uip, ulp); | |
512 | call3c (fp, dp); | |
513 | ||
514 | /* Test dereferencing pointers to structs and unions */ | |
515 | ||
516 | call4a (stp); | |
517 | un.u1 = 1; | |
518 | call4b (unp); | |
519 | ||
520 | /* Test calling with structures and unions. */ | |
521 | ||
522 | call5a (st); | |
523 | un.u1 = 2; | |
524 | call5b (un); | |
525 | ||
526 | /* Test shuffling of args */ | |
527 | ||
528 | call6a (c, s, i, l, f, d, uc, us, ui, ul); | |
529 | call7a (c, i, s, l, f, uc, d, us, ul, ui); | |
530 | ||
531 | /* Test passing structures recursively. */ | |
532 | ||
533 | test_struct_args (); | |
534 | ||
535 | localvars_after_alloca (c, s, i, l); | |
536 | ||
537 | /* This is for localvars_in_indirect_call. */ | |
538 | marker_indirect_call (); | |
539 | /* The comment on the following two lines is used by funcargs.exp, | |
540 | don't change it. */ | |
541 | (*pointer_to_call0a) (c, s, i, l); /* First step into call0a. */ | |
542 | (*pointer_to_call0a) (c, s, i, l); /* Second step into call0a. */ | |
543 | marker_call_with_trampolines (); | |
544 | (*pointer_to_call_with_trampolines) (d); /* Test multiple trampolines. */ | |
545 | } |