cls_align_longdouble_split2.c 3.1 KB

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