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. */
5 /* AIX requires this to be the first thing in the file. */
7 # define alloca __builtin_alloca
8 # define HAVE_STACK_ALLOCA 1
9 #else /* not __GNUC__ */
12 # define HAVE_STACK_ALLOCA 1
16 # define HAVE_STACK_ALLOCA 1
21 # endif /* __STDC__ */
24 #endif /* not __GNUC__ */
29 unsigned char uc
= 'b';
30 unsigned char *ucp
= &uc
;
35 unsigned short us
= 6;
36 unsigned short *usp
= &us
;
42 unsigned int *uip
= &ui
;
48 unsigned long *ulp
= &ul
;
60 struct stag
*stp
= &st
;
66 union utag
*unp
= &un
;
68 char carray
[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
71 /* Test various permutations and interleaving of integral arguments */
75 void call0a (char c
, short s
, int i
, long l
)
78 char c
; short s
; int i
; long l
;
88 void call0b (short s
, int i
, long l
, char c
)
91 short s
; int i
; long l
; char c
;
94 s
= 6; i
= 7; l
= 8; c
= 'j';
98 void call0c (int i
, long l
, char c
, short s
)
101 int i
; long l
; char c
; short s
;
104 i
= 3; l
= 4; c
= 'k'; s
= 5;
108 void call0d (long l
, char c
, short s
, int i
)
111 long l
; char c
; short s
; int i
;
114 l
= 7; c
= 'z'; s
= 8; i
= 9;
118 void call0e (char c1
, long l
, char c2
, int i
, char c3
, short s
, char c4
, char c5
)
120 call0e (c1
, l
, c2
, i
, c3
, s
, c4
, c5
)
121 char c1
; long l
; char c2
; int i
; char c3
; short s
; char c4
; char c5
;
124 c1
= 'a'; l
= 5; c2
= 'b'; i
= 7; c3
= 'c'; s
= 7; c4
= 'f'; c5
= 'g';
128 /* Test various permutations and interleaving of unsigned integral arguments */
132 void call1a (unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
134 call1a (uc
, us
, ui
, ul
)
135 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
138 uc
= 5; us
= 6; ui
= 7; ul
= 8;
142 void call1b (unsigned short us
, unsigned int ui
, unsigned long ul
, unsigned char uc
)
144 call1b (us
, ui
, ul
, uc
)
145 unsigned short us
; unsigned int ui
; unsigned long ul
; unsigned char uc
;
148 uc
= 5; us
= 6; ui
= 7; ul
= 8;
152 void call1c (unsigned int ui
, unsigned long ul
, unsigned char uc
, unsigned short us
)
154 call1c (ui
, ul
, uc
, us
)
155 unsigned int ui
; unsigned long ul
; unsigned char uc
; unsigned short us
;
158 uc
= 5; us
= 6; ui
= 7; ul
= 8;
162 void call1d (unsigned long ul
, unsigned char uc
, unsigned short us
, unsigned int ui
)
164 call1d (ul
, uc
, us
, ui
)
165 unsigned long ul
; unsigned char uc
; unsigned short us
; unsigned int ui
;
168 uc
= 5; us
= 6; ui
= 7; ul
= 8;
172 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
)
174 call1e (uc1
, ul
, uc2
, ui
, uc3
, us
, uc4
, uc5
)
175 unsigned char uc1
; unsigned long ul
; unsigned char uc2
; unsigned int ui
;
176 unsigned char uc3
; unsigned short us
; unsigned char uc4
; unsigned char uc5
;
179 uc1
= 5; ul
= 7; uc2
= 8; ui
= 9; uc3
= 10; us
= 11; uc4
= 12; uc5
= 55;
182 /* Test various permutations and interleaving of integral arguments with
183 floating point arguments. */
187 void call2a (char c
, float f1
, short s
, double d1
, int i
, float f2
, long l
, double d2
)
189 call2a (c
, f1
, s
, d1
, i
, f2
, l
, d2
)
190 char c
; float f1
; short s
; double d1
; int i
; float f2
; long l
; double d2
;
193 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
197 void call2b (float f1
, short s
, double d1
, int i
, float f2
, long l
, double d2
, char c
)
199 call2b (f1
, s
, d1
, i
, f2
, l
, d2
, c
)
200 float f1
; short s
; double d1
; int i
; float f2
; long l
; double d2
; char c
;
203 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
207 void call2c (short s
, double d1
, int i
, float f2
, long l
, double d2
, char c
, float f1
)
209 call2c (s
, d1
, i
, f2
, l
, d2
, c
, f1
)
210 short s
; double d1
; int i
; float f2
; long l
; double d2
; char c
; float f1
;
213 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
217 void call2d (double d1
, int i
, float f2
, long l
, double d2
, char c
, float f1
, short s
)
219 call2d (d1
, i
, f2
, l
, d2
, c
, f1
, s
)
220 double d1
; int i
; float f2
; long l
; double d2
; char c
; float f1
; short s
;
223 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
227 void call2e (int i
, float f2
, long l
, double d2
, char c
, float f1
, short s
, double d1
)
229 call2e (i
, f2
, l
, d2
, c
, f1
, s
, d1
)
230 int i
; float f2
; long l
; double d2
; char c
; float f1
; short s
; double d1
;
233 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
237 void call2f (float f2
, long l
, double d2
, char c
, float f1
, short s
, double d1
, int i
)
239 call2f (f2
, l
, d2
, c
, f1
, s
, d1
, i
)
240 float f2
; long l
; double d2
; char c
; float f1
; short s
; double d1
; int i
;
243 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
247 void call2g (long l
, double d2
, char c
, float f1
, short s
, double d1
, int i
, float f2
)
249 call2g (l
, d2
, c
, f1
, s
, d1
, i
, f2
)
250 long l
; double d2
; char c
; float f1
; short s
; double d1
; int i
; float f2
;
253 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
257 void call2h (double d2
, char c
, float f1
, short s
, double d1
, int i
, float f2
, long l
)
259 call2h (d2
, c
, f1
, s
, d1
, i
, f2
, l
)
260 double d2
; char c
; float f1
; short s
; double d1
; int i
; float f2
; long l
;
263 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
267 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
)
269 call2i (c1
, f1
, c2
, c3
, d1
, c4
, c5
, c6
, f2
, s
, c7
, d2
)
270 char c1
; float f1
; char c2
; char c3
; double d1
; char c4
; char c5
; char c6
;
271 float f2
; short s
; char c7
; double d2
;
274 c1
= 'a'; f1
= 0.0; c2
= 5; d1
= 0.0; c3
= 6; f2
= 0.1; c4
= 7; d2
= 0.2;
275 c5
= 's'; c6
= 'f'; c7
= 'z'; s
= 77;
279 /* Test pointers to various integral and floating types. */
283 void call3a (char *cp
, short *sp
, int *ip
, long *lp
)
285 call3a (cp
, sp
, ip
, lp
)
286 char *cp
; short *sp
; int *ip
; long *lp
;
289 cp
= 0; sp
= 0; ip
= 0; lp
= 0;
293 void call3b (unsigned char *ucp
, unsigned short *usp
, unsigned int *uip
, unsigned long *ulp
)
295 call3b (ucp
, usp
, uip
, ulp
)
296 unsigned char *ucp
; unsigned short *usp
; unsigned int *uip
;
300 ucp
= 0; usp
= 0; uip
= 0; ulp
= 0;
304 void call3c (float *fp
, double *dp
)
307 float *fp
; double *dp
;
314 /* Test passing structures and unions by reference. */
318 void call4a (struct stag
*stp
)
326 void call4b (union utag
*unp
)
336 /* Test passing structures and unions by value. */
340 void call5a (struct stag st
)
348 void call5b (union utag un
)
356 /* Test shuffling of args */
364 void call6j (unsigned long ul
)
375 void call6i (unsigned int ui
, unsigned long ul
)
378 unsigned int ui
; unsigned long ul
;
386 void call6h (unsigned short us
, unsigned int ui
, unsigned long ul
)
389 unsigned short us
; unsigned int ui
; unsigned long ul
;
397 void call6g (unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
399 call6g (uc
, us
, ui
, ul
)
400 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
408 void call6f (double d
, unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
410 call6f (d
, uc
, us
, ui
, ul
)
412 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
416 call6g (uc
, us
, ui
, ul
);
420 void call6e (float f
, double d
, unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
422 call6e (f
, d
, uc
, us
, ui
, ul
)
424 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
428 call6f (d
, uc
, us
, ui
, ul
);
432 void call6d (long l
, float f
, double d
, unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
434 call6d (l
, f
, d
, uc
, us
, ui
, ul
)
435 long l
; float f
; double d
;
436 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
440 call6e (f
, d
, uc
, us
, ui
, ul
);
444 void call6c (int i
, long l
, float f
, double d
, unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
446 call6c (i
, l
, f
, d
, uc
, us
, ui
, ul
)
447 int i
; long l
; float f
; double d
;
448 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
452 call6d (l
, f
, d
, uc
, us
, ui
, ul
);
456 void call6b (short s
, int i
, long l
, float f
, double d
, unsigned char uc
, unsigned short us
, unsigned int ui
, unsigned long ul
)
458 call6b (s
, i
, l
, f
, d
, uc
, us
, ui
, ul
)
459 short s
; int i
; long l
; float f
; double d
;
460 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
464 call6c (i
, l
, f
, d
, uc
, us
, ui
, ul
);
468 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
)
470 call6a (c
, s
, i
, l
, f
, d
, uc
, us
, ui
, ul
)
471 char c
; short s
; int i
; long l
; float f
; double d
;
472 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
476 call6b (s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
479 /* Test shuffling of args, round robin */
483 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
)
485 call7k (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
)
486 char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
;
489 c
= 'a'; i
= 7; s
= 8; l
= 7; f
= 0.3; uc
= 44; d
= 0.44; us
= 77;
494 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
)
496 call7j (ui
, c
, i
, s
, l
, f
, uc
, d
, us
, ul
)
497 unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
;
500 call7k (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
504 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
)
506 call7i (ul
, ui
, c
, i
, s
, l
, f
, uc
, d
, us
)
507 unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
;
510 call7j (ui
, c
, i
, s
, l
, f
, uc
, d
, us
, ul
);
514 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
)
516 call7h (us
, ul
, ui
, c
, i
, s
, l
, f
, uc
, d
)
517 unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
;
520 call7i (ul
, ui
, c
, i
, s
, l
, f
, uc
, d
, us
);
524 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
)
526 call7g (d
, us
, ul
, ui
, c
, i
, s
, l
, f
, uc
)
527 double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
;
530 call7h (us
, ul
, ui
, c
, i
, s
, l
, f
, uc
, d
);
534 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
)
536 call7f (uc
, d
, us
, ul
, ui
, c
, i
, s
, l
, f
)
537 unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
;
540 call7g (d
, us
, ul
, ui
, c
, i
, s
, l
, f
, uc
);
544 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
)
546 call7e (f
, uc
, d
, us
, ul
, ui
, c
, i
, s
, l
)
547 float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
;
550 call7f (uc
, d
, us
, ul
, ui
, c
, i
, s
, l
, f
);
554 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
)
556 call7d (l
, f
, uc
, d
, us
, ul
, ui
, c
, i
, s
)
557 long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
;
560 call7e (f
, uc
, d
, us
, ul
, ui
, c
, i
, s
, l
);
564 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
)
566 call7c (s
, l
, f
, uc
, d
, us
, ul
, ui
, c
, i
)
567 short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
;
570 call7d (l
, f
, uc
, d
, us
, ul
, ui
, c
, i
, s
);
574 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
)
576 call7b (i
, s
, l
, f
, uc
, d
, us
, ul
, ui
, c
)
577 int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
;
580 call7c (s
, l
, f
, uc
, d
, us
, ul
, ui
, c
, i
);
584 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
)
586 call7a (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
)
587 char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
;
590 call7b (i
, s
, l
, f
, uc
, d
, us
, ul
, ui
, c
);
594 /* Test printing of structures passed as arguments to recursive functions. */
609 void recurse (SVAL a
, int depth
)
611 void recurse (a
, depth
)
616 a
.s
= a
.i
= a
.l
= --depth
;
623 void test_struct_args ()
625 SVAL s
; s
.s
= 5; s
.i
= 5; s
.l
= 5;
630 /* On various machines (pa, 29k, and rs/6000, at least), a function which
631 calls alloca may do things differently with respect to frames. So give
635 void localvars_after_alloca (char c
, short s
, int i
, long l
)
638 localvars_after_alloca (c
, s
, i
, l
)
645 #ifdef HAVE_STACK_ALLOCA
646 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
647 test what we are looking for, so if we don't have an alloca which
648 allocates on the stack, just don't bother to call alloca at all. */
650 char *z
= alloca (s
+ 50);
659 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
)
662 call_after_alloca_subr (c
, s
, i
, l
, uc
, us
, ui
, ul
)
663 char c
; int i
; short s
; long l
; unsigned char uc
; unsigned short us
; unsigned long ul
; unsigned int ui
;
667 i
= 7; s
= 8; l
= 7; uc
= 44; us
= 77;
672 void call_after_alloca (char c
, short s
, int i
, long l
)
675 call_after_alloca (c
, s
, i
, l
)
682 #ifdef HAVE_STACK_ALLOCA
683 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
684 test what we are looking for, so if we don't have an alloca which
685 allocates on the stack, just don't bother to call alloca at all. */
687 char *z
= alloca (s
+ 50);
689 call_after_alloca_subr (c
, s
, i
, l
, 'b', 11, 12, (unsigned long)13);
694 /* The point behind this test is the PA will call this indirectly
695 through dyncall. Unlike the indirect calls to call0a, this test
696 will require a trampoline between dyncall and this function on the
697 call path, then another trampoline on between this function and main
698 on the return path. */
700 double call_with_trampolines (double d1
)
703 call_with_trampolines (d1
)
708 } /* End of call_with_trampolines, this comment is needed by funcargs.exp */
710 /* Dummy functions which the testsuite can use to run to, etc. */
713 marker_indirect_call () {}
716 marker_call_with_trampolines () {}
720 void (*pointer_to_call0a
) (char, short, int, long) = (void (*)(char, short, int, long))call0a
;
721 double (*pointer_to_call_with_trampolines
) (double) = call_with_trampolines
;
727 /* Test calling with basic integer types */
732 call0e (c
, l
, c
, i
, c
, s
, c
, c
);
734 /* Test calling with unsigned integer types */
735 call1a (uc
, us
, ui
, ul
);
736 call1b (us
, ui
, ul
, uc
);
737 call1c (ui
, ul
, uc
, us
);
738 call1d (ul
, uc
, us
, ui
);
739 call1e (uc
, ul
, uc
, ui
, uc
, us
, uc
, uc
);
741 /* Test calling with integral types mixed with floating point types */
742 call2a (c
, f
, s
, d
, i
, f
, l
, d
);
743 call2b (f
, s
, d
, i
, f
, l
, d
, c
);
744 call2c (s
, d
, i
, f
, l
, d
, c
, f
);
745 call2d (d
, i
, f
, l
, d
, c
, f
, s
);
746 call2e (i
, f
, l
, d
, c
, f
, s
, d
);
747 call2f (f
, l
, d
, c
, f
, s
, d
, i
);
748 call2g (l
, d
, c
, f
, s
, d
, i
, f
);
749 call2h (d
, c
, f
, s
, d
, i
, f
, l
);
750 call2i (c
, f
, c
, c
, d
, c
, c
, c
, f
, s
, c
, d
);
752 /* Test dereferencing pointers to various integral and floating types */
754 call3a (cp
, sp
, ip
, lp
);
755 call3b (ucp
, usp
, uip
, ulp
);
758 /* Test dereferencing pointers to structs and unions */
764 /* Test calling with structures and unions. */
770 /* Test shuffling of args */
772 call6a (c
, s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
773 call7a (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
775 /* Test passing structures recursively. */
779 localvars_after_alloca (c
, s
, i
, l
);
781 call_after_alloca (c
, s
, i
, l
);
783 /* This is for localvars_in_indirect_call. */
784 marker_indirect_call ();
785 /* The comment on the following two lines is used by funcargs.exp,
787 (*pointer_to_call0a
) (c
, s
, i
, l
); /* First step into call0a. */
788 (*pointer_to_call0a
) (c
, s
, i
, l
); /* Second step into call0a. */
789 marker_call_with_trampolines ();
790 (*pointer_to_call_with_trampolines
) (d
); /* Test multiple trampolines. */