float4.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Area: ffi_call
  2. Purpose: Check denorm double value.
  3. Limitations: none.
  4. PR: PR26483.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. /* { dg-options "-mieee" { target alpha*-*-* } } */
  8. #include "ffitest.h"
  9. #include "float.h"
  10. typedef union
  11. {
  12. double d;
  13. unsigned char c[sizeof (double)];
  14. } value_type;
  15. #define CANARY 0xba
  16. static double dblit(double d)
  17. {
  18. return d;
  19. }
  20. int main (void)
  21. {
  22. ffi_cif cif;
  23. ffi_type *args[MAX_ARGS];
  24. void *values[MAX_ARGS];
  25. double d;
  26. value_type result[2];
  27. unsigned int i;
  28. args[0] = &ffi_type_double;
  29. values[0] = &d;
  30. /* Initialize the cif */
  31. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  32. &ffi_type_double, args) == FFI_OK);
  33. d = DBL_MIN / 2;
  34. /* Put a canary in the return array. This is a regression test for
  35. a buffer overrun. */
  36. memset(result[1].c, CANARY, sizeof (double));
  37. ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
  38. /* The standard delta check doesn't work for denorms. Since we didn't do
  39. any arithmetic, we should get the original result back, and hence an
  40. exact check should be OK here. */
  41. CHECK(result[0].d == dblit(d));
  42. /* Check the canary. */
  43. for (i = 0; i < sizeof (double); ++i)
  44. CHECK(result[1].c[i] == CANARY);
  45. exit(0);
  46. }