1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 * BTF-to-C dumper test for majority of C syntax quirks.
6 * Copyright (c) 2019 Facebook
8 /* ----- START-EXPECTED-OUTPUT ----- */
28 /* ----- START-EXPECTED-OUTPUT ----- */
33 *} __attribute__((mode(byte)));
36 /* ----- END-EXPECTED-OUTPUT ----- */
40 } __attribute__((mode(byte)));
42 /* ----- START-EXPECTED-OUTPUT ----- */
47 *} __attribute__((mode(word)));
50 /* ----- END-EXPECTED-OUTPUT ----- */
54 } __attribute__((mode(word))); /* force to use 8-byte backing for this enum */
56 /* ----- START-EXPECTED-OUTPUT ----- */
58 EBIG_1 = 1000000000000ULL,
63 typedef volatile const int * volatile const crazy_ptr_t;
65 typedef int *****we_need_to_go_deeper_ptr_t;
67 typedef 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;
69 typedef int *ptr_arr_t[10];
71 typedef void (*fn_ptr1_t)(int);
73 typedef void (*printf_fn_t)(const char *, ...);
75 /* ------ END-EXPECTED-OUTPUT ------ */
77 * While previous function pointers are pretty trivial (C-syntax-level
78 * trivial), the following are deciphered here for future generations:
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);
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.
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);
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.
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];
106 /* ----- START-EXPECTED-OUTPUT ----- */
107 typedef char * const * (*fn_ptr2_t)(struct {
113 void (*b)(int, struct {
119 } (*fn_complex_t)(union {
126 typedef void (* (*signal_t)(int, void (*)(int)))(int);
128 typedef char * (*fn_ptr_arr1_t[10])(int **);
130 typedef char * (* (* const fn_ptr_arr2_t[5])(void))(char * (*)(int));
132 struct struct_w_typedefs {
135 we_need_to_go_deeper_ptr_t c;
136 how_about_this_ptr_t d;
155 typedef struct struct_fwd struct_fwd_t;
157 typedef struct struct_fwd *struct_fwd_ptr_t;
161 typedef union union_fwd union_fwd_t;
163 typedef union union_fwd *union_fwd_ptr_t;
165 struct struct_empty {};
167 struct struct_simple {
171 struct struct_empty s;
181 union union_empty {};
190 struct struct_in_struct {
191 struct struct_simple simple;
192 union union_simple also_simple;
195 } not_so_hard_as_well;
199 } anon_union_is_good;
210 struct struct_in_array {};
212 struct struct_in_array_typed {};
214 typedef struct struct_in_array_typed struct_in_array_t[2];
216 struct struct_with_embedded_stuff {
221 struct struct_with_embedded_stuff *c;
231 void (*i)(char, int, void *);
243 struct struct_in_struct s[10];
245 struct struct_in_array (*u)[2];
246 struct_in_array_t *v;
249 struct float_struct {
252 volatile long double *ld;
263 struct struct_w_typedefs _3;
265 struct struct_fwd *_8;
267 struct_fwd_ptr_t _10;
268 union union_fwd *_11;
271 struct struct_with_embedded_stuff _14;
272 struct float_struct _15;
275 /* ------ END-EXPECTED-OUTPUT ------ */
277 int f(struct root_struct *s)