cls_multi_sshortchar.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check passing of multiple signed short/char values.
  3. Limitations: none.
  4. PR: PR13221.
  5. Originator: <andreast@gcc.gnu.org> 20031129 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. signed short test_func_fn(signed char a1, signed short a2,
  9. signed char a3, signed short a4)
  10. {
  11. signed short result;
  12. result = a1 + a2 + a3 + a4;
  13. printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
  14. return result;
  15. }
  16. static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
  17. void *data __UNUSED__)
  18. {
  19. signed char a1, a3;
  20. signed short a2, a4;
  21. a1 = *(signed char *)avals[0];
  22. a2 = *(signed short *)avals[1];
  23. a3 = *(signed char *)avals[2];
  24. a4 = *(signed short *)avals[3];
  25. *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
  26. }
  27. typedef signed short (*test_type)(signed char, signed short,
  28. signed char, signed short);
  29. int main (void)
  30. {
  31. ffi_cif cif;
  32. void *code;
  33. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  34. void * args_dbl[5];
  35. ffi_type * cl_arg_types[5];
  36. ffi_arg res_call;
  37. signed char a, c;
  38. signed short b, d, res_closure;
  39. a = 1;
  40. b = 32765;
  41. c = 127;
  42. d = -128;
  43. args_dbl[0] = &a;
  44. args_dbl[1] = &b;
  45. args_dbl[2] = &c;
  46. args_dbl[3] = &d;
  47. args_dbl[4] = NULL;
  48. cl_arg_types[0] = &ffi_type_schar;
  49. cl_arg_types[1] = &ffi_type_sshort;
  50. cl_arg_types[2] = &ffi_type_schar;
  51. cl_arg_types[3] = &ffi_type_sshort;
  52. cl_arg_types[4] = NULL;
  53. /* Initialize the cif */
  54. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
  55. &ffi_type_sshort, cl_arg_types) == FFI_OK);
  56. ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
  57. /* { dg-output "1 32765 127 -128: 32765" } */
  58. printf("res: %d\n", (signed short)res_call);
  59. /* { dg-output "\nres: 32765" } */
  60. CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
  61. res_closure = (*((test_type)code))(1, 32765, 127, -128);
  62. /* { dg-output "\n1 32765 127 -128: 32765" } */
  63. printf("res: %d\n", res_closure);
  64. /* { dg-output "\nres: 32765" } */
  65. exit(0);
  66. }