1169689Skan/* Check calls to formatted I/O functions (-Wformat). 2169689Skan Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3169689Skan 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 4169689Skan 5169689SkanThis file is part of GCC. 6169689Skan 7169689SkanGCC is free software; you can redistribute it and/or modify it under 8169689Skanthe terms of the GNU General Public License as published by the Free 9169689SkanSoftware Foundation; either version 2, or (at your option) any later 10169689Skanversion. 11169689Skan 12169689SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY 13169689SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or 14169689SkanFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15169689Skanfor more details. 16169689Skan 17169689SkanYou should have received a copy of the GNU General Public License 18169689Skanalong with GCC; see the file COPYING. If not, write to the Free 19169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 20169689Skan02110-1301, USA. */ 21169689Skan 22169689Skan#ifndef GCC_C_FORMAT_H 23169689Skan#define GCC_C_FORMAT_H 24169689Skan 25169689Skan/* The meaningfully distinct length modifiers for format checking recognized 26169689Skan by GCC. */ 27169689Skanenum format_lengths 28169689Skan{ 29169689Skan FMT_LEN_none, 30169689Skan FMT_LEN_hh, 31169689Skan FMT_LEN_h, 32169689Skan FMT_LEN_l, 33169689Skan FMT_LEN_ll, 34169689Skan FMT_LEN_L, 35169689Skan FMT_LEN_z, 36169689Skan FMT_LEN_t, 37169689Skan FMT_LEN_j, 38169689Skan FMT_LEN_H, 39169689Skan FMT_LEN_D, 40169689Skan FMT_LEN_DD, 41169689Skan FMT_LEN_MAX 42169689Skan}; 43169689Skan 44169689Skan 45169689Skan/* The standard versions in which various format features appeared. */ 46169689Skanenum format_std_version 47169689Skan{ 48169689Skan STD_C89, 49169689Skan STD_C94, 50169689Skan STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */ 51169689Skan STD_C99, 52169689Skan STD_EXT 53169689Skan}; 54169689Skan 55169689Skan/* Flags that may apply to a particular kind of format checked by GCC. */ 56169689Skanenum 57169689Skan{ 58169689Skan /* This format converts arguments of types determined by the 59169689Skan format string. */ 60169689Skan FMT_FLAG_ARG_CONVERT = 1, 61169689Skan /* The scanf allocation 'a' kludge applies to this format kind. */ 62169689Skan FMT_FLAG_SCANF_A_KLUDGE = 2, 63169689Skan /* A % during parsing a specifier is allowed to be a modified % rather 64169689Skan that indicating the format is broken and we are out-of-sync. */ 65169689Skan FMT_FLAG_FANCY_PERCENT_OK = 4, 66169689Skan /* With $ operand numbers, it is OK to reference the same argument more 67169689Skan than once. */ 68169689Skan FMT_FLAG_DOLLAR_MULTIPLE = 8, 69169689Skan /* This format type uses $ operand numbers (strfmon doesn't). */ 70169689Skan FMT_FLAG_USE_DOLLAR = 16, 71169689Skan /* Zero width is bad in this type of format (scanf). */ 72169689Skan FMT_FLAG_ZERO_WIDTH_BAD = 32, 73169689Skan /* Empty precision specification is OK in this type of format (printf). */ 74169689Skan FMT_FLAG_EMPTY_PREC_OK = 64, 75169689Skan /* Gaps are allowed in the arguments with $ operand numbers if all 76169689Skan arguments are pointers (scanf). */ 77169710Skan FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128, 78169689Skan /* Not included here: details of whether width or precision may occur 79169689Skan (controlled by width_char and precision_char); details of whether 80169689Skan '*' can be used for these (width_type and precision_type); details 81169689Skan of whether length modifiers can occur (length_char_specs). */ 82169710Skan FMT_FLAG_NULL_FORMAT_OK = 256 83169689Skan}; 84169689Skan 85169689Skan 86169689Skan/* Structure describing a length modifier supported in format checking, and 87169689Skan possibly a doubled version such as "hh". */ 88169689Skantypedef struct 89169689Skan{ 90169689Skan /* Name of the single-character length modifier. */ 91169689Skan const char *name; 92169689Skan /* Index into a format_char_info.types array. */ 93169689Skan enum format_lengths index; 94169689Skan /* Standard version this length appears in. */ 95169689Skan enum format_std_version std; 96169689Skan /* Same, if the modifier can be repeated, or NULL if it can't. */ 97169689Skan const char *double_name; 98169689Skan enum format_lengths double_index; 99169689Skan enum format_std_version double_std; 100169689Skan} format_length_info; 101169689Skan 102169689Skan 103169689Skan/* Structure describing the combination of a conversion specifier 104169689Skan (or a set of specifiers which act identically) and a length modifier. */ 105169689Skantypedef struct 106169689Skan{ 107169689Skan /* The standard version this combination of length and type appeared in. 108169689Skan This is only relevant if greater than those for length and type 109169689Skan individually; otherwise it is ignored. */ 110169689Skan enum format_std_version std; 111169689Skan /* The name to use for the type, if different from that generated internally 112169689Skan (e.g., "signed size_t"). */ 113169689Skan const char *name; 114169689Skan /* The type itself. */ 115169689Skan tree *type; 116169689Skan} format_type_detail; 117169689Skan 118169689Skan 119169689Skan/* Macros to fill out tables of these. */ 120169689Skan#define NOARGUMENTS { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 121169689Skan#define BADLEN { 0, NULL, NULL } 122169689Skan#define NOLENGTHS { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 123169689Skan 124169689Skan 125169689Skan/* Structure describing a format conversion specifier (or a set of specifiers 126169689Skan which act identically), and the length modifiers used with it. */ 127169689Skantypedef struct format_char_info 128169689Skan{ 129169689Skan const char *format_chars; 130169689Skan int pointer_count; 131169689Skan enum format_std_version std; 132169689Skan /* Types accepted for each length modifier. */ 133169689Skan format_type_detail types[FMT_LEN_MAX]; 134169689Skan /* List of other modifier characters allowed with these specifiers. 135169689Skan This lists flags, and additionally "w" for width, "p" for precision 136169689Skan (right precision, for strfmon), "#" for left precision (strfmon), 137169689Skan "a" for scanf "a" allocation extension (not applicable in C99 mode), 138169689Skan "*" for scanf suppression, and "E" and "O" for those strftime 139169689Skan modifiers. */ 140169689Skan const char *flag_chars; 141169689Skan /* List of additional flags describing these conversion specifiers. 142169689Skan "c" for generic character pointers being allowed, "2" for strftime 143169689Skan two digit year formats, "3" for strftime formats giving two digit 144169689Skan years in some locales, "4" for "2" which becomes "3" with an "E" modifier, 145169689Skan "o" if use of strftime "O" is a GNU extension beyond C99, 146169689Skan "W" if the argument is a pointer which is dereferenced and written into, 147169689Skan "R" if the argument is a pointer which is dereferenced and read from, 148169689Skan "i" for printf integer formats where the '0' flag is ignored with 149169689Skan precision, and "[" for the starting character of a scanf scanset. */ 150169689Skan const char *flags2; 151169689Skan /* If this format conversion character consumes more than one argument, 152169689Skan CHAIN points to information about the next argument. For later 153169689Skan arguments, only POINTER_COUNT, TYPES, and the "c", "R", and "W" flags 154169689Skan in FLAGS2 are used. */ 155169689Skan const struct format_char_info *chain; 156169689Skan} format_char_info; 157169689Skan 158169689Skan 159169689Skan/* Structure describing a flag accepted by some kind of format. */ 160169689Skantypedef struct 161169689Skan{ 162169689Skan /* The flag character in question (0 for end of array). */ 163169689Skan int flag_char; 164169689Skan /* Zero if this entry describes the flag character in general, or a 165169689Skan nonzero character that may be found in flags2 if it describes the 166169689Skan flag when used with certain formats only. If the latter, only 167169689Skan the first such entry found that applies to the current conversion 168169689Skan specifier is used; the values of 'name' and 'long_name' it supplies 169169689Skan will be used, if non-NULL and the standard version is higher than 170169689Skan the unpredicated one, for any pedantic warning. For example, 'o' 171169689Skan for strftime formats (meaning 'O' is an extension over C99). */ 172169689Skan int predicate; 173169689Skan /* Nonzero if the next character after this flag in the format should 174169689Skan be skipped ('=' in strfmon), zero otherwise. */ 175169689Skan int skip_next_char; 176169689Skan /* The name to use for this flag in diagnostic messages. For example, 177169689Skan N_("'0' flag"), N_("field width"). */ 178169689Skan const char *name; 179169689Skan /* Long name for this flag in diagnostic messages; currently only used for 180169689Skan "ISO C does not support ...". For example, N_("the 'I' printf flag"). */ 181169689Skan const char *long_name; 182169689Skan /* The standard version in which it appeared. */ 183169689Skan enum format_std_version std; 184169689Skan} format_flag_spec; 185169689Skan 186169689Skan 187169689Skan/* Structure describing a combination of flags that is bad for some kind 188169689Skan of format. */ 189169689Skantypedef struct 190169689Skan{ 191169689Skan /* The first flag character in question (0 for end of array). */ 192169689Skan int flag_char1; 193169689Skan /* The second flag character. */ 194169689Skan int flag_char2; 195169689Skan /* Nonzero if the message should say that the first flag is ignored with 196169689Skan the second, zero if the combination should simply be objected to. */ 197169689Skan int ignored; 198169689Skan /* Zero if this entry applies whenever this flag combination occurs, 199169689Skan a nonzero character from flags2 if it only applies in some 200169689Skan circumstances (e.g. 'i' for printf formats ignoring 0 with precision). */ 201169689Skan int predicate; 202169689Skan} format_flag_pair; 203169689Skan 204169689Skan 205169689Skan/* Structure describing a particular kind of format processed by GCC. */ 206169689Skantypedef struct 207169689Skan{ 208169689Skan /* The name of this kind of format, for use in diagnostics. Also 209169689Skan the name of the attribute (without preceding and following __). */ 210169689Skan const char *name; 211169689Skan /* Specifications of the length modifiers accepted; possibly NULL. */ 212169689Skan const format_length_info *length_char_specs; 213169689Skan /* Details of the conversion specification characters accepted. */ 214169689Skan const format_char_info *conversion_specs; 215169689Skan /* String listing the flag characters that are accepted. */ 216169689Skan const char *flag_chars; 217169689Skan /* String listing modifier characters (strftime) accepted. May be NULL. */ 218169689Skan const char *modifier_chars; 219169689Skan /* Details of the flag characters, including pseudo-flags. */ 220169689Skan const format_flag_spec *flag_specs; 221169689Skan /* Details of bad combinations of flags. */ 222169689Skan const format_flag_pair *bad_flag_pairs; 223169689Skan /* Flags applicable to this kind of format. */ 224169689Skan int flags; 225169689Skan /* Flag character to treat a width as, or 0 if width not used. */ 226169689Skan int width_char; 227169689Skan /* Flag character to treat a left precision (strfmon) as, 228169689Skan or 0 if left precision not used. */ 229169689Skan int left_precision_char; 230169689Skan /* Flag character to treat a precision (for strfmon, right precision) as, 231169689Skan or 0 if precision not used. */ 232169689Skan int precision_char; 233169689Skan /* If a flag character has the effect of suppressing the conversion of 234169689Skan an argument ('*' in scanf), that flag character, otherwise 0. */ 235169689Skan int suppression_char; 236169689Skan /* Flag character to treat a length modifier as (ignored if length 237169689Skan modifiers not used). Need not be placed in flag_chars for conversion 238169689Skan specifiers, but is used to check for bad combinations such as length 239169689Skan modifier with assignment suppression in scanf. */ 240169689Skan int length_code_char; 241169689Skan /* Pointer to type of argument expected if '*' is used for a width, 242169689Skan or NULL if '*' not used for widths. */ 243169689Skan tree *width_type; 244169689Skan /* Pointer to type of argument expected if '*' is used for a precision, 245169689Skan or NULL if '*' not used for precisions. */ 246169689Skan tree *precision_type; 247169689Skan} format_kind_info; 248169689Skan 249169689Skan#define T_I &integer_type_node 250169689Skan#define T89_I { STD_C89, NULL, T_I } 251169689Skan#define T_L &long_integer_type_node 252169689Skan#define T89_L { STD_C89, NULL, T_L } 253169689Skan#define T_LL &long_long_integer_type_node 254169689Skan#define T9L_LL { STD_C9L, NULL, T_LL } 255169689Skan#define TEX_LL { STD_EXT, NULL, T_LL } 256169689Skan#define T_S &short_integer_type_node 257169689Skan#define T89_S { STD_C89, NULL, T_S } 258169689Skan#define T_UI &unsigned_type_node 259169689Skan#define T89_UI { STD_C89, NULL, T_UI } 260169689Skan#define T_UL &long_unsigned_type_node 261169689Skan#define T89_UL { STD_C89, NULL, T_UL } 262169689Skan#define T_ULL &long_long_unsigned_type_node 263169689Skan#define T9L_ULL { STD_C9L, NULL, T_ULL } 264169689Skan#define TEX_ULL { STD_EXT, NULL, T_ULL } 265169689Skan#define T_US &short_unsigned_type_node 266169689Skan#define T89_US { STD_C89, NULL, T_US } 267169689Skan#define T_F &float_type_node 268169689Skan#define T89_F { STD_C89, NULL, T_F } 269169689Skan#define T99_F { STD_C99, NULL, T_F } 270169689Skan#define T_D &double_type_node 271169689Skan#define T89_D { STD_C89, NULL, T_D } 272169689Skan#define T99_D { STD_C99, NULL, T_D } 273169689Skan#define T_LD &long_double_type_node 274169689Skan#define T89_LD { STD_C89, NULL, T_LD } 275169689Skan#define T99_LD { STD_C99, NULL, T_LD } 276169689Skan#define T_C &char_type_node 277169689Skan#define T89_C { STD_C89, NULL, T_C } 278169689Skan#define T_SC &signed_char_type_node 279169689Skan#define T99_SC { STD_C99, NULL, T_SC } 280169689Skan#define T_UC &unsigned_char_type_node 281169689Skan#define T99_UC { STD_C99, NULL, T_UC } 282169689Skan#define T_V &void_type_node 283169689Skan#define T89_V { STD_C89, NULL, T_V } 284169689Skan#define T_W &wchar_type_node 285169689Skan#define T94_W { STD_C94, "wchar_t", T_W } 286169689Skan#define TEX_W { STD_EXT, "wchar_t", T_W } 287169689Skan#define T_WI &wint_type_node 288169689Skan#define T94_WI { STD_C94, "wint_t", T_WI } 289169689Skan#define TEX_WI { STD_EXT, "wint_t", T_WI } 290169689Skan#define T_ST &size_type_node 291169689Skan#define T99_ST { STD_C99, "size_t", T_ST } 292169689Skan#define T_SST &signed_size_type_node 293169689Skan#define T99_SST { STD_C99, "signed size_t", T_SST } 294169689Skan#define T_PD &ptrdiff_type_node 295169689Skan#define T99_PD { STD_C99, "ptrdiff_t", T_PD } 296169689Skan#define T_UPD &unsigned_ptrdiff_type_node 297169689Skan#define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD } 298169689Skan#define T_IM &intmax_type_node 299169689Skan#define T99_IM { STD_C99, "intmax_t", T_IM } 300169689Skan#define T_UIM &uintmax_type_node 301169689Skan#define T99_UIM { STD_C99, "uintmax_t", T_UIM } 302169689Skan#define T_D32 &dfloat32_type_node 303169689Skan#define TEX_D32 { STD_EXT, "_Decimal32", T_D32 } 304169689Skan#define T_D64 &dfloat64_type_node 305169689Skan#define TEX_D64 { STD_EXT, "_Decimal64", T_D64 } 306169689Skan#define T_D128 &dfloat128_type_node 307169689Skan#define TEX_D128 { STD_EXT, "_Decimal128", T_D128 } 308169689Skan 309169689Skan#endif /* GCC_C_FORMAT_H */ 310