OSDN Git Service

662d48b3ed55a5de7eb1fbd6e4a7f6edc4e8e6f0
[pf3gnuchains/gcc-fork.git] / libffi / testsuite / libffi.call / cls_multi_sshort.c
1 /* Area:        ffi_call, closure_call
2    Purpose:     Check passing of multiple signed short values.
3    Limitations: none.
4    PR:          PR13221.
5    Originator:  <andreast@gcc.gnu.org> 20031129  */
6
7 /* { dg-do run { xfail mips64*-*-* } } */
8 #include "ffitest.h"
9
10 signed short test_func_fn(signed short a1, signed short a2)
11 {
12   signed short result;
13
14   result = a1 + a2;
15
16   printf("%d %d: %d\n", a1, a2, result);
17
18   return result;
19
20 }
21
22 static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
23                          void *data __UNUSED__)
24 {
25   signed short a1, a2;
26
27   a1 = *(signed short *)avals[0];
28   a2 = *(signed short *)avals[1];
29
30   *(ffi_arg *)rval = test_func_fn(a1, a2);
31
32 }
33
34 typedef signed short (*test_type)(signed short, signed short);
35
36 int main (void)
37 {
38   ffi_cif cif;
39 #ifndef USING_MMAP
40   static ffi_closure cl;
41 #endif
42   ffi_closure *pcl;
43   void * args_dbl[3];
44   ffi_type * cl_arg_types[3];
45   ffi_arg res_call;
46   unsigned short a, b, res_closure;
47
48 #ifdef USING_MMAP
49   pcl = allocate_mmap (sizeof(ffi_closure));
50 #else
51   pcl = &cl;
52 #endif
53
54   a = 2;
55   b = 32765;
56
57   args_dbl[0] = &a;
58   args_dbl[1] = &b;
59   args_dbl[2] = NULL;
60
61   cl_arg_types[0] = &ffi_type_sshort;
62   cl_arg_types[1] = &ffi_type_sshort;
63   cl_arg_types[2] = NULL;
64
65   /* Initialize the cif */
66   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
67                      &ffi_type_sshort, cl_arg_types) == FFI_OK);
68
69   ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
70   /* { dg-output "2 32765: 32767" } */
71   printf("res: %d\n", (unsigned short)res_call);
72   /* { dg-output "\nres: 32767" } */
73
74   CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL)  == FFI_OK);
75
76   res_closure = (*((test_type)pcl))(2, 32765);
77   /* { dg-output "\n2 32765: 32767" } */
78   printf("res: %d\n", res_closure);
79   /* { dg-output "\nres: 32767" } */
80
81   exit(0);
82 }