]> git.proxmox.com Git - mirror_frr.git/blame - tools/gcc-plugins/frr-format.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tools / gcc-plugins / frr-format.h
CommitLineData
47a3a827 1// SPDX-License-Identifier: GPL-3.0-or-later
891eac59
DL
2/* Check calls to formatted I/O functions (-Wformat).
3 Copyright (C) 1992-2018 Free Software Foundation, Inc.
47a3a827 4 */
891eac59
DL
5
6#ifndef GCC_C_FORMAT_H
7#define GCC_C_FORMAT_H
8
9/* The meaningfully distinct length modifiers for format checking recognized
10 by GCC. */
11enum format_lengths
12{
13 FMT_LEN_none,
14 FMT_LEN_hh,
15 FMT_LEN_h,
16 FMT_LEN_l,
17 FMT_LEN_ll,
18 FMT_LEN_L,
19 FMT_LEN_z,
20 FMT_LEN_t,
21 FMT_LEN_j,
22 FMT_LEN_H,
23 FMT_LEN_D,
24 FMT_LEN_DD,
25 FMT_LEN_MAX
26};
27
28
29/* The standard versions in which various format features appeared. */
30enum format_std_version
31{
32 STD_C89,
33 STD_C94,
34 STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */
35 STD_C99,
36 STD_EXT
37};
38
39/* Flags that may apply to a particular kind of format checked by GCC. */
40enum
41{
42 /* This format converts arguments of types determined by the
43 format string. */
44 FMT_FLAG_ARG_CONVERT = 1,
45 /* The scanf allocation 'a' kludge applies to this format kind. */
46 FMT_FLAG_SCANF_A_KLUDGE = 2,
47 /* A % during parsing a specifier is allowed to be a modified % rather
48 that indicating the format is broken and we are out-of-sync. */
49 FMT_FLAG_FANCY_PERCENT_OK = 4,
50 /* With $ operand numbers, it is OK to reference the same argument more
51 than once. */
52 FMT_FLAG_DOLLAR_MULTIPLE = 8,
53 /* This format type uses $ operand numbers (strfmon doesn't). */
54 FMT_FLAG_USE_DOLLAR = 16,
55 /* Zero width is bad in this type of format (scanf). */
56 FMT_FLAG_ZERO_WIDTH_BAD = 32,
57 /* Empty precision specification is OK in this type of format (printf). */
58 FMT_FLAG_EMPTY_PREC_OK = 64,
59 /* Gaps are allowed in the arguments with $ operand numbers if all
60 arguments are pointers (scanf). */
61 FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128,
62 /* The format arg is an opaque object that will be parsed by an external
63 facility. */
64 FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL = 256
65 /* Not included here: details of whether width or precision may occur
66 (controlled by width_char and precision_char); details of whether
67 '*' can be used for these (width_type and precision_type); details
68 of whether length modifiers can occur (length_char_specs). */
69};
70
71/* Structure describing a length modifier supported in format checking, and
72 possibly a doubled version such as "hh". */
73struct format_length_info
74{
75 /* Name of the single-character length modifier. If prefixed by
76 a zero character, it describes a multi character length
77 modifier, like I64, I32, etc. */
78 const char *name;
79 /* Index into a format_char_info.types array. */
80 enum format_lengths index;
81 /* Standard version this length appears in. */
82 enum format_std_version std;
83 /* Same, if the modifier can be repeated, or NULL if it can't. */
84 const char *double_name;
85 enum format_lengths double_index;
86 enum format_std_version double_std;
87
88 /* If this flag is set, just scalar width identity is checked, and
89 not the type identity itself. */
90 int scalar_identity_flag;
91};
92
93
7ff91206
DL
94struct kernel_ext_fmt
95{
96 const char *suffix;
97
98 /* RECORD_TYPE, UNION_TYPE, ENUMERAL_TYPE, or NULL for typedef */
99 tree_code type_code;
100 int ptrlevel;
101 bool t_const;
bcf9d7d8
DL
102 bool t_unsigned;
103 bool t_signed;
7ff91206
DL
104 bool warned;
105
106 const char *type_str;
107 GTY(()) tree type;
108
109 location_t origin_loc;
110};
111
112
891eac59
DL
113/* Structure describing the combination of a conversion specifier
114 (or a set of specifiers which act identically) and a length modifier. */
115struct format_type_detail
116{
117 /* The standard version this combination of length and type appeared in.
118 This is only relevant if greater than those for length and type
119 individually; otherwise it is ignored. */
120 enum format_std_version std;
121 /* The name to use for the type, if different from that generated internally
122 (e.g., "signed size_t"). */
123 const char *name;
124 /* The type itself. */
125 tree *type;
126};
127
128
129/* Macros to fill out tables of these. */
130#define NOARGUMENTS { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }
131#define BADLEN { STD_C89, NULL, NULL }
132#define NOLENGTHS { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }
133
134
135/* Structure describing a format conversion specifier (or a set of specifiers
136 which act identically), and the length modifiers used with it. */
137struct format_char_info
138{
139 const char *format_chars;
140 int pointer_count;
141 enum format_std_version std;
142 /* Types accepted for each length modifier. */
143 format_type_detail types[FMT_LEN_MAX];
144 /* List of other modifier characters allowed with these specifiers.
145 This lists flags, and additionally "w" for width, "p" for precision
146 (right precision, for strfmon), "#" for left precision (strfmon),
147 "a" for scanf "a" allocation extension (not applicable in C99 mode),
148 "*" for scanf suppression, and "E" and "O" for those strftime
149 modifiers. */
150 const char *flag_chars;
151 /* List of additional flags describing these conversion specifiers.
152 "c" for generic character pointers being allowed, "2" for strftime
153 two digit year formats, "3" for strftime formats giving two digit
154 years in some locales, "4" for "2" which becomes "3" with an "E" modifier,
155 "o" if use of strftime "O" is a GNU extension beyond C99,
156 "W" if the argument is a pointer which is dereferenced and written into,
157 "R" if the argument is a pointer which is dereferenced and read from,
158 "i" for printf integer formats where the '0' flag is ignored with
159 precision, and "[" for the starting character of a scanf scanset,
160 "<" if the specifier introduces a quoted sequence (such as "%<"),
161 ">" if the specifier terminates a quoted sequence (such as "%>"),
162 "[" if the specifier introduces a color sequence (such as "%r"),
163 "]" if the specifier terminates a color sequence (such as "%R"),
164 "'" (single quote) if the specifier is expected to be quoted when
165 it appears outside a quoted sequence and unquoted otherwise (such
166 as the GCC internal printf format directive "%T"), and
167 "\"" (double quote) if the specifier is not expected to appear in
168 a quoted sequence (such as the GCC internal format directive "%K". */
169 const char *flags2;
170 /* If this format conversion character consumes more than one argument,
171 CHAIN points to information about the next argument. For later
172 arguments, only POINTER_COUNT, TYPES, and the "c", "R", and "W" flags
173 in FLAGS2 are used. */
174 const struct format_char_info *chain;
7ff91206
DL
175
176 struct kernel_ext_fmt *kernel_ext;
891eac59
DL
177};
178
179
180/* Structure describing a flag accepted by some kind of format. */
181struct format_flag_spec
182{
183 /* The flag character in question (0 for end of array). */
184 int flag_char;
185 /* Zero if this entry describes the flag character in general, or a
186 nonzero character that may be found in flags2 if it describes the
187 flag when used with certain formats only. If the latter, only
188 the first such entry found that applies to the current conversion
189 specifier is used; the values of 'name' and 'long_name' it supplies
190 will be used, if non-NULL and the standard version is higher than
191 the unpredicated one, for any pedantic warning. For example, 'o'
192 for strftime formats (meaning 'O' is an extension over C99). */
193 int predicate;
194 /* Nonzero if the next character after this flag in the format should
195 be skipped ('=' in strfmon), zero otherwise. */
196 int skip_next_char;
197 /* True if the flag introduces quoting (as in GCC's %qE). */
198 bool quoting;
199 /* The name to use for this flag in diagnostic messages. For example,
200 N_("'0' flag"), N_("field width"). */
201 const char *name;
202 /* Long name for this flag in diagnostic messages; currently only used for
203 "ISO C does not support ...". For example, N_("the 'I' printf flag"). */
204 const char *long_name;
205 /* The standard version in which it appeared. */
206 enum format_std_version std;
207};
208
209
210/* Structure describing a combination of flags that is bad for some kind
211 of format. */
212struct format_flag_pair
213{
214 /* The first flag character in question (0 for end of array). */
215 int flag_char1;
216 /* The second flag character. */
217 int flag_char2;
218 /* Nonzero if the message should say that the first flag is ignored with
219 the second, zero if the combination should simply be objected to. */
220 int ignored;
221 /* Zero if this entry applies whenever this flag combination occurs,
222 a nonzero character from flags2 if it only applies in some
223 circumstances (e.g. 'i' for printf formats ignoring 0 with precision). */
224 int predicate;
225};
226
227
228/* Structure describing a particular kind of format processed by GCC. */
229struct format_kind_info
230{
231 /* The name of this kind of format, for use in diagnostics. Also
232 the name of the attribute (without preceding and following __). */
233 const char *name;
234 /* Specifications of the length modifiers accepted; possibly NULL. */
235 const format_length_info *length_char_specs;
236 /* Details of the conversion specification characters accepted. */
237 const format_char_info *conversion_specs;
238 /* String listing the flag characters that are accepted. */
239 const char *flag_chars;
240 /* String listing modifier characters (strftime) accepted. May be NULL. */
241 const char *modifier_chars;
242 /* Details of the flag characters, including pseudo-flags. */
243 const format_flag_spec *flag_specs;
244 /* Details of bad combinations of flags. */
245 const format_flag_pair *bad_flag_pairs;
246 /* Flags applicable to this kind of format. */
247 int flags;
248 /* Flag character to treat a width as, or 0 if width not used. */
249 int width_char;
250 /* Flag character to treat a left precision (strfmon) as,
251 or 0 if left precision not used. */
252 int left_precision_char;
253 /* Flag character to treat a precision (for strfmon, right precision) as,
254 or 0 if precision not used. */
255 int precision_char;
256 /* If a flag character has the effect of suppressing the conversion of
257 an argument ('*' in scanf), that flag character, otherwise 0. */
258 int suppression_char;
259 /* Flag character to treat a length modifier as (ignored if length
260 modifiers not used). Need not be placed in flag_chars for conversion
261 specifiers, but is used to check for bad combinations such as length
262 modifier with assignment suppression in scanf. */
263 int length_code_char;
264 /* Assignment-allocation flag character ('m' in scanf), otherwise 0. */
265 int alloc_char;
266 /* Pointer to type of argument expected if '*' is used for a width,
267 or NULL if '*' not used for widths. */
268 tree *width_type;
269 /* Pointer to type of argument expected if '*' is used for a precision,
270 or NULL if '*' not used for precisions. */
271 tree *precision_type;
272};
273
274#define T_I &integer_type_node
275#define T89_I { STD_C89, NULL, T_I }
276#define T_L &long_integer_type_node
277#define T89_L { STD_C89, NULL, T_L }
278#define T_LL &long_long_integer_type_node
279#define T9L_LL { STD_C9L, NULL, T_LL }
280#define TEX_LL { STD_EXT, NULL, T_LL }
7ff91206
DL
281#define T_U64 &local_uint64_t_node
282#define TEX_U64 { STD_EXT, "uint64_t", T_U64 }
283#define T_S64 &local_int64_t_node
284#define TEX_S64 { STD_EXT, "int64_t", T_S64 }
891eac59
DL
285#define T_S &short_integer_type_node
286#define T89_S { STD_C89, NULL, T_S }
287#define T_UI &unsigned_type_node
288#define T89_UI { STD_C89, NULL, T_UI }
289#define T_UL &long_unsigned_type_node
290#define T89_UL { STD_C89, NULL, T_UL }
291#define T_ULL &long_long_unsigned_type_node
292#define T9L_ULL { STD_C9L, NULL, T_ULL }
293#define TEX_ULL { STD_EXT, NULL, T_ULL }
294#define T_US &short_unsigned_type_node
295#define T89_US { STD_C89, NULL, T_US }
296#define T_F &float_type_node
297#define T89_F { STD_C89, NULL, T_F }
298#define T99_F { STD_C99, NULL, T_F }
299#define T_D &double_type_node
300#define T89_D { STD_C89, NULL, T_D }
301#define T99_D { STD_C99, NULL, T_D }
302#define T_LD &long_double_type_node
303#define T89_LD { STD_C89, NULL, T_LD }
304#define T99_LD { STD_C99, NULL, T_LD }
305#define T_C &char_type_node
306#define T89_C { STD_C89, NULL, T_C }
307#define T_SC &signed_char_type_node
308#define T99_SC { STD_C99, NULL, T_SC }
309#define T_UC &unsigned_char_type_node
310#define T99_UC { STD_C99, NULL, T_UC }
311#define T_V &void_type_node
312#define T89_G { STD_C89, NULL, &local_gimple_ptr_node }
313#define T89_T { STD_C89, NULL, &local_tree_type_node }
314#define T89_V { STD_C89, NULL, T_V }
315#define T_W &wchar_type_node
316#define T94_W { STD_C94, "wchar_t", T_W }
317#define TEX_W { STD_EXT, "wchar_t", T_W }
318#define T_WI &wint_type_node
319#define T94_WI { STD_C94, "wint_t", T_WI }
320#define TEX_WI { STD_EXT, "wint_t", T_WI }
7ff91206 321#define T_ST &local_size_t_node
891eac59 322#define T99_ST { STD_C99, "size_t", T_ST }
7ff91206
DL
323#define T_SST &local_ssize_t_node
324#define T99_SST { STD_C99, "ssize_t", T_SST }
891eac59
DL
325#define T_PD &ptrdiff_type_node
326#define T99_PD { STD_C99, "ptrdiff_t", T_PD }
327#define T_UPD &unsigned_ptrdiff_type_node
328#define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD }
329#define T_IM &intmax_type_node
330#define T99_IM { STD_C99, "intmax_t", T_IM }
331#define T_UIM &uintmax_type_node
332#define T99_UIM { STD_C99, "uintmax_t", T_UIM }
333#define T_D32 &dfloat32_type_node
334#define TEX_D32 { STD_EXT, "_Decimal32", T_D32 }
335#define T_D64 &dfloat64_type_node
336#define TEX_D64 { STD_EXT, "_Decimal64", T_D64 }
337#define T_D128 &dfloat128_type_node
338#define TEX_D128 { STD_EXT, "_Decimal128", T_D128 }
339
340/* Structure describing how format attributes such as "printf" are
341 interpreted as "gnu_printf" or "ms_printf" on a particular system.
342 TARGET_OVERRIDES_FORMAT_ATTRIBUTES is used to specify target-specific
343 defaults. */
344struct target_ovr_attr
345{
346 /* The name of the to be copied format attribute. */
347 const char *named_attr_src;
348 /* The name of the to be overridden format attribute. */
349 const char *named_attr_dst;
350};
351
352#endif /* GCC_C_FORMAT_H */