closure_fn3.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Area: closure_call
  2. Purpose: Check multiple values passing from different type.
  3. Also, exceed the limit of gpr and fpr registers on PowerPC
  4. Darwin.
  5. Limitations: none.
  6. PR: none.
  7. Originator: <andreast@gcc.gnu.org> 20030828 */
  8. /* { dg-do run } */
  9. #include "ffitest.h"
  10. static void closure_test_fn3(ffi_cif* cif __UNUSED__, void* resp, void** args,
  11. void* userdata)
  12. {
  13. *(ffi_arg*)resp =
  14. (int)*(float *)args[0] +(int)(*(float *)args[1]) +
  15. (int)(*(float *)args[2]) + (int)*(float *)args[3] +
  16. (int)(*(float *)args[4]) + (int)(*(float *)args[5]) +
  17. (int)*(float *)args[6] + (int)(*(float *)args[7]) +
  18. (int)(*(double *)args[8]) + (int)*(int *)args[9] +
  19. (int)(*(float *)args[10]) + (int)(*(float *)args[11]) +
  20. (int)*(int *)args[12] + (int)(*(float *)args[13]) +
  21. (int)(*(float *)args[14]) + *(int *)args[15] + (intptr_t)userdata;
  22. printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
  23. (int)*(float *)args[0], (int)(*(float *)args[1]),
  24. (int)(*(float *)args[2]), (int)*(float *)args[3],
  25. (int)(*(float *)args[4]), (int)(*(float *)args[5]),
  26. (int)*(float *)args[6], (int)(*(float *)args[7]),
  27. (int)(*(double *)args[8]), (int)*(int *)args[9],
  28. (int)(*(float *)args[10]), (int)(*(float *)args[11]),
  29. (int)*(int *)args[12], (int)(*(float *)args[13]),
  30. (int)(*(float *)args[14]), *(int *)args[15], (int)(intptr_t)userdata,
  31. (int)*(ffi_arg *)resp);
  32. }
  33. typedef int (*closure_test_type3)(float, float, float, float, float, float,
  34. float, float, double, int, float, float, int,
  35. float, float, int);
  36. int main (void)
  37. {
  38. ffi_cif cif;
  39. void *code;
  40. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  41. ffi_type * cl_arg_types[17];
  42. int res;
  43. cl_arg_types[0] = &ffi_type_float;
  44. cl_arg_types[1] = &ffi_type_float;
  45. cl_arg_types[2] = &ffi_type_float;
  46. cl_arg_types[3] = &ffi_type_float;
  47. cl_arg_types[4] = &ffi_type_float;
  48. cl_arg_types[5] = &ffi_type_float;
  49. cl_arg_types[6] = &ffi_type_float;
  50. cl_arg_types[7] = &ffi_type_float;
  51. cl_arg_types[8] = &ffi_type_double;
  52. cl_arg_types[9] = &ffi_type_sint;
  53. cl_arg_types[10] = &ffi_type_float;
  54. cl_arg_types[11] = &ffi_type_float;
  55. cl_arg_types[12] = &ffi_type_sint;
  56. cl_arg_types[13] = &ffi_type_float;
  57. cl_arg_types[14] = &ffi_type_float;
  58. cl_arg_types[15] = &ffi_type_sint;
  59. cl_arg_types[16] = NULL;
  60. /* Initialize the cif */
  61. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
  62. &ffi_type_sint, cl_arg_types) == FFI_OK);
  63. CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn3,
  64. (void *) 3 /* userdata */, code) == FFI_OK);
  65. res = (*((closure_test_type3)code))
  66. (1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9, 10, 11.11, 12.0, 13,
  67. 19.19, 21.21, 1);
  68. /* { dg-output "1 2 3 4 5 6 7 8 9 10 11 12 13 19 21 1 3: 135" } */
  69. printf("res: %d\n",res);
  70. /* { dg-output "\nres: 135" } */
  71. exit(0);
  72. }