closure_fn4.c 2.9 KB

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