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
20 #endif /* not __GNUC__ */
25 unsigned char uc
= 'b';
26 unsigned char *ucp
= &uc
;
31 unsigned short us
= 6;
32 unsigned short *usp
= &us
;
38 unsigned int *uip
= &ui
;
44 unsigned long *ulp
= &ul
;
56 struct stag
*stp
= &st
;
62 union utag
*unp
= &un
;
64 char carray
[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
67 /* Test various permutations and interleaving of integral arguments */
71 char c
; short s
; int i
; long l
;
80 short s
; int i
; long l
; char c
;
82 s
= 6; i
= 7; l
= 8; c
= 'j';
86 int i
; long l
; char c
; short s
;
88 i
= 3; l
= 4; c
= 'k'; s
= 5;
92 long l
; char c
; short s
; int i
;
94 l
= 7; c
= 'z'; s
= 8; i
= 9;
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
;
100 c1
= 'a'; l
= 5; c2
= 'b'; i
= 7; c3
= 'c'; s
= 7; c4
= 'f'; c5
= 'g';
104 /* Test various permutations and interleaving of unsigned integral arguments */
107 call1a (uc
, us
, ui
, ul
)
108 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
110 uc
= 5; us
= 6; ui
= 7; ul
= 8;
113 call1b (us
, ui
, ul
, uc
)
114 unsigned short us
; unsigned int ui
; unsigned long ul
; unsigned char uc
;
116 uc
= 5; us
= 6; ui
= 7; ul
= 8;
119 call1c (ui
, ul
, uc
, us
)
120 unsigned int ui
; unsigned long ul
; unsigned char uc
; unsigned short us
;
122 uc
= 5; us
= 6; ui
= 7; ul
= 8;
125 call1d (ul
, uc
, us
, ui
)
126 unsigned long ul
; unsigned char uc
; unsigned short us
; unsigned int ui
;
128 uc
= 5; us
= 6; ui
= 7; ul
= 8;
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
;
135 uc1
= 5; ul
= 7; uc2
= 8; ui
= 9; uc3
= 10; us
= 11; uc4
= 12; uc5
= 55;
138 /* Test various permutations and interleaving of integral arguments with
139 floating point arguments. */
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
;
145 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
151 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
157 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
163 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
169 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
175 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
181 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
187 c
= 'a'; f1
= 0.0; s
= 5; d1
= 0.0; i
= 6; f2
= 0.1; l
= 7; d2
= 0.2;
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
;
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;
199 /* Test pointers to various integral and floating types. */
202 call3a (cp
, sp
, ip
, lp
)
203 char *cp
; short *sp
; int *ip
; long *lp
;
205 cp
= 0; sp
= 0; ip
= 0; lp
= 0;
208 call3b (ucp
, usp
, uip
, ulp
)
209 unsigned char *ucp
; unsigned short *usp
; unsigned int *uip
;
212 ucp
= 0; usp
= 0; uip
= 0; ulp
= 0;
216 float *fp
; double *dp
;
222 /* Test passing structures and unions by reference. */
236 /* Test passing structures and unions by value. */
240 struct stag st
; {st
.s1
= 5;}
243 union utag un
; {un
.u1
= 7;}
246 /* Test shuffling of args */
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
;
254 call6b (s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
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
;
262 call6c (i
, l
, f
, d
, uc
, us
, ui
, ul
);
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
;
270 call6d (l
, f
, d
, uc
, us
, ui
, ul
);
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
;
278 call6e (f
, d
, uc
, us
, ui
, ul
);
281 call6e (f
, d
, uc
, us
, ui
, ul
)
283 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
286 call6f (d
, uc
, us
, ui
, ul
);
289 call6f (d
, uc
, us
, ui
, ul
)
291 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
294 call6g (uc
, us
, ui
, ul
);
297 call6g (uc
, us
, ui
, ul
)
298 unsigned char uc
; unsigned short us
; unsigned int ui
; unsigned long ul
;
305 unsigned short us
; unsigned int ui
; unsigned long ul
;
312 unsigned int ui
; unsigned long ul
;
330 /* Test shuffling of args, round robin */
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
;
336 call7b (i
, s
, l
, f
, uc
, d
, us
, ul
, ui
, c
);
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
;
342 call7c (s
, l
, f
, uc
, d
, us
, ul
, ui
, c
, i
);
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
;
348 call7d (l
, f
, uc
, d
, us
, ul
, ui
, c
, i
, s
);
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
;
354 call7e (f
, uc
, d
, us
, ul
, ui
, c
, i
, s
, l
);
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
;
360 call7f (uc
, d
, us
, ul
, ui
, c
, i
, s
, l
, f
);
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
;
366 call7g (d
, us
, ul
, ui
, c
, i
, s
, l
, f
, uc
);
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
;
372 call7h (us
, ul
, ui
, c
, i
, s
, l
, f
, uc
, d
);
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
;
378 call7i (ul
, ui
, c
, i
, s
, l
, f
, uc
, d
, us
);
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
;
384 call7j (ui
, c
, i
, s
, l
, f
, uc
, d
, us
, ul
);
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
;
390 call7k (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
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
;
396 c
= 'a'; i
= 7; s
= 8; l
= 7; f
= 0.3; uc
= 44; d
= 0.44; us
= 77;
401 /* Test printing of structures passed as arguments to recursive functions. */
415 void recurse (a
, depth
)
419 a
.s
= a
.i
= a
.l
= --depth
;
428 SVAL s
; s
.s
= 5; s
.i
= 5; s
.l
= 5;
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
438 localvars_after_alloca (c
, s
, i
, l
)
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. */
449 char *z
= alloca (s
+ 50);
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. */
464 call_with_trampolines (d1
)
468 } /* End of call_with_trampolines, this comment is needed by funcargs.exp */
470 /* Dummy functions which the testsuite can use to run to, etc. */
473 marker_indirect_call () {}
476 marker_call_with_trampolines () {}
480 int (*pointer_to_call0a
) () = call0a
;
481 double (*pointer_to_call_with_trampolines
) () = call_with_trampolines
;
483 /* Test calling with basic integer types */
488 call0e (c
, l
, c
, i
, c
, s
, c
, c
);
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
);
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
);;
508 /* Test dereferencing pointers to various integral and floating types */
510 call3a (cp
, sp
, ip
, lp
);
511 call3b (ucp
, usp
, uip
, ulp
);
514 /* Test dereferencing pointers to structs and unions */
520 /* Test calling with structures and unions. */
526 /* Test shuffling of args */
528 call6a (c
, s
, i
, l
, f
, d
, uc
, us
, ui
, ul
);
529 call7a (c
, i
, s
, l
, f
, uc
, d
, us
, ul
, ui
);
531 /* Test passing structures recursively. */
535 localvars_after_alloca (c
, s
, i
, l
);
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,
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. */