2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_sshortchar.c
blobae5ce7f72a4411e2660d226966e0bbf03f0ee264
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple signed short/char values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <andreast@gcc.gnu.org> 20031129 */
7 /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
10 signed short test_func_fn(signed char a1, signed short a2,
11 signed char a3, signed short a4)
13 signed 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, void *rval, void **avals, void *data)
25 signed char a1, a3;
26 signed short a2, a4;
28 a1 = *(signed char *)avals[0];
29 a2 = *(signed short *)avals[1];
30 a3 = *(signed char *)avals[2];
31 a4 = *(signed short *)avals[3];
33 *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
37 typedef signed short (*test_type)(signed char, signed short,
38 signed char, signed short);
40 int main (void)
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 signed char a, c;
51 signed short b, d, res_closure;
53 #ifdef USING_MMAP
54 pcl = allocate_mmap (sizeof(ffi_closure));
55 #else
56 pcl = &cl;
57 #endif
59 a = 1;
60 b = 32765;
61 c = 127;
62 d = -128;
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;
70 cl_arg_types[0] = &ffi_type_schar;
71 cl_arg_types[1] = &ffi_type_sshort;
72 cl_arg_types[2] = &ffi_type_schar;
73 cl_arg_types[3] = &ffi_type_sshort;
74 cl_arg_types[4] = NULL;
76 /* Initialize the cif */
77 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
78 &ffi_type_sshort, cl_arg_types) == FFI_OK);
80 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
81 /* { dg-output "1 32765 127 -128: 32765" } */
82 printf("res: %d\n", res_call);
83 /* { dg-output "\nres: 32765" } */
85 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
87 res_closure = (*((test_type)pcl))(1, 32765, 127, -128);
88 /* { dg-output "\n1 32765 127 -128: 32765" } */
89 printf("res: %d\n", res_closure);
90 /* { dg-output "\nres: 32765" } */
92 exit(0);