1/* Area:	closure_call
2   Purpose:	Check multiple values passing from different type.
3		Also, exceed the limit of gpr and fpr registers on PowerPC.
4   Limitations:	none.
5   PR:		PR23404
6   Originator:	<andreast@gcc.gnu.org> 20050830	 */
7
8/* { dg-do run } */
9#include "ffitest.h"
10
11static void
12closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args,
13		 void* userdata)
14{
15  *(ffi_arg*)resp =
16    (int)*(unsigned long long *)args[0] +
17    (int)(*(unsigned long long *)args[1]) +
18    (int)(*(unsigned long long *)args[2]) +
19    (int)*(unsigned long long *)args[3] +
20    (int)(*(int *)args[4]) + (int)(*(double *)args[5]) +
21    (int)*(double *)args[6] + (int)(*(float *)args[7]) +
22    (int)(*(double *)args[8]) + (int)*(double *)args[9] +
23    (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
24    (int)*(int *)args[12] + (int)(*(int *)args[13]) +
25    (int)(*(double *)args[14]) +  (int)*(double *)args[15] +
26    (int)(long)userdata;
27
28  printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
29	 (int)*(unsigned long long  *)args[0],
30	 (int)(*(unsigned long long  *)args[1]),
31	 (int)(*(unsigned long long  *)args[2]),
32	 (int)*(unsigned long long  *)args[3],
33	 (int)(*(int *)args[4]), (int)(*(double *)args[5]),
34	 (int)*(double *)args[6], (int)(*(float *)args[7]),
35	 (int)(*(double *)args[8]), (int)*(double *)args[9],
36	 (int)(*(int *)args[10]), (int)(*(float *)args[11]),
37	 (int)*(int *)args[12], (int)(*(int *)args[13]),
38	 (int)(*(double *)args[14]), (int)(*(double *)args[15]),
39	 (int)(long)userdata, (int)*(ffi_arg *)resp);
40
41}
42
43typedef int (*closure_test_type0)(unsigned long long,
44				  unsigned long long,
45				  unsigned long long,
46				  unsigned long long,
47				  int, double, double, float, double, double,
48				  int, float, int, int, double, double);
49
50int main (void)
51{
52  ffi_cif cif;
53#ifndef USING_MMAP
54  static ffi_closure cl;
55#endif
56  ffi_closure *pcl;
57  ffi_type * cl_arg_types[17];
58  int res;
59
60#ifdef USING_MMAP
61  pcl = allocate_mmap (sizeof(ffi_closure));
62#else
63  pcl = &cl;
64#endif
65
66  cl_arg_types[0] = &ffi_type_uint64;
67  cl_arg_types[1] = &ffi_type_uint64;
68  cl_arg_types[2] = &ffi_type_uint64;
69  cl_arg_types[3] = &ffi_type_uint64;
70  cl_arg_types[4] = &ffi_type_sint;
71  cl_arg_types[5] = &ffi_type_double;
72  cl_arg_types[6] = &ffi_type_double;
73  cl_arg_types[7] = &ffi_type_float;
74  cl_arg_types[8] = &ffi_type_double;
75  cl_arg_types[9] = &ffi_type_double;
76  cl_arg_types[10] = &ffi_type_sint;
77  cl_arg_types[11] = &ffi_type_float;
78  cl_arg_types[12] = &ffi_type_sint;
79  cl_arg_types[13] = &ffi_type_sint;
80  cl_arg_types[14] = &ffi_type_double;
81  cl_arg_types[15] = &ffi_type_double;
82  cl_arg_types[16] = NULL;
83
84  /* Initialize the cif */
85  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
86		     &ffi_type_sint, cl_arg_types) == FFI_OK);
87
88  CHECK(ffi_prep_closure(pcl, &cif, closure_test_fn0,
89			 (void *) 3 /* userdata */) == FFI_OK);
90
91  res = (*((closure_test_type0)pcl))
92    (1, 2, 3, 4, 127, 429., 7., 8., 9.5, 10., 11, 12., 13,
93     19, 21., 1.);
94  /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
95  printf("res: %d\n",res);
96  /* { dg-output "\nres: 680" } */
97  exit(0);
98}
99