123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /* Area: ffi_call, closure_call
- Purpose: Check parameter passing with nested structs
- of a single type. This tests the special cases
- for homogeneous 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);
- }
|