| 1 |
/* Area: closure_call |
| 2 |
Purpose: Check return value float. |
| 3 |
Limitations: none. |
| 4 |
PR: 41908. |
| 5 |
Originator: <[email protected]> 20091102 */ |
| 6 |
|
| 7 |
/* { dg-do run } */ |
| 8 |
#include "ffitest.h" |
| 9 |
|
| 10 |
typedef struct cls_struct_combined { |
| 11 |
float a; |
| 12 |
float b; |
| 13 |
float c; |
| 14 |
float d; |
| 15 |
} cls_struct_combined; |
| 16 |
|
| 17 |
static void cls_struct_combined_fn(struct cls_struct_combined arg) |
| 18 |
{ |
| 19 |
printf("%g %g %g %g\n", |
| 20 |
arg.a, arg.b, |
| 21 |
arg.c, arg.d); |
| 22 |
fflush(stdout); |
| 23 |
|
| 24 |
CHECK_FLOAT_EQ(arg.a, 4); |
| 25 |
CHECK_FLOAT_EQ(arg.b, 5); |
| 26 |
CHECK_FLOAT_EQ(arg.c, 1); |
| 27 |
CHECK_FLOAT_EQ(arg.d, 8); |
| 28 |
} |
| 29 |
|
| 30 |
static void |
| 31 |
cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__, |
| 32 |
void** args, void* userdata __UNUSED__) |
| 33 |
{ |
| 34 |
struct cls_struct_combined a0; |
| 35 |
|
| 36 |
a0 = *(struct cls_struct_combined*)(args[0]); |
| 37 |
|
| 38 |
cls_struct_combined_fn(a0); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
int main (void) |
| 43 |
{ |
| 44 |
ffi_cif cif; |
| 45 |
void *code; |
| 46 |
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); |
| 47 |
ffi_type* cls_struct_fields0[5]; |
| 48 |
ffi_type cls_struct_type0; |
| 49 |
ffi_type* dbl_arg_types[5]; |
| 50 |
|
| 51 |
struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0}; |
| 52 |
|
| 53 |
cls_struct_type0.size = 0; |
| 54 |
cls_struct_type0.alignment = 0; |
| 55 |
cls_struct_type0.type = FFI_TYPE_STRUCT; |
| 56 |
cls_struct_type0.elements = cls_struct_fields0; |
| 57 |
|
| 58 |
cls_struct_fields0[0] = &ffi_type_float; |
| 59 |
cls_struct_fields0[1] = &ffi_type_float; |
| 60 |
cls_struct_fields0[2] = &ffi_type_float; |
| 61 |
cls_struct_fields0[3] = &ffi_type_float; |
| 62 |
cls_struct_fields0[4] = NULL; |
| 63 |
|
| 64 |
dbl_arg_types[0] = &cls_struct_type0; |
| 65 |
dbl_arg_types[1] = NULL; |
| 66 |
|
| 67 |
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, |
| 68 |
dbl_arg_types) == FFI_OK); |
| 69 |
|
| 70 |
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK); |
| 71 |
|
| 72 |
((void(*)(cls_struct_combined)) (code))(g_dbl); |
| 73 |
/* { dg-output "4 5 1 8" } */ |
| 74 |
exit(0); |
| 75 |
} |