closure_fn6.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. Limitations: none.
  5. PR: PR23404
  6. Originator: <andreast@gcc.gnu.org> 20050830 */
  7. /* { dg-do run } */
  8. #include "ffitest.h"
  9. static void
  10. closure_test_fn0(ffi_cif* cif __UNUSED__, void* resp, void** args,
  11. void* userdata)
  12. {
  13. *(ffi_arg*)resp =
  14. (int)*(unsigned long long *)args[0] +
  15. (int)(*(unsigned long long *)args[1]) +
  16. (int)(*(unsigned long long *)args[2]) +
  17. (int)*(unsigned long long *)args[3] +
  18. (int)(*(int *)args[4]) + (int)(*(double *)args[5]) +
  19. (int)*(double *)args[6] + (int)(*(float *)args[7]) +
  20. (int)(*(double *)args[8]) + (int)*(double *)args[9] +
  21. (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
  22. (int)*(int *)args[12] + (int)(*(int *)args[13]) +
  23. (int)(*(double *)args[14]) + (int)*(double *)args[15] +
  24. (intptr_t)userdata;
  25. printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
  26. (int)*(unsigned long long *)args[0],
  27. (int)(*(unsigned long long *)args[1]),
  28. (int)(*(unsigned long long *)args[2]),
  29. (int)*(unsigned long long *)args[3],
  30. (int)(*(int *)args[4]), (int)(*(double *)args[5]),
  31. (int)*(double *)args[6], (int)(*(float *)args[7]),
  32. (int)(*(double *)args[8]), (int)*(double *)args[9],
  33. (int)(*(int *)args[10]), (int)(*(float *)args[11]),
  34. (int)*(int *)args[12], (int)(*(int *)args[13]),
  35. (int)(*(double *)args[14]), (int)(*(double *)args[15]),
  36. (int)(intptr_t)userdata, (int)*(ffi_arg *)resp);
  37. }
  38. typedef int (*closure_test_type0)(unsigned long long,
  39. unsigned long long,
  40. unsigned long long,
  41. unsigned long long,
  42. int, double, double, float, double, double,
  43. int, float, int, int, double, double);
  44. int main (void)
  45. {
  46. ffi_cif cif;
  47. void *code;
  48. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  49. ffi_type * cl_arg_types[17];
  50. int res;
  51. cl_arg_types[0] = &ffi_type_uint64;
  52. cl_arg_types[1] = &ffi_type_uint64;
  53. cl_arg_types[2] = &ffi_type_uint64;
  54. cl_arg_types[3] = &ffi_type_uint64;
  55. cl_arg_types[4] = &ffi_type_sint;
  56. cl_arg_types[5] = &ffi_type_double;
  57. cl_arg_types[6] = &ffi_type_double;
  58. cl_arg_types[7] = &ffi_type_float;
  59. cl_arg_types[8] = &ffi_type_double;
  60. cl_arg_types[9] = &ffi_type_double;
  61. cl_arg_types[10] = &ffi_type_sint;
  62. cl_arg_types[11] = &ffi_type_float;
  63. cl_arg_types[12] = &ffi_type_sint;
  64. cl_arg_types[13] = &ffi_type_sint;
  65. cl_arg_types[14] = &ffi_type_double;
  66. cl_arg_types[15] = &ffi_type_double;
  67. cl_arg_types[16] = NULL;
  68. /* Initialize the cif */
  69. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
  70. &ffi_type_sint, cl_arg_types) == FFI_OK);
  71. CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn0,
  72. (void *) 3 /* userdata */, code) == FFI_OK);
  73. res = (*((closure_test_type0)code))
  74. (1, 2, 3, 4, 127, 429., 7., 8., 9.5, 10., 11, 12., 13,
  75. 19, 21., 1.);
  76. /* { dg-output "1 2 3 4 127 429 7 8 9 10 11 12 13 19 21 1 3: 680" } */
  77. printf("res: %d\n",res);
  78. /* { dg-output "\nres: 680" } */
  79. exit(0);
  80. }