Loading...
1// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2
3/*
4 * BTF-to-C dumper test for majority of C syntax quirks.
5 *
6 * Copyright (c) 2019 Facebook
7 */
8/* ----- START-EXPECTED-OUTPUT ----- */
9enum e1 {
10 A = 0,
11 B = 1,
12};
13
14enum e2 {
15 C = 100,
16 D = 4294967295,
17 E = 0,
18};
19
20typedef enum e2 e2_t;
21
22typedef enum {
23 F = 0,
24 G = 1,
25 H = 2,
26} e3_t;
27
28/* ----- START-EXPECTED-OUTPUT ----- */
29/*
30 *enum e_byte {
31 * EBYTE_1 = 0,
32 * EBYTE_2 = 1,
33 *} __attribute__((mode(byte)));
34 *
35 */
36/* ----- END-EXPECTED-OUTPUT ----- */
37enum e_byte {
38 EBYTE_1,
39 EBYTE_2,
40} __attribute__((mode(byte)));
41
42/* ----- START-EXPECTED-OUTPUT ----- */
43/*
44 *enum e_word {
45 * EWORD_1 = 0LL,
46 * EWORD_2 = 1LL,
47 *} __attribute__((mode(word)));
48 *
49 */
50/* ----- END-EXPECTED-OUTPUT ----- */
51enum e_word {
52 EWORD_1,
53 EWORD_2,
54} __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
55
56/* ----- START-EXPECTED-OUTPUT ----- */
57enum e_big {
58 EBIG_1 = 1000000000000ULL,
59};
60
61typedef int int_t;
62
63typedef volatile const int * volatile const crazy_ptr_t;
64
65typedef int *****we_need_to_go_deeper_ptr_t;
66
67typedef volatile const we_need_to_go_deeper_ptr_t * restrict * volatile * const * restrict volatile * restrict const * volatile const * restrict volatile const how_about_this_ptr_t;
68
69typedef int *ptr_arr_t[10];
70
71typedef void (*fn_ptr1_t)(int);
72
73typedef void (*printf_fn_t)(const char *, ...);
74
75/* ------ END-EXPECTED-OUTPUT ------ */
76/*
77 * While previous function pointers are pretty trivial (C-syntax-level
78 * trivial), the following are deciphered here for future generations:
79 *
80 * - `fn_ptr2_t`: function, taking anonymous struct as a first arg and pointer
81 * to a function, that takes int and returns int, as a second arg; returning
82 * a pointer to a const pointer to a char. Equivalent to:
83 * typedef struct { int a; } s_t;
84 * typedef int (*fn_t)(int);
85 * typedef char * const * (*fn_ptr2_t)(s_t, fn_t);
86 *
87 * - `fn_complex_t`: pointer to a function returning struct and accepting
88 * union and struct. All structs and enum are anonymous and defined inline.
89 *
90 * - `signal_t: pointer to a function accepting a pointer to a function as an
91 * argument and returning pointer to a function as a result. Sane equivalent:
92 * typedef void (*signal_handler_t)(int);
93 * typedef signal_handler_t (*signal_ptr_t)(int, signal_handler_t);
94 *
95 * - fn_ptr_arr1_t: array of pointers to a function accepting pointer to
96 * a pointer to an int and returning pointer to a char. Easy.
97 *
98 * - fn_ptr_arr2_t: array of const pointers to a function taking no arguments
99 * and returning a const pointer to a function, that takes pointer to a
100 * `int -> char *` function and returns pointer to a char. Equivalent:
101 * typedef char * (*fn_input_t)(int);
102 * typedef char * (*fn_output_outer_t)(fn_input_t);
103 * typedef const fn_output_outer_t (* fn_output_inner_t)(void);
104 * typedef const fn_output_inner_t fn_ptr_arr2_t[5];
105 */
106/* ----- START-EXPECTED-OUTPUT ----- */
107typedef char * const * (*fn_ptr2_t)(struct {
108 int a;
109}, int (*)(int));
110
111typedef struct {
112 int a;
113 void (*b)(int, struct {
114 int c;
115 }, union {
116 char d;
117 int e[5];
118 });
119} (*fn_complex_t)(union {
120 void *f;
121 char g[16];
122}, struct {
123 int h;
124});
125
126typedef void (* (*signal_t)(int, void (*)(int)))(int);
127
128typedef char * (*fn_ptr_arr1_t[10])(int **);
129
130typedef char * (* (* const fn_ptr_arr2_t[5])(void))(char * (*)(int));
131
132struct struct_w_typedefs {
133 int_t a;
134 crazy_ptr_t b;
135 we_need_to_go_deeper_ptr_t c;
136 how_about_this_ptr_t d;
137 ptr_arr_t e;
138 fn_ptr1_t f;
139 printf_fn_t g;
140 fn_ptr2_t h;
141 fn_complex_t i;
142 signal_t j;
143 fn_ptr_arr1_t k;
144 fn_ptr_arr2_t l;
145};
146
147typedef struct {
148 int x;
149 int y;
150 int z;
151} anon_struct_t;
152
153struct struct_fwd;
154
155typedef struct struct_fwd struct_fwd_t;
156
157typedef struct struct_fwd *struct_fwd_ptr_t;
158
159union union_fwd;
160
161typedef union union_fwd union_fwd_t;
162
163typedef union union_fwd *union_fwd_ptr_t;
164
165struct struct_empty {};
166
167struct struct_simple {
168 int a;
169 char b;
170 const int_t *p;
171 struct struct_empty s;
172 enum e2 e;
173 enum {
174 ANON_VAL1 = 1,
175 ANON_VAL2 = 2,
176 } f;
177 int arr1[13];
178 enum e2 arr2[5];
179};
180
181union union_empty {};
182
183union union_simple {
184 void *ptr;
185 int num;
186 int_t num2;
187 union union_empty u;
188};
189
190struct struct_in_struct {
191 struct struct_simple simple;
192 union union_simple also_simple;
193 struct {
194 int a;
195 } not_so_hard_as_well;
196 union {
197 int b;
198 int c;
199 } anon_union_is_good;
200 struct {
201 int d;
202 int e;
203 };
204 union {
205 int f;
206 int g;
207 };
208};
209
210struct struct_in_array {};
211
212struct struct_in_array_typed {};
213
214typedef struct struct_in_array_typed struct_in_array_t[2];
215
216struct struct_with_embedded_stuff {
217 int a;
218 struct {
219 int b;
220 struct {
221 struct struct_with_embedded_stuff *c;
222 const char *d;
223 } e;
224 union {
225 volatile long f;
226 void * restrict g;
227 };
228 };
229 union {
230 const int_t *h;
231 void (*i)(char, int, void *);
232 } j;
233 enum {
234 K = 100,
235 L = 200,
236 } m;
237 char n[16];
238 struct {
239 char o;
240 int p;
241 void (*q)(int);
242 } r[5];
243 struct struct_in_struct s[10];
244 int t[11];
245 struct struct_in_array (*u)[2];
246 struct_in_array_t *v;
247};
248
249struct float_struct {
250 float f;
251 const double *d;
252 volatile long double *ld;
253};
254
255struct root_struct {
256 enum e1 _1;
257 enum e2 _2;
258 e2_t _2_1;
259 e3_t _2_2;
260 enum e_byte _100;
261 enum e_word _101;
262 enum e_big _102;
263 struct struct_w_typedefs _3;
264 anon_struct_t _7;
265 struct struct_fwd *_8;
266 struct_fwd_t *_9;
267 struct_fwd_ptr_t _10;
268 union union_fwd *_11;
269 union_fwd_t *_12;
270 union_fwd_ptr_t _13;
271 struct struct_with_embedded_stuff _14;
272 struct float_struct _15;
273};
274
275/* ------ END-EXPECTED-OUTPUT ------ */
276
277int f(struct root_struct *s)
278{
279 return 0;
280}
1// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2
3/*
4 * BTF-to-C dumper test for majority of C syntax quirks.
5 *
6 * Copyright (c) 2019 Facebook
7 */
8/* ----- START-EXPECTED-OUTPUT ----- */
9enum e1 {
10 A = 0,
11 B = 1,
12};
13
14enum e2 {
15 C = 100,
16 D = 4294967295,
17 E = 0,
18};
19
20typedef enum e2 e2_t;
21
22typedef enum {
23 F = 0,
24 G = 1,
25 H = 2,
26} e3_t;
27
28typedef int int_t;
29
30typedef volatile const int * volatile const crazy_ptr_t;
31
32typedef int *****we_need_to_go_deeper_ptr_t;
33
34typedef volatile const we_need_to_go_deeper_ptr_t * restrict * volatile * const * restrict volatile * restrict const * volatile const * restrict volatile const how_about_this_ptr_t;
35
36typedef int *ptr_arr_t[10];
37
38typedef void (*fn_ptr1_t)(int);
39
40typedef void (*printf_fn_t)(const char *, ...);
41
42/* ------ END-EXPECTED-OUTPUT ------ */
43/*
44 * While previous function pointers are pretty trivial (C-syntax-level
45 * trivial), the following are deciphered here for future generations:
46 *
47 * - `fn_ptr2_t`: function, taking anonymous struct as a first arg and pointer
48 * to a function, that takes int and returns int, as a second arg; returning
49 * a pointer to a const pointer to a char. Equivalent to:
50 * typedef struct { int a; } s_t;
51 * typedef int (*fn_t)(int);
52 * typedef char * const * (*fn_ptr2_t)(s_t, fn_t);
53 *
54 * - `fn_complext_t`: pointer to a function returning struct and accepting
55 * union and struct. All structs and enum are anonymous and defined inline.
56 *
57 * - `signal_t: pointer to a function accepting a pointer to a function as an
58 * argument and returning pointer to a function as a result. Sane equivalent:
59 * typedef void (*signal_handler_t)(int);
60 * typedef signal_handler_t (*signal_ptr_t)(int, signal_handler_t);
61 *
62 * - fn_ptr_arr1_t: array of pointers to a function accepting pointer to
63 * a pointer to an int and returning pointer to a char. Easy.
64 *
65 * - fn_ptr_arr2_t: array of const pointers to a function taking no arguments
66 * and returning a const pointer to a function, that takes pointer to a
67 * `int -> char *` function and returns pointer to a char. Equivalent:
68 * typedef char * (*fn_input_t)(int);
69 * typedef char * (*fn_output_outer_t)(fn_input_t);
70 * typedef const fn_output_outer_t (* fn_output_inner_t)();
71 * typedef const fn_output_inner_t fn_ptr_arr2_t[5];
72 */
73/* ----- START-EXPECTED-OUTPUT ----- */
74typedef char * const * (*fn_ptr2_t)(struct {
75 int a;
76}, int (*)(int));
77
78typedef struct {
79 int a;
80 void (*b)(int, struct {
81 int c;
82 }, union {
83 char d;
84 int e[5];
85 });
86} (*fn_complex_t)(union {
87 void *f;
88 char g[16];
89}, struct {
90 int h;
91});
92
93typedef void (* (*signal_t)(int, void (*)(int)))(int);
94
95typedef char * (*fn_ptr_arr1_t[10])(int **);
96
97typedef char * (* const (* const fn_ptr_arr2_t[5])())(char * (*)(int));
98
99struct struct_w_typedefs {
100 int_t a;
101 crazy_ptr_t b;
102 we_need_to_go_deeper_ptr_t c;
103 how_about_this_ptr_t d;
104 ptr_arr_t e;
105 fn_ptr1_t f;
106 printf_fn_t g;
107 fn_ptr2_t h;
108 fn_complex_t i;
109 signal_t j;
110 fn_ptr_arr1_t k;
111 fn_ptr_arr2_t l;
112};
113
114typedef struct {
115 int x;
116 int y;
117 int z;
118} anon_struct_t;
119
120struct struct_fwd;
121
122typedef struct struct_fwd struct_fwd_t;
123
124typedef struct struct_fwd *struct_fwd_ptr_t;
125
126union union_fwd;
127
128typedef union union_fwd union_fwd_t;
129
130typedef union union_fwd *union_fwd_ptr_t;
131
132struct struct_empty {};
133
134struct struct_simple {
135 int a;
136 char b;
137 const int_t *p;
138 struct struct_empty s;
139 enum e2 e;
140 enum {
141 ANON_VAL1 = 1,
142 ANON_VAL2 = 2,
143 } f;
144 int arr1[13];
145 enum e2 arr2[5];
146};
147
148union union_empty {};
149
150union union_simple {
151 void *ptr;
152 int num;
153 int_t num2;
154 union union_empty u;
155};
156
157struct struct_in_struct {
158 struct struct_simple simple;
159 union union_simple also_simple;
160 struct {
161 int a;
162 } not_so_hard_as_well;
163 union {
164 int b;
165 int c;
166 } anon_union_is_good;
167 struct {
168 int d;
169 int e;
170 };
171 union {
172 int f;
173 int g;
174 };
175};
176
177struct struct_in_array {};
178
179struct struct_in_array_typed {};
180
181typedef struct struct_in_array_typed struct_in_array_t[2];
182
183struct struct_with_embedded_stuff {
184 int a;
185 struct {
186 int b;
187 struct {
188 struct struct_with_embedded_stuff *c;
189 const char *d;
190 } e;
191 union {
192 volatile long int f;
193 void * restrict g;
194 };
195 };
196 union {
197 const int_t *h;
198 void (*i)(char, int, void *);
199 } j;
200 enum {
201 K = 100,
202 L = 200,
203 } m;
204 char n[16];
205 struct {
206 char o;
207 int p;
208 void (*q)(int);
209 } r[5];
210 struct struct_in_struct s[10];
211 int t[11];
212 struct struct_in_array (*u)[2];
213 struct_in_array_t *v;
214};
215
216struct float_struct {
217 float f;
218 const double *d;
219 volatile long double *ld;
220};
221
222struct root_struct {
223 enum e1 _1;
224 enum e2 _2;
225 e2_t _2_1;
226 e3_t _2_2;
227 struct struct_w_typedefs _3;
228 anon_struct_t _7;
229 struct struct_fwd *_8;
230 struct_fwd_t *_9;
231 struct_fwd_ptr_t _10;
232 union union_fwd *_11;
233 union_fwd_t *_12;
234 union_fwd_ptr_t _13;
235 struct struct_with_embedded_stuff _14;
236 struct float_struct _15;
237};
238
239/* ------ END-EXPECTED-OUTPUT ------ */
240
241int f(struct root_struct *s)
242{
243 return 0;
244}