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 char c
; short s
; int i
; long l
;
84 short s
; int i
; long l
; char c
;
86 s
= 6; i
= 7; l
= 8; c
= 'j';
90 int i
; long l
; char c
; short s
;
92 i
= 3; l
= 4; c
= 'k'; s
= 5;
96 long l
; char c
; short s
; int i
;
98 l
= 7; c
= 'z'; s
= 8; i
= 9;
101 call0e (c1
, l
, c2
, i
, c3
, s
, c4
, c5
)
102 char c1
; long l
; char c2
; int i
; char c3
; short s
; char c4
; char c5
;
104 c1
= 'a'; l
= 5; c2
= 'b'; i
= 7; c3
= 'c'; s
= 7; c4
= 'f'; c5
= 'g';
108 /* Test various permutations and interleaving of unsigned integral arguments */
111 call1a (uc
, us
, ui
, ul
)
112 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
114 uc
= 5; us
= 6; ui
= 7; ul
= 8;
117 call1b (us
, ui
, ul
, uc
)
118 unsigned short us
; unsigned int ui
; unsigned long ul
; unsigned char uc
;
120 uc
= 5; us
= 6; ui
= 7; ul
= 8;
123 call1c (ui
, ul
, uc
, us
)
124 unsigned int ui
; unsigned long ul
; unsigned char uc
; unsigned short us
;
126 uc
= 5; us
= 6; ui
= 7; ul
= 8;
129 call1d (ul
, uc
, us
, ui
)
130 unsigned long ul
; unsigned char uc
; unsigned short us
; unsigned int ui
;
132 uc
= 5; us
= 6; ui
= 7; ul
= 8;
135 call1e (uc1
, ul
, uc2
, ui
, uc3
, us
, uc4
, uc5
)
136 unsigned char uc1
; unsigned long ul
; unsigned char uc2
; unsigned int ui
;
137 unsigned char uc3
; unsigned short us
; unsigned char uc4
; unsigned char uc5
;
139 uc1
= 5; ul
= 7; uc2
= 8; ui
= 9; uc3
= 10; us
= 11; uc4
= 12; uc5
= 55;
142 /* Test various permutations and interleaving of integral arguments with
143 floating point arguments. */
146 call2a (c
, f1
, s
, d1
, i
, f2
, l
, d2
)
147 char c
; float f1
; short s
; double d1
; int i
; float f2
; long l
; double d2
;
149 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
152 call2b (f1
, s
, d1
, i
, f2
, l
, d2
, c
)
153 float f1
; short s
; double d1
; int i
; float f2
; long l
; double d2
; char c
;
155 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
158 call2c (s
, d1
, i
, f2
, l
, d2
, c
, f1
)
159 short s
; double d1
; int i
; float f2
; long l
; double d2
; char c
; float f1
;
161 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
164 call2d (d1
, i
, f2
, l
, d2
, c
, f1
, s
)
165 double d1
; int i
; float f2
; long l
; double d2
; char c
; float f1
; short s
;
167 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
170 call2e (i
, f2
, l
, d2
, c
, f1
, s
, d1
)
171 int i
; float f2
; long l
; double d2
; char c
; float f1
; short s
; double d1
;
173 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
176 call2f (f2
, l
, d2
, c
, f1
, s
, d1
, i
)
177 float f2
; long l
; double d2
; char c
; float f1
; short s
; double d1
; int i
;
179 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
182 call2g (l
, d2
, c
, f1
, s
, d1
, i
, f2
)
183 long l
; double d2
; char c
; float f1
; short s
; double d1
; int i
; float f2
;
185 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
188 call2h (d2
, c
, f1
, s
, d1
, i
, f2
, l
)
189 double d2
; char c
; float f1
; short s
; double d1
; int i
; float f2
; long l
;
191 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
194 call2i (c1
, f1
, c2
, c3
, d1
, c4
, c5
, c6
, f2
, s
, c7
, d2
)
195 char c1
; float f1
; char c2
; char c3
; double d1
; char c4
; char c5
; char c6
;
196 float f2
; short s
; char c7
; double d2
;
198 c1
= 'a'; f1
= 0.0; c2
= 5; d1
= 0.0; c3
= 6; f2
= 0.1; c4
= 7; d2
= 0.2;
199 c5
= 's'; c6
= 'f'; c7
= 'z'; s
= 77;
203 /* Test pointers to various integral and floating types. */
206 call3a (cp
, sp
, ip
, lp
)
207 char *cp
; short *sp
; int *ip
; long *lp
;
209 cp
= 0; sp
= 0; ip
= 0; lp
= 0;
212 call3b (ucp
, usp
, uip
, ulp
)
213 unsigned char *ucp
; unsigned short *usp
; unsigned int *uip
;
216 ucp
= 0; usp
= 0; uip
= 0; ulp
= 0;
220 float *fp
; double *dp
;
226 /* Test passing structures and unions by reference. */
240 /* Test passing structures and unions by value. */
244 struct stag st
; {st
.s1
= 5;}
247 union utag un
; {un
.u1
= 7;}
250 /* Test shuffling of args */
253 call6a (c
, s
, i
, l
, f
, d
, uc
, us
, ui
, ul
)
254 char c
; short s
; int i
; long l
; float f
; double d
;
255 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
258 call6b (s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
261 call6b (s
, i
, l
, f
, d
, uc
, us
, ui
, ul
)
262 short s
; int i
; long l
; float f
; double d
;
263 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
266 call6c (i
, l
, f
, d
, uc
, us
, ui
, ul
);
269 call6c (i
, l
, f
, d
, uc
, us
, ui
, ul
)
270 int i
; long l
; float f
; double d
;
271 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
274 call6d (l
, f
, d
, uc
, us
, ui
, ul
);
277 call6d (l
, f
, d
, uc
, us
, ui
, ul
)
278 long l
; float f
; double d
;
279 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
282 call6e (f
, d
, uc
, us
, ui
, ul
);
285 call6e (f
, d
, uc
, us
, ui
, ul
)
287 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
290 call6f (d
, uc
, us
, ui
, ul
);
293 call6f (d
, uc
, us
, ui
, ul
)
295 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
298 call6g (uc
, us
, ui
, ul
);
301 call6g (uc
, us
, ui
, ul
)
302 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
309 unsigned short us
; unsigned int ui
; unsigned long ul
;
316 unsigned int ui
; unsigned long ul
;
334 /* Test shuffling of args, round robin */
337 call7a (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
)
338 char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
;
340 call7b (i
, s
, l
, f
, uc
, d
, us
, ul
, ui
, c
);
343 call7b (i
, s
, l
, f
, uc
, d
, us
, ul
, ui
, c
)
344 int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
;
346 call7c (s
, l
, f
, uc
, d
, us
, ul
, ui
, c
, i
);
349 call7c (s
, l
, f
, uc
, d
, us
, ul
, ui
, c
, i
)
350 short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
;
352 call7d (l
, f
, uc
, d
, us
, ul
, ui
, c
, i
, s
);
355 call7d (l
, f
, uc
, d
, us
, ul
, ui
, c
, i
, s
)
356 long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
;
358 call7e (f
, uc
, d
, us
, ul
, ui
, c
, i
, s
, l
);
361 call7e (f
, uc
, d
, us
, ul
, ui
, c
, i
, s
, l
)
362 float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
;
364 call7f (uc
, d
, us
, ul
, ui
, c
, i
, s
, l
, f
);
367 call7f (uc
, d
, us
, ul
, ui
, c
, i
, s
, l
, f
)
368 unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
;
370 call7g (d
, us
, ul
, ui
, c
, i
, s
, l
, f
, uc
);
373 call7g (d
, us
, ul
, ui
, c
, i
, s
, l
, f
, uc
)
374 double d
; unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
;
376 call7h (us
, ul
, ui
, c
, i
, s
, l
, f
, uc
, d
);
379 call7h (us
, ul
, ui
, c
, i
, s
, l
, f
, uc
, d
)
380 unsigned short us
; unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
;
382 call7i (ul
, ui
, c
, i
, s
, l
, f
, uc
, d
, us
);
385 call7i (ul
, ui
, c
, i
, s
, l
, f
, uc
, d
, us
)
386 unsigned long ul
; unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
;
388 call7j (ui
, c
, i
, s
, l
, f
, uc
, d
, us
, ul
);
391 call7j (ui
, c
, i
, s
, l
, f
, uc
, d
, us
, ul
)
392 unsigned int ui
; char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
;
394 call7k (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
397 call7k (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
)
398 char c
; int i
; short s
; long l
; float f
; unsigned char uc
; double d
; unsigned short us
; unsigned long ul
; unsigned int ui
;
400 c
= 'a'; i
= 7; s
= 8; l
= 7; f
= 0.3; uc
= 44; d
= 0.44; us
= 77;
405 /* Test printing of structures passed as arguments to recursive functions. */
419 void recurse (a
, depth
)
423 a
.s
= a
.i
= a
.l
= --depth
;
432 SVAL s
; s
.s
= 5; s
.i
= 5; s
.l
= 5;
437 /* On various machines (pa, 29k, and rs/6000, at least), a function which
438 calls alloca may do things differently with respect to frames. So give
442 localvars_after_alloca (c
, s
, i
, l
)
448 #ifdef HAVE_STACK_ALLOCA
449 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
450 test what we are looking for, so if we don't have an alloca which
451 allocates on the stack, just don't bother to call alloca at all. */
453 char *z
= alloca (s
+ 50);
462 call_after_alloca_subr (c
, s
, i
, l
, uc
, us
, ui
, ul
)
463 char c
; int i
; short s
; long l
; unsigned char uc
; unsigned short us
; unsigned long ul
; unsigned int ui
;
466 i
= 7; s
= 8; l
= 7; uc
= 44; us
= 77;
471 call_after_alloca (c
, s
, i
, l
)
477 #ifdef HAVE_STACK_ALLOCA
478 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
479 test what we are looking for, so if we don't have an alloca which
480 allocates on the stack, just don't bother to call alloca at all. */
482 char *z
= alloca (s
+ 50);
484 call_after_alloca_subr (c
, s
, i
, l
, 'b', 11, 12, (unsigned long)13);
489 /* The point behind this test is the PA will call this indirectly
490 through dyncall. Unlike the indirect calls to call0a, this test
491 will require a trampoline between dyncall and this function on the
492 call path, then another trampoline on between this function and main
493 on the return path. */
495 call_with_trampolines (d1
)
499 } /* End of call_with_trampolines, this comment is needed by funcargs.exp */
501 /* Dummy functions which the testsuite can use to run to, etc. */
504 marker_indirect_call () {}
507 marker_call_with_trampolines () {}
511 int (*pointer_to_call0a
) () = call0a
;
512 double (*pointer_to_call_with_trampolines
) () = call_with_trampolines
;
518 /* Test calling with basic integer types */
523 call0e (c
, l
, c
, i
, c
, s
, c
, c
);
525 /* Test calling with unsigned integer types */
526 call1a (uc
, us
, ui
, ul
);
527 call1b (us
, ui
, ul
, uc
);
528 call1c (ui
, ul
, uc
, us
);
529 call1d (ul
, uc
, us
, ui
);
530 call1e (uc
, ul
, uc
, ui
, uc
, us
, uc
, uc
);
532 /* Test calling with integral types mixed with floating point types */
533 call2a (c
, f
, s
, d
, i
, f
, l
, d
);
534 call2b (f
, s
, d
, i
, f
, l
, d
, c
);
535 call2c (s
, d
, i
, f
, l
, d
, c
, f
);
536 call2d (d
, i
, f
, l
, d
, c
, f
, s
);
537 call2e (i
, f
, l
, d
, c
, f
, s
, d
);
538 call2f (f
, l
, d
, c
, f
, s
, d
, i
);
539 call2g (l
, d
, c
, f
, s
, d
, i
, f
);
540 call2h (d
, c
, f
, s
, d
, i
, f
, l
);
541 call2i (c
, f
, c
, c
, d
, c
, c
, c
, f
, s
, c
, d
);;
543 /* Test dereferencing pointers to various integral and floating types */
545 call3a (cp
, sp
, ip
, lp
);
546 call3b (ucp
, usp
, uip
, ulp
);
549 /* Test dereferencing pointers to structs and unions */
555 /* Test calling with structures and unions. */
561 /* Test shuffling of args */
563 call6a (c
, s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
564 call7a (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
566 /* Test passing structures recursively. */
570 localvars_after_alloca (c
, s
, i
, l
);
572 call_after_alloca (c
, s
, i
, l
);
574 /* This is for localvars_in_indirect_call. */
575 marker_indirect_call ();
576 /* The comment on the following two lines is used by funcargs.exp,
578 (*pointer_to_call0a
) (c
, s
, i
, l
); /* First step into call0a. */
579 (*pointer_to_call0a
) (c
, s
, i
, l
); /* Second step into call0a. */
580 marker_call_with_trampolines ();
581 (*pointer_to_call_with_trampolines
) (d
); /* Test multiple trampolines. */