unwindtest.cc 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Area: ffi_closure, unwind info
  2. Purpose: Check if the unwind information is passed correctly.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Jeff Sturm <jsturm@one-point.com> */
  6. /* { dg-do run } */
  7. #include "ffitestcxx.h"
  8. #if defined HAVE_STDINT_H
  9. #include <stdint.h>
  10. #endif
  11. #if defined HAVE_INTTYPES_H
  12. #include <inttypes.h>
  13. #endif
  14. void
  15. closure_test_fn(ffi_cif* cif __UNUSED__, void* resp __UNUSED__,
  16. void** args __UNUSED__, void* userdata __UNUSED__)
  17. {
  18. throw 9;
  19. }
  20. typedef void (*closure_test_type)();
  21. void closure_test_fn1(ffi_cif* cif __UNUSED__, void* resp,
  22. void** args, void* userdata __UNUSED__)
  23. {
  24. *(ffi_arg*)resp =
  25. (int)*(float *)args[0] +(int)(*(float *)args[1]) +
  26. (int)(*(float *)args[2]) + (int)*(float *)args[3] +
  27. (int)(*(signed short *)args[4]) + (int)(*(float *)args[5]) +
  28. (int)*(float *)args[6] + (int)(*(int *)args[7]) +
  29. (int)(*(double*)args[8]) + (int)*(int *)args[9] +
  30. (int)(*(int *)args[10]) + (int)(*(float *)args[11]) +
  31. (int)*(int *)args[12] + (int)(*(int *)args[13]) +
  32. (int)(*(int *)args[14]) + *(int *)args[15] + (int)(intptr_t)userdata;
  33. printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d: %d\n",
  34. (int)*(float *)args[0], (int)(*(float *)args[1]),
  35. (int)(*(float *)args[2]), (int)*(float *)args[3],
  36. (int)(*(signed short *)args[4]), (int)(*(float *)args[5]),
  37. (int)*(float *)args[6], (int)(*(int *)args[7]),
  38. (int)(*(double *)args[8]), (int)*(int *)args[9],
  39. (int)(*(int *)args[10]), (int)(*(float *)args[11]),
  40. (int)*(int *)args[12], (int)(*(int *)args[13]),
  41. (int)(*(int *)args[14]), *(int *)args[15],
  42. (int)(intptr_t)userdata, (int)*(ffi_arg*)resp);
  43. throw (int)*(ffi_arg*)resp;
  44. }
  45. typedef int (*closure_test_type1)(float, float, float, float, signed short,
  46. float, float, int, double, int, int, float,
  47. int, int, int, int);
  48. int main (void)
  49. {
  50. ffi_cif cif;
  51. void *code;
  52. ffi_closure *pcl = (ffi_closure *)ffi_closure_alloc(sizeof(ffi_closure), &code);
  53. ffi_type * cl_arg_types[17];
  54. {
  55. cl_arg_types[1] = NULL;
  56. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0,
  57. &ffi_type_void, cl_arg_types) == FFI_OK);
  58. CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn, NULL, code) == FFI_OK);
  59. try
  60. {
  61. (*((closure_test_type)(code)))();
  62. } catch (int exception_code)
  63. {
  64. CHECK(exception_code == 9);
  65. }
  66. printf("part one OK\n");
  67. /* { dg-output "part one OK" } */
  68. }
  69. {
  70. cl_arg_types[0] = &ffi_type_float;
  71. cl_arg_types[1] = &ffi_type_float;
  72. cl_arg_types[2] = &ffi_type_float;
  73. cl_arg_types[3] = &ffi_type_float;
  74. cl_arg_types[4] = &ffi_type_sshort;
  75. cl_arg_types[5] = &ffi_type_float;
  76. cl_arg_types[6] = &ffi_type_float;
  77. cl_arg_types[7] = &ffi_type_uint;
  78. cl_arg_types[8] = &ffi_type_double;
  79. cl_arg_types[9] = &ffi_type_uint;
  80. cl_arg_types[10] = &ffi_type_uint;
  81. cl_arg_types[11] = &ffi_type_float;
  82. cl_arg_types[12] = &ffi_type_uint;
  83. cl_arg_types[13] = &ffi_type_uint;
  84. cl_arg_types[14] = &ffi_type_uint;
  85. cl_arg_types[15] = &ffi_type_uint;
  86. cl_arg_types[16] = NULL;
  87. /* Initialize the cif */
  88. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 16,
  89. &ffi_type_sint, cl_arg_types) == FFI_OK);
  90. CHECK(ffi_prep_closure_loc(pcl, &cif, closure_test_fn1,
  91. (void *) 3 /* userdata */, code) == FFI_OK);
  92. try
  93. {
  94. (*((closure_test_type1)code))
  95. (1.1, 2.2, 3.3, 4.4, 127, 5.5, 6.6, 8, 9, 10, 11, 12.0, 13,
  96. 19, 21, 1);
  97. /* { dg-output "\n1 2 3 4 127 5 6 8 9 10 11 12 13 19 21 1 3: 255" } */
  98. } catch (int exception_code)
  99. {
  100. CHECK(exception_code == 255);
  101. }
  102. printf("part two OK\n");
  103. /* { dg-output "\npart two OK" } */
  104. }
  105. exit(0);
  106. }