2018-02-18 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_uchar.c
blob009c02c72ba5360c95122443520595194be3cbb0
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned char values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
7 /* { dg-do run } */
8 #include "ffitest.h"
10 unsigned char test_func_fn(unsigned char a1, unsigned char a2,
11 unsigned char a3, unsigned char a4)
13 unsigned char result;
15 result = a1 + a2 + a3 + a4;
17 printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
19 return result;
23 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
24 void *data __UNUSED__)
26 unsigned char a1, a2, a3, a4;
28 a1 = *(unsigned char *)avals[0];
29 a2 = *(unsigned char *)avals[1];
30 a3 = *(unsigned char *)avals[2];
31 a4 = *(unsigned char *)avals[3];
33 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
37 typedef unsigned char (*test_type)(unsigned char, unsigned char,
38 unsigned char, unsigned char);
40 void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
41 void *data __UNUSED__)
43 printf("%d %d %d %d\n", *(unsigned char *)avals[0],
44 *(unsigned char *)avals[1], *(unsigned char *)avals[2],
45 *(unsigned char *)avals[3]);
47 int main (void)
49 ffi_cif cif;
50 void *code;
51 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
52 void * args_dbl[5];
53 ffi_type * cl_arg_types[5];
54 ffi_arg res_call;
55 unsigned char a, b, c, d, res_closure;
57 a = 1;
58 b = 2;
59 c = 127;
60 d = 125;
62 args_dbl[0] = &a;
63 args_dbl[1] = &b;
64 args_dbl[2] = &c;
65 args_dbl[3] = &d;
66 args_dbl[4] = NULL;
68 cl_arg_types[0] = &ffi_type_uchar;
69 cl_arg_types[1] = &ffi_type_uchar;
70 cl_arg_types[2] = &ffi_type_uchar;
71 cl_arg_types[3] = &ffi_type_uchar;
72 cl_arg_types[4] = NULL;
74 /* Initialize the cif */
75 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
76 &ffi_type_uchar, cl_arg_types) == FFI_OK);
78 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
79 /* { dg-output "1 2 127 125: 255" } */
80 printf("res: %d\n", (unsigned char)res_call);
81 /* { dg-output "\nres: 255" } */
83 CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
85 res_closure = (*((test_type)code))(1, 2, 127, 125);
86 /* { dg-output "\n1 2 127 125: 255" } */
87 printf("res: %d\n", res_closure);
88 /* { dg-output "\nres: 255" } */
90 exit(0);