PR target/64688
[official-gcc.git] / libffi / testsuite / libffi.call / cls_many_mixed_args.c
blob7fd6c8207ac756dd7c5583be805d5b8d6b358b15
1 /* Area: closure_call
2 Purpose: Check closures called with many args of mixed types
3 Limitations: none.
4 PR: none.
5 Originator: <david.schneider@picle.org> */
7 /* { dg-do run } */
8 #include "ffitest.h"
9 #include <float.h>
10 #include <math.h>
12 #define NARGS 16
14 static void cls_ret_double_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
15 void* userdata __UNUSED__)
17 int i;
18 double r = 0;
19 double t;
20 for(i = 0; i < NARGS; i++)
22 if(i == 4 || i == 9 || i == 11 || i == 13 || i == 15)
24 t = *(long int *)args[i];
25 CHECK(t == i+1);
27 else
29 t = *(double *)args[i];
30 CHECK(fabs(t - ((i+1) * 0.1)) < FLT_EPSILON);
32 r += t;
34 *(double *)resp = r;
36 typedef double (*cls_ret_double)(double, double, double, double, long int,
37 double, double, double, double, long int, double, long int, double, long int,
38 double, long int);
40 int main (void)
42 ffi_cif cif;
43 void *code;
44 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
45 ffi_type * cl_arg_types[NARGS];
46 double res;
47 int i;
48 double expected = 64.9;
50 for(i = 0; i < NARGS; i++)
52 if(i == 4 || i == 9 || i == 11 || i == 13 || i == 15)
53 cl_arg_types[i] = &ffi_type_slong;
54 else
55 cl_arg_types[i] = &ffi_type_double;
58 /* Initialize the cif */
59 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, NARGS,
60 &ffi_type_double, cl_arg_types) == FFI_OK);
62 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_double_fn, NULL, code) == FFI_OK);
64 res = (((cls_ret_double)code))(0.1, 0.2, 0.3, 0.4, 5, 0.6, 0.7, 0.8, 0.9, 10,
65 1.1, 12, 1.3, 14, 1.5, 16);
66 if (fabs(res - expected) < FLT_EPSILON)
67 exit(0);
68 else
69 abort();