OSDN Git Service

3379eeda1d3c32deac4e667476eb0b6070bd2cc6
[pf3gnuchains/gcc-fork.git] / libffi / testsuite / libffi.call / cls_multi_ushortchar.c
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  */
6
7 /* { dg-do run { xfail mips64*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
9
10 unsigned short test_func_fn(unsigned char a1, unsigned short a2,
11                             unsigned char a3, unsigned short a4)
12 {
13   unsigned short result;
14
15   result = a1 + a2 + a3 + a4;
16
17   printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
18
19   return result;
20
21 }
22
23 static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
24 {
25   unsigned char a1, a3;
26   unsigned short a2, a4;
27
28   a1 = *(unsigned char *)avals[0];
29   a2 = *(unsigned short *)avals[1];
30   a3 = *(unsigned char *)avals[2];
31   a4 = *(unsigned short *)avals[3];
32
33   *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
34
35 }
36
37 typedef unsigned short (*test_type)(unsigned char, unsigned short,
38                                    unsigned char, unsigned short);
39
40 int main (void)
41 {
42   ffi_cif cif;
43 #ifndef USING_MMAP
44   static ffi_closure cl;
45 #endif
46   ffi_closure *pcl;
47   void * args_dbl[5];
48   ffi_type * cl_arg_types[5];
49   ffi_arg res_call;
50   unsigned char a, c;
51   unsigned short b, d, res_closure;
52
53 #ifdef USING_MMAP
54   pcl = allocate_mmap (sizeof(ffi_closure));
55 #else
56   pcl = &cl;
57 #endif
58
59   a = 1;
60   b = 2;
61   c = 127;
62   d = 128;
63
64   args_dbl[0] = &a;
65   args_dbl[1] = &b;
66   args_dbl[2] = &c;
67   args_dbl[3] = &d;
68   args_dbl[4] = NULL;
69
70   cl_arg_types[0] = &ffi_type_uchar;
71   cl_arg_types[1] = &ffi_type_ushort;
72   cl_arg_types[2] = &ffi_type_uchar;
73   cl_arg_types[3] = &ffi_type_ushort;
74   cl_arg_types[4] = NULL;
75
76   /* Initialize the cif */
77   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
78                      &ffi_type_ushort, cl_arg_types) == FFI_OK);
79
80   ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
81   /* { dg-output "1 2 127 128: 258" } */
82   printf("res: %d\n", res_call);
83   /* { dg-output "\nres: 258" } */
84
85   CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL)  == FFI_OK);
86
87   res_closure = (*((test_type)pcl))(1, 2, 127, 128);
88   /* { dg-output "\n1 2 127 128: 258" } */
89   printf("res: %d\n", res_closure);
90   /* { dg-output "\nres: 258" } */
91
92   exit(0);
93 }