1 /* Area: ffi_call, closure_call
2 Purpose: Check structure alignment of long double.
5 Originator: Blake Chaffin 6/18/2007
8 /* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
9 /* { dg-do run { xfail strongarm*-*-* } } */
10 /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
11 /* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
15 typedef struct cls_struct_align
{
25 cls_struct_align
cls_struct_align_fn(
29 struct cls_struct_align r
;
39 printf("%Lg %Lg %Lg %Lg %Lg %g %Lg %Lg %Lg %Lg %Lg %Lg %g %Lg: "
40 "%Lg %Lg %Lg %Lg %Lg %g %Lg\n",
41 a1
.a
, a1
.b
, a1
.c
, a1
.d
, a1
.e
, a1
.f
, a1
.g
,
42 a2
.a
, a2
.b
, a2
.c
, a2
.d
, a2
.e
, a2
.f
, a2
.g
,
43 r
.a
, r
.b
, r
.c
, r
.d
, r
.e
, r
.f
, r
.g
);
49 cls_struct_align_gn(ffi_cif
* cif __UNUSED__
, void* resp
, void** args
,
50 void* userdata __UNUSED__
)
52 struct cls_struct_align a1
, a2
;
54 a1
= *(struct cls_struct_align
*)(args
[0]);
55 a2
= *(struct cls_struct_align
*)(args
[1]);
57 *(cls_struct_align
*)resp
= cls_struct_align_fn(a1
, a2
);
64 ffi_closure
*pcl
= ffi_closure_alloc(sizeof(ffi_closure
), &code
);
66 ffi_type
* cls_struct_fields
[8];
67 ffi_type cls_struct_type
;
68 ffi_type
* dbl_arg_types
[3];
70 cls_struct_type
.size
= 0;
71 cls_struct_type
.alignment
= 0;
72 cls_struct_type
.type
= FFI_TYPE_STRUCT
;
73 cls_struct_type
.elements
= cls_struct_fields
;
75 struct cls_struct_align g_dbl
= { 1, 2, 3, 4, 5, 6, 7 };
76 struct cls_struct_align f_dbl
= { 8, 9, 10, 11, 12, 13, 14 };
77 struct cls_struct_align res_dbl
;
79 cls_struct_fields
[0] = &ffi_type_longdouble
;
80 cls_struct_fields
[1] = &ffi_type_longdouble
;
81 cls_struct_fields
[2] = &ffi_type_longdouble
;
82 cls_struct_fields
[3] = &ffi_type_longdouble
;
83 cls_struct_fields
[4] = &ffi_type_longdouble
;
84 cls_struct_fields
[5] = &ffi_type_double
;
85 cls_struct_fields
[6] = &ffi_type_longdouble
;
86 cls_struct_fields
[7] = NULL
;
88 dbl_arg_types
[0] = &cls_struct_type
;
89 dbl_arg_types
[1] = &cls_struct_type
;
90 dbl_arg_types
[2] = NULL
;
92 CHECK(ffi_prep_cif(&cif
, FFI_DEFAULT_ABI
, 2, &cls_struct_type
,
93 dbl_arg_types
) == FFI_OK
);
99 ffi_call(&cif
, FFI_FN(cls_struct_align_fn
), &res_dbl
, args_dbl
);
100 /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
101 printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl
.a
, res_dbl
.b
,
102 res_dbl
.c
, res_dbl
.d
, res_dbl
.e
, res_dbl
.f
, res_dbl
.g
);
103 /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
105 CHECK(ffi_prep_closure_loc(pcl
, &cif
, cls_struct_align_gn
, NULL
, code
) == FFI_OK
);
107 res_dbl
= ((cls_struct_align(*)(cls_struct_align
, cls_struct_align
))(code
))(g_dbl
, f_dbl
);
108 /* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
109 printf("res: %Lg %Lg %Lg %Lg %Lg %g %Lg\n", res_dbl
.a
, res_dbl
.b
,
110 res_dbl
.c
, res_dbl
.d
, res_dbl
.e
, res_dbl
.f
, res_dbl
.g
);
111 /* { dg-output "\nres: 9 11 13 15 17 19 21" } */