Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

cls_align_longdouble_split2.c
Go to the documentation of this file.
1 /* Area: ffi_call, closure_call
2 Purpose: Check structure alignment of long double.
3 Limitations: none.
4 PR: none.
5 Originator: Blake Chaffin 6/18/2007
6 */
7
8 /* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* x86_64-*msys* } } */
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* x86_64-*-msys* } } */
12
13 #include "ffitest.h"
14
15 typedef struct cls_struct_align {
16 long double a;
17 long double b;
18 long double c;
19 long double d;
20 long double e;
21 double f;
22 long double g;
23 } cls_struct_align;
24
25 cls_struct_align cls_struct_align_fn(
26 cls_struct_align a1,
27 cls_struct_align a2)
28 {
29 struct cls_struct_align r;
30
31 r.a = a1.a + a2.a;
32 r.b = a1.b + a2.b;
33 r.c = a1.c + a2.c;
34 r.d = a1.d + a2.d;
35 r.e = a1.e + a2.e;
36 r.f = a1.f + a2.f;
37 r.g = a1.g + a2.g;
38
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);
44
45 return r;
46 }
47
48 static void
49 cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args,
50 void* userdata __UNUSED__)
51 {
52 struct cls_struct_align a1, a2;
53
54 a1 = *(struct cls_struct_align*)(args[0]);
55 a2 = *(struct cls_struct_align*)(args[1]);
56
57 *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2);
58 }
59
60 int main (void)
61 {
62 ffi_cif cif;
63 void *code;
64 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
65 void* args_dbl[3];
66 ffi_type* cls_struct_fields[8];
67 ffi_type cls_struct_type;
68 ffi_type* dbl_arg_types[3];
69
70 struct cls_struct_align g_dbl = { 1, 2, 3, 4, 5, 6, 7 };
71 struct cls_struct_align f_dbl = { 8, 9, 10, 11, 12, 13, 14 };
72 struct cls_struct_align res_dbl;
73
74 cls_struct_type.size = 0;
75 cls_struct_type.alignment = 0;
76 cls_struct_type.type = FFI_TYPE_STRUCT;
77 cls_struct_type.elements = cls_struct_fields;
78
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;
87
88 dbl_arg_types[0] = &cls_struct_type;
89 dbl_arg_types[1] = &cls_struct_type;
90 dbl_arg_types[2] = NULL;
91
92 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
93 dbl_arg_types) == FFI_OK);
94
95 args_dbl[0] = &g_dbl;
96 args_dbl[1] = &f_dbl;
97 args_dbl[2] = NULL;
98
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" } */
104
105 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK);
106
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" } */
112
113 exit(0);
114 }
115
116
117
cls_struct_align::a
unsigned char a
Definition: cls_align_double.c:13
cls_struct_align::b
double b
Definition: cls_align_double.c:14
cls_struct_align
struct cls_struct_align cls_struct_align
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:28
CHECK
#define CHECK(sub)
Definition: compile.c:448
cls_struct_align::f
long double f
Definition: cls_align_longdouble_split.c:20
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
main
int main(void)
Definition: cls_align_longdouble_split2.c:60
cls_struct_align_fn
cls_struct_align cls_struct_align_fn(cls_struct_align a1, cls_struct_align a2)
Definition: cls_align_longdouble_split2.c:25
cls_struct_align::f
double f
Definition: cls_align_longdouble_split2.c:21
cls_struct_align::e
long double e
Definition: cls_align_longdouble_split.c:19
ffi_prep_cif
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226
cls_struct_align
Definition: cls_align_double.c:12
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928
cls_struct_align::g
long double g
Definition: cls_align_longdouble_split.c:21
cls_struct_align::d
long double d
Definition: cls_align_longdouble_split.c:18
cls_struct_align::c
unsigned char c
Definition: cls_align_double.c:15