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;
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 */
66 struct stag *stp = &st;
72 union utag *unp = &un;
74 char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
77 /* Test various permutations and interleaving of integral arguments */
81 void call0a (char c, short s, int i, long l)
84 char c; short s; int i; long l;
94 void call0b (short s, int i, long l, char c)
97 short s; int i; long l; char c;
100 s = 6; i = 7; l = 8; c = 'j';
104 void call0c (int i, long l, char c, short s)
107 int i; long l; char c; short s;
110 i = 3; l = 4; c = 'k'; s = 5;
114 void call0d (long l, char c, short s, int i)
117 long l; char c; short s; int i;
120 l = 7; c = 'z'; s = 8; i = 9;
124 void call0e (char c1, long l, char c2, int i, char c3, short s, char c4, char c5)
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;
130 c1 = 'a'; l = 5; c2 = 'b'; i = 7; c3 = 'c'; s = 7; c4 = 'f'; c5 = 'g';
134 /* Test various permutations and interleaving of unsigned integral arguments */
138 void call1a (unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
140 call1a (uc, us, ui, ul)
141 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
144 uc = 5; us = 6; ui = 7; ul = 8;
148 void call1b (unsigned short us, unsigned int ui, unsigned long ul, unsigned char uc)
150 call1b (us, ui, ul, uc)
151 unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc;
154 uc = 5; us = 6; ui = 7; ul = 8;
158 void call1c (unsigned int ui, unsigned long ul, unsigned char uc, unsigned short us)
160 call1c (ui, ul, uc, us)
161 unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us;
164 uc = 5; us = 6; ui = 7; ul = 8;
168 void call1d (unsigned long ul, unsigned char uc, unsigned short us, unsigned int ui)
170 call1d (ul, uc, us, ui)
171 unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui;
174 uc = 5; us = 6; ui = 7; ul = 8;
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)
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;
185 uc1 = 5; ul = 7; uc2 = 8; ui = 9; uc3 = 10; us = 11; uc4 = 12; uc5 = 55;
188 /* Test various permutations and interleaving of integral arguments with
189 floating point arguments. */
193 void call2a (char c, float f1, short s, double d1, int i, float f2, long l, double d2)
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;
199 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
203 void call2b (float f1, short s, double d1, int i, float f2, long l, double d2, char c)
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;
209 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
213 void call2c (short s, double d1, int i, float f2, long l, double d2, char c, float f1)
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;
219 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
223 void call2d (double d1, int i, float f2, long l, double d2, char c, float f1, short s)
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;
229 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
233 void call2e (int i, float f2, long l, double d2, char c, float f1, short s, double d1)
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;
239 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
243 void call2f (float f2, long l, double d2, char c, float f1, short s, double d1, int i)
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;
249 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
253 void call2g (long l, double d2, char c, float f1, short s, double d1, int i, float f2)
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;
259 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
263 void call2h (double d2, char c, float f1, short s, double d1, int i, float f2, long l)
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;
269 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
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)
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;
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;
285 /* Test pointers to various integral and floating types. */
289 void call3a (char *cp, short *sp, int *ip, long *lp)
291 call3a (cp, sp, ip, lp)
292 char *cp; short *sp; int *ip; long *lp;
295 cp = 0; sp = 0; ip = 0; lp = 0;
299 void call3b (unsigned char *ucp, unsigned short *usp, unsigned int *uip, unsigned long *ulp)
301 call3b (ucp, usp, uip, ulp)
302 unsigned char *ucp; unsigned short *usp; unsigned int *uip;
306 ucp = 0; usp = 0; uip = 0; ulp = 0;
310 void call3c (float *fp, double *dp)
313 float *fp; double *dp;
323 /* Test various _Complex type args. */
326 void callca (float _Complex f1, float _Complex f2, float _Complex f3)
329 float _Complex f1; float _Complex f2; float _Complex f3;
336 void callcb (double _Complex d1, double _Complex d2, double _Complex d3)
339 double _Complex d1; double _Complex d2; double _Complex d3;
346 void callcc (long double _Complex ld1, long double _Complex ld2, long double _Complex ld3)
348 callcc (ld1, ld2, ld3)
349 long double _Complex ld1; long double _Complex ld2; long double _Complex ld3;
356 void callcd (float _Complex fc1, double _Complex dc1, long double _Complex ldc1)
358 callcd (fc1, dc1, ldc1)
359 float _Complex fc1; double _Complex dc1; long double _Complex ldc1;
365 void callce (double _Complex dc1, long double _Complex ldc1, float _Complex fc1)
367 callce (dc1, ldc1, fc1)
368 double _Complex dc1; long double _Complex ldc1; float _Complex fc1;
374 void callcf (long double _Complex ldc1, float _Complex fc1, double _Complex dc1)
376 callcf (ldc1, fc1, dc1)
377 long double _Complex ldc1; float _Complex fc1; double _Complex dc1;
383 /* Test passing _Complex type and integral. */
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)
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;
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)
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;
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)
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;
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,
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;
429 #endif /* TEST_COMPLEX */
431 /* Test passing structures and unions by reference. */
435 void call4a (struct stag *stp)
443 void call4b (union utag *unp)
453 /* Test passing structures and unions by value. */
457 void call5a (struct stag st)
465 void call5b (union utag un)
473 /* Test shuffling of args */
481 void call6j (unsigned long ul)
492 void call6i (unsigned int ui, unsigned long ul)
495 unsigned int ui; unsigned long ul;
503 void call6h (unsigned short us, unsigned int ui, unsigned long ul)
506 unsigned short us; unsigned int ui; unsigned long ul;
514 void call6g (unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
516 call6g (uc, us, ui, ul)
517 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
525 void call6f (double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
527 call6f (d, uc, us, ui, ul)
529 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
533 call6g (uc, us, ui, ul);
537 void call6e (float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
539 call6e (f, d, uc, us, ui, ul)
541 unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
545 call6f (d, uc, us, ui, ul);
549 void call6d (long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
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;
557 call6e (f, d, uc, us, ui, ul);
561 void call6c (int i, long l, float f, double d, unsigned char uc, unsigned short us, unsigned int ui, unsigned long ul)
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;
569 call6d (l, f, d, uc, us, ui, ul);
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)
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;
581 call6c (i, l, f, d, uc, us, ui, ul);
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)
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;
593 call6b (s, i, l, f, d, uc, us, ui, ul);
596 /* Test shuffling of args, round robin */
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)
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;
606 c = 'a'; i = 7; s = 8; l = 7; f = 0.3; uc = 44; d = 0.44; us = 77;
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)
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;
617 call7k (c, i, s, l, f, uc, d, us, ul, ui);
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)
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;
627 call7j (ui, c, i, s, l, f, uc, d, us, ul);
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)
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;
637 call7i (ul, ui, c, i, s, l, f, uc, d, us);
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)
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;
647 call7h (us, ul, ui, c, i, s, l, f, uc, d);
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)
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;
657 call7g (d, us, ul, ui, c, i, s, l, f, uc);
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)
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;
667 call7f (uc, d, us, ul, ui, c, i, s, l, f);
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)
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;
677 call7e (f, uc, d, us, ul, ui, c, i, s, l);
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)
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;
687 call7d (l, f, uc, d, us, ul, ui, c, i, s);
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)
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;
697 call7c (s, l, f, uc, d, us, ul, ui, c, i);
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)
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;
707 call7b (i, s, l, f, uc, d, us, ul, ui, c);
711 /* Test printing of structures passed as arguments to recursive functions. */
726 void recurse (SVAL a, int depth)
728 void recurse (a, depth)
733 a.s = a.i = a.l = --depth;
740 void test_struct_args ()
742 SVAL s; s.s = 5; s.i = 5; s.l = 5;
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
752 void localvars_after_alloca (char c, short s, int i, long l)
755 localvars_after_alloca (c, s, i, l)
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. */
767 char *z = alloca (s + 50);
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)
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;
784 i = 7; s = 8; l = 7; uc = 44; us = 77;
789 void call_after_alloca (char c, short s, int i, long l)
792 call_after_alloca (c, s, i, l)
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. */
804 char *z = alloca (s + 50);
806 call_after_alloca_subr (c, s, i, l, 'b', 11, 12, (unsigned long)13);
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. */
817 double call_with_trampolines (double d1)
820 call_with_trampolines (d1)
825 } /* End of call_with_trampolines, this comment is needed by funcargs.exp */
827 /* Dummy functions which the testsuite can use to run to, etc. */
830 marker_indirect_call () {}
833 marker_call_with_trampolines () {}
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;
840 /* Test calling with basic integer types */
845 call0e (c, l, c, i, c, s, c, c);
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);
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);
866 /* Test calling with _Complex types. */
869 callcc (ldc, ldc, ldc);
870 callcd (fc, dc, ldc);
871 callce (dc, ldc, fc);
872 callcf (ldc, fc, dc);
875 callc1a (c, s, i, ui, l, fc, dc, ldc);
876 callc1b (ldc, c, s, i, fc, ui, l, dc);
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 */
882 /* Test dereferencing pointers to various integral and floating types */
884 call3a (cp, sp, ip, lp);
885 call3b (ucp, usp, uip, ulp);
888 /* Test dereferencing pointers to structs and unions */
894 /* Test calling with structures and unions. */
900 /* Test shuffling of args */
902 call6a (c, s, i, l, f, d, uc, us, ui, ul);
903 call7a (c, i, s, l, f, uc, d, us, ul, ui);
905 /* Test passing structures recursively. */
909 localvars_after_alloca (c, s, i, l);
911 call_after_alloca (c, s, i, l);
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,
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. */