• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ----- */
9 enum e1 {
10 	A = 0,
11 	B = 1,
12 };
13 
14 enum e2 {
15 	C = 100,
16 	D = 4294967295,
17 	E = 0,
18 };
19 
20 typedef enum e2 e2_t;
21 
22 typedef enum {
23 	F = 0,
24 	G = 1,
25 	H = 2,
26 } e3_t;
27 
28 typedef int int_t;
29 
30 typedef volatile const int * volatile const crazy_ptr_t;
31 
32 typedef int *****we_need_to_go_deeper_ptr_t;
33 
34 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;
35 
36 typedef int *ptr_arr_t[10];
37 
38 typedef void (*fn_ptr1_t)(int);
39 
40 typedef 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 ----- */
74 typedef char * const * (*fn_ptr2_t)(struct {
75 	int a;
76 }, int (*)(int));
77 
78 typedef 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 
93 typedef void (* (*signal_t)(int, void (*)(int)))(int);
94 
95 typedef char * (*fn_ptr_arr1_t[10])(int **);
96 
97 typedef char * (* (* const fn_ptr_arr2_t[5])())(char * (*)(int));
98 
99 struct 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 
114 typedef struct {
115 	int x;
116 	int y;
117 	int z;
118 } anon_struct_t;
119 
120 struct struct_fwd;
121 
122 typedef struct struct_fwd struct_fwd_t;
123 
124 typedef struct struct_fwd *struct_fwd_ptr_t;
125 
126 union union_fwd;
127 
128 typedef union union_fwd union_fwd_t;
129 
130 typedef union union_fwd *union_fwd_ptr_t;
131 
132 struct struct_empty {};
133 
134 struct 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 
148 union union_empty {};
149 
150 union union_simple {
151 	void *ptr;
152 	int num;
153 	int_t num2;
154 	union union_empty u;
155 };
156 
157 struct 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 
177 struct struct_with_embedded_stuff {
178 	int a;
179 	struct {
180 		int b;
181 		struct {
182 			struct struct_with_embedded_stuff *c;
183 			const char *d;
184 		} e;
185 		union {
186 			volatile long int f;
187 			void * restrict g;
188 		};
189 	};
190 	union {
191 		const int_t *h;
192 		void (*i)(char, int, void *);
193 	} j;
194 	enum {
195 		K = 100,
196 		L = 200,
197 	} m;
198 	char n[16];
199 	struct {
200 		char o;
201 		int p;
202 		void (*q)(int);
203 	} r[5];
204 	struct struct_in_struct s[10];
205 	int t[11];
206 };
207 
208 struct root_struct {
209 	enum e1 _1;
210 	enum e2 _2;
211 	e2_t _2_1;
212 	e3_t _2_2;
213 	struct struct_w_typedefs _3;
214 	anon_struct_t _7;
215 	struct struct_fwd *_8;
216 	struct_fwd_t *_9;
217 	struct_fwd_ptr_t _10;
218 	union union_fwd *_11;
219 	union_fwd_t *_12;
220 	union_fwd_ptr_t _13;
221 	struct struct_with_embedded_stuff _14;
222 };
223 
224 /* ------ END-EXPECTED-OUTPUT ------ */
225 
f(struct root_struct * s)226 int f(struct root_struct *s)
227 {
228 	return 0;
229 }
230