1*404b540aSrobert /* Check calls to formatted I/O functions (-Wformat). 2*404b540aSrobert Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 3*404b540aSrobert 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 4*404b540aSrobert 5*404b540aSrobert This file is part of GCC. 6*404b540aSrobert 7*404b540aSrobert GCC is free software; you can redistribute it and/or modify it under 8*404b540aSrobert the terms of the GNU General Public License as published by the Free 9*404b540aSrobert Software Foundation; either version 2, or (at your option) any later 10*404b540aSrobert version. 11*404b540aSrobert 12*404b540aSrobert GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*404b540aSrobert WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*404b540aSrobert FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*404b540aSrobert for more details. 16*404b540aSrobert 17*404b540aSrobert You should have received a copy of the GNU General Public License 18*404b540aSrobert along with GCC; see the file COPYING. If not, write to the Free 19*404b540aSrobert Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 20*404b540aSrobert 02110-1301, USA. */ 21*404b540aSrobert 22*404b540aSrobert #ifndef GCC_C_FORMAT_H 23*404b540aSrobert #define GCC_C_FORMAT_H 24*404b540aSrobert 25*404b540aSrobert /* The meaningfully distinct length modifiers for format checking recognized 26*404b540aSrobert by GCC. */ 27*404b540aSrobert enum format_lengths 28*404b540aSrobert { 29*404b540aSrobert FMT_LEN_none, 30*404b540aSrobert FMT_LEN_hh, 31*404b540aSrobert FMT_LEN_h, 32*404b540aSrobert FMT_LEN_l, 33*404b540aSrobert FMT_LEN_ll, 34*404b540aSrobert FMT_LEN_L, 35*404b540aSrobert FMT_LEN_z, 36*404b540aSrobert FMT_LEN_t, 37*404b540aSrobert FMT_LEN_j, 38*404b540aSrobert FMT_LEN_H, 39*404b540aSrobert FMT_LEN_D, 40*404b540aSrobert FMT_LEN_DD, 41*404b540aSrobert FMT_LEN_MAX 42*404b540aSrobert }; 43*404b540aSrobert 44*404b540aSrobert 45*404b540aSrobert /* The standard versions in which various format features appeared. */ 46*404b540aSrobert enum format_std_version 47*404b540aSrobert { 48*404b540aSrobert STD_C89, 49*404b540aSrobert STD_C94, 50*404b540aSrobert STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */ 51*404b540aSrobert STD_C99, 52*404b540aSrobert STD_EXT 53*404b540aSrobert }; 54*404b540aSrobert 55*404b540aSrobert /* Flags that may apply to a particular kind of format checked by GCC. */ 56*404b540aSrobert enum 57*404b540aSrobert { 58*404b540aSrobert /* This format converts arguments of types determined by the 59*404b540aSrobert format string. */ 60*404b540aSrobert FMT_FLAG_ARG_CONVERT = 1, 61*404b540aSrobert /* The scanf allocation 'a' kludge applies to this format kind. */ 62*404b540aSrobert FMT_FLAG_SCANF_A_KLUDGE = 2, 63*404b540aSrobert /* A % during parsing a specifier is allowed to be a modified % rather 64*404b540aSrobert that indicating the format is broken and we are out-of-sync. */ 65*404b540aSrobert FMT_FLAG_FANCY_PERCENT_OK = 4, 66*404b540aSrobert /* With $ operand numbers, it is OK to reference the same argument more 67*404b540aSrobert than once. */ 68*404b540aSrobert FMT_FLAG_DOLLAR_MULTIPLE = 8, 69*404b540aSrobert /* This format type uses $ operand numbers (strfmon doesn't). */ 70*404b540aSrobert FMT_FLAG_USE_DOLLAR = 16, 71*404b540aSrobert /* Zero width is bad in this type of format (scanf). */ 72*404b540aSrobert FMT_FLAG_ZERO_WIDTH_BAD = 32, 73*404b540aSrobert /* Empty precision specification is OK in this type of format (printf). */ 74*404b540aSrobert FMT_FLAG_EMPTY_PREC_OK = 64, 75*404b540aSrobert /* Gaps are allowed in the arguments with $ operand numbers if all 76*404b540aSrobert arguments are pointers (scanf). */ 77*404b540aSrobert FMT_FLAG_DOLLAR_GAP_POINTER_OK = 128 78*404b540aSrobert /* Not included here: details of whether width or precision may occur 79*404b540aSrobert (controlled by width_char and precision_char); details of whether 80*404b540aSrobert '*' can be used for these (width_type and precision_type); details 81*404b540aSrobert of whether length modifiers can occur (length_char_specs). */ 82*404b540aSrobert }; 83*404b540aSrobert 84*404b540aSrobert 85*404b540aSrobert /* Structure describing a length modifier supported in format checking, and 86*404b540aSrobert possibly a doubled version such as "hh". */ 87*404b540aSrobert typedef struct 88*404b540aSrobert { 89*404b540aSrobert /* Name of the single-character length modifier. */ 90*404b540aSrobert const char *name; 91*404b540aSrobert /* Index into a format_char_info.types array. */ 92*404b540aSrobert enum format_lengths index; 93*404b540aSrobert /* Standard version this length appears in. */ 94*404b540aSrobert enum format_std_version std; 95*404b540aSrobert /* Same, if the modifier can be repeated, or NULL if it can't. */ 96*404b540aSrobert const char *double_name; 97*404b540aSrobert enum format_lengths double_index; 98*404b540aSrobert enum format_std_version double_std; 99*404b540aSrobert } format_length_info; 100*404b540aSrobert 101*404b540aSrobert 102*404b540aSrobert /* Structure describing the combination of a conversion specifier 103*404b540aSrobert (or a set of specifiers which act identically) and a length modifier. */ 104*404b540aSrobert typedef struct 105*404b540aSrobert { 106*404b540aSrobert /* The standard version this combination of length and type appeared in. 107*404b540aSrobert This is only relevant if greater than those for length and type 108*404b540aSrobert individually; otherwise it is ignored. */ 109*404b540aSrobert enum format_std_version std; 110*404b540aSrobert /* The name to use for the type, if different from that generated internally 111*404b540aSrobert (e.g., "signed size_t"). */ 112*404b540aSrobert const char *name; 113*404b540aSrobert /* The type itself. */ 114*404b540aSrobert tree *type; 115*404b540aSrobert } format_type_detail; 116*404b540aSrobert 117*404b540aSrobert 118*404b540aSrobert /* Macros to fill out tables of these. */ 119*404b540aSrobert #define NOARGUMENTS { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 120*404b540aSrobert #define BADLEN { 0, NULL, NULL } 121*404b540aSrobert #define NOLENGTHS { BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN } 122*404b540aSrobert 123*404b540aSrobert 124*404b540aSrobert /* Structure describing a format conversion specifier (or a set of specifiers 125*404b540aSrobert which act identically), and the length modifiers used with it. */ 126*404b540aSrobert typedef struct format_char_info 127*404b540aSrobert { 128*404b540aSrobert const char *format_chars; 129*404b540aSrobert int pointer_count; 130*404b540aSrobert enum format_std_version std; 131*404b540aSrobert /* Types accepted for each length modifier. */ 132*404b540aSrobert format_type_detail types[FMT_LEN_MAX]; 133*404b540aSrobert /* List of other modifier characters allowed with these specifiers. 134*404b540aSrobert This lists flags, and additionally "w" for width, "p" for precision 135*404b540aSrobert (right precision, for strfmon), "#" for left precision (strfmon), 136*404b540aSrobert "a" for scanf "a" allocation extension (not applicable in C99 mode), 137*404b540aSrobert "*" for scanf suppression, and "E" and "O" for those strftime 138*404b540aSrobert modifiers. */ 139*404b540aSrobert const char *flag_chars; 140*404b540aSrobert /* List of additional flags describing these conversion specifiers. 141*404b540aSrobert "c" for generic character pointers being allowed, "2" for strftime 142*404b540aSrobert two digit year formats, "3" for strftime formats giving two digit 143*404b540aSrobert years in some locales, "4" for "2" which becomes "3" with an "E" modifier, 144*404b540aSrobert "o" if use of strftime "O" is a GNU extension beyond C99, 145*404b540aSrobert "W" if the argument is a pointer which is dereferenced and written into, 146*404b540aSrobert "R" if the argument is a pointer which is dereferenced and read from, 147*404b540aSrobert "i" for printf integer formats where the '0' flag is ignored with 148*404b540aSrobert precision, and "[" for the starting character of a scanf scanset. */ 149*404b540aSrobert const char *flags2; 150*404b540aSrobert /* If this format conversion character consumes more than one argument, 151*404b540aSrobert CHAIN points to information about the next argument. For later 152*404b540aSrobert arguments, only POINTER_COUNT, TYPES, and the "c", "R", and "W" flags 153*404b540aSrobert in FLAGS2 are used. */ 154*404b540aSrobert const struct format_char_info *chain; 155*404b540aSrobert } format_char_info; 156*404b540aSrobert 157*404b540aSrobert 158*404b540aSrobert /* Structure describing a flag accepted by some kind of format. */ 159*404b540aSrobert typedef struct 160*404b540aSrobert { 161*404b540aSrobert /* The flag character in question (0 for end of array). */ 162*404b540aSrobert int flag_char; 163*404b540aSrobert /* Zero if this entry describes the flag character in general, or a 164*404b540aSrobert nonzero character that may be found in flags2 if it describes the 165*404b540aSrobert flag when used with certain formats only. If the latter, only 166*404b540aSrobert the first such entry found that applies to the current conversion 167*404b540aSrobert specifier is used; the values of 'name' and 'long_name' it supplies 168*404b540aSrobert will be used, if non-NULL and the standard version is higher than 169*404b540aSrobert the unpredicated one, for any pedantic warning. For example, 'o' 170*404b540aSrobert for strftime formats (meaning 'O' is an extension over C99). */ 171*404b540aSrobert int predicate; 172*404b540aSrobert /* Nonzero if the next character after this flag in the format should 173*404b540aSrobert be skipped ('=' in strfmon), zero otherwise. */ 174*404b540aSrobert int skip_next_char; 175*404b540aSrobert /* The name to use for this flag in diagnostic messages. For example, 176*404b540aSrobert N_("'0' flag"), N_("field width"). */ 177*404b540aSrobert const char *name; 178*404b540aSrobert /* Long name for this flag in diagnostic messages; currently only used for 179*404b540aSrobert "ISO C does not support ...". For example, N_("the 'I' printf flag"). */ 180*404b540aSrobert const char *long_name; 181*404b540aSrobert /* The standard version in which it appeared. */ 182*404b540aSrobert enum format_std_version std; 183*404b540aSrobert } format_flag_spec; 184*404b540aSrobert 185*404b540aSrobert 186*404b540aSrobert /* Structure describing a combination of flags that is bad for some kind 187*404b540aSrobert of format. */ 188*404b540aSrobert typedef struct 189*404b540aSrobert { 190*404b540aSrobert /* The first flag character in question (0 for end of array). */ 191*404b540aSrobert int flag_char1; 192*404b540aSrobert /* The second flag character. */ 193*404b540aSrobert int flag_char2; 194*404b540aSrobert /* Nonzero if the message should say that the first flag is ignored with 195*404b540aSrobert the second, zero if the combination should simply be objected to. */ 196*404b540aSrobert int ignored; 197*404b540aSrobert /* Zero if this entry applies whenever this flag combination occurs, 198*404b540aSrobert a nonzero character from flags2 if it only applies in some 199*404b540aSrobert circumstances (e.g. 'i' for printf formats ignoring 0 with precision). */ 200*404b540aSrobert int predicate; 201*404b540aSrobert } format_flag_pair; 202*404b540aSrobert 203*404b540aSrobert 204*404b540aSrobert /* Structure describing a particular kind of format processed by GCC. */ 205*404b540aSrobert typedef struct 206*404b540aSrobert { 207*404b540aSrobert /* The name of this kind of format, for use in diagnostics. Also 208*404b540aSrobert the name of the attribute (without preceding and following __). */ 209*404b540aSrobert const char *name; 210*404b540aSrobert /* Specifications of the length modifiers accepted; possibly NULL. */ 211*404b540aSrobert const format_length_info *length_char_specs; 212*404b540aSrobert /* Details of the conversion specification characters accepted. */ 213*404b540aSrobert const format_char_info *conversion_specs; 214*404b540aSrobert /* String listing the flag characters that are accepted. */ 215*404b540aSrobert const char *flag_chars; 216*404b540aSrobert /* String listing modifier characters (strftime) accepted. May be NULL. */ 217*404b540aSrobert const char *modifier_chars; 218*404b540aSrobert /* Details of the flag characters, including pseudo-flags. */ 219*404b540aSrobert const format_flag_spec *flag_specs; 220*404b540aSrobert /* Details of bad combinations of flags. */ 221*404b540aSrobert const format_flag_pair *bad_flag_pairs; 222*404b540aSrobert /* Flags applicable to this kind of format. */ 223*404b540aSrobert int flags; 224*404b540aSrobert /* Flag character to treat a width as, or 0 if width not used. */ 225*404b540aSrobert int width_char; 226*404b540aSrobert /* Flag character to treat a left precision (strfmon) as, 227*404b540aSrobert or 0 if left precision not used. */ 228*404b540aSrobert int left_precision_char; 229*404b540aSrobert /* Flag character to treat a precision (for strfmon, right precision) as, 230*404b540aSrobert or 0 if precision not used. */ 231*404b540aSrobert int precision_char; 232*404b540aSrobert /* If a flag character has the effect of suppressing the conversion of 233*404b540aSrobert an argument ('*' in scanf), that flag character, otherwise 0. */ 234*404b540aSrobert int suppression_char; 235*404b540aSrobert /* Flag character to treat a length modifier as (ignored if length 236*404b540aSrobert modifiers not used). Need not be placed in flag_chars for conversion 237*404b540aSrobert specifiers, but is used to check for bad combinations such as length 238*404b540aSrobert modifier with assignment suppression in scanf. */ 239*404b540aSrobert int length_code_char; 240*404b540aSrobert /* Pointer to type of argument expected if '*' is used for a width, 241*404b540aSrobert or NULL if '*' not used for widths. */ 242*404b540aSrobert tree *width_type; 243*404b540aSrobert /* Pointer to type of argument expected if '*' is used for a precision, 244*404b540aSrobert or NULL if '*' not used for precisions. */ 245*404b540aSrobert tree *precision_type; 246*404b540aSrobert } format_kind_info; 247*404b540aSrobert 248*404b540aSrobert #define T_I &integer_type_node 249*404b540aSrobert #define T89_I { STD_C89, NULL, T_I } 250*404b540aSrobert #define T_L &long_integer_type_node 251*404b540aSrobert #define T89_L { STD_C89, NULL, T_L } 252*404b540aSrobert #define T_LL &long_long_integer_type_node 253*404b540aSrobert #define T9L_LL { STD_C9L, NULL, T_LL } 254*404b540aSrobert #define TEX_LL { STD_EXT, NULL, T_LL } 255*404b540aSrobert #define T_S &short_integer_type_node 256*404b540aSrobert #define T89_S { STD_C89, NULL, T_S } 257*404b540aSrobert #define T_UI &unsigned_type_node 258*404b540aSrobert #define T89_UI { STD_C89, NULL, T_UI } 259*404b540aSrobert #define T_UL &long_unsigned_type_node 260*404b540aSrobert #define T89_UL { STD_C89, NULL, T_UL } 261*404b540aSrobert #define T_ULL &long_long_unsigned_type_node 262*404b540aSrobert #define T9L_ULL { STD_C9L, NULL, T_ULL } 263*404b540aSrobert #define TEX_ULL { STD_EXT, NULL, T_ULL } 264*404b540aSrobert #define T_US &short_unsigned_type_node 265*404b540aSrobert #define T89_US { STD_C89, NULL, T_US } 266*404b540aSrobert #define T_F &float_type_node 267*404b540aSrobert #define T89_F { STD_C89, NULL, T_F } 268*404b540aSrobert #define T99_F { STD_C99, NULL, T_F } 269*404b540aSrobert #define T_D &double_type_node 270*404b540aSrobert #define T89_D { STD_C89, NULL, T_D } 271*404b540aSrobert #define T99_D { STD_C99, NULL, T_D } 272*404b540aSrobert #define T_LD &long_double_type_node 273*404b540aSrobert #define T89_LD { STD_C89, NULL, T_LD } 274*404b540aSrobert #define T99_LD { STD_C99, NULL, T_LD } 275*404b540aSrobert #define T_C &char_type_node 276*404b540aSrobert #define T89_C { STD_C89, NULL, T_C } 277*404b540aSrobert #define T_SC &signed_char_type_node 278*404b540aSrobert #define T99_SC { STD_C99, NULL, T_SC } 279*404b540aSrobert #define T_UC &unsigned_char_type_node 280*404b540aSrobert #define T99_UC { STD_C99, NULL, T_UC } 281*404b540aSrobert #define T_V &void_type_node 282*404b540aSrobert #define T89_V { STD_C89, NULL, T_V } 283*404b540aSrobert #define T_W &wchar_type_node 284*404b540aSrobert #define T94_W { STD_C94, "wchar_t", T_W } 285*404b540aSrobert #define TEX_W { STD_EXT, "wchar_t", T_W } 286*404b540aSrobert #define T_WI &wint_type_node 287*404b540aSrobert #define T94_WI { STD_C94, "wint_t", T_WI } 288*404b540aSrobert #define TEX_WI { STD_EXT, "wint_t", T_WI } 289*404b540aSrobert #define T_ST &size_type_node 290*404b540aSrobert #define T99_ST { STD_C99, "size_t", T_ST } 291*404b540aSrobert #define T_SST &signed_size_type_node 292*404b540aSrobert #define T99_SST { STD_C99, "signed size_t", T_SST } 293*404b540aSrobert #define T_PD &ptrdiff_type_node 294*404b540aSrobert #define T99_PD { STD_C99, "ptrdiff_t", T_PD } 295*404b540aSrobert #define T_UPD &unsigned_ptrdiff_type_node 296*404b540aSrobert #define T99_UPD { STD_C99, "unsigned ptrdiff_t", T_UPD } 297*404b540aSrobert #define T_IM &intmax_type_node 298*404b540aSrobert #define T99_IM { STD_C99, "intmax_t", T_IM } 299*404b540aSrobert #define T_UIM &uintmax_type_node 300*404b540aSrobert #define T99_UIM { STD_C99, "uintmax_t", T_UIM } 301*404b540aSrobert #define T_D32 &dfloat32_type_node 302*404b540aSrobert #define TEX_D32 { STD_EXT, "_Decimal32", T_D32 } 303*404b540aSrobert #define T_D64 &dfloat64_type_node 304*404b540aSrobert #define TEX_D64 { STD_EXT, "_Decimal64", T_D64 } 305*404b540aSrobert #define T_D128 &dfloat128_type_node 306*404b540aSrobert #define TEX_D128 { STD_EXT, "_Decimal128", T_D128 } 307*404b540aSrobert 308*404b540aSrobert #endif /* GCC_C_FORMAT_H */ 309