]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/i386/msformat-c.c
2015-06-04 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / config / i386 / msformat-c.c
1 /* Check calls to formatted I/O functions (-Wformat).
2 Copyright (C) 1992-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "hash-set.h"
25 #include "vec.h"
26 #include "input.h"
27 #include "alias.h"
28 #include "symtab.h"
29 #include "inchash.h"
30 #include "tree.h"
31 #include "flags.h"
32 #include "c-family/c-common.h"
33 #include "intl.h"
34 #include "diagnostic.h"
35 #include "langhooks.h"
36 #include "c-family/c-format.h"
37 #include "alloc-pool.h"
38
39 /* Mingw specific format attributes ms_printf, ms_scanf, and ms_strftime. */
40
41 static format_length_info ms_printf_length_specs[] =
42 {
43 { "h", FMT_LEN_h, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 },
44 { "l", FMT_LEN_l, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 },
45 { "I32", FMT_LEN_l, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 },
46 { "I64", FMT_LEN_ll, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 },
47 { "I", FMT_LEN_L, STD_EXT, NULL, FMT_LEN_none, STD_C89, 1 },
48 { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }
49 };
50
51 static const format_flag_spec ms_printf_flag_specs[] =
52 {
53 { ' ', 0, 0, N_("' ' flag"), N_("the ' ' printf flag"), STD_C89 },
54 { '+', 0, 0, N_("'+' flag"), N_("the '+' printf flag"), STD_C89 },
55 { '#', 0, 0, N_("'#' flag"), N_("the '#' printf flag"), STD_C89 },
56 { '0', 0, 0, N_("'0' flag"), N_("the '0' printf flag"), STD_C89 },
57 { '-', 0, 0, N_("'-' flag"), N_("the '-' printf flag"), STD_C89 },
58 { '\'', 0, 0, N_("''' flag"), N_("the ''' printf flag"), STD_EXT },
59 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
60 { 'p', 0, 0, N_("precision"), N_("precision in printf format"), STD_C89 },
61 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
62 { 0, 0, 0, NULL, NULL, STD_C89 }
63 };
64
65 static const format_flag_pair ms_printf_flag_pairs[] =
66 {
67 { ' ', '+', 1, 0 },
68 { '0', '-', 1, 0 }, { '0', 'p', 1, 'i' },
69 { 0, 0, 0, 0 }
70 };
71
72 static const format_flag_spec ms_scanf_flag_specs[] =
73 {
74 { '*', 0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89 },
75 { 'a', 0, 0, N_("'a' flag"), N_("the 'a' scanf flag"), STD_EXT },
76 { 'w', 0, 0, N_("field width"), N_("field width in scanf format"), STD_C89 },
77 { 'L', 0, 0, N_("length modifier"), N_("length modifier in scanf format"), STD_C89 },
78 { '\'', 0, 0, N_("''' flag"), N_("the ''' scanf flag"), STD_EXT },
79 { 0, 0, 0, NULL, NULL, STD_C89 }
80 };
81
82 static const format_flag_pair ms_scanf_flag_pairs[] =
83 {
84 { '*', 'L', 0, 0 },
85 { 0, 0, 0, 0 }
86 };
87
88 static const format_flag_spec ms_strftime_flag_specs[] =
89 {
90 { '#', 0, 0, N_("'#' flag"), N_("the '#' strftime flag"), STD_EXT },
91 { 0, 0, 0, NULL, NULL, STD_C89 }
92 };
93
94 static const format_flag_pair ms_strftime_flag_pairs[] =
95 {
96 { 0, 0, 0, 0 }
97 };
98
99 static const format_char_info ms_print_char_table[] =
100 {
101 /* C89 conversion specifiers. */
102 { "di", 0, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +'", "i", NULL },
103 { "oxX", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0#", "i", NULL },
104 { "u", 0, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0'", "i", NULL },
105 { "fgG", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "", NULL },
106 { "eE", 0, STD_C89, { T89_D, BADLEN, BADLEN, T99_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp0 +#", "", NULL },
107 { "c", 0, STD_C89, { T89_I, BADLEN, T89_S, T94_WI, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "", NULL },
108 { "s", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "cR", NULL },
109 { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "c", NULL },
110 { "n", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, T99_IM, BADLEN, BADLEN, BADLEN }, "", "W", NULL },
111 /* X/Open conversion specifiers. */
112 { "C", 0, STD_EXT, { TEX_WI, BADLEN, T89_S, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-w", "", NULL },
113 { "S", 1, STD_EXT, { TEX_W, BADLEN, T89_S, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "-wp", "R", NULL },
114 { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
115 };
116
117 static const format_char_info ms_scan_char_table[] =
118 {
119 /* C89 conversion specifiers. */
120 { "di", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, T99_SST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w'", "W", NULL },
121 { "u", 1, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w'", "W", NULL },
122 { "oxX", 1, STD_C89, { T89_UI, BADLEN, T89_US, T89_UL, T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "W", NULL },
123 { "efgEG", 1, STD_C89, { T89_F, BADLEN, BADLEN, T89_D, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w'", "W", NULL },
124 { "c", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "cW", NULL },
125 { "s", 1, STD_C89, { T89_C, BADLEN, T89_S, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "cW", NULL },
126 { "[", 1, STD_C89, { T89_C, BADLEN, BADLEN, T94_W, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "cW[", NULL },
127 { "p", 2, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "W", NULL },
128 { "n", 1, STD_C89, { T89_I, BADLEN, T89_S, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "W", NULL },
129 /* X/Open conversion specifiers. */
130 { "C", 1, STD_EXT, { TEX_W, BADLEN, T89_S, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*w", "W", NULL },
131 { "S", 1, STD_EXT, { TEX_W, BADLEN, T89_S, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "*aw", "W", NULL },
132 { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
133 };
134
135 static const format_char_info ms_time_char_table[] =
136 {
137 /* C89 conversion specifiers. */
138 { "ABZab", 0, STD_C89, NOLENGTHS, "#", "", NULL },
139 { "cx", 0, STD_C89, NOLENGTHS, "#", "3", NULL },
140 { "HIMSUWdmw", 0, STD_C89, NOLENGTHS, "#", "", NULL },
141 { "j", 0, STD_C89, NOLENGTHS, "#", "", NULL },
142 { "p", 0, STD_C89, NOLENGTHS, "#", "", NULL },
143 { "X", 0, STD_C89, NOLENGTHS, "#", "", NULL },
144 { "y", 0, STD_C89, NOLENGTHS, "#", "4", NULL },
145 { "Y", 0, STD_C89, NOLENGTHS, "#", "", NULL },
146 { "%", 0, STD_C89, NOLENGTHS, "", "", NULL },
147 /* C99 conversion specifiers. */
148 { "z", 0, STD_C99, NOLENGTHS, "#", "", NULL },
149 { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
150 };
151
152 EXPORTED_CONST format_kind_info mingw_format_attributes[3] =
153 {
154 { "ms_printf", ms_printf_length_specs, ms_print_char_table, " +#0-'", NULL,
155 ms_printf_flag_specs, ms_printf_flag_pairs,
156 FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
157 'w', 0, 'p', 0, 'L', 0,
158 &integer_type_node, &integer_type_node
159 },
160 { "ms_scanf", ms_printf_length_specs, ms_scan_char_table, "*'", NULL,
161 ms_scanf_flag_specs, ms_scanf_flag_pairs,
162 FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
163 'w', 0, 0, '*', 'L', 0,
164 NULL, NULL
165 },
166 { "ms_strftime", NULL, ms_time_char_table, "", "#",
167 ms_strftime_flag_specs, ms_strftime_flag_pairs,
168 FMT_FLAG_FANCY_PERCENT_OK, 0, 0, 0, 0, 0, 0,
169 NULL, NULL
170 }
171 };
172
173 /* Default overrides for printf, scanf and strftime. */
174 EXPORTED_CONST target_ovr_attr mingw_format_attribute_overrides[4] =
175 {
176 { "ms_printf", "printf" },
177 { "ms_scanf", "scanf" },
178 { "ms_strftime", "strftime" }
179 };
180
181 /* Setup for option Wpedantic-ms-format. */
182
183 #ifdef TARGET_OVERRIDES_FORMAT_INIT
184
185 /* Make sure TARGET_OVERRIDES_FORMAT_INIT is prototyped. */
186 extern void TARGET_OVERRIDES_FORMAT_INIT (void);
187
188 /* Helper. */
189 #define C89_OR_EXT (warn_pedantic_ms_format ? STD_EXT : STD_C89)
190
191 void
192 TARGET_OVERRIDES_FORMAT_INIT (void)
193 {
194 ms_printf_length_specs[2].std = C89_OR_EXT; /* I32 */
195 ms_printf_length_specs[3].std = C89_OR_EXT; /* I64 */
196 ms_printf_length_specs[4].std = C89_OR_EXT; /* I */
197 }
198
199 #undef C89_OR_EXT
200
201 #endif