1 | n/a | /* Area: ffi_call |
---|
2 | n/a | Purpose: Test passing struct in variable argument lists. |
---|
3 | n/a | Limitations: none. |
---|
4 | n/a | PR: none. |
---|
5 | n/a | Originator: ARM Ltd. */ |
---|
6 | n/a | |
---|
7 | n/a | /* { dg-do run } */ |
---|
8 | n/a | /* { dg-output "" { xfail avr32*-*-* } } */ |
---|
9 | n/a | |
---|
10 | n/a | #include "ffitest.h" |
---|
11 | n/a | #include <stdarg.h> |
---|
12 | n/a | |
---|
13 | n/a | struct small_tag |
---|
14 | n/a | { |
---|
15 | n/a | unsigned char a; |
---|
16 | n/a | unsigned char b; |
---|
17 | n/a | }; |
---|
18 | n/a | |
---|
19 | n/a | struct large_tag |
---|
20 | n/a | { |
---|
21 | n/a | unsigned a; |
---|
22 | n/a | unsigned b; |
---|
23 | n/a | unsigned c; |
---|
24 | n/a | unsigned d; |
---|
25 | n/a | unsigned e; |
---|
26 | n/a | }; |
---|
27 | n/a | |
---|
28 | n/a | static struct large_tag |
---|
29 | n/a | test_fn (int n, ...) |
---|
30 | n/a | { |
---|
31 | n/a | va_list ap; |
---|
32 | n/a | struct small_tag s1; |
---|
33 | n/a | struct small_tag s2; |
---|
34 | n/a | struct large_tag l; |
---|
35 | n/a | |
---|
36 | n/a | va_start (ap, n); |
---|
37 | n/a | s1 = va_arg (ap, struct small_tag); |
---|
38 | n/a | l = va_arg (ap, struct large_tag); |
---|
39 | n/a | s2 = va_arg (ap, struct small_tag); |
---|
40 | n/a | printf ("%u %u %u %u %u %u %u %u %u\n", s1.a, s1.b, l.a, l.b, l.c, l.d, l.e, |
---|
41 | n/a | s2.a, s2.b); |
---|
42 | n/a | va_end (ap); |
---|
43 | n/a | l.a += s1.a; |
---|
44 | n/a | l.b += s1.b; |
---|
45 | n/a | l.c += s2.a; |
---|
46 | n/a | l.d += s2.b; |
---|
47 | n/a | return l; |
---|
48 | n/a | } |
---|
49 | n/a | |
---|
50 | n/a | int |
---|
51 | n/a | main (void) |
---|
52 | n/a | { |
---|
53 | n/a | ffi_cif cif; |
---|
54 | n/a | void* args[5]; |
---|
55 | n/a | ffi_type* arg_types[5]; |
---|
56 | n/a | |
---|
57 | n/a | ffi_type s_type; |
---|
58 | n/a | ffi_type *s_type_elements[3]; |
---|
59 | n/a | |
---|
60 | n/a | ffi_type l_type; |
---|
61 | n/a | ffi_type *l_type_elements[6]; |
---|
62 | n/a | |
---|
63 | n/a | struct small_tag s1; |
---|
64 | n/a | struct small_tag s2; |
---|
65 | n/a | struct large_tag l1; |
---|
66 | n/a | |
---|
67 | n/a | int n; |
---|
68 | n/a | struct large_tag res; |
---|
69 | n/a | |
---|
70 | n/a | s_type.size = 0; |
---|
71 | n/a | s_type.alignment = 0; |
---|
72 | n/a | s_type.type = FFI_TYPE_STRUCT; |
---|
73 | n/a | s_type.elements = s_type_elements; |
---|
74 | n/a | |
---|
75 | n/a | s_type_elements[0] = &ffi_type_uchar; |
---|
76 | n/a | s_type_elements[1] = &ffi_type_uchar; |
---|
77 | n/a | s_type_elements[2] = NULL; |
---|
78 | n/a | |
---|
79 | n/a | l_type.size = 0; |
---|
80 | n/a | l_type.alignment = 0; |
---|
81 | n/a | l_type.type = FFI_TYPE_STRUCT; |
---|
82 | n/a | l_type.elements = l_type_elements; |
---|
83 | n/a | |
---|
84 | n/a | l_type_elements[0] = &ffi_type_uint; |
---|
85 | n/a | l_type_elements[1] = &ffi_type_uint; |
---|
86 | n/a | l_type_elements[2] = &ffi_type_uint; |
---|
87 | n/a | l_type_elements[3] = &ffi_type_uint; |
---|
88 | n/a | l_type_elements[4] = &ffi_type_uint; |
---|
89 | n/a | l_type_elements[5] = NULL; |
---|
90 | n/a | |
---|
91 | n/a | arg_types[0] = &ffi_type_sint; |
---|
92 | n/a | arg_types[1] = &s_type; |
---|
93 | n/a | arg_types[2] = &l_type; |
---|
94 | n/a | arg_types[3] = &s_type; |
---|
95 | n/a | arg_types[4] = NULL; |
---|
96 | n/a | |
---|
97 | n/a | CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 4, &l_type, arg_types) == FFI_OK); |
---|
98 | n/a | |
---|
99 | n/a | s1.a = 5; |
---|
100 | n/a | s1.b = 6; |
---|
101 | n/a | |
---|
102 | n/a | l1.a = 10; |
---|
103 | n/a | l1.b = 11; |
---|
104 | n/a | l1.c = 12; |
---|
105 | n/a | l1.d = 13; |
---|
106 | n/a | l1.e = 14; |
---|
107 | n/a | |
---|
108 | n/a | s2.a = 7; |
---|
109 | n/a | s2.b = 8; |
---|
110 | n/a | |
---|
111 | n/a | n = 41; |
---|
112 | n/a | |
---|
113 | n/a | args[0] = &n; |
---|
114 | n/a | args[1] = &s1; |
---|
115 | n/a | args[2] = &l1; |
---|
116 | n/a | args[3] = &s2; |
---|
117 | n/a | args[4] = NULL; |
---|
118 | n/a | |
---|
119 | n/a | ffi_call(&cif, FFI_FN(test_fn), &res, args); |
---|
120 | n/a | /* { dg-output "5 6 10 11 12 13 14 7 8" } */ |
---|
121 | n/a | printf("res: %d %d %d %d %d\n", res.a, res.b, res.c, res.d, res.e); |
---|
122 | n/a | /* { dg-output "\nres: 15 17 19 21 14" } */ |
---|
123 | n/a | |
---|
124 | n/a | return 0; |
---|
125 | n/a | } |
---|