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