negint.c 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Area: ffi_call
  2. Purpose: Check that negative integers are passed correctly.
  3. Limitations: none.
  4. PR: none.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static int checking(int a, short b, signed char c)
  9. {
  10. return (a < 0 && b < 0 && c < 0);
  11. }
  12. int main (void)
  13. {
  14. ffi_cif cif;
  15. ffi_type *args[MAX_ARGS];
  16. void *values[MAX_ARGS];
  17. ffi_arg rint;
  18. signed int si;
  19. signed short ss;
  20. signed char sc;
  21. args[0] = &ffi_type_sint;
  22. values[0] = &si;
  23. args[1] = &ffi_type_sshort;
  24. values[1] = &ss;
  25. args[2] = &ffi_type_schar;
  26. values[2] = &sc;
  27. /* Initialize the cif */
  28. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
  29. &ffi_type_sint, args) == FFI_OK);
  30. si = -6;
  31. ss = -12;
  32. sc = -1;
  33. checking (si, ss, sc);
  34. ffi_call(&cif, FFI_FN(checking), &rint, values);
  35. printf ("%d vs %d\n", (int)rint, checking (si, ss, sc));
  36. CHECK(rint != 0);
  37. exit (0);
  38. }