1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing with different structure size.
3 Depending on the ABI. Check overlapping.
6 Originator: <andreast@gcc.gnu.org> 20030828 */
11 typedef struct cls_struct_24byte
{
18 cls_struct_24byte
cls_struct_24byte_fn(struct cls_struct_24byte b0
,
19 struct cls_struct_24byte b1
,
20 struct cls_struct_24byte b2
,
21 struct cls_struct_24byte b3
)
23 struct cls_struct_24byte result
;
25 result
.a
= b0
.a
+ b1
.a
+ b2
.a
+ b3
.a
;
26 result
.b
= b0
.b
+ b1
.b
+ b2
.b
+ b3
.b
;
27 result
.c
= b0
.c
+ b1
.c
+ b2
.c
+ b3
.c
;
28 result
.d
= b0
.d
+ b1
.d
+ b2
.d
+ b3
.d
;
30 printf("%g %g %d %g %g %g %d %g %g %g %d %g %g %g %d %g: %g %g %d %g\n",
31 b0
.a
, b0
.b
, b0
.c
, b0
.d
,
32 b1
.a
, b1
.b
, b1
.c
, b1
.d
,
33 b2
.a
, b2
.b
, b2
.c
, b2
.d
,
34 b3
.a
, b3
.b
, b3
.c
, b2
.d
,
35 result
.a
, result
.b
, result
.c
, result
.d
);
41 cls_struct_24byte_gn(ffi_cif
* cif
, void* resp
, void** args
, void* userdata
)
43 struct cls_struct_24byte b0
, b1
, b2
, b3
;
45 b0
= *(struct cls_struct_24byte
*)(args
[0]);
46 b1
= *(struct cls_struct_24byte
*)(args
[1]);
47 b2
= *(struct cls_struct_24byte
*)(args
[2]);
48 b3
= *(struct cls_struct_24byte
*)(args
[3]);
50 *(cls_struct_24byte
*)resp
= cls_struct_24byte_fn(b0
, b1
, b2
, b3
);
56 static ffi_closure cl
;
57 ffi_closure
*pcl
= &cl
;
59 ffi_type
* cls_struct_fields
[5];
60 ffi_type cls_struct_type
;
61 ffi_type
* dbl_arg_types
[5];
63 cls_struct_type
.size
= 0;
64 cls_struct_type
.alignment
= 0;
65 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
66 cls_struct_type
.elements
= cls_struct_fields
;
68 struct cls_struct_24byte e_dbl
= { 9.0, 2.0, 6, 5.0 };
69 struct cls_struct_24byte f_dbl
= { 1.0, 2.0, 3, 7.0 };
70 struct cls_struct_24byte g_dbl
= { 4.0, 5.0, 7, 9.0 };
71 struct cls_struct_24byte h_dbl
= { 8.0, 6.0, 1, 4.0 };
72 struct cls_struct_24byte res_dbl
;
74 cls_struct_fields
[0] = &ffi_type_double
;
75 cls_struct_fields
[1] = &ffi_type_double
;
76 cls_struct_fields
[2] = &ffi_type_uint32
;
77 cls_struct_fields
[3] = &ffi_type_float
;
78 cls_struct_fields
[4] = NULL
;
80 dbl_arg_types
[0] = &cls_struct_type
;
81 dbl_arg_types
[1] = &cls_struct_type
;
82 dbl_arg_types
[2] = &cls_struct_type
;
83 dbl_arg_types
[3] = &cls_struct_type
;
84 dbl_arg_types
[4] = NULL
;
86 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 4, &cls_struct_type
,
87 dbl_arg_types
) == FFI_OK
);
95 ffi_call(&cif
, FFI_FN(cls_struct_24byte_fn
), &res_dbl
, args_dbl
);
96 /* { dg-output "9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 9: 22 15 17 25" } */
97 CHECK( res_dbl
.a
== (e_dbl
.a
+ f_dbl
.a
+ g_dbl
.a
+ h_dbl
.a
));
98 CHECK( res_dbl
.b
== (e_dbl
.b
+ f_dbl
.b
+ g_dbl
.b
+ h_dbl
.b
));
99 CHECK( res_dbl
.c
== (e_dbl
.c
+ f_dbl
.c
+ g_dbl
.c
+ h_dbl
.c
));
100 CHECK( res_dbl
.d
== (e_dbl
.d
+ f_dbl
.d
+ g_dbl
.d
+ h_dbl
.d
));
102 CHECK(ffi_prep_closure(pcl
, &cif
, cls_struct_24byte_gn
, NULL
) == FFI_OK
);
104 res_dbl
= ((cls_struct_24byte(*)(cls_struct_24byte
,
108 (pcl
))(e_dbl
, f_dbl
, g_dbl
, h_dbl
);
109 /* { dg-output "\n9 2 6 5 1 2 3 7 4 5 7 9 8 6 1 9: 22 15 17 25" } */
110 CHECK( res_dbl
.a
== (e_dbl
.a
+ f_dbl
.a
+ g_dbl
.a
+ h_dbl
.a
));
111 CHECK( res_dbl
.b
== (e_dbl
.b
+ f_dbl
.b
+ g_dbl
.b
+ h_dbl
.b
));
112 CHECK( res_dbl
.c
== (e_dbl
.c
+ f_dbl
.c
+ g_dbl
.c
+ h_dbl
.c
));
113 CHECK( res_dbl
.d
== (e_dbl
.d
+ f_dbl
.d
+ g_dbl
.d
+ h_dbl
.d
));