return_fl2.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Area: ffi_call
  2. Purpose: Check return value float.
  3. Limitations: none.
  4. PR: none.
  5. Originator: <andreast@gcc.gnu.org> 20050212 */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. /* Use volatile float to avoid false negative on ix86. See PR target/323. */
  9. static float return_fl(float fl1, float fl2, float fl3, float fl4)
  10. {
  11. volatile float sum;
  12. sum = fl1 + fl2 + fl3 + fl4;
  13. return sum;
  14. }
  15. int main (void)
  16. {
  17. ffi_cif cif;
  18. ffi_type *args[MAX_ARGS];
  19. void *values[MAX_ARGS];
  20. float fl1, fl2, fl3, fl4, rfl;
  21. volatile float sum;
  22. args[0] = &ffi_type_float;
  23. args[1] = &ffi_type_float;
  24. args[2] = &ffi_type_float;
  25. args[3] = &ffi_type_float;
  26. values[0] = &fl1;
  27. values[1] = &fl2;
  28. values[2] = &fl3;
  29. values[3] = &fl4;
  30. /* Initialize the cif */
  31. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
  32. &ffi_type_float, args) == FFI_OK);
  33. fl1 = 127.0;
  34. fl2 = 128.0;
  35. fl3 = 255.1;
  36. fl4 = 512.7;
  37. ffi_call(&cif, FFI_FN(return_fl), &rfl, values);
  38. printf ("%f vs %f\n", rfl, return_fl(fl1, fl2, fl3, fl4));
  39. sum = fl1 + fl2 + fl3 + fl4;
  40. CHECK(rfl == sum);
  41. exit(0);
  42. }