1 /* Area: ffi_call, closure_call
2 Purpose: Check structure alignment of long double.
5 Originator: <hos@tamanegi.org> 20031203 */
7 /* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
8 /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
9 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
10 /* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
14 typedef struct cls_struct_align
{
24 cls_struct_align
cls_struct_align_fn(
28 struct cls_struct_align r
;
38 printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: "
39 "%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n",
40 a1
.a
, a1
.b
, a1
.c
, a1
.d
, a1
.e
, a1
.f
, a1
.g
,
41 a2
.a
, a2
.b
, a2
.c
, a2
.d
, a2
.e
, a2
.f
, a2
.g
,
42 r
.a
, r
.b
, r
.c
, r
.d
, r
.e
, r
.f
, r
.g
);
47 cls_struct_align
cls_struct_align_fn2(
50 struct cls_struct_align r
;
60 printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg: "
61 "%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n",
62 a1
.a
, a1
.b
, a1
.c
, a1
.d
, a1
.e
, a1
.f
, a1
.g
,
63 r
.a
, r
.b
, r
.c
, r
.d
, r
.e
, r
.f
, r
.g
);
69 cls_struct_align_gn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
70 void* userdata __UNUSED__
)
72 struct cls_struct_align a1
, a2
;
74 a1
= *(struct cls_struct_align
*)(args
[0]);
75 a2
= *(struct cls_struct_align
*)(args
[1]);
77 *(cls_struct_align
*)resp
= cls_struct_align_fn(a1
, a2
);
84 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
86 ffi_type
* cls_struct_fields
[8];
87 ffi_type cls_struct_type
;
88 ffi_type
* dbl_arg_types
[3];
90 cls_struct_type
.size
= 0;
91 cls_struct_type
.alignment
= 0;
92 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
93 cls_struct_type
.elements
= cls_struct_fields
;
95 struct cls_struct_align g_dbl
= { 1, 2, 3, 4, 5, 6, 7 };
96 struct cls_struct_align f_dbl
= { 8, 9, 10, 11, 12, 13, 14 };
97 struct cls_struct_align res_dbl
;
99 cls_struct_fields
[0] = &ffi_type_longdouble
;
100 cls_struct_fields
[1] = &ffi_type_longdouble
;
101 cls_struct_fields
[2] = &ffi_type_longdouble
;
102 cls_struct_fields
[3] = &ffi_type_longdouble
;
103 cls_struct_fields
[4] = &ffi_type_longdouble
;
104 cls_struct_fields
[5] = &ffi_type_longdouble
;
105 cls_struct_fields
[6] = &ffi_type_longdouble
;
106 cls_struct_fields
[7] = NULL
;
108 dbl_arg_types
[0] = &cls_struct_type
;
109 dbl_arg_types
[1] = &cls_struct_type
;
110 dbl_arg_types
[2] = NULL
;
112 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &cls_struct_type
,
113 dbl_arg_types
) == FFI_OK
);
115 args_dbl
[0] = &g_dbl
;
116 args_dbl
[1] = &f_dbl
;
119 ffi_call(&cif
, FFI_FN(cls_struct_align_fn
), &res_dbl
, args_dbl
);
120 /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
121 printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl
.a
, res_dbl
.b
,
122 res_dbl
.c
, res_dbl
.d
, res_dbl
.e
, res_dbl
.f
, res_dbl
.g
);
123 /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
125 CHECK(ffi_prep_closure_loc(pcl
, &cif
, cls_struct_align_gn
, NULL
, code
) == FFI_OK
);
127 res_dbl
= ((cls_struct_align(*)(cls_struct_align
, cls_struct_align
))(code
))(g_dbl
, f_dbl
);
128 /* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
129 printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl
.a
, res_dbl
.b
,
130 res_dbl
.c
, res_dbl
.d
, res_dbl
.e
, res_dbl
.f
, res_dbl
.g
);
131 /* { dg-output "\nres: 9 11 13 15 17 19 21" } */