testclosure.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Area: closure_call
  2. Purpose: Check return value float.
  3. Limitations: none.
  4. PR: 41908.
  5. Originator: <rfm@gnu.org> 20091102 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. typedef struct cls_struct_combined {
  9. float a;
  10. float b;
  11. float c;
  12. float d;
  13. } cls_struct_combined;
  14. void cls_struct_combined_fn(struct cls_struct_combined arg)
  15. {
  16. printf("%g %g %g %g\n",
  17. arg.a, arg.b,
  18. arg.c, arg.d);
  19. fflush(stdout);
  20. }
  21. static void
  22. cls_struct_combined_gn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
  23. void** args, void* userdata __UNUSED__)
  24. {
  25. struct cls_struct_combined a0;
  26. a0 = *(struct cls_struct_combined*)(args[0]);
  27. cls_struct_combined_fn(a0);
  28. }
  29. int main (void)
  30. {
  31. ffi_cif cif;
  32. void *code;
  33. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  34. ffi_type* cls_struct_fields0[5];
  35. ffi_type cls_struct_type0;
  36. ffi_type* dbl_arg_types[5];
  37. struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0};
  38. cls_struct_type0.size = 0;
  39. cls_struct_type0.alignment = 0;
  40. cls_struct_type0.type = FFI_TYPE_STRUCT;
  41. cls_struct_type0.elements = cls_struct_fields0;
  42. cls_struct_fields0[0] = &ffi_type_float;
  43. cls_struct_fields0[1] = &ffi_type_float;
  44. cls_struct_fields0[2] = &ffi_type_float;
  45. cls_struct_fields0[3] = &ffi_type_float;
  46. cls_struct_fields0[4] = NULL;
  47. dbl_arg_types[0] = &cls_struct_type0;
  48. dbl_arg_types[1] = NULL;
  49. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void,
  50. dbl_arg_types) == FFI_OK);
  51. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code) == FFI_OK);
  52. ((void(*)(cls_struct_combined)) (code))(g_dbl);
  53. /* { dg-output "4 5 1 8" } */
  54. exit(0);
  55. }