gdb/doc/
[external/binutils.git] / gdb / testsuite / gdb.base / funcargs.c
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 #      ifdef __STDC__
18          void *alloca ();
19 #      else
20          char *alloca ();
21 #      endif /* __STDC__ */
22 #    endif /* sparc */
23 #  endif /* Not AIX */
24 #endif /* not __GNUC__ */
25
26 char c = 'a';
27 char *cp = &c;
28
29 unsigned char uc = 'b';
30 unsigned char *ucp = &uc;
31
32 short s = 1;
33 short *sp = &s;
34
35 unsigned short us = 6;
36 unsigned short *usp = &us;
37
38 int i = 2;
39 int *ip = &i;
40
41 unsigned int ui = 7;
42 unsigned int *uip = &ui;
43
44 long l = 3;
45 long *lp = &l;
46
47 unsigned long ul = 8;
48 unsigned long *ulp = &ul;
49
50 float f = 4.0;
51 float *fp = &f;
52
53 double d = 5.0;
54 double *dp = &d;
55
56 #ifdef TEST_COMPLEX
57 float _Complex fc = 1.0F + 2.0iF;
58 double _Complex dc = 3.0 + 4.0i;
59 long double _Complex ldc = 5.0L + 6.0iL;
60 #endif /* TEST_COMPLEX */
61
62 struct stag {
63     int s1;
64     int s2;
65 } st = { 101, 102 };
66 struct stag *stp = &st;
67
68 union utag {
69     int u1;
70     long u2;
71 } un;
72 union utag *unp = &un;
73
74 char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
75
76
77 /* Test various permutations and interleaving of integral arguments */
78
79
80 #ifdef PROTOTYPES
81 void call0a (char c, short s, int i, long l)
82 #else
83 call0a (c, s, i, l)
84 char c; short s; int i; long l;
85 #endif
86 {
87   c = 'a';
88   s = 5;
89   i = 6;
90   l = 7;
91 }
92
93 #ifdef PROTOTYPES
94 void call0b (short s, int i, long l, char c)
95 #else
96 call0b (s, i, l, c)
97 short s; int i; long l; char c;
98 #endif
99 {
100   s = 6; i = 7; l = 8; c = 'j';
101 }
102
103 #ifdef PROTOTYPES
104 void call0c (int i, long l, char c, short s)
105 #else
106 call0c (i, l, c, s)
107 int i; long l; char c; short s;
108 #endif
109 {
110   i = 3; l = 4; c = 'k'; s = 5;
111 }
112
113 #ifdef PROTOTYPES
114 void call0d (long l, char c, short s, int i)
115 #else
116 call0d (l, c, s, i)
117 long l; char c; short s; int i;
118 #endif
119 {
120   l = 7; c = 'z'; s = 8; i = 9;
121 }
122
123 #ifdef PROTOTYPES
124 void call0e (char c1, long l, char c2, int i, char c3, short s, char c4, char c5)
125 #else
126 call0e (c1, l, c2, i, c3, s, c4, c5)
127 char c1; long l; char c2; int i; char c3; short s; char c4; char c5;
128 #endif
129 {
130   c1 = 'a'; l = 5; c2 = 'b'; i = 7; c3 = 'c'; s = 7; c4 = 'f'; c5 = 'g';
131 }
132
133
134 /* Test various permutations and interleaving of unsigned integral arguments */
135
136
137 #ifdef PROTOTYPES
138 void call1a (unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
139 #else
140 call1a (uc, us, ui, ul)
141 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
142 #endif
143 {
144   uc = 5; us = 6; ui = 7; ul = 8;
145 }
146
147 #ifdef PROTOTYPES
148 void call1b (unsigned short us, unsigned int ui, unsigned long ul, unsigned char uc)
149 #else
150 call1b (us, ui, ul, uc)
151 unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc;
152 #endif
153 {
154   uc = 5; us = 6; ui = 7; ul = 8;
155 }
156
157 #ifdef PROTOTYPES
158 void call1c (unsigned int ui, unsigned long ul, unsigned char uc, unsigned short us)
159 #else
160 call1c (ui, ul, uc, us)
161 unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us;
162 #endif
163 {
164   uc = 5; us = 6; ui = 7; ul = 8;
165 }
166
167 #ifdef PROTOTYPES
168 void call1d (unsigned long ul, unsigned char uc, unsigned short us, unsigned int ui)
169 #else
170 call1d (ul, uc, us, ui)
171 unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui;
172 #endif
173 {
174   uc = 5; us = 6; ui = 7; ul = 8;
175 }
176
177 #ifdef PROTOTYPES
178 void call1e (unsigned char uc1, unsigned long ul, unsigned char uc2, unsigned int ui, unsigned char uc3, unsigned short us, unsigned char uc4, unsigned char uc5)
179 #else
180 call1e (uc1, ul, uc2, ui, uc3, us, uc4, uc5)
181 unsigned char uc1; unsigned long ul; unsigned char uc2; unsigned int ui;
182 unsigned char uc3; unsigned short us; unsigned char uc4; unsigned char uc5;
183 #endif
184 {
185   uc1 = 5; ul = 7; uc2 = 8; ui = 9; uc3 = 10; us = 11; uc4 = 12; uc5 = 55;
186 }
187
188 /* Test various permutations and interleaving of integral arguments with
189    floating point arguments. */
190
191
192 #ifdef PROTOTYPES
193 void call2a (char c, float f1, short s, double d1, int i, float f2, long l, double d2)
194 #else
195 call2a (c, f1, s, d1, i, f2, l, d2)
196 char c; float f1; short s; double d1; int i; float f2; long l; double d2;
197 #endif
198 {
199   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
200 }
201
202 #ifdef PROTOTYPES
203 void call2b (float f1, short s, double d1, int i, float f2, long l, double d2, char c)
204 #else
205 call2b (f1, s, d1, i, f2, l, d2, c)
206 float f1; short s; double d1; int i; float f2; long l; double d2; char c;
207 #endif
208 {
209   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
210 }
211
212 #ifdef PROTOTYPES
213 void call2c (short s, double d1, int i, float f2, long l, double d2, char c, float f1)
214 #else
215 call2c (s, d1, i, f2, l, d2, c, f1)
216 short s; double d1; int i; float f2; long l; double d2; char c; float f1;
217 #endif
218 {
219   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
220 }
221
222 #ifdef PROTOTYPES
223 void call2d (double d1, int i, float f2, long l, double d2, char c, float f1, short s)
224 #else
225 call2d (d1, i, f2, l, d2, c, f1, s)
226 double d1; int i; float f2; long l; double d2; char c; float f1; short s;
227 #endif
228 {
229   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
230 }
231
232 #ifdef PROTOTYPES
233 void call2e (int i, float f2, long l, double d2, char c, float f1, short s, double d1)
234 #else
235 call2e (i, f2, l, d2, c, f1, s, d1)
236 int i; float f2; long l; double d2; char c; float f1; short s; double d1;
237 #endif
238 {
239   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
240 }
241
242 #ifdef PROTOTYPES
243 void call2f (float f2, long l, double d2, char c, float f1, short s, double d1, int i)
244 #else
245 call2f (f2, l, d2, c, f1, s, d1, i)
246 float f2; long l; double d2; char c; float f1; short s; double d1; int i;
247 #endif
248 {
249   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
250 }
251
252 #ifdef PROTOTYPES
253 void call2g (long l, double d2, char c, float f1, short s, double d1, int i, float f2)
254 #else
255 call2g (l, d2, c, f1, s, d1, i, f2)
256 long l; double d2; char c; float f1; short s; double d1; int i; float f2;
257 #endif
258 {
259   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
260 }
261
262 #ifdef PROTOTYPES
263 void call2h (double d2, char c, float f1, short s, double d1, int i, float f2, long l)
264 #else
265 call2h (d2, c, f1, s, d1, i, f2, l)
266 double d2; char c; float f1; short s; double d1; int i; float f2; long l;
267 #endif
268 {
269   c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
270 }
271
272 #ifdef PROTOTYPES
273 void call2i (char c1, float f1, char c2, char c3, double d1, char c4, char c5, char c6, float f2, short s, char c7, double d2)
274 #else
275 call2i (c1, f1, c2, c3, d1, c4, c5, c6, f2, s, c7, d2)
276 char c1; float f1; char c2; char c3; double d1; char c4; char c5; char c6;
277 float f2; short s; char c7; double d2;
278 #endif
279 {
280   c1 = 'a'; f1 = 0.0; c2 = 5; d1 = 0.0; c3 = 6; f2 = 0.1; c4 = 7; d2 = 0.2;
281   c5 = 's'; c6 = 'f'; c7 = 'z'; s = 77;
282 }
283
284
285 /* Test pointers to various integral and floating types. */
286
287
288 #ifdef PROTOTYPES
289 void call3a (char *cp, short *sp, int *ip, long *lp)
290 #else
291 call3a (cp, sp, ip, lp)
292 char *cp; short *sp; int *ip; long *lp;
293 #endif
294 {
295   cp = 0; sp = 0; ip = 0; lp = 0;
296 }
297
298 #ifdef PROTOTYPES
299 void call3b (unsigned char *ucp, unsigned short *usp, unsigned int *uip, unsigned long *ulp)
300 #else
301 call3b (ucp, usp, uip, ulp)
302 unsigned char *ucp; unsigned short *usp; unsigned int *uip;
303 unsigned long *ulp;
304 #endif
305 {
306   ucp = 0; usp = 0; uip = 0; ulp = 0;
307 }
308
309 #ifdef PROTOTYPES
310 void call3c (float *fp, double *dp)
311 #else
312 call3c (fp, dp)
313 float *fp; double *dp;
314 #endif
315 {
316   fp = 0; dp = 0;
317 }
318
319
320
321 #ifdef TEST_COMPLEX
322
323 /* Test various _Complex type args.  */
324
325 #ifdef PROTOTYPES
326 void callca (float _Complex f1, float _Complex f2, float _Complex f3)
327 #else
328 callca (f1, f2, f3)
329 float _Complex f1; float _Complex f2; float _Complex f3;
330 #endif
331 {
332
333 }
334
335 #ifdef PROTOTYPES
336 void callcb (double _Complex d1, double _Complex d2, double _Complex d3)
337 #else
338 callcb (d1, d2, d3)
339 double _Complex d1; double _Complex d2; double _Complex d3;
340 #endif
341 {
342
343 }
344
345 #ifdef PROTOTYPES
346 void callcc (long double _Complex ld1, long double _Complex ld2, long double _Complex ld3)
347 #else
348 callcc (ld1, ld2, ld3)
349 long double _Complex ld1; long double _Complex ld2; long double _Complex ld3;
350 #endif
351 {
352
353 }
354
355 #ifdef PROTOTYPES
356 void callcd (float _Complex fc1, double _Complex dc1, long double _Complex ldc1)
357 #else
358 callcd (fc1, dc1, ldc1)
359 float _Complex fc1; double _Complex dc1; long double _Complex ldc1;
360 #endif
361 {
362 }
363
364 #ifdef PROTOTYPES
365 void callce (double _Complex dc1, long double _Complex ldc1, float _Complex fc1)
366 #else
367 callce (dc1, ldc1, fc1)
368 double _Complex dc1; long double _Complex ldc1; float _Complex fc1;
369 #endif
370 {
371 }
372
373 #ifdef PROTOTYPES
374 void callcf (long double _Complex ldc1, float _Complex fc1, double _Complex dc1)
375 #else
376 callcf (ldc1, fc1, dc1)
377 long double _Complex ldc1; float _Complex fc1; double _Complex dc1;
378 #endif
379 {
380 }
381
382
383 /* Test passing _Complex type and integral.  */
384 #ifdef PROTOTYPES
385 void callc1a (char c, short s, int i, unsigned int ui, long l,
386               float _Complex fc1, double _Complex dc1,
387               long double _Complex ldc1)
388 #else
389 callc1a (c, s, i, ui, l, fc1, dc1, ldc1)
390 char c; short s; int i; unsigned int ui; long l; float _Complex fc1; double _Complex dc1; long double _Complex ldc1;
391 #endif
392 {}
393
394 #ifdef PROTOTYPES
395 void callc1b (long double _Complex ldc1, char c, short s, int i,
396               float _Complex fc1, unsigned int ui, long l,  double _Complex dc1)
397 #else
398 callc1b (ldc1, c, s, i, fc1, ui, l, dc1)
399 char c; short s; int i; unsigned int ui; long l; float _Complex fc1; double _Complex dc1; long double _Complex ldc1;
400 #endif
401 {}
402
403
404 #ifdef PROTOTYPES
405 void callc2a (char c, short s, int i, unsigned int ui, long l, float f,
406               double d, float _Complex fc1, double _Complex dc1,
407               long double _Complex ldc1)
408 #else
409 callc2a (c, s, i, ui, l, f, d, fc1, dc1, ldc1)
410      char c; short s; int i; unsigned int ui; long l; float f; double d;
411      float _Complex fc1; double _Complex dc1;
412      long double _Complex ldc1;
413 #endif
414 {}
415
416 #ifdef PROTOTYPES
417 void callc2b (float _Complex fc1, char c, short s, int i, unsigned int ui,
418               long double _Complex ldc1, long l, float f, double d,
419               double _Complex dc1)
420 #else
421 callc2b (fc1, c, s, i, ui, ldc1, l, f, d, dc1)
422      char c; short s; int i; unsigned int ui; long l; float f; double d;
423      float _Complex fc1; double _Complex dc1;
424      long double _Complex ldc1;
425 #endif
426 {}
427
428
429 #endif /* TEST_COMPLEX */
430
431 /* Test passing structures and unions by reference. */
432
433
434 #ifdef PROTOTYPES
435 void call4a (struct stag *stp)
436 #else
437 call4a (stp)
438 struct stag *stp;
439 #endif
440 {stp = 0;}
441
442 #ifdef PROTOTYPES
443 void call4b (union utag *unp)
444 #else
445 call4b (unp)
446 union utag *unp;
447 #endif
448 {
449   unp = 0;
450 }
451
452
453 /* Test passing structures and unions by value. */
454
455
456 #ifdef PROTOTYPES
457 void call5a (struct stag st)
458 #else
459 call5a (st)
460 struct stag st;
461 #endif
462 {st.s1 = 5;}
463
464 #ifdef PROTOTYPES
465 void call5b (union utag un)
466 #else
467 call5b (un)
468 union utag un;
469 #endif
470 {un.u1 = 7;}
471
472
473 /* Test shuffling of args */
474
475
476 void call6k ()
477 {
478 }
479
480 #ifdef PROTOTYPES
481 void call6j (unsigned long ul)
482 #else
483 call6j (ul)
484 unsigned long ul;
485 #endif
486 {
487   ul = ul;
488     call6k ();
489 }
490
491 #ifdef PROTOTYPES
492 void call6i (unsigned int ui, unsigned long ul)
493 #else
494 call6i (ui, ul)
495 unsigned int ui; unsigned long ul;
496 #endif
497 {
498   ui = ui;
499     call6j (ul);
500 }
501
502 #ifdef PROTOTYPES
503 void call6h (unsigned short us, unsigned int ui, unsigned long ul)
504 #else
505 call6h (us, ui, ul)
506 unsigned short us; unsigned int ui; unsigned long ul;
507 #endif
508 {
509   us = us;
510     call6i (ui, ul);
511 }
512
513 #ifdef PROTOTYPES
514 void call6g (unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
515 #else
516 call6g (uc, us, ui, ul)
517 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
518 #endif
519 {
520   uc = uc;
521     call6h (us, ui, ul);
522 }
523
524 #ifdef PROTOTYPES
525 void call6f (double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
526 #else
527 call6f (d, uc, us, ui, ul)
528 double d;
529 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
530 #endif
531 {
532   d = d;
533     call6g (uc, us, ui, ul);
534 }
535
536 #ifdef PROTOTYPES
537 void call6e (float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
538 #else
539 call6e (f, d, uc, us, ui, ul)
540 float f; double d;
541 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
542 #endif
543 {
544   f = f;
545     call6f (d, uc, us, ui, ul);
546 }
547
548 #ifdef PROTOTYPES
549 void call6d (long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
550 #else
551 call6d (l, f, d, uc, us, ui, ul)
552 long l; float f; double d;
553 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
554 #endif
555 {
556   l = l;
557     call6e (f, d, uc, us, ui, ul);
558 }
559
560 #ifdef PROTOTYPES
561 void call6c (int i, long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
562 #else
563 call6c (i, l, f, d, uc, us, ui, ul)
564 int i; long l; float f; double d;
565 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
566 #endif
567 {
568   i = i;
569     call6d (l, f, d, uc, us, ui, ul);
570 }
571
572 #ifdef PROTOTYPES
573 void call6b (short s, int i, long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
574 #else
575 call6b (s, i, l, f, d, uc, us, ui, ul)
576 short s; int i; long l; float f; double d;
577 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
578 #endif
579 {
580   s = s;
581     call6c (i, l, f, d, uc, us, ui, ul);
582 }
583
584 #ifdef PROTOTYPES
585 void call6a (char c, short s, int i, long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
586 #else
587 call6a (c, s, i, l, f, d, uc, us, ui, ul)
588 char c; short s; int i; long l; float f; double d;
589 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
590 #endif
591 {
592   c = c;
593     call6b (s, i, l, f, d, uc, us, ui, ul);
594 }
595
596 /*  Test shuffling of args, round robin */
597
598
599 #ifdef PROTOTYPES
600 void call7k (char c, int i, short s, long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui)
601 #else
602 call7k (c, i, s, l, f, uc, d, us, ul, ui)
603 char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
604 #endif
605 {
606   c = 'a'; i = 7; s = 8; l = 7; f = 0.3; uc = 44; d = 0.44; us = 77;
607   ul = 43; ui = 33;
608 }
609
610 #ifdef PROTOTYPES
611 void call7j (unsigned int ui, char c, int i, short s, long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul)
612 #else
613 call7j (ui, c, i, s, l, f, uc, d, us, ul)
614 unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul;
615 #endif
616 {
617     call7k (c, i, s, l, f, uc, d, us, ul, ui);
618 }
619
620 #ifdef PROTOTYPES
621 void call7i (unsigned long ul, unsigned int ui, char c, int i, short s, long l, float f, unsigned char uc, double d, unsigned short us)
622 #else
623 call7i (ul, ui, c, i, s, l, f, uc, d, us)
624 unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us;
625 #endif
626 {
627     call7j (ui, c, i, s, l, f, uc, d, us, ul);
628 }
629
630 #ifdef PROTOTYPES
631 void call7h (unsigned short us, unsigned long ul, unsigned int ui, char c, int i, short s, long l, float f, unsigned char uc, double d)
632 #else
633 call7h (us, ul, ui, c, i, s, l, f, uc, d)
634 unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d;
635 #endif
636 {
637     call7i (ul, ui, c, i, s, l, f, uc, d, us);
638 }
639
640 #ifdef PROTOTYPES
641 void call7g (double d, unsigned short us, unsigned long ul, unsigned int ui, char c, int i, short s, long l, float f, unsigned char uc)
642 #else
643 call7g (d, us, ul, ui, c, i, s, l, f, uc)
644 double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc;
645 #endif
646 {
647     call7h (us, ul, ui, c, i, s, l, f, uc, d);
648 }
649
650 #ifdef PROTOTYPES
651 void call7f (unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui, char c, int i, short s, long l, float f)
652 #else
653 call7f (uc, d, us, ul, ui, c, i, s, l, f)
654 unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f;
655 #endif
656 {
657     call7g (d, us, ul, ui, c, i, s, l, f, uc);
658 }
659
660 #ifdef PROTOTYPES
661 void call7e (float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui, char c, int i, short s, long l)
662 #else
663 call7e (f, uc, d, us, ul, ui, c, i, s, l)
664 float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l;
665 #endif
666 {
667     call7f (uc, d, us, ul, ui, c, i, s, l, f);
668 }
669
670 #ifdef PROTOTYPES
671 void call7d (long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui, char c, int i, short s)
672 #else
673 call7d (l, f, uc, d, us, ul, ui, c, i, s)
674 long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s;
675 #endif
676 {
677     call7e (f, uc, d, us, ul, ui, c, i, s, l);
678 }
679
680 #ifdef PROTOTYPES
681 void call7c (short s, long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui, char c, int i)
682 #else
683 call7c (s, l, f, uc, d, us, ul, ui, c, i)
684 short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i;
685 #endif
686 {
687     call7d (l, f, uc, d, us, ul, ui, c, i, s);
688 }
689
690 #ifdef PROTOTYPES
691 void call7b (int i, short s, long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui, char c)
692 #else
693 call7b (i, s, l, f, uc, d, us, ul, ui, c)
694 int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c;
695 #endif
696 {
697     call7c (s, l, f, uc, d, us, ul, ui, c, i);
698 }
699
700 #ifdef PROTOTYPES
701 void call7a (char c, int i, short s, long l, float f, unsigned char uc, double d, unsigned short us, unsigned long ul, unsigned int ui)
702 #else
703 call7a (c, i, s, l, f, uc, d, us, ul, ui)
704 char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
705 #endif
706 {
707     call7b (i, s, l, f, uc, d, us, ul, ui, c);
708 }
709
710
711 /*  Test printing of structures passed as arguments to recursive functions. */
712
713
714 typedef struct s
715 {
716   short s;
717   int i;
718   long l;
719 } SVAL; 
720
721 void hitbottom ()
722 {
723 }
724
725 #ifdef PROTOTYPES
726 void recurse (SVAL a, int depth)
727 #else
728 void recurse (a, depth)
729 SVAL a;
730 int depth;
731 #endif
732 {
733   a.s = a.i = a.l = --depth;
734   if (depth == 0)
735     hitbottom ();
736   else
737     recurse (a, depth);
738 }
739
740 void test_struct_args ()
741 {
742   SVAL s; s.s = 5; s.i = 5; s.l = 5;
743
744   recurse (s, 5);
745 }
746
747 /* On various machines (pa, 29k, and rs/6000, at least), a function which
748    calls alloca may do things differently with respect to frames.  So give
749    it a try.  */
750
751 #ifdef PROTOTYPES
752 void localvars_after_alloca (char c, short s, int i, long l)
753 #else
754 void
755 localvars_after_alloca (c, s, i, l)
756      char c;
757      short s;
758      int i;
759      long l;
760 #endif
761 {
762 #ifdef HAVE_STACK_ALLOCA
763   /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
764      test what we are looking for, so if we don't have an alloca which
765      allocates on the stack, just don't bother to call alloca at all.  */
766
767   char *z = alloca (s + 50);
768 #endif
769   c = 'a';
770   s = 5;
771   i = 6;
772   l = 7;
773 }
774
775 #ifdef PROTOTYPES
776 void call_after_alloca_subr (char c, short s, int i, long l, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
777 #else
778 void
779 call_after_alloca_subr (c, s, i, l, uc, us, ui, ul)
780 char c; int i; short s; long l; unsigned char uc; unsigned short us; unsigned long ul; unsigned int ui;
781 #endif
782 {
783   c = 'a';
784   i = 7; s = 8; l = 7; uc = 44; us = 77;
785   ul = 43; ui = 33;
786 }
787
788 #ifdef PROTOTYPES
789 void call_after_alloca (char c, short s, int i, long l)
790 #else
791 void
792 call_after_alloca (c, s, i, l)
793      char c;
794      short s;
795      int i;
796      long l;
797 #endif
798 {
799 #ifdef HAVE_STACK_ALLOCA
800   /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
801      test what we are looking for, so if we don't have an alloca which
802      allocates on the stack, just don't bother to call alloca at all.  */
803
804   char *z = alloca (s + 50);
805 #endif
806   call_after_alloca_subr (c, s, i, l, 'b', 11, 12, (unsigned long)13);
807 }
808
809 \f
810
811 /* The point behind this test is the PA will call this indirectly
812    through dyncall.  Unlike the indirect calls to call0a, this test
813    will require a trampoline between dyncall and this function on the
814    call path, then another trampoline on between this function and main
815    on the return path.  */
816 #ifdef PROTOTYPES
817 double call_with_trampolines (double d1)
818 #else
819 double
820 call_with_trampolines (d1)
821 double d1;
822 #endif
823 {
824   return d1;
825 } /* End of call_with_trampolines, this comment is needed by funcargs.exp */
826
827 /* Dummy functions which the testsuite can use to run to, etc.  */
828
829 void
830 marker_indirect_call () {}
831
832 void
833 marker_call_with_trampolines () {}
834 \f
835 int main ()
836 {
837   void (*pointer_to_call0a) (char, short, int, long) = (void (*)(char, short, int, long))call0a;
838   double (*pointer_to_call_with_trampolines) (double) = call_with_trampolines;
839
840   /* Test calling with basic integer types */
841   call0a (c, s, i, l);
842   call0b (s, i, l, c);
843   call0c (i, l, c, s);
844   call0d (l, c, s, i);
845   call0e (c, l, c, i, c, s, c, c);
846
847   /* Test calling with unsigned integer types */
848   call1a (uc, us, ui, ul);
849   call1b (us, ui, ul, uc);
850   call1c (ui, ul, uc, us);
851   call1d (ul, uc, us, ui);
852   call1e (uc, ul, uc, ui, uc, us, uc, uc);
853
854   /* Test calling with integral types mixed with floating point types */
855   call2a (c, f, s, d, i, f, l, d);
856   call2b (f, s, d, i, f, l, d, c);
857   call2c (s, d, i, f, l, d, c, f);
858   call2d (d, i, f, l, d, c, f, s);
859   call2e (i, f, l, d, c, f, s, d);
860   call2f (f, l, d, c, f, s, d, i);
861   call2g (l, d, c, f, s, d, i, f);
862   call2h (d, c, f, s, d, i, f, l);
863   call2i (c, f, c, c, d, c, c, c, f, s, c, d);
864
865 #ifdef TEST_COMPLEX
866   /* Test calling with _Complex types.  */
867   callca (fc, fc, fc);
868   callcb (dc, dc, dc);
869   callcc (ldc, ldc, ldc);
870   callcd (fc, dc, ldc);
871   callce (dc, ldc, fc);
872   callcf (ldc, fc, dc);
873
874
875   callc1a (c, s, i, ui, l, fc, dc, ldc);
876   callc1b (ldc, c, s, i, fc, ui, l, dc);
877
878   callc2a (c, s, i, ui, l, f, d, fc, dc, ldc);
879   callc2b (fc, c, s, i, ui, ldc, l, f, d, dc);
880 #endif /* TEST_COMPLEX */
881
882   /* Test dereferencing pointers to various integral and floating types */
883
884   call3a (cp, sp, ip, lp);
885   call3b (ucp, usp, uip, ulp);
886   call3c (fp, dp);
887
888   /* Test dereferencing pointers to structs and unions */
889
890   call4a (stp);
891   un.u1 = 1;
892   call4b (unp);
893
894   /* Test calling with structures and unions. */
895
896   call5a (st);
897   un.u1 = 2;
898   call5b (un);
899
900   /* Test shuffling of args */
901
902   call6a (c, s, i, l, f, d, uc, us, ui, ul);
903   call7a (c, i, s, l, f, uc, d, us, ul, ui);
904   
905   /* Test passing structures recursively. */
906
907   test_struct_args ();
908
909   localvars_after_alloca (c, s, i, l);
910
911   call_after_alloca (c, s, i, l);
912
913   /* This is for localvars_in_indirect_call.  */
914   marker_indirect_call ();
915   /* The comment on the following two lines is used by funcargs.exp,
916      don't change it.  */
917   (*pointer_to_call0a) (c, s, i, l);    /* First step into call0a.  */
918   (*pointer_to_call0a) (c, s, i, l);    /* Second step into call0a.  */
919   marker_call_with_trampolines ();
920   (*pointer_to_call_with_trampolines) (d); /* Test multiple trampolines.  */
921   return 0;
922 }