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