2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_ushortchar.c
blob2588e97f987fbb5c386f78bc9b80719b674244b1
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple unsigned short/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 short test_func_fn(unsigned char a1, unsigned short a2,
11 unsigned char a3, unsigned short a4)
13 unsigned short 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, a3;
27 unsigned short a2, a4;
29 a1 = *(unsigned char *)avals[0];
30 a2 = *(unsigned short *)avals[1];
31 a3 = *(unsigned char *)avals[2];
32 a4 = *(unsigned short *)avals[3];
34 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
38 typedef unsigned short (*test_type)(unsigned char, unsigned short,
39 unsigned char, unsigned short);
41 int main (void)
43 ffi_cif cif;
44 void *code;
45 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
46 void * args_dbl[5];
47 ffi_type * cl_arg_types[5];
48 ffi_arg res_call;
49 unsigned char a, c;
50 unsigned short b, d, res_closure;
52 a = 1;
53 b = 2;
54 c = 127;
55 d = 128;
57 args_dbl[0] = &a;
58 args_dbl[1] = &b;
59 args_dbl[2] = &c;
60 args_dbl[3] = &d;
61 args_dbl[4] = NULL;
63 cl_arg_types[0] = &ffi_type_uchar;
64 cl_arg_types[1] = &ffi_type_ushort;
65 cl_arg_types[2] = &ffi_type_uchar;
66 cl_arg_types[3] = &ffi_type_ushort;
67 cl_arg_types[4] = NULL;
69 /* Initialize the cif */
70 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
71 &ffi_type_ushort, cl_arg_types) == FFI_OK);
73 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
74 /* { dg-output "1 2 127 128: 258" } */
75 printf("res: %d\n", (unsigned short)res_call);
76 /* { dg-output "\nres: 258" } */
78 CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
80 res_closure = (*((test_type)code))(1, 2, 127, 128);
81 /* { dg-output "\n1 2 127 128: 258" } */
82 printf("res: %d\n", res_closure);
83 /* { dg-output "\nres: 258" } */
85 exit(0);