*** empty log message ***
[official-gcc.git] / libffi / testsuite / libffi.call / cls_16byte.c
blobe4fdeb86be097c18c16a559d08136aceaa6022de
1 /* Area: ffi_call, closure_call
2 Purpose: Check structure passing with different structure size.
3 Depending on the ABI. Check overlapping.
4 Limitations: none.
5 PR: none.
6 Originator: <andreast@gcc.gnu.org> 20030828 */
8 /* { dg-do run } */
9 #include "ffitest.h"
11 typedef struct cls_struct_16byte {
12 int a;
13 double b;
14 int c;
15 } cls_struct_16byte;
17 cls_struct_16byte cls_struct_16byte_fn(struct cls_struct_16byte b1,
18 struct cls_struct_16byte b2)
20 struct cls_struct_16byte result;
22 result.a = b1.a + b2.a;
23 result.b = b1.b + b2.b;
24 result.c = b1.c + b2.c;
26 printf("%d %g %d %d %g %d: %d %g %d\n", b1.a, b1.b, b1.c, b2.a, b2.b, b2.c,
27 result.a, result.b, result.c);
29 return result;
32 static void cls_struct_16byte_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
34 struct cls_struct_16byte b1, b2;
36 b1 = *(struct cls_struct_16byte*)(args[0]);
37 b2 = *(struct cls_struct_16byte*)(args[1]);
39 *(cls_struct_16byte*)resp = cls_struct_16byte_fn(b1, b2);
42 int main (void)
44 ffi_cif cif;
45 static ffi_closure cl;
46 ffi_closure *pcl = &cl;
47 void* args_dbl[5];
48 ffi_type* cls_struct_fields[4];
49 ffi_type cls_struct_type;
50 ffi_type* dbl_arg_types[5];
52 cls_struct_type.size = 0;
53 cls_struct_type.alignment = 0;
54 cls_struct_type.type = FFI_TYPE_STRUCT;
55 cls_struct_type.elements = cls_struct_fields;
57 struct cls_struct_16byte h_dbl = { 7, 8.0, 9 };
58 struct cls_struct_16byte j_dbl = { 1, 9.0, 3 };
59 struct cls_struct_16byte res_dbl;
61 cls_struct_fields[0] = &ffi_type_uint32;
62 cls_struct_fields[1] = &ffi_type_double;
63 cls_struct_fields[2] = &ffi_type_uint32;
64 cls_struct_fields[3] = NULL;
66 dbl_arg_types[0] = &cls_struct_type;
67 dbl_arg_types[1] = &cls_struct_type;
68 dbl_arg_types[2] = NULL;
70 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
71 dbl_arg_types) == FFI_OK);
73 args_dbl[0] = &h_dbl;
74 args_dbl[1] = &j_dbl;
75 args_dbl[2] = NULL;
77 ffi_call(&cif, FFI_FN(cls_struct_16byte_fn), &res_dbl, args_dbl);
78 /* { dg-output "7 8 9 1 9 3: 8 17 12" } */
79 CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
80 CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
81 CHECK( res_dbl.c == (h_dbl.c + j_dbl.c));
83 CHECK(ffi_prep_closure(pcl, &cif, cls_struct_16byte_gn, NULL) == FFI_OK);
85 res_dbl = ((cls_struct_16byte(*)(cls_struct_16byte, cls_struct_16byte))(pcl))(h_dbl, j_dbl);
86 /* { dg-output "\n7 8 9 1 9 3: 8 17 12" } */
87 CHECK( res_dbl.a == (h_dbl.a + j_dbl.a));
88 CHECK( res_dbl.b == (h_dbl.b + j_dbl.b));
89 CHECK( res_dbl.c == (h_dbl.c + j_dbl.c));
91 exit(0);