2009-07-17 Richard Guenther <rguenther@suse.de>
[official-gcc.git] / libffi / testsuite / libffi.call / cls_multi_schar.c
blob71df7b6516e657cee68bcc430d36cbd75f1c17fc
1 /* Area: ffi_call, closure_call
2 Purpose: Check passing of multiple signed char values.
3 Limitations: none.
4 PR: PR13221.
5 Originator: <hos@tamanegi.org> 20031129 */
7 /* { dg-do run } */
8 #include "ffitest.h"
10 signed char test_func_fn(signed char a1, signed char a2)
12 signed char 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 __UNUSED__, void *rval, void **avals,
23 void *data __UNUSED__)
25 signed char a1, a2;
27 a1 = *(signed char *)avals[0];
28 a2 = *(signed char *)avals[1];
30 *(ffi_arg *)rval = test_func_fn(a1, a2);
34 typedef signed char (*test_type)(signed char, signed char);
36 int main (void)
38 ffi_cif cif;
39 void *code;
40 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
41 void * args_dbl[3];
42 ffi_type * cl_arg_types[3];
43 ffi_arg res_call;
44 signed char a, b, res_closure;
46 a = 2;
47 b = 125;
49 args_dbl[0] = &a;
50 args_dbl[1] = &b;
51 args_dbl[2] = NULL;
53 cl_arg_types[0] = &ffi_type_schar;
54 cl_arg_types[1] = &ffi_type_schar;
55 cl_arg_types[2] = NULL;
57 /* Initialize the cif */
58 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
59 &ffi_type_schar, cl_arg_types) == FFI_OK);
61 ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
62 /* { dg-output "2 125: 127" } */
63 printf("res: %d\n", (signed char)res_call);
64 /* { dg-output "\nres: 127" } */
66 CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
68 res_closure = (*((test_type)code))(2, 125);
69 /* { dg-output "\n2 125: 127" } */
70 printf("res: %d\n", res_closure);
71 /* { dg-output "\nres: 127" } */
73 exit(0);