1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing with different structure size.
3 Contains structs as parameter of the struct itself.
4 Sample taken from Alan Modras patch to src/prep_cif.c.
7 Originator: <andreast@gcc.gnu.org> 20030911 */
22 B
B_fn(struct A b0
, struct B b1
)
26 result
.x
.a
= b0
.a
+ b1
.x
.a
;
27 result
.x
.b
= b0
.b
+ b1
.x
.b
+ b1
.y
;
28 result
.y
= b0
.b
+ b1
.x
.b
;
30 printf("%d %d %d %d %d: %d %d %d\n", (int)b0
.a
, b0
.b
,
31 (int)b1
.x
.a
, b1
.x
.b
, b1
.y
,
32 (int)result
.x
.a
, result
.x
.b
, result
.y
);
38 B_gn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
39 void* userdata __UNUSED__
)
44 b0
= *(struct A
*)(args
[0]);
45 b1
= *(struct B
*)(args
[1]);
47 *(B
*)resp
= B_fn(b0
, b1
);
54 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
56 ffi_type
* cls_struct_fields
[3];
57 ffi_type
* cls_struct_fields1
[3];
58 ffi_type cls_struct_type
, cls_struct_type1
;
59 ffi_type
* dbl_arg_types
[3];
61 struct A e_dbl
= { 1LL, 7};
62 struct B f_dbl
= {{12LL , 127}, 99};
66 cls_struct_type
.size
= 0;
67 cls_struct_type
.alignment
= 0;
68 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
69 cls_struct_type
.elements
= cls_struct_fields
;
71 cls_struct_type1
.size
= 0;
72 cls_struct_type1
.alignment
= 0;
73 cls_struct_type1
.type
= FFI_TYPE_STRUCT
;
74 cls_struct_type1
.elements
= cls_struct_fields1
;
76 cls_struct_fields
[0] = &ffi_type_uint64
;
77 cls_struct_fields
[1] = &ffi_type_uchar
;
78 cls_struct_fields
[2] = NULL
;
80 cls_struct_fields1
[0] = &cls_struct_type
;
81 cls_struct_fields1
[1] = &ffi_type_uchar
;
82 cls_struct_fields1
[2] = NULL
;
85 dbl_arg_types
[0] = &cls_struct_type
;
86 dbl_arg_types
[1] = &cls_struct_type1
;
87 dbl_arg_types
[2] = NULL
;
89 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &cls_struct_type1
,
90 dbl_arg_types
) == FFI_OK
);
96 ffi_call(&cif
, FFI_FN(B_fn
), &res_dbl
, args_dbl
);
97 /* { dg-output "1 7 12 127 99: 13 233 134" } */
98 CHECK( res_dbl
.x
.a
== (e_dbl
.a
+ f_dbl
.x
.a
));
99 CHECK( res_dbl
.x
.b
== (e_dbl
.b
+ f_dbl
.x
.b
+ f_dbl
.y
));
100 CHECK( res_dbl
.y
== (e_dbl
.b
+ f_dbl
.x
.b
));
103 CHECK(ffi_prep_closure_loc(pcl
, &cif
, B_gn
, NULL
, code
) == FFI_OK
);
105 res_dbl
= ((B(*)(A
, B
))(code
))(e_dbl
, f_dbl
);
106 /* { dg-output "\n1 7 12 127 99: 13 233 134" } */
107 CHECK( res_dbl
.x
.a
== (e_dbl
.a
+ f_dbl
.x
.a
));
108 CHECK( res_dbl
.x
.b
== (e_dbl
.b
+ f_dbl
.x
.b
+ f_dbl
.y
));
109 CHECK( res_dbl
.y
== (e_dbl
.b
+ f_dbl
.x
.b
));