closure_fn1.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_fn1(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)(*(signed short *)args[4]) + (int)(*(float *)args[5]) +
  17. (int)*(float *)args[6] + (int)(*(int *)args[7]) +
  18. (int)(*(double*)args[8]) + (int)*(int *)args[9] +
  19. (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
  20. (int)*(int *)args[12] + (int)(*(int *)args[13]) +
  21. (int)(*(int *)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)(*(signed short *)args[4]), (int)(*(float *)args[5]),
  26. (int)*(float *)args[6], (int)(*(int *)args[7]),
  27. (int)(*(double *)args[8]), (int)*(int *)args[9],
  28. (int)(*(int *)args[10]), (int)(*(float *)args[11]),
  29. (int)*(int *)args[12], (int)(*(int *)args[13]),
  30. (int)(*(int *)args[14]), *(int *)args[15],
  31. (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
  32. }
  33. typedef int (*closure_test_type1)(float, float, float, float, signed short,
  34. float, float, int, double, int, int, float,
  35. int, int, int, 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_sshort;
  48. cl_arg_types[5] = &ffi_type_float;
  49. cl_arg_types[6] = &ffi_type_float;
  50. cl_arg_types[7] = &ffi_type_sint;
  51. cl_arg_types[8] = &ffi_type_double;
  52. cl_arg_types[9] = &ffi_type_sint;
  53. cl_arg_types[10] = &ffi_type_sint;
  54. cl_arg_types[11] = &ffi_type_float;
  55. cl_arg_types[12] = &ffi_type_sint;
  56. cl_arg_types[13] = &ffi_type_sint;
  57. cl_arg_types[14] = &ffi_type_sint;
  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_fn1,
  64. (void *) 3 /* userdata */, code) == FFI_OK);
  65. res = (*((closure_test_type1)code))
  66. (1.1, 2.2, 3.3, 4.4, 127, 5.5, 6.6, 8, 9, 10, 11, 12.0, 13,
  67. 19, 21, 1);
  68. /* { dg-output "1 2 3 4 127 5 6 8 9 10 11 12 13 19 21 1 3: 255" } */
  69. printf("res: %d\n",res);
  70. /* { dg-output "\nres: 255" } */
  71. exit(0);
  72. }