1457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* Area:	closure_call
2457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Purpose:	Check return value schar.
3457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Limitations:	none.
4457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   PR:		none.
5457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique   Originator:	<andreast@gcc.gnu.org> 20031108	 */
6457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
7457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
8457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
9457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique/* { dg-do run } */
10457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique#include "ffitest.h"
11457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
12457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquestatic void cls_ret_schar_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
13457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique			     void* userdata __UNUSED__)
14457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique{
15457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  *(ffi_arg*)resp = *(signed char *)args[0];
16457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  printf("%d: %d\n",*(signed char *)args[0],
17457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique	 (int)*(ffi_arg *)(resp));
18457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique}
19457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piquetypedef signed char (*cls_ret_schar)(signed char);
20457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
21457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Piqueint main (void)
22457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique{
23457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_cif cif;
24457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  void *code;
25457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
26457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  ffi_type * cl_arg_types[2];
27457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  signed char res;
28457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
29457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  cl_arg_types[0] = &ffi_type_schar;
30457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  cl_arg_types[1] = NULL;
31457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
32457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  /* Initialize the cif */
33457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
34457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique		     &ffi_type_schar, cl_arg_types) == FFI_OK);
35457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
36457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_schar_fn, NULL, code)  == FFI_OK);
37457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
38457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  res = (*((cls_ret_schar)code))(127);
39457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  /* { dg-output "127: 127" } */
40457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  printf("res: %d\n", res);
41457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  /* { dg-output "\nres: 127" } */
42457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique
43457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique  exit(0);
44457ba79995d512b9e8c07061fe10d4cd88273b2Lloyd Pique}
45