Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

closure_fn5.c
Go to the documentation of this file.
1 /* Area: closure_call
2 Purpose: Check multiple long long values passing.
3 Exceed the limit of gpr registers on PowerPC
4 Darwin.
5 Limitations: none.
6 PR: none.
7 Originator: <andreast@gcc.gnu.org> 20031026 */
8
9 /* { dg-do run } */
10 #include "ffitest.h"
11
12 static void
13 closure_test_fn5(ffi_cif* cif __UNUSED__, void* resp, void** args,
14 void* userdata)
15 {
16 *(ffi_arg*)resp =
17 (int)*(unsigned long long *)args[0] + (int)*(unsigned long long *)args[1] +
18 (int)*(unsigned long long *)args[2] + (int)*(unsigned long long *)args[3] +
19 (int)*(unsigned long long *)args[4] + (int)*(unsigned long long *)args[5] +
20 (int)*(unsigned long long *)args[6] + (int)*(unsigned long long *)args[7] +
21 (int)*(unsigned long long *)args[8] + (int)*(unsigned long long *)args[9] +
22 (int)*(int *)args[10] +
23 (int)*(unsigned long long *)args[11] +
24 (int)*(unsigned long long *)args[12] +
25 (int)*(unsigned long long *)args[13] +
26 (int)*(unsigned long long *)args[14] +
27 *(int *)args[15] + (intptr_t)userdata;
28
29 printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
30 (int)*(unsigned long long *)args[0],
31 (int)*(unsigned long long *)args[1],
32 (int)*(unsigned long long *)args[2],
33 (int)*(unsigned long long *)args[3],
34 (int)*(unsigned long long *)args[4],
35 (int)*(unsigned long long *)args[5],
36 (int)*(unsigned long long *)args[6],
37 (int)*(unsigned long long *)args[7],
38 (int)*(unsigned long long *)args[8],
39 (int)*(unsigned long long *)args[9],
40 (int)*(int *)args[10],
41 (int)*(unsigned long long *)args[11],
42 (int)*(unsigned long long *)args[12],
43 (int)*(unsigned long long *)args[13],
44 (int)*(unsigned long long *)args[14],
45 *(int *)args[15],
46 (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
47
48 }
49
50 typedef int (*closure_test_type0)(unsigned long long, unsigned long long,
51 unsigned long long, unsigned long long,
52 unsigned long long, unsigned long long,
53 unsigned long long, unsigned long long,
54 unsigned long long, unsigned long long,
55 int, unsigned long long,
56 unsigned long long, unsigned long long,
57 unsigned long long, int);
58
59 int main (void)
60 {
61 ffi_cif cif;
62 void *code;
63 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
64 ffi_type * cl_arg_types[17];
65 int i, res;
66
67 for (i = 0; i < 10; i++) {
68 cl_arg_types[i] = &ffi_type_uint64;
69 }
70 cl_arg_types[10] = &ffi_type_sint;
71 for (i = 11; i < 15; i++) {
72 cl_arg_types[i] = &ffi_type_uint64;
73 }
74 cl_arg_types[15] = &ffi_type_sint;
75 cl_arg_types[16] = NULL;
76
77 /* Initialize the cif */
78 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
79 &ffi_type_sint, cl_arg_types) == FFI_OK);
80
81 CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn5,
82 (void *) 3 /* userdata */, code) == FFI_OK);
83
84 res = (*((closure_test_type0)code))
85 (1LL, 2LL, 3LL, 4LL, 127LL, 429LL, 7LL, 8LL, 9LL, 10LL, 11, 12LL,
86 13LL, 19LL, 21LL, 1);
87 /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
88 printf("res: %d\n",res);
89 /* { dg-output "\nres: 680" } */
90
91 exit(0);
92 }
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
closure_test_type0
int(* closure_test_type0)(unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, unsigned long long, int, unsigned long long, unsigned long long, unsigned long long, unsigned long long, int)
Definition: closure_fn5.c:50
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
long
#define long
Definition: rb_mjit_min_header-2.7.0.h:2880
main
int main(void)
Definition: closure_fn5.c:59
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
ffi_prep_cif
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226
intptr_t
int intptr_t
Definition: win32.h:90
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928