Debian Codegraph @

testsuite/libffi.call/struct_by_value_big.c

raw
1 /* Area: ffi_call
2 Purpose: Check structures.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7 /* { dg-do run } */
8 #include "ffitest.h"
9
10 typedef struct
11 {
12 unsigned int ui01;
13 unsigned int ui02;
14 unsigned int ui03;
15 unsigned int ui04;
16 unsigned int ui05;
17 unsigned int ui06;
18 unsigned int ui07;
19 unsigned int ui08;
20 unsigned int ui09;
21 unsigned int ui10;
22 unsigned int ui11;
23 unsigned int ui12;
24 unsigned int ui13;
25 unsigned int ui14;
26 unsigned int ui15;
27 unsigned int ui16;
28 unsigned int ui17;
29 } test_structure_1;
30
31 static test_structure_1 ABI_ATTR struct1(test_structure_1 ts)
32 {
33 ts.ui17++;
34
35 return ts;
36 }
37
38 int main (void)
39 {
40 ffi_cif cif;
41 ffi_type *args[MAX_ARGS];
42 void *values[MAX_ARGS];
43 ffi_type ts1_type;
44 ffi_type *ts1_type_elements[18];
45
46 test_structure_1 ts1_arg;
47
48 /* This is a hack to get a properly aligned result buffer */
49 test_structure_1 *ts1_result =
50 (test_structure_1 *) malloc (sizeof(test_structure_1));
51
52 ts1_type.size = 0;
53 ts1_type.alignment = 0;
54 ts1_type.type = FFI_TYPE_STRUCT;
55 ts1_type.elements = ts1_type_elements;
56 ts1_type_elements[0] = &ffi_type_uint;
57 ts1_type_elements[1] = &ffi_type_uint;
58 ts1_type_elements[2] = &ffi_type_uint;
59 ts1_type_elements[3] = &ffi_type_uint;
60 ts1_type_elements[4] = &ffi_type_uint;
61 ts1_type_elements[5] = &ffi_type_uint;
62 ts1_type_elements[6] = &ffi_type_uint;
63 ts1_type_elements[7] = &ffi_type_uint;
64 ts1_type_elements[8] = &ffi_type_uint;
65 ts1_type_elements[9] = &ffi_type_uint;
66 ts1_type_elements[10] = &ffi_type_uint;
67 ts1_type_elements[11] = &ffi_type_uint;
68 ts1_type_elements[12] = &ffi_type_uint;
69 ts1_type_elements[13] = &ffi_type_uint;
70 ts1_type_elements[14] = &ffi_type_uint;
71 ts1_type_elements[15] = &ffi_type_uint;
72 ts1_type_elements[16] = &ffi_type_uint;
73 ts1_type_elements[17] = NULL;
74
75 args[0] = &ts1_type;
76 values[0] = &ts1_arg;
77
78 /* Initialize the cif */
79 CHECK(ffi_prep_cif(&cif, ABI_NUM, 1,
80 &ts1_type, args) == FFI_OK);
81
82 ts1_arg.ui17 = 555;
83
84 ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
85
86 CHECK(ts1_result->ui17 == 556);
87
88 /* This will fail if ffi_call isn't passing the struct by value. */
89 CHECK(ts1_arg.ui17 == 555);
90
91 free (ts1_result);
92 exit(0);
93 }