| 1 |
/* Area: ffi_call, closure_call |
| 2 |
Purpose: Check structure alignment of long double. |
| 3 |
Limitations: none. |
| 4 |
PR: none. |
| 5 |
Originator: <[email protected]> 20031203 */ |
| 6 |
|
| 7 |
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ |
| 8 |
/* { dg-options -mlong-double-128 { target powerpc64*-*-linux-gnu* } } */ |
| 9 |
|
| 10 |
#include "ffitest.h" |
| 11 |
|
| 12 |
typedef struct cls_struct_align { |
| 13 |
long double a; |
| 14 |
long double b; |
| 15 |
long double c; |
| 16 |
long double d; |
| 17 |
long double e; |
| 18 |
long double f; |
| 19 |
long double g; |
| 20 |
} cls_struct_align; |
| 21 |
|
| 22 |
static cls_struct_align cls_struct_align_fn( |
| 23 |
cls_struct_align a1, |
| 24 |
cls_struct_align a2) |
| 25 |
{ |
| 26 |
struct cls_struct_align r; |
| 27 |
|
| 28 |
r.a = a1.a + a2.a; |
| 29 |
r.b = a1.b + a2.b; |
| 30 |
r.c = a1.c + a2.c; |
| 31 |
r.d = a1.d + a2.d; |
| 32 |
r.e = a1.e + a2.e; |
| 33 |
r.f = a1.f + a2.f; |
| 34 |
r.g = a1.g + a2.g; |
| 35 |
|
| 36 |
printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: " |
| 37 |
"%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", |
| 38 |
a1.a, a1.b, a1.c, a1.d, a1.e, a1.f, a1.g, |
| 39 |
a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g, |
| 40 |
r.a, r.b, r.c, r.d, r.e, r.f, r.g); |
| 41 |
|
| 42 |
CHECK(a1.a == 1); |
| 43 |
CHECK(a1.b == 2); |
| 44 |
CHECK(a1.c == 3); |
| 45 |
CHECK(a1.d == 4); |
| 46 |
CHECK(a1.e == 5); |
| 47 |
CHECK(a1.f == 6); |
| 48 |
CHECK(a1.g == 7); |
| 49 |
|
| 50 |
CHECK(a2.a == 8); |
| 51 |
CHECK(a2.b == 9); |
| 52 |
CHECK(a2.c == 10); |
| 53 |
CHECK(a2.d == 11); |
| 54 |
CHECK(a2.e == 12); |
| 55 |
CHECK(a2.f == 13); |
| 56 |
CHECK(a2.g == 14); |
| 57 |
|
| 58 |
CHECK(r.a == 9); |
| 59 |
CHECK(r.b == 11); |
| 60 |
CHECK(r.c == 13); |
| 61 |
CHECK(r.d == 15); |
| 62 |
CHECK(r.e == 17); |
| 63 |
CHECK(r.f == 19); |
| 64 |
CHECK(r.g == 21); |
| 65 |
return r; |
| 66 |
} |
| 67 |
|
| 68 |
static void |
| 69 |
cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args, |
| 70 |
void* userdata __UNUSED__) |
| 71 |
{ |
| 72 |
struct cls_struct_align a1, a2; |
| 73 |
|
| 74 |
a1 = *(struct cls_struct_align*)(args[0]); |
| 75 |
a2 = *(struct cls_struct_align*)(args[1]); |
| 76 |
|
| 77 |
*(cls_struct_align*)resp = cls_struct_align_fn(a1, a2); |
| 78 |
} |
| 79 |
|
| 80 |
int main (void) |
| 81 |
{ |
| 82 |
ffi_cif cif; |
| 83 |
void *code; |
| 84 |
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); |
| 85 |
void* args_dbl[3]; |
| 86 |
ffi_type* cls_struct_fields[8]; |
| 87 |
ffi_type cls_struct_type; |
| 88 |
ffi_type* dbl_arg_types[3]; |
| 89 |
|
| 90 |
struct cls_struct_align g_dbl = { 1, 2, 3, 4, 5, 6, 7 }; |
| 91 |
struct cls_struct_align f_dbl = { 8, 9, 10, 11, 12, 13, 14 }; |
| 92 |
struct cls_struct_align res_dbl; |
| 93 |
|
| 94 |
cls_struct_type.size = 0; |
| 95 |
cls_struct_type.alignment = 0; |
| 96 |
cls_struct_type.type = FFI_TYPE_STRUCT; |
| 97 |
cls_struct_type.elements = cls_struct_fields; |
| 98 |
|
| 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; |
| 107 |
|
| 108 |
dbl_arg_types[0] = &cls_struct_type; |
| 109 |
dbl_arg_types[1] = &cls_struct_type; |
| 110 |
dbl_arg_types[2] = NULL; |
| 111 |
|
| 112 |
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type, |
| 113 |
dbl_arg_types) == FFI_OK); |
| 114 |
|
| 115 |
args_dbl[0] = &g_dbl; |
| 116 |
args_dbl[1] = &f_dbl; |
| 117 |
args_dbl[2] = NULL; |
| 118 |
|
| 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" } */ |
| 124 |
CHECK(res_dbl.a == 9); |
| 125 |
CHECK(res_dbl.b == 11); |
| 126 |
CHECK(res_dbl.c == 13); |
| 127 |
CHECK(res_dbl.d == 15); |
| 128 |
CHECK(res_dbl.e == 17); |
| 129 |
CHECK(res_dbl.f == 19); |
| 130 |
CHECK(res_dbl.g == 21); |
| 131 |
|
| 132 |
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK); |
| 133 |
|
| 134 |
res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl); |
| 135 |
/* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */ |
| 136 |
printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl.a, res_dbl.b, |
| 137 |
res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g); |
| 138 |
/* { dg-output "\nres: 9 11 13 15 17 19 21" } */ |
| 139 |
CHECK(res_dbl.a == 9); |
| 140 |
CHECK(res_dbl.b == 11); |
| 141 |
CHECK(res_dbl.c == 13); |
| 142 |
CHECK(res_dbl.d == 15); |
| 143 |
CHECK(res_dbl.e == 17); |
| 144 |
CHECK(res_dbl.f == 19); |
| 145 |
CHECK(res_dbl.g == 21); |
| 146 |
exit(0); |
| 147 |
} |