Debian Codegraph @

testsuite/libffi.call/va_1.c

raw
1 /* Area: ffi_call
2 Purpose: Test passing struct in variable argument lists.
3 Limitations: none.
4 PR: none.
5 Originator: ARM Ltd. */
6
7 /* { dg-do run } */
8
9 #include "ffitest.h"
10 #include <stdarg.h>
11
12 struct small_tag
13 {
14 unsigned char a;
15 unsigned char b;
16 };
17
18 struct large_tag
19 {
20 unsigned a;
21 unsigned b;
22 unsigned c;
23 unsigned d;
24 unsigned e;
25 };
26
27 int
28 main (void)
29 {
30 ffi_cif cif;
31 ffi_type* arg_types[15];
32
33 ffi_type s_type;
34 ffi_type *s_type_elements[3];
35
36 ffi_type l_type;
37 ffi_type *l_type_elements[6];
38
39 s_type.size = 0;
40 s_type.alignment = 0;
41 s_type.type = FFI_TYPE_STRUCT;
42 s_type.elements = s_type_elements;
43
44 s_type_elements[0] = &ffi_type_uchar;
45 s_type_elements[1] = &ffi_type_uchar;
46 s_type_elements[2] = NULL;
47
48 l_type.size = 0;
49 l_type.alignment = 0;
50 l_type.type = FFI_TYPE_STRUCT;
51 l_type.elements = l_type_elements;
52
53 l_type_elements[0] = &ffi_type_uint;
54 l_type_elements[1] = &ffi_type_uint;
55 l_type_elements[2] = &ffi_type_uint;
56 l_type_elements[3] = &ffi_type_uint;
57 l_type_elements[4] = &ffi_type_uint;
58 l_type_elements[5] = NULL;
59
60 arg_types[0] = &ffi_type_sint;
61 arg_types[1] = &s_type;
62 arg_types[2] = &l_type;
63 arg_types[3] = &s_type;
64 arg_types[4] = &ffi_type_uchar;
65 arg_types[5] = &ffi_type_schar;
66 arg_types[6] = &ffi_type_ushort;
67 arg_types[7] = &ffi_type_sshort;
68 arg_types[8] = &ffi_type_uint;
69 arg_types[9] = &ffi_type_sint;
70 arg_types[10] = &ffi_type_ulong;
71 arg_types[11] = &ffi_type_slong;
72 arg_types[12] = &ffi_type_double;
73 arg_types[13] = &ffi_type_double;
74 arg_types[14] = NULL;
75
76 CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 14, &ffi_type_sint, arg_types) == FFI_BAD_ARGTYPE);
77 return 0;
78 }