Debian Codegraph @

testsuite/libffi.closures/cls_uint_va.c

raw
1 /* Area: closure_call
2 Purpose: Test anonymous unsigned int argument.
3 Limitations: none.
4 PR: none.
5 Originator: ARM Ltd. */
6
7 /* { dg-do run } */
8
9 #include "ffitest.h"
10
11 typedef unsigned int T;
12
13 static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
14 void* userdata __UNUSED__)
15 {
16 *(ffi_arg *)resp = *(T *)args[0];
17
18 printf("%d: %d %d\n", (int)*(ffi_arg *)resp, *(T *)args[0], *(T *)args[1]);
19 CHECK(*(T *)args[0] == 67);
20 CHECK(*(T *)args[1] == 4);
21 CHECK((int)*(ffi_arg *)resp == 67);
22 }
23
24 typedef T (*cls_ret_T)(T, ...);
25
26 int main (void)
27 {
28 ffi_cif cif;
29 void *code;
30 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
31 ffi_type * cl_arg_types[3];
32 T res;
33
34 cl_arg_types[0] = &ffi_type_uint;
35 cl_arg_types[1] = &ffi_type_uint;
36 cl_arg_types[2] = NULL;
37
38 /* Initialize the cif */
39 CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
40 &ffi_type_uint, cl_arg_types) == FFI_OK);
41
42 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
43 res = ((((cls_ret_T)code)(67, 4)));
44 /* { dg-output "67: 67 4" } */
45 printf("res: %d\n", res);
46 /* { dg-output "\nres: 67" } */
47 CHECK(res == 67);
48 exit(0);
49 }