1 /* Area: ffi_call
2 Purpose: Check uint8_t arguments.
3 Limitations: none.
4 PR: PR45677.
5 Originator: Dan Witte <dwitte@gmail.com> 20100916 */
6
7 /* { dg-do run } */
8
9 #include "ffitest.h"
10
11 #define NARGS 7
12
13 typedef unsigned char u8;
14
15 __attribute__((noinline)) uint8_t
foo(uint8_t a,uint8_t b,uint8_t c,uint8_t d,uint8_t e,uint8_t f,uint8_t g)16 foo (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
17 uint8_t e, uint8_t f, uint8_t g)
18 {
19 return a + b + c + d + e + f + g;
20 }
21
22 uint8_t
bar(uint8_t a,uint8_t b,uint8_t c,uint8_t d,uint8_t e,uint8_t f,uint8_t g)23 bar (uint8_t a, uint8_t b, uint8_t c, uint8_t d,
24 uint8_t e, uint8_t f, uint8_t g)
25 {
26 return foo (a, b, c, d, e, f, g);
27 }
28
29 int
main(void)30 main (void)
31 {
32 ffi_type *ffitypes[NARGS];
33 int i;
34 ffi_cif cif;
35 ffi_arg result = 0;
36 uint8_t args[NARGS];
37 void *argptrs[NARGS];
38
39 for (i = 0; i < NARGS; ++i)
40 ffitypes[i] = &ffi_type_uint8;
41
42 CHECK (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, NARGS,
43 &ffi_type_uint8, ffitypes) == FFI_OK);
44
45 for (i = 0; i < NARGS; ++i)
46 {
47 args[i] = i;
48 argptrs[i] = &args[i];
49 }
50 ffi_call (&cif, FFI_FN (bar), &result, argptrs);
51
52 CHECK (result == 21);
53 return 0;
54 }
55