promotion.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Area: ffi_call
  2. Purpose: Promotion test.
  3. Limitations: none.
  4. PR: none.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static int promotion(signed char sc, signed short ss,
  9. unsigned char uc, unsigned short us)
  10. {
  11. int r = (int) sc + (int) ss + (int) uc + (int) us;
  12. return r;
  13. }
  14. int main (void)
  15. {
  16. ffi_cif cif;
  17. ffi_type *args[MAX_ARGS];
  18. void *values[MAX_ARGS];
  19. ffi_arg rint;
  20. signed char sc;
  21. unsigned char uc;
  22. signed short ss;
  23. unsigned short us;
  24. unsigned long ul;
  25. args[0] = &ffi_type_schar;
  26. args[1] = &ffi_type_sshort;
  27. args[2] = &ffi_type_uchar;
  28. args[3] = &ffi_type_ushort;
  29. values[0] = ≻
  30. values[1] = &ss;
  31. values[2] = &uc;
  32. values[3] = &us;
  33. /* Initialize the cif */
  34. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
  35. &ffi_type_sint, args) == FFI_OK);
  36. us = 0;
  37. ul = 0;
  38. for (sc = (signed char) -127;
  39. sc <= (signed char) 120; sc += 1)
  40. for (ss = -30000; ss <= 30000; ss += 10000)
  41. for (uc = (unsigned char) 0;
  42. uc <= (unsigned char) 200; uc += 20)
  43. for (us = 0; us <= 60000; us += 10000)
  44. {
  45. ul++;
  46. ffi_call(&cif, FFI_FN(promotion), &rint, values);
  47. CHECK((int)rint == (signed char) sc + (signed short) ss +
  48. (unsigned char) uc + (unsigned short) us);
  49. }
  50. printf("%lu promotion tests run\n", ul);
  51. exit(0);
  52. }