cls_align_longdouble_split.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check structure alignment of long double.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <hos@tamanegi.org> 20031203 */
  6. /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
  7. /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
  8. #include "ffitest.h"
  9. typedef struct cls_struct_align {
  10. long double a;
  11. long double b;
  12. long double c;
  13. long double d;
  14. long double e;
  15. long double f;
  16. long double g;
  17. } cls_struct_align;
  18. cls_struct_align cls_struct_align_fn(
  19. cls_struct_align a1,
  20. cls_struct_align a2)
  21. {
  22. struct cls_struct_align r;
  23. r.a = a1.a + a2.a;
  24. r.b = a1.b + a2.b;
  25. r.c = a1.c + a2.c;
  26. r.d = a1.d + a2.d;
  27. r.e = a1.e + a2.e;
  28. r.f = a1.f + a2.f;
  29. r.g = a1.g + a2.g;
  30. printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: "
  31. "%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n",
  32. a1.a, a1.b, a1.c, a1.d, a1.e, a1.f, a1.g,
  33. a2.a, a2.b, a2.c, a2.d, a2.e, a2.f, a2.g,
  34. r.a, r.b, r.c, r.d, r.e, r.f, r.g);
  35. return r;
  36. }
  37. cls_struct_align cls_struct_align_fn2(
  38. cls_struct_align a1)
  39. {
  40. struct cls_struct_align r;
  41. r.a = a1.a + 1;
  42. r.b = a1.b + 1;
  43. r.c = a1.c + 1;
  44. r.d = a1.d + 1;
  45. r.e = a1.e + 1;
  46. r.f = a1.f + 1;
  47. r.g = a1.g + 1;
  48. printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg: "
  49. "%Lg %Lg %Lg %Lg %Lg %Lg %Lg\n",
  50. a1.a, a1.b, a1.c, a1.d, a1.e, a1.f, a1.g,
  51. r.a, r.b, r.c, r.d, r.e, r.f, r.g);
  52. return r;
  53. }
  54. static void
  55. cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  56. void* userdata __UNUSED__)
  57. {
  58. struct cls_struct_align a1, a2;
  59. a1 = *(struct cls_struct_align*)(args[0]);
  60. a2 = *(struct cls_struct_align*)(args[1]);
  61. *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2);
  62. }
  63. int main (void)
  64. {
  65. ffi_cif cif;
  66. void *code;
  67. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  68. void* args_dbl[3];
  69. ffi_type* cls_struct_fields[8];
  70. ffi_type cls_struct_type;
  71. ffi_type* dbl_arg_types[3];
  72. struct cls_struct_align g_dbl = { 1, 2, 3, 4, 5, 6, 7 };
  73. struct cls_struct_align f_dbl = { 8, 9, 10, 11, 12, 13, 14 };
  74. struct cls_struct_align res_dbl;
  75. cls_struct_type.size = 0;
  76. cls_struct_type.alignment = 0;
  77. cls_struct_type.type = FFI_TYPE_STRUCT;
  78. cls_struct_type.elements = cls_struct_fields;
  79. cls_struct_fields[0] = &ffi_type_longdouble;
  80. cls_struct_fields[1] = &ffi_type_longdouble;
  81. cls_struct_fields[2] = &ffi_type_longdouble;
  82. cls_struct_fields[3] = &ffi_type_longdouble;
  83. cls_struct_fields[4] = &ffi_type_longdouble;
  84. cls_struct_fields[5] = &ffi_type_longdouble;
  85. cls_struct_fields[6] = &ffi_type_longdouble;
  86. cls_struct_fields[7] = NULL;
  87. dbl_arg_types[0] = &cls_struct_type;
  88. dbl_arg_types[1] = &cls_struct_type;
  89. dbl_arg_types[2] = NULL;
  90. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
  91. dbl_arg_types) == FFI_OK);
  92. args_dbl[0] = &g_dbl;
  93. args_dbl[1] = &f_dbl;
  94. args_dbl[2] = NULL;
  95. ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl);
  96. /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
  97. printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl.a, res_dbl.b,
  98. res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g);
  99. /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
  100. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK);
  101. res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl);
  102. /* { dg-output "\n1 2 3 4 5 6 7 8 9 10 11 12 13 14: 9 11 13 15 17 19 21" } */
  103. printf("res: %Lg %Lg %Lg %Lg %Lg %Lg %Lg\n", res_dbl.a, res_dbl.b,
  104. res_dbl.c, res_dbl.d, res_dbl.e, res_dbl.f, res_dbl.g);
  105. /* { dg-output "\nres: 9 11 13 15 17 19 21" } */
  106. exit(0);
  107. }