1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing.
5 Originator: <jincheng@ca.ibm.com> and <jakub@redhat.com> 20210609 */
19 B
B_fn(float b0
, struct B b1
)
24 result
.y
.a
= b0
+ b1
.y
.a
;
25 result
.y
.b
= b0
+ b1
.y
.b
;
27 printf("%g %g %g %g: %g %g %g\n", b0
, b1
.x
, b1
.y
.a
, b1
.y
.b
,
28 result
.x
, result
.y
.a
, result
.y
.b
);
34 B_gn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
35 void* userdata __UNUSED__
)
40 b0
= *(float*)(args
[0]);
41 b1
= *(struct B
*)(args
[1]);
43 *(B
*)resp
= B_fn(b0
, b1
);
50 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
52 ffi_type
* cls_struct_fields
[3];
53 ffi_type
* cls_struct_fields1
[3];
54 ffi_type cls_struct_type
, cls_struct_type1
;
55 ffi_type
* dbl_arg_types
[3];
57 float e_dbl
= 12.125f
;
58 struct B f_dbl
= { 24.75f
, { 31.625f
, 32.25f
} };
62 cls_struct_type
.size
= 0;
63 cls_struct_type
.alignment
= 0;
64 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
65 cls_struct_type
.elements
= cls_struct_fields
;
67 cls_struct_type1
.size
= 0;
68 cls_struct_type1
.alignment
= 0;
69 cls_struct_type1
.type
= FFI_TYPE_STRUCT
;
70 cls_struct_type1
.elements
= cls_struct_fields1
;
72 cls_struct_fields
[0] = &ffi_type_float
;
73 cls_struct_fields
[1] = &ffi_type_float
;
74 cls_struct_fields
[2] = NULL
;
76 cls_struct_fields1
[0] = &ffi_type_float
;
77 cls_struct_fields1
[1] = &cls_struct_type
;
78 cls_struct_fields1
[2] = NULL
;
81 dbl_arg_types
[0] = &ffi_type_float
;
82 dbl_arg_types
[1] = &cls_struct_type1
;
83 dbl_arg_types
[2] = NULL
;
85 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &cls_struct_type1
,
86 dbl_arg_types
) == FFI_OK
);
92 ffi_call(&cif
, FFI_FN(B_fn
), &res_dbl
, args_dbl
);
93 /* { dg-output "12.125 24.75 31.625 32.25: 36.875 43.75 44.375" } */
94 CHECK( res_dbl
.x
== (e_dbl
+ f_dbl
.x
));
95 CHECK( res_dbl
.y
.a
== (e_dbl
+ f_dbl
.y
.a
));
96 CHECK( res_dbl
.y
.b
== (e_dbl
+ f_dbl
.y
.b
));
98 CHECK(ffi_prep_closure_loc(pcl
, &cif
, B_gn
, NULL
, code
) == FFI_OK
);
100 res_dbl
= ((B(*)(float, B
))(code
))(e_dbl
, f_dbl
);
101 /* { dg-output "\n12.125 24.75 31.625 32.25: 36.875 43.75 44.375" } */
102 CHECK( res_dbl
.x
== (e_dbl
+ f_dbl
.x
));
103 CHECK( res_dbl
.y
.a
== (e_dbl
+ f_dbl
.y
.a
));
104 CHECK( res_dbl
.y
.b
== (e_dbl
+ f_dbl
.y
.b
));