closure_fn0.c 2.9 KB

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