many2.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Area: ffi_call
  2. Purpose: Check uint8_t arguments.
  3. Limitations: none.
  4. PR: PR45677.
  5. Originator: Dan Witte <dwitte@gmail.com> 20100916 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. #define NARGS 7
  9. typedef unsigned char u8;
  10. #ifdef __GNUC__
  11. __attribute__((noinline))
  12. #endif
  13. uint8_t
  14. foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
  15. uint8_t e, uint8_t f, uint8_t g)
  16. {
  17. return a + b + c + d + e + f + g;
  18. }
  19. uint8_t ABI_ATTR
  20. bar (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
  21. uint8_t e, uint8_t f, uint8_t g)
  22. {
  23. return foo (a, b, c, d, e, f, g);
  24. }
  25. int
  26. main (void)
  27. {
  28. ffi_type *ffitypes[NARGS];
  29. int i;
  30. ffi_cif cif;
  31. ffi_arg result = 0;
  32. uint8_t args[NARGS];
  33. void *argptrs[NARGS];
  34. for (i = 0; i < NARGS; ++i)
  35. ffitypes[i] = &ffi_type_uint8;
  36. CHECK (ffi_prep_cif (&cif, ABI_NUM, NARGS,
  37. &ffi_type_uint8, ffitypes) == FFI_OK);
  38. for (i = 0; i < NARGS; ++i)
  39. {
  40. args[i] = i;
  41. argptrs[i] = &args[i];
  42. }
  43. ffi_call (&cif, FFI_FN (bar), &result, argptrs);
  44. CHECK (result == 21);
  45. return 0;
  46. }