Debian Codegraph @

testsuite/libffi.closures/closure_fn3.c

raw
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: <[email protected]> 20030828 */
8
9 /* { dg-do run } */
10 #include "ffitest.h"
11
12 static void closure_test_fn3(ffi_cif* cif __UNUSED__, void* resp, void** args,
13 void* userdata)
14 {
15 *(ffi_arg*)resp =
16 (int)*(float *)args[0] +(int)(*(float *)args[1]) +
17 (int)(*(float *)args[2]) + (int)*(float *)args[3] +
18 (int)(*(float *)args[4]) + (int)(*(float *)args[5]) +
19 (int)*(float *)args[6] + (int)(*(float *)args[7]) +
20 (int)(*(double *)args[8]) + (int)*(int *)args[9] +
21 (int)(*(float *)args[10]) + (int)(*(float *)args[11]) +
22 (int)*(int *)args[12] + (int)(*(float *)args[13]) +
23 (int)(*(float *)args[14]) + *(int *)args[15] + (intptr_t)userdata;
24
25 printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
26 (int)*(float *)args[0], (int)(*(float *)args[1]),
27 (int)(*(float *)args[2]), (int)*(float *)args[3],
28 (int)(*(float *)args[4]), (int)(*(float *)args[5]),
29 (int)*(float *)args[6], (int)(*(float *)args[7]),
30 (int)(*(double *)args[8]), (int)*(int *)args[9],
31 (int)(*(float *)args[10]), (int)(*(float *)args[11]),
32 (int)*(int *)args[12], (int)(*(float *)args[13]),
33 (int)(*(float *)args[14]), *(int *)args[15], (int)(intptr_t)userdata,
34 (int)*(ffi_arg *)resp);
35
36 CHECK((int)*(float *)args[0] == 1);
37 CHECK((int)(*(float *)args[1]) == 2);
38 CHECK((int)(*(float *)args[2]) == 3);
39 CHECK((int)(*(float *)args[3]) == 4);
40 CHECK((int)(*(float *)args[4]) == 5);
41 CHECK((int)(*(float *)args[5]) == 6);
42 CHECK((int)*(float *)args[6] == 7);
43 CHECK((int)(*(float *)args[7]) == 8);
44 CHECK((int)(*(double *)args[8]) == 9);
45 CHECK((int)*(int *)args[9] == 10);
46 CHECK((int)(*(float *)args[10]) == 11);
47 CHECK((int)(*(float *)args[11]) == 12);
48 CHECK((int)*(int *)args[12] == 13);
49 CHECK((int)(*(float *)args[13]) == 19);
50 CHECK((int)(*(float *)args[14]) == 21);
51 CHECK(*(int *)args[15] == 1);
52 CHECK((int)(intptr_t)userdata == 3);
53
54 CHECK((int)*(ffi_arg *)resp == 135);
55 }
56
57 typedef int (*closure_test_type3)(float, float, float, float, float, float,
58 float, float, double, int, float, float, int,
59 float, float, int);
60
61 int main (void)
62 {
63 ffi_cif cif;
64 void *code;
65 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
66 ffi_type * cl_arg_types[17];
67 int res;
68
69 cl_arg_types[0] = &ffi_type_float;
70 cl_arg_types[1] = &ffi_type_float;
71 cl_arg_types[2] = &ffi_type_float;
72 cl_arg_types[3] = &ffi_type_float;
73 cl_arg_types[4] = &ffi_type_float;
74 cl_arg_types[5] = &ffi_type_float;
75 cl_arg_types[6] = &ffi_type_float;
76 cl_arg_types[7] = &ffi_type_float;
77 cl_arg_types[8] = &ffi_type_double;
78 cl_arg_types[9] = &ffi_type_sint;
79 cl_arg_types[10] = &ffi_type_float;
80 cl_arg_types[11] = &ffi_type_float;
81 cl_arg_types[12] = &ffi_type_sint;
82 cl_arg_types[13] = &ffi_type_float;
83 cl_arg_types[14] = &ffi_type_float;
84 cl_arg_types[15] = &ffi_type_sint;
85 cl_arg_types[16] = NULL;
86
87 /* Initialize the cif */
88 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
89 &ffi_type_sint, cl_arg_types) == FFI_OK);
90
91 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn3,
92 (void *) 3 /* userdata */, code) == FFI_OK);
93
94 res = (*((closure_test_type3)code))
95 (1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9, 10, 11.11, 12.0, 13,
96 19.19, 21.21, 1);
97 /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 19 21 1 3: 135" } */
98 printf("res: %d\n",res);
99 /* { dg-output "\nres: 135" } */
100 CHECK(res == 135);
101 exit(0);
102 }