nested_struct11.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* { dg-do run } */
  10. #include "ffitest.h"
  11. typedef struct A {
  12. float a_x;
  13. float a_y;
  14. } A;
  15. typedef struct B {
  16. float b_x;
  17. float b_y;
  18. } B;
  19. typedef struct C {
  20. A a;
  21. B b;
  22. } C;
  23. static C C_fn (int x, int y, int z, C source, int i, int j, int k)
  24. {
  25. C result;
  26. result.a.a_x = source.a.a_x;
  27. result.a.a_y = source.a.a_y;
  28. result.b.b_x = source.b.b_x;
  29. result.b.b_y = source.b.b_y;
  30. printf ("%d, %d, %d, %d, %d, %d\n", x, y, z, i, j, k);
  31. printf ("%.1f, %.1f, %.1f, %.1f, "
  32. "%.1f, %.1f, %.1f, %.1f\n",
  33. source.a.a_x, source.a.a_y,
  34. source.b.b_x, source.b.b_y,
  35. result.a.a_x, result.a.a_y,
  36. result.b.b_x, result.b.b_y);
  37. return result;
  38. }
  39. int main (void)
  40. {
  41. ffi_cif cif;
  42. ffi_type* struct_fields_source_a[3];
  43. ffi_type* struct_fields_source_b[3];
  44. ffi_type* struct_fields_source_c[3];
  45. ffi_type* arg_types[8];
  46. ffi_type struct_type_a, struct_type_b, struct_type_c;
  47. struct A source_fld_a = {1.0, 2.0};
  48. struct B source_fld_b = {4.0, 8.0};
  49. int k = 1;
  50. struct C result;
  51. struct C source = {source_fld_a, source_fld_b};
  52. struct_type_a.size = 0;
  53. struct_type_a.alignment = 0;
  54. struct_type_a.type = FFI_TYPE_STRUCT;
  55. struct_type_a.elements = struct_fields_source_a;
  56. struct_type_b.size = 0;
  57. struct_type_b.alignment = 0;
  58. struct_type_b.type = FFI_TYPE_STRUCT;
  59. struct_type_b.elements = struct_fields_source_b;
  60. struct_type_c.size = 0;
  61. struct_type_c.alignment = 0;
  62. struct_type_c.type = FFI_TYPE_STRUCT;
  63. struct_type_c.elements = struct_fields_source_c;
  64. struct_fields_source_a[0] = &ffi_type_float;
  65. struct_fields_source_a[1] = &ffi_type_float;
  66. struct_fields_source_a[2] = NULL;
  67. struct_fields_source_b[0] = &ffi_type_float;
  68. struct_fields_source_b[1] = &ffi_type_float;
  69. struct_fields_source_b[2] = NULL;
  70. struct_fields_source_c[0] = &struct_type_a;
  71. struct_fields_source_c[1] = &struct_type_b;
  72. struct_fields_source_c[2] = NULL;
  73. arg_types[0] = &ffi_type_sint32;
  74. arg_types[1] = &ffi_type_sint32;
  75. arg_types[2] = &ffi_type_sint32;
  76. arg_types[3] = &struct_type_c;
  77. arg_types[4] = &ffi_type_sint32;
  78. arg_types[5] = &ffi_type_sint32;
  79. arg_types[6] = &ffi_type_sint32;
  80. arg_types[7] = NULL;
  81. void *args[7];
  82. args[0] = &k;
  83. args[1] = &k;
  84. args[2] = &k;
  85. args[3] = &source;
  86. args[4] = &k;
  87. args[5] = &k;
  88. args[6] = &k;
  89. CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 7, &struct_type_c,
  90. arg_types) == FFI_OK);
  91. ffi_call (&cif, FFI_FN (C_fn), &result, args);
  92. /* { dg-output "1, 1, 1, 1, 1, 1\n" } */
  93. /* { dg-output "1.0, 2.0, 4.0, 8.0, 1.0, 2.0, 4.0, 8.0" } */
  94. CHECK (result.a.a_x == source.a.a_x);
  95. CHECK (result.a.a_y == source.a.a_y);
  96. CHECK (result.b.b_x == source.b.b_x);
  97. CHECK (result.b.b_y == source.b.b_y);
  98. exit (0);
  99. }