Matthias Klose | a834975 | 2010-03-15 13:25:28 +0000 | [diff] [blame] | 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 | |
| 7 | /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */ |
| 8 | /* { dg-output "" { xfail avr32*-*-* x86_64-*-mingw* } } */ |
| 9 | #include "ffitest.h" |
| 10 | |
| 11 | static void |
| 12 | cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp, |
| 13 | void** args, void* userdata __UNUSED__) |
| 14 | { |
| 15 | char* format = *(char**)args[0]; |
| 16 | long double ldValue = *(long double*)args[1]; |
| 17 | |
| 18 | *(ffi_arg*)resp = printf(format, ldValue); |
| 19 | } |
| 20 | |
| 21 | int main (void) |
| 22 | { |
| 23 | ffi_cif cif; |
| 24 | void *code; |
| 25 | ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); |
| 26 | void* args[3]; |
| 27 | ffi_type* arg_types[3]; |
| 28 | |
| 29 | char* format = "%.1Lf\n"; |
| 30 | long double ldArg = 7; |
| 31 | ffi_arg res = 0; |
| 32 | |
| 33 | arg_types[0] = &ffi_type_pointer; |
| 34 | arg_types[1] = &ffi_type_longdouble; |
| 35 | arg_types[2] = NULL; |
| 36 | |
| 37 | CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint, |
| 38 | arg_types) == FFI_OK); |
| 39 | |
| 40 | args[0] = &format; |
| 41 | args[1] = &ldArg; |
| 42 | args[2] = NULL; |
| 43 | |
| 44 | ffi_call(&cif, FFI_FN(printf), &res, args); |
| 45 | // { dg-output "7.0" } |
| 46 | printf("res: %d\n", (int) res); |
| 47 | // { dg-output "\nres: 4" } |
| 48 | |
| 49 | CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, code) == FFI_OK); |
| 50 | |
| 51 | res = ((int(*)(char*, long double))(code))(format, ldArg); |
| 52 | // { dg-output "\n7.0" } |
| 53 | printf("res: %d\n", (int) res); |
| 54 | // { dg-output "\nres: 4" } |
| 55 | |
| 56 | exit(0); |
| 57 | } |