Refresh config.guess and config.sub
[libffi.git] / .pc / arm-test-fix / testsuite / libffi.call / cls_double_va.c
1 /* Area: ffi_call, closure_call
2 Purpose: Test 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*-*-* } } */
9 /* { dg-output "" { xfail mips-sgi-irix6* } } PR libffi/46660 */
10 /* { dg-skip-if "" arm*-*-* { "-mfloat-abi=hard" } { "" } } */
11
12 #include "ffitest.h"
13
14 static void
15 cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp,
16 void** args, void* userdata __UNUSED__)
17 {
18 char* format = *(char**)args[0];
19 double doubleValue = *(double*)args[1];
20
21 *(ffi_arg*)resp = printf(format, doubleValue);
22 }
23
24 int main (void)
25 {
26 ffi_cif cif;
27 void *code;
28 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
29 void* args[3];
30 ffi_type* arg_types[3];
31
32 char* format = "%.1f\n";
33 double doubleArg = 7;
34 ffi_arg res = 0;
35
36 arg_types[0] = &ffi_type_pointer;
37 arg_types[1] = &ffi_type_double;
38 arg_types[2] = NULL;
39
40 /* This printf call is variadic */
41 CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2, &ffi_type_sint,
42 arg_types) == FFI_OK);
43
44 args[0] = &format;
45 args[1] = &doubleArg;
46 args[2] = NULL;
47
48 ffi_call(&cif, FFI_FN(printf), &res, args);
49 // { dg-output "7.0" }
50 printf("res: %d\n", (int) res);
51 // { dg-output "\nres: 4" }
52
53 /* The call to cls_double_va_fn is static, so have to use a normal prep_cif */
54 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint, arg_types) == FFI_OK);
55
56 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK);
57
58 res = ((int(*)(char*, double))(code))(format, doubleArg);
59 // { dg-output "\n7.0" }
60 printf("res: %d\n", (int) res);
61 // { dg-output "\nres: 4" }
62
63 exit(0);
64 }