]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libffi/testsuite/libffi.closures/single_entry_structs1.c
1 /* Area: ffi_call, closure_call
2 Purpose: Single argument structs have a different ABI in emscripten.
5 Originator: <hood@mit.edu> */
14 static struct A
A_fn(int b0
, struct A b1
)
21 A_gn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
22 void* userdata __UNUSED__
)
27 b0
= *(int*)(args
[0]);
28 b1
= *(struct A
*)(args
[1]);
30 *(A
*)resp
= A_fn(b0
, b1
);
38 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
40 ffi_type
* cls_struct_fields
[2];
41 ffi_type cls_struct_type
;
42 ffi_type
* dbl_arg_types
[3];
45 struct A f_dbl
= { 31625 };
49 cls_struct_type
.size
= 0;
50 cls_struct_type
.alignment
= 0;
51 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
52 cls_struct_type
.elements
= cls_struct_fields
;
54 cls_struct_fields
[0] = &ffi_type_sint
;
55 cls_struct_fields
[1] = NULL
;
57 dbl_arg_types
[0] = &ffi_type_sint
;
58 dbl_arg_types
[1] = &cls_struct_type
;
59 dbl_arg_types
[2] = NULL
;
61 res_dbl
= A_fn(e_dbl
, f_dbl
);
62 printf("0 res: %d\n", res_dbl
.a
);
63 /* { dg-output "0 res: 43750" } */
65 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &cls_struct_type
,
66 dbl_arg_types
) == FFI_OK
);
73 ffi_call(&cif
, FFI_FN(A_fn
), &res_dbl
, args_dbl
);
74 printf("1 res: %d\n", res_dbl
.a
);
75 /* { dg-output "\n1 res: 43750" } */
76 CHECK( res_dbl
.a
== (e_dbl
+ f_dbl
.a
));
78 CHECK(ffi_prep_closure_loc(pcl
, &cif
, A_gn
, NULL
, code
) == FFI_OK
);
80 res_dbl
= ((A(*)(int, A
))(code
))(e_dbl
, f_dbl
);
81 printf("2 res: %d\n", res_dbl
.a
);
82 /* { dg-output "\n2 res: 43750" } */
83 CHECK( res_dbl
.a
== (e_dbl
+ f_dbl
.a
));