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