Debian Codegraph @

testsuite/libffi.closures/nested_struct11.c

raw
1 /* Area: ffi_call, closure_call
2 Purpose: Check parameter passing with nested structs
3 of a single type. This tests the special cases
4 for homogeneous floating-point aggregates in the
5 AArch64 PCS.
6 Limitations: none.
7 PR: none.
8 Originator: ARM Ltd. */
9
10 /* { dg-do run } */
11 #include "ffitest.h"
12
13 typedef struct A {
14 float a_x;
15 float a_y;
16 } A;
17
18 typedef struct B {
19 float b_x;
20 float b_y;
21 } B;
22
23 typedef struct C {
24 A a;
25 B b;
26 } C;
27
28 static C C_fn (int x, int y, int z, C source, int i, int j, int k)
29 {
30 C result;
31 result.a.a_x = source.a.a_x;
32 result.a.a_y = source.a.a_y;
33 result.b.b_x = source.b.b_x;
34 result.b.b_y = source.b.b_y;
35
36 printf ("%d, %d, %d, %d, %d, %d\n", x, y, z, i, j, k);
37
38 CHECK(x == 1);
39 CHECK(y == 1);
40 CHECK(z == 1);
41 CHECK(i == 1);
42 CHECK(j == 1);
43 CHECK(k == 1);
44
45 printf ("%.1f, %.1f, %.1f, %.1f, "
46 "%.1f, %.1f, %.1f, %.1f\n",
47 source.a.a_x, source.a.a_y,
48 source.b.b_x, source.b.b_y,
49 result.a.a_x, result.a.a_y,
50 result.b.b_x, result.b.b_y);
51
52 CHECK_FLOAT_EQ(source.a.a_x, 1.0);
53 CHECK_FLOAT_EQ(source.a.a_y, 2.0);
54 CHECK_FLOAT_EQ(source.b.b_x, 4.0);
55 CHECK_FLOAT_EQ(source.b.b_y, 8.0);
56 CHECK_FLOAT_EQ(result.a.a_x, 1.0);
57 CHECK_FLOAT_EQ(result.a.a_y, 2.0);
58 CHECK_FLOAT_EQ(result.b.b_x, 4.0);
59 CHECK_FLOAT_EQ(result.b.b_y, 8.0);
60
61 return result;
62 }
63
64 int main (void)
65 {
66 ffi_cif cif;
67
68 ffi_type* struct_fields_source_a[3];
69 ffi_type* struct_fields_source_b[3];
70 ffi_type* struct_fields_source_c[3];
71 ffi_type* arg_types[8];
72
73 ffi_type struct_type_a, struct_type_b, struct_type_c;
74
75 struct A source_fld_a = {1.0, 2.0};
76 struct B source_fld_b = {4.0, 8.0};
77 int k = 1;
78
79 struct C result;
80 struct C source = {source_fld_a, source_fld_b};
81
82 struct_type_a.size = 0;
83 struct_type_a.alignment = 0;
84 struct_type_a.type = FFI_TYPE_STRUCT;
85 struct_type_a.elements = struct_fields_source_a;
86
87 struct_type_b.size = 0;
88 struct_type_b.alignment = 0;
89 struct_type_b.type = FFI_TYPE_STRUCT;
90 struct_type_b.elements = struct_fields_source_b;
91
92 struct_type_c.size = 0;
93 struct_type_c.alignment = 0;
94 struct_type_c.type = FFI_TYPE_STRUCT;
95 struct_type_c.elements = struct_fields_source_c;
96
97 struct_fields_source_a[0] = &ffi_type_float;
98 struct_fields_source_a[1] = &ffi_type_float;
99 struct_fields_source_a[2] = NULL;
100
101 struct_fields_source_b[0] = &ffi_type_float;
102 struct_fields_source_b[1] = &ffi_type_float;
103 struct_fields_source_b[2] = NULL;
104
105 struct_fields_source_c[0] = &struct_type_a;
106 struct_fields_source_c[1] = &struct_type_b;
107 struct_fields_source_c[2] = NULL;
108
109 arg_types[0] = &ffi_type_sint32;
110 arg_types[1] = &ffi_type_sint32;
111 arg_types[2] = &ffi_type_sint32;
112 arg_types[3] = &struct_type_c;
113 arg_types[4] = &ffi_type_sint32;
114 arg_types[5] = &ffi_type_sint32;
115 arg_types[6] = &ffi_type_sint32;
116 arg_types[7] = NULL;
117
118 void *args[7];
119 args[0] = &k;
120 args[1] = &k;
121 args[2] = &k;
122 args[3] = &source;
123 args[4] = &k;
124 args[5] = &k;
125 args[6] = &k;
126 CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 7, &struct_type_c,
127 arg_types) == FFI_OK);
128
129 ffi_call (&cif, FFI_FN (C_fn), &result, args);
130 /* { dg-output "1, 1, 1, 1, 1, 1\n" } */
131 /* { dg-output "1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0" } */
132 CHECK_FLOAT_EQ(result.a.a_x, source.a.a_x);
133 CHECK_FLOAT_EQ(result.a.a_y, source.a.a_y);
134 CHECK_FLOAT_EQ(result.b.b_x, source.b.b_x);
135 CHECK_FLOAT_EQ(result.b.b_y, source.b.b_y);
136 exit(0);
137 }