cls_align_sint64.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check structure alignment of sint64.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <hos@tamanegi.org> 20031203 */
  6. /* { dg-do run } */
  7. /* { dg-options "-Wno-format" { target alpha*-dec-osf* } } */
  8. #include "ffitest.h"
  9. typedef struct cls_struct_align {
  10. unsigned char a;
  11. signed long long b;
  12. unsigned char c;
  13. } cls_struct_align;
  14. cls_struct_align cls_struct_align_fn(struct cls_struct_align a1,
  15. struct cls_struct_align a2)
  16. {
  17. struct cls_struct_align result;
  18. result.a = a1.a + a2.a;
  19. result.b = a1.b + a2.b;
  20. result.c = a1.c + a2.c;
  21. printf("%d %" PRIdLL " %d %d %" PRIdLL " %d: %d %" PRIdLL " %d\n", a1.a, a1.b, a1.c, a2.a, a2.b, a2.c, result.a, result.b, result.c);
  22. return result;
  23. }
  24. static void
  25. cls_struct_align_gn(ffi_cif* cif __UNUSED__, void* resp, void** args,
  26. void* userdata __UNUSED__)
  27. {
  28. struct cls_struct_align a1, a2;
  29. a1 = *(struct cls_struct_align*)(args[0]);
  30. a2 = *(struct cls_struct_align*)(args[1]);
  31. *(cls_struct_align*)resp = cls_struct_align_fn(a1, a2);
  32. }
  33. int main (void)
  34. {
  35. ffi_cif cif;
  36. void *code;
  37. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  38. void* args_dbl[5];
  39. ffi_type* cls_struct_fields[4];
  40. ffi_type cls_struct_type;
  41. ffi_type* dbl_arg_types[5];
  42. struct cls_struct_align g_dbl = { 12, 4951, 127 };
  43. struct cls_struct_align f_dbl = { 1, 9320, 13 };
  44. struct cls_struct_align res_dbl;
  45. cls_struct_type.size = 0;
  46. cls_struct_type.alignment = 0;
  47. cls_struct_type.type = FFI_TYPE_STRUCT;
  48. cls_struct_type.elements = cls_struct_fields;
  49. cls_struct_fields[0] = &ffi_type_uchar;
  50. cls_struct_fields[1] = &ffi_type_sint64;
  51. cls_struct_fields[2] = &ffi_type_uchar;
  52. cls_struct_fields[3] = NULL;
  53. dbl_arg_types[0] = &cls_struct_type;
  54. dbl_arg_types[1] = &cls_struct_type;
  55. dbl_arg_types[2] = NULL;
  56. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &cls_struct_type,
  57. dbl_arg_types) == FFI_OK);
  58. args_dbl[0] = &g_dbl;
  59. args_dbl[1] = &f_dbl;
  60. args_dbl[2] = NULL;
  61. ffi_call(&cif, FFI_FN(cls_struct_align_fn), &res_dbl, args_dbl);
  62. /* { dg-output "12 4951 127 1 9320 13: 13 14271 140" } */
  63. printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c);
  64. /* { dg-output "\nres: 13 14271 140" } */
  65. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_align_gn, NULL, code) == FFI_OK);
  66. res_dbl = ((cls_struct_align(*)(cls_struct_align, cls_struct_align))(code))(g_dbl, f_dbl);
  67. /* { dg-output "\n12 4951 127 1 9320 13: 13 14271 140" } */
  68. printf("res: %d %" PRIdLL " %d\n", res_dbl.a, res_dbl.b, res_dbl.c);
  69. /* { dg-output "\nres: 13 14271 140" } */
  70. exit(0);
  71. }