2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_sshort.c
blobeaa15d8cdc13707148934774d11ddf8e43981ea0
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 */
7 /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
8 #include "ffitest.h"
10 signed short test_func_fn(signed short a1, signed short a2)
12 signed short result;
14 result = a1 + a2;
16 printf("%d %d: %d\n", a1, a2, result);
18 return result;
22 static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
24 signed short a1, a2;
26 a1 = *(signed short *)avals[0];
27 a2 = *(signed short *)avals[1];
29 *(ffi_arg *)rval = test_func_fn(a1, a2);
33 typedef signed short (*test_type)(signed short, signed short);
35 int main (void)
37 ffi_cif cif;
38 #ifndef USING_MMAP
39 static ffi_closure cl;
40 #endif
41 ffi_closure *pcl;
42 void * args_dbl[3];
43 ffi_type * cl_arg_types[3];
44 ffi_arg res_call;
45 unsigned short a, b, res_closure;
47 #ifdef USING_MMAP
48 pcl = allocate_mmap (sizeof(ffi_closure));
49 #else
50 pcl = &cl;
51 #endif
53 a = 2;
54 b = 32765;
56 args_dbl[0] = &a;
57 args_dbl[1] = &b;
58 args_dbl[3] = NULL;
60 cl_arg_types[0] = &ffi_type_sshort;
61 cl_arg_types[1] = &ffi_type_sshort;
62 cl_arg_types[2] = NULL;
64 /* Initialize the cif */
65 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
66 &ffi_type_sshort, cl_arg_types) == FFI_OK);
68 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
69 /* { dg-output "2 32765: 32767" } */
70 printf("res: %d\n", res_call);
71 /* { dg-output "\nres: 32767" } */
73 CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
75 res_closure = (*((test_type)pcl))(2, 32765);
76 /* { dg-output "\n2 32765: 32767" } */
77 printf("res: %d\n", res_closure);
78 /* { dg-output "\nres: 32767" } */
80 exit(0);