Debian Codegraph @

testsuite/libffi.call/struct_int_float.c

raw
1 /* Area: ffi_call
2 Purpose: Demonstrate structures with integers corrupting earlier floats
3 Limitations: none.
4 PR: #848
5 Originator: kellda */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 typedef struct
11 {
12 unsigned long i;
13 float f;
14 } test_structure_int_float;
15
16 static float ABI_ATTR struct_int_float(test_structure_int_float ts1,
17 test_structure_int_float ts2 __UNUSED__,
18 test_structure_int_float ts3 __UNUSED__,
19 test_structure_int_float ts4 __UNUSED__,
20 test_structure_int_float ts5 __UNUSED__,
21 test_structure_int_float ts6 __UNUSED__)
22 {
23 return ts1.f;
24 }
25
26 int main (void)
27 {
28 ffi_cif cif;
29 ffi_type *args[MAX_ARGS];
30 void *values[MAX_ARGS];
31 ffi_type ts_type;
32 ffi_type *ts_type_elements[3];
33 float rfloat;
34
35 test_structure_int_float ts_arg[6];
36
37 ts_type.size = 0;
38 ts_type.alignment = 0;
39 ts_type.type = FFI_TYPE_STRUCT;
40 ts_type.elements = ts_type_elements;
41 ts_type_elements[0] = &ffi_type_ulong;
42 ts_type_elements[1] = &ffi_type_float;
43 ts_type_elements[2] = NULL;
44
45 args[0] = &ts_type;
46 values[0] = &ts_arg[0];
47 args[1] = &ts_type;
48 values[1] = &ts_arg[1];
49 args[2] = &ts_type;
50 values[2] = &ts_arg[2];
51 args[3] = &ts_type;
52 values[3] = &ts_arg[3];
53 args[4] = &ts_type;
54 values[4] = &ts_arg[4];
55 args[5] = &ts_type;
56 values[5] = &ts_arg[5];
57
58 /* Initialize the cif */
59 CHECK(ffi_prep_cif(&cif, ABI_NUM, 6, &ffi_type_float, args) == FFI_OK);
60
61 ts_arg[0].i = 1;
62 ts_arg[0].f = 11.11f;
63 ts_arg[1].i = 2;
64 ts_arg[1].f = 22.22f;
65 ts_arg[2].i = 3;
66 ts_arg[2].f = 33.33f;
67 ts_arg[3].i = 4;
68 ts_arg[3].f = 44.44f;
69 ts_arg[4].i = 5;
70 ts_arg[4].f = 55.55f;
71 ts_arg[5].i = 6;
72 ts_arg[5].f = 66.66f;
73
74 printf ("%g\n", ts_arg[0].f);
75 printf ("%g\n", ts_arg[1].f);
76 printf ("%g\n", ts_arg[2].f);
77 printf ("%g\n", ts_arg[3].f);
78 printf ("%g\n", ts_arg[4].f);
79 printf ("%g\n", ts_arg[5].f);
80
81 ffi_call(&cif, FFI_FN(struct_int_float), &rfloat, values);
82
83 printf ("%g\n", rfloat);
84
85 CHECK(fabs(rfloat - 11.11) < 3 * FLT_EPSILON);
86
87 exit(0);
88 }