]> git.ipfire.org Git - thirdparty/gcc.git/blame - libffi/testsuite/libffi.call/cls_double_va.c
cls_double_va.c: Move PR number to comment.
[thirdparty/gcc.git] / libffi / testsuite / libffi.call / cls_double_va.c
CommitLineData
3b5b1a73
AH
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
1098bcf8 7/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
bc472c00 8/* { dg-output "" { xfail avr32*-*-* } } */
902233e0 9/* { dg-output "" { xfail mips-sgi-irix6* } } PR libffi/46660 */
46e0720d
CLT
10/* { dg-skip-if "" arm*-*-* { "-mfloat-abi=hard" } { "" } } */
11
3b5b1a73
AH
12#include "ffitest.h"
13
14static void
15cls_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
24int main (void)
25{
26 ffi_cif cif;
062b8279
AH
27 void *code;
28 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
3b5b1a73
AH
29 void* args[3];
30 ffi_type* arg_types[3];
31
3b5b1a73
AH
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 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint,
41 arg_types) == FFI_OK);
42
43 args[0] = &format;
44 args[1] = &doubleArg;
45 args[2] = NULL;
46
47 ffi_call(&cif, FFI_FN(printf), &res, args);
48 // { dg-output "7.0" }
49 printf("res: %d\n", (int) res);
50 // { dg-output "\nres: 4" }
51
062b8279 52 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK);
3b5b1a73 53
062b8279 54 res = ((int(*)(char*, double))(code))(format, doubleArg);
3b5b1a73
AH
55 // { dg-output "\n7.0" }
56 printf("res: %d\n", (int) res);
57 // { dg-output "\nres: 4" }
58
59 exit(0);
60}