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