Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libffi / testsuite / libffi.call / struct2.c
blob14bc9fdc6f217b924c5ea78ab2cc905d88dff081
1 /* Area: ffi_call
2 Purpose: Check structures.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
7 /* { dg-do run } */
8 #include "ffitest.h"
10 typedef struct
12 double d1;
13 double d2;
14 } test_structure_2;
16 static test_structure_2 struct2(test_structure_2 ts)
18 ts.d1--;
19 ts.d2--;
21 return ts;
24 int main (void)
26 ffi_cif cif;
27 ffi_type *args[MAX_ARGS];
28 void *values[MAX_ARGS];
29 test_structure_2 ts2_arg;
30 ffi_type ts2_type;
31 ffi_type *ts2_type_elements[3];
32 ts2_type.size = 0;
33 ts2_type.alignment = 0;
34 ts2_type.type = FFI_TYPE_STRUCT;
35 ts2_type.elements = ts2_type_elements;
36 ts2_type_elements[0] = &ffi_type_double;
37 ts2_type_elements[1] = &ffi_type_double;
38 ts2_type_elements[2] = NULL;
41 /* This is a hack to get a properly aligned result buffer */
42 test_structure_2 *ts2_result =
43 (test_structure_2 *) malloc (sizeof(test_structure_2));
45 args[0] = &ts2_type;
46 values[0] = &ts2_arg;
48 /* Initialize the cif */
49 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts2_type, args) == FFI_OK);
51 ts2_arg.d1 = 5.55;
52 ts2_arg.d2 = 6.66;
54 printf ("%g\n", ts2_arg.d1);
55 printf ("%g\n", ts2_arg.d2);
57 ffi_call(&cif, FFI_FN(struct2), ts2_result, values);
59 printf ("%g\n", ts2_result->d1);
60 printf ("%g\n", ts2_result->d2);
62 CHECK(ts2_result->d1 == 5.55 - 1);
63 CHECK(ts2_result->d2 == 6.66 - 1);
65 free (ts2_result);
66 exit(0);