cls_longdouble_va.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Area: ffi_call, closure_call
  2. Purpose: Test long doubles passed in variable argument lists.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Blake Chaffin 6/6/2007 */
  6. /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
  7. /* { dg-output "" { xfail avr32*-*-* x86_64-*-mingw* } } */
  8. /* { dg-output "" { xfail mips-sgi-irix6* } } PR libffi/46660 */
  9. #include "ffitest.h"
  10. static void
  11. cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp,
  12. void** args, void* userdata __UNUSED__)
  13. {
  14. char* format = *(char**)args[0];
  15. long double ldValue = *(long double*)args[1];
  16. *(ffi_arg*)resp = printf(format, ldValue);
  17. }
  18. int main (void)
  19. {
  20. ffi_cif cif;
  21. void *code;
  22. ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  23. void* args[3];
  24. ffi_type* arg_types[3];
  25. char* format = "%.1Lf\n";
  26. long double ldArg = 7;
  27. ffi_arg res = 0;
  28. arg_types[0] = &ffi_type_pointer;
  29. arg_types[1] = &ffi_type_longdouble;
  30. arg_types[2] = NULL;
  31. /* This printf call is variadic */
  32. CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint,
  33. arg_types) == FFI_OK);
  34. args[0] = &format;
  35. args[1] = &ldArg;
  36. args[2] = NULL;
  37. ffi_call(&cif, FFI_FN(printf), &res, args);
  38. /* { dg-output "7.0" } */
  39. printf("res: %d\n", (int) res);
  40. /* { dg-output "\nres: 4" } */
  41. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL,
  42. code) == FFI_OK);
  43. res = ((int(*)(char*, ...))(code))(format, ldArg);
  44. /* { dg-output "\n7.0" } */
  45. printf("res: %d\n", (int) res);
  46. /* { dg-output "\nres: 4" } */
  47. exit(0);
  48. }