]> git.pld-linux.org Git - packages/crossmingw64-gcc.git/blob - crossmingw64-gcc-msvcrt-fmt.patch
- fixes backported from 4.4.
[packages/crossmingw64-gcc.git] / crossmingw64-gcc-msvcrt-fmt.patch
1 diff -r ddadaee88373 gcc/c-format.c
2 --- a/gcc/c-format.c    Thu May 29 20:27:38 2008 -0600
3 +++ b/gcc/c-format.c    Mon Jun 02 08:07:22 2008 -0600
4 @@ -62,8 +62,7 @@
5                    gcc_diag_format_type, gcc_tdiag_format_type,
6                    gcc_cdiag_format_type,
7                    gcc_cxxdiag_format_type, gcc_gfc_format_type,
8 -                  scanf_format_type, strftime_format_type,
9 -                  strfmon_format_type, format_type_error = -1};
10 +                  format_type_error = -1};
11  
12  typedef struct function_format_info
13  {
14 @@ -80,7 +79,8 @@
15                                  int flags, bool *no_add_attrs);
16  static bool get_constant (tree expr, unsigned HOST_WIDE_INT *value,
17                           int validated_p);
18 -
19 +static const char *convert_format_name_to_system_name (const char *attr_name);
20 +static bool cmp_attribs (const char *tattr_name, const char *attr_name);
21  
22  /* Handle a "format_arg" attribute; arguments as in
23     struct attribute_spec.handler.  */
24 @@ -190,6 +190,8 @@
25    else
26      {
27        const char *p = IDENTIFIER_POINTER (format_type_id);
28 +
29 +      p = convert_format_name_to_system_name (p);
30  
31        info->format_type = decode_format_type (p);
32  
33 @@ -715,7 +717,7 @@
34  /* This must be in the same order as enum format_type.  */
35  static const format_kind_info format_types_orig[] =
36  {
37 -  { "printf",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
38 +  { "gnu_printf",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
39      printf_flag_specs, printf_flag_pairs,
40      FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
41      'w', 0, 'p', 0, 'L', 0,
42 @@ -757,18 +759,18 @@
43      0, 0, 0, 0, 0, 0,
44      NULL, NULL
45    },
46 -  { "scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
47 +  { "gnu_scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
48      scanf_flag_specs, scanf_flag_pairs,
49      FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
50      'w', 0, 0, '*', 'L', 'm',
51      NULL, NULL
52    },
53 -  { "strftime", NULL,                 time_char_table,  "_-0^#", "EO",
54 +  { "gnu_strftime", NULL,                 time_char_table,  "_-0^#", "EO",
55      strftime_flag_specs, strftime_flag_pairs,
56      FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0, 0,
57      NULL, NULL
58    },
59 -  { "strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
60 +  { "gnu_strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
61      strfmon_flag_specs, strfmon_flag_pairs,
62      FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
63      NULL, NULL
64 @@ -847,6 +849,8 @@
65  {
66    int i;
67    int slen;
68 +
69 +  s = convert_format_name_to_system_name (s);
70    slen = strlen (s);
71    for (i = 0; i < n_format_types; i++)
72      {
73 @@ -1775,11 +1779,12 @@
74        length_chars_std = STD_C89;
75        if (fli)
76         {
77 -         while (fli->name != 0 && fli->name[0] != *format_chars)
78 -           fli++;
79 +         while (fli->name != 0 
80 +                && strncmp (fli->name, format_chars, strlen (fli->name)))
81 +             fli++;
82           if (fli->name != 0)
83             {
84 -             format_chars++;
85 +             format_chars += strlen (fli->name);
86               if (fli->double_name != 0 && fli->name[0] == *format_chars)
87                 {
88                   format_chars++;
89 @@ -2703,6 +2708,84 @@
90  extern const format_kind_info TARGET_FORMAT_TYPES[];
91  #endif
92  
93 +#ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
94 +extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[];
95 +#endif
96 +
97 +/* Attributes such as "printf" are equivalent to those such as
98 +   "gnu_printf" unless this is overridden by a target.  */
99 +static const target_ovr_attr gnu_target_overrides_format_attributes[] =
100 +{
101 +  { "gnu_printf",   "printf" },
102 +  { "gnu_scanf",    "scanf" },
103 +  { "gnu_strftime", "strftime" },
104 +  { "gnu_strfmon",  "strfmon" },
105 +  { NULL,           NULL }
106 +};
107 +
108 +/* Translate to unified attribute name. This is used in decode_format_type and
109 +   decode_format_attr. In attr_name the user specified argument is passed. It
110 +   returns the unified format name from TARGET_OVERRIDES_FORMAT_ATTRIBUTES
111 +   or the attr_name passed to this function, if there is no matching entry.  */
112 +static const char *
113 +convert_format_name_to_system_name (const char *attr_name)
114 +{
115 +  int i;
116 +
117 +  if (attr_name == NULL || *attr_name == 0
118 +      || strncmp (attr_name, "gcc_", 4) == 0)
119 +    return attr_name;
120 +
121 +#ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
122 +  /* Check if format attribute is overridden by target.  */
123 +  if (TARGET_OVERRIDES_FORMAT_ATTRIBUTES != NULL
124 +      && TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT > 0)
125 +    {
126 +      for (i = 0; i < TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT; ++i)
127 +        {
128 +          if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src,
129 +                          attr_name))
130 +            return attr_name;
131 +          if (cmp_attribs (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_dst,
132 +                          attr_name))
133 +            return TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src;
134 +        }
135 +    }
136 +#endif
137 +  /* Otherwise default to gnu format.  */
138 +  for (i = 0;
139 +       gnu_target_overrides_format_attributes[i].named_attr_src != NULL;
140 +       ++i)
141 +    {
142 +      if (cmp_attribs (gnu_target_overrides_format_attributes[i].named_attr_src,
143 +                      attr_name))
144 +        return attr_name;
145 +      if (cmp_attribs (gnu_target_overrides_format_attributes[i].named_attr_dst,
146 +                      attr_name))
147 +        return gnu_target_overrides_format_attributes[i].named_attr_src;
148 +    }
149 +
150 +  return attr_name;
151 +}
152 +
153 +/* Return true if TATTR_NAME and ATTR_NAME are the same format attribute,
154 +   counting "name" and "__name__" as the same, false otherwise.  */
155 +static bool
156 +cmp_attribs (const char *tattr_name, const char *attr_name)
157 +{
158 +  int alen = strlen (attr_name);
159 +  int slen = (tattr_name ? strlen (tattr_name) : 0);
160 +  if (alen > 4 && attr_name[0] == '_' && attr_name[1] == '_'
161 +      && attr_name[alen - 1] == '_' && attr_name[alen - 2] == '_')
162 +    {
163 +      attr_name += 2;
164 +      alen -= 4;
165 +    }
166 +  if (alen != slen || strncmp (tattr_name, attr_name, alen) != 0)
167 +    return false;
168 +  return true;
169 +}
170 +
171  /* Handle a "format" attribute; arguments as in
172     struct attribute_spec.handler.  */
173  tree
174 @@ -2762,7 +2845,10 @@
175         }
176      }
177  
178 -  if (info.format_type == strftime_format_type && info.first_arg_num != 0)
179 +  /* Check if this is a strftime variant. Just for this variant
180 +     FMT_FLAG_ARG_CONVERT is not set.  */
181 +  if ((format_types[info.format_type].flags & (int) FMT_FLAG_ARG_CONVERT) == 0
182 +      && info.first_arg_num != 0)
183      {
184        error ("strftime formats cannot format arguments");
185        *no_add_attrs = true;
186 diff -r ddadaee88373 gcc/c-format.h
187 --- a/gcc/c-format.h    Thu May 29 20:27:38 2008 -0600
188 +++ b/gcc/c-format.h    Mon Jun 02 08:07:22 2008 -0600
189 @@ -80,12 +80,13 @@
190       of whether length modifiers can occur (length_char_specs).  */
191  };
192  
193 -
194  /* Structure describing a length modifier supported in format checking, and
195     possibly a doubled version such as "hh".  */
196  typedef struct
197  {
198 -  /* Name of the single-character length modifier.  */
199 +  /* Name of the single-character length modifier. If prefixed by
200 +     a zero character, it describes a multi character length
201 +     modifier, like I64, I32, etc.  */
202    const char *name;
203    /* Index into a format_char_info.types array.  */
204    enum format_lengths index;
205 @@ -306,4 +307,16 @@
206  #define T_D128  &dfloat128_type_node
207  #define TEX_D128 { STD_EXT, "_Decimal128", T_D128 }
208  
209 +/* Structure describing how format attributes such as "printf" are
210 +   interpreted as "gnu_printf" or "ms_printf" on a particular system.
211 +   TARGET_OVERRIDES_FORMAT_ATTRIBUTES is used to specify target-specific
212 +   defaults.  */
213 +typedef struct
214 +{
215 +  /* The name of the to be copied format attribute. */
216 +  const char *named_attr_src;
217 +  /* The name of the to be overridden format attribute. */
218 +  const char *named_attr_dst;
219 +} target_ovr_attr;
220 +
221  #endif /* GCC_C_FORMAT_H */
222 diff -r ddadaee88373 gcc/config.gcc
223 --- a/gcc/config.gcc    Thu May 29 20:27:38 2008 -0600
224 +++ b/gcc/config.gcc    Mon Jun 02 08:07:22 2008 -0600
225 @@ -1365,8 +1365,8 @@
226         target_gtfiles="\$(srcdir)/config/i386/winnt.c"
227         extra_options="${extra_options} i386/cygming.opt"
228         extra_objs="winnt.o winnt-stubs.o"
229 -       c_target_objs=cygwin2.o
230 -       cxx_target_objs="cygwin2.o winnt-cxx.o"
231 +       c_target_objs="cygwin2.o msformat-c.o"
232 +       cxx_target_objs="cygwin2.o winnt-cxx.o msformat-c.o"
233         extra_gcc_objs=cygwin1.o
234         if test x$enable_threads = xyes; then
235                 thread_file='posix'
236 @@ -1379,7 +1379,8 @@
237         target_gtfiles="\$(srcdir)/config/i386/winnt.c"
238         extra_options="${extra_options} i386/cygming.opt"
239         extra_objs="winnt.o winnt-stubs.o"
240 -       cxx_target_objs=winnt-cxx.o
241 +       c_target_objs="msformat-c.o"
242 +       cxx_target_objs="winnt-cxx.o msformat-c.o"
243         default_use_cxa_atexit=yes
244         case ${enable_threads} in
245           "" | yes | win32)
246 diff -r ddadaee88373 gcc/config/i386/mingw32.h
247 --- a/gcc/config/i386/mingw32.h Thu May 29 20:27:38 2008 -0600
248 +++ b/gcc/config/i386/mingw32.h Mon Jun 02 08:07:22 2008 -0600
249 @@ -143,6 +143,23 @@
250     to register C++ static destructors.  */
251  #define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true
252  
253 +/* Contains a pointer to type target_ovr_attr defining the target specific
254 +   overrides of format attributes.  See c-format.h for structure
255 +   definition.  */
256 +#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
257 +#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES mingw_format_attribute_overrides
258 +
259 +/* Specify the count of elements in TARGET_OVERRIDES_ATTRIBUTE.  */
260 +#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
261 +#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3
262 +
263 +/* MS specific format attributes for ms_printf, ms_scanf, ms_strftime.  */
264 +#undef TARGET_FORMAT_TYPES
265 +#define TARGET_FORMAT_TYPES mingw_format_attributes
266 +
267 +#undef TARGET_N_FORMAT_TYPES
268 +#define TARGET_N_FORMAT_TYPES 3
269 +
270  /* JCR_SECTION works on mingw32.  */
271  #undef TARGET_USE_JCR_SECTION
272  #define TARGET_USE_JCR_SECTION 1
273 diff -r ddadaee88373 gcc/config/i386/msformat-c.c
274 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
275 +++ b/gcc/config/i386/msformat-c.c      Mon Jun 02 08:07:22 2008 -0600
276 @@ -0,0 +1,175 @@
277 +/* Check calls to formatted I/O functions (-Wformat).
278 +   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
279 +   2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
280 +
281 +This file is part of GCC.
282 +
283 +GCC is free software; you can redistribute it and/or modify it under
284 +the terms of the GNU General Public License as published by the Free
285 +Software Foundation; either version 3, or (at your option) any later
286 +version.
287 +
288 +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
289 +WARRANTY; without even the implied warranty of MERCHANTABILITY or
290 +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
291 +for more details.
292 +
293 +You should have received a copy of the GNU General Public License
294 +along with GCC; see the file COPYING3.  If not see
295 +<http://www.gnu.org/licenses/>.  */
296 +
297 +#include "config.h"
298 +#include "system.h"
299 +#include "coretypes.h"
300 +#include "tm.h"
301 +#include "tree.h"
302 +#include "flags.h"
303 +#include "c-common.h"
304 +#include "toplev.h"
305 +#include "intl.h"
306 +#include "diagnostic.h"
307 +#include "langhooks.h"
308 +#include "c-format.h"
309 +#include "alloc-pool.h"
310 +
311 +/* Mingw specific format attributes ms_printf, ms_scanf, and ms_strftime.  */
312 +
313 +static const format_length_info ms_printf_length_specs[] =
314 +{
315 +  { "h", FMT_LEN_h, STD_C89, NULL, 0, 0 },
316 +  { "l", FMT_LEN_l, STD_C89, NULL, 0, 0 },
317 +  { "I32", FMT_LEN_l, STD_EXT, NULL, 0, 0 },
318 +  { "I64", FMT_LEN_ll, STD_EXT, NULL, 0, 0 },
319 +  { "I", FMT_LEN_L, STD_EXT, NULL, 0, 0 },
320 +  { NULL, 0, 0, NULL, 0, 0 }
321 +};
322 +
323 +static const format_flag_spec ms_printf_flag_specs[] =
324 +{
325 +  { ' ',  0, 0, N_("' ' flag"),        N_("the ' ' printf flag"),              STD_C89 },
326 +  { '+',  0, 0, N_("'+' flag"),        N_("the '+' printf flag"),              STD_C89 },
327 +  { '#',  0, 0, N_("'#' flag"),        N_("the '#' printf flag"),              STD_C89 },
328 +  { '0',  0, 0, N_("'0' flag"),        N_("the '0' printf flag"),              STD_C89 },
329 +  { '-',  0, 0, N_("'-' flag"),        N_("the '-' printf flag"),              STD_C89 },
330 +  { '\'', 0, 0, N_("''' flag"),        N_("the ''' printf flag"),              STD_EXT },
331 +  { 'w',  0, 0, N_("field width"),     N_("field width in printf format"),     STD_C89 },
332 +  { 'p',  0, 0, N_("precision"),       N_("precision in printf format"),       STD_C89 },
333 +  { 'L',  0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
334 +  { 0, 0, 0, NULL, NULL, 0 }
335 +};
336 +
337 +static const format_flag_pair ms_printf_flag_pairs[] =
338 +{
339 +  { ' ', '+', 1, 0   },
340 +  { '0', '-', 1, 0   }, { '0', 'p', 1, 'i' },
341 +  { 0, 0, 0, 0 }
342 +};
343 +
344 +static const format_flag_spec ms_scanf_flag_specs[] =
345 +{
346 +  { '*',  0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89 },
347 +  { 'a',  0, 0, N_("'a' flag"),               N_("the 'a' scanf flag"),                       STD_EXT },
348 +  { 'w',  0, 0, N_("field width"),            N_("field width in scanf format"),              STD_C89 },
349 +  { 'L',  0, 0, N_("length modifier"),        N_("length modifier in scanf format"),          STD_C89 },
350 +  { '\'', 0, 0, N_("''' flag"),               N_("the ''' scanf flag"),                       STD_EXT },
351 +  { 0, 0, 0, NULL, NULL, 0 }
352 +};
353 +
354 +static const format_flag_pair ms_scanf_flag_pairs[] =
355 +{
356 +  { '*', 'L', 0, 0 },
357 +  { 0, 0, 0, 0 }
358 +};
359 +
360 +static const format_flag_spec ms_strftime_flag_specs[] =
361 +{
362 +  { '#', 0,   0, N_("'#' flag"),     N_("the '#' strftime flag"),          STD_EXT },
363 +  { 0, 0, 0, NULL, NULL, 0 }
364 +};
365 +
366 +static const format_flag_pair ms_strftime_flag_pairs[] =
367 +{
368 +  { 0, 0, 0, 0 }
369 +};
370 +
371 +static const format_char_info ms_print_char_table[] =
372 +{
373 +  /* C89 conversion specifiers.  */
374 +  { "di",  0, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  T99_SST,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +'",  "i",  NULL },
375 +  { "oxX", 0, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "-wp0#",     "i",  NULL },
376 +  { "u",   0, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T99_ST, BADLEN, BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "-wp0'",    "i",  NULL },
377 +  { "fgG", 0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "",   NULL },
378 +  { "eE",  0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "-wp0 +#",  "",   NULL },
379 +  { "c",   0, STD_C89, { T89_I,   BADLEN,  T89_S,  T94_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
380 +  { "s",   1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "cR", NULL },
381 +  { "p",   1, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "c",  NULL },
382 +  { "n",   1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  BADLEN,  BADLEN, BADLEN,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },
383 +  /* X/Open conversion specifiers.  */
384 +  { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
385 +  { "S",   1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },
386 +  { NULL,  0, 0, NOLENGTHS, NULL, NULL, NULL }
387 +};
388 +
389 +static const format_char_info ms_scan_char_table[] =
390 +{
391 +  /* C89 conversion specifiers.  */
392 +  { "di",    1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  T99_SST,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w'", "W",   NULL },
393 +  { "u",     1, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T99_ST, BADLEN,  BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "*w'", "W",   NULL },
394 +  { "oxX",   1, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T99_ST, BADLEN,  BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
395 +  { "efgEG", 1, STD_C89, { T89_F,   BADLEN,  BADLEN,  T89_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "*w'",  "W",   NULL },
396 +  { "c",     1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "cW",  NULL },
397 +  { "s",     1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "cW",  NULL },
398 +  { "[",     1, STD_C89, { T89_C,   BADLEN,  BADLEN,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "cW[", NULL },
399 +  { "p",     2, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
400 +  { "n",     1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  BADLEN,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "",     "W",   NULL },
401 +  /* X/Open conversion specifiers.  */
402 +  { "C",     1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
403 +  { "S",     1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "W",   NULL },
404 +  { NULL, 0, 0, NOLENGTHS, NULL, NULL, NULL }
405 +};
406 +
407 +static const format_char_info ms_time_char_table[] =
408 +{
409 +  /* C89 conversion specifiers.  */
410 +  { "ABZab",           0, STD_C89, NOLENGTHS, "#",     "",   NULL },
411 +  { "cx",              0, STD_C89, NOLENGTHS, "#",      "3",  NULL },
412 +  { "HIMSUWdmw",       0, STD_C89, NOLENGTHS, "#",  "",   NULL },
413 +  { "j",               0, STD_C89, NOLENGTHS, "#",  "",  NULL },
414 +  { "p",               0, STD_C89, NOLENGTHS, "#",      "",   NULL },
415 +  { "X",               0, STD_C89, NOLENGTHS, "#",      "",   NULL },
416 +  { "y",               0, STD_C89, NOLENGTHS, "#", "4",  NULL },
417 +  { "Y",               0, STD_C89, NOLENGTHS, "#", "",  NULL },
418 +  { "%",               0, STD_C89, NOLENGTHS, "",       "",   NULL },
419 +  /* C99 conversion specifiers.  */
420 +  { "z",               0, STD_C99, NOLENGTHS, "#",      "",  NULL },
421 +  { NULL,              0, 0, NOLENGTHS, NULL, NULL, NULL }
422 +};
423 +
424 +const format_kind_info mingw_format_attributes[3] =
425 +{
426 +  { "ms_printf",   ms_printf_length_specs,  ms_print_char_table, " +#0-'", NULL,
427 +    ms_printf_flag_specs, ms_printf_flag_pairs,
428 +    FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
429 +    'w', 0, 'p', 0, 'L', 0,
430 +    &integer_type_node, &integer_type_node
431 +  },
432 +  { "ms_scanf",    ms_printf_length_specs,   ms_scan_char_table,  "*'", NULL,
433 +    ms_scanf_flag_specs, ms_scanf_flag_pairs,
434 +    FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
435 +    'w', 0, 0, '*', 'L', 0,
436 +    NULL, NULL
437 +  },
438 +  { "ms_strftime", NULL,                 ms_time_char_table,  "", "#",
439 +    ms_strftime_flag_specs, ms_strftime_flag_pairs,
440 +    FMT_FLAG_FANCY_PERCENT_OK, 0, 0, 0, 0, 0, 0,
441 +    NULL, NULL
442 +  }
443 +};
444 +
445 +/* Default overrides for printf, scanf and strftime.  */
446 +const target_ovr_attr mingw_format_attribute_overrides[4] =
447 +{
448 +  { "ms_printf", "printf" },
449 +  { "ms_scanf", "scanf" },
450 +  { "ms_strftime", "strftime" }
451 +};
452 diff -r ddadaee88373 gcc/config/i386/t-cygming
453 --- a/gcc/config/i386/t-cygming Thu May 29 20:27:38 2008 -0600
454 +++ b/gcc/config/i386/t-cygming Mon Jun 02 08:07:22 2008 -0600
455 @@ -29,4 +29,10 @@
456         $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
457         $(srcdir)/config/i386/winnt-stubs.c
458  
459 +msformat-c.o: $(srcdir)/config/i386/msformat-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
460 +  $(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
461 +  $(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H)
462 +       $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
463 +       $(srcdir)/config/i386/msformat-c.c
464 +
465  STMP_FIXINC=stmp-fixinc
466 diff -r ddadaee88373 gcc/doc/extend.texi
467 --- a/gcc/doc/extend.texi       Thu May 29 20:27:38 2008 -0600
468 +++ b/gcc/doc/extend.texi       Mon Jun 02 08:07:22 2008 -0600
469 @@ -2204,13 +2204,22 @@
470  @code{my_format}.
471  
472  The parameter @var{archetype} determines how the format string is
473 -interpreted, and should be @code{printf}, @code{scanf}, @code{strftime}
474 -or @code{strfmon}.  (You can also use @code{__printf__},
475 -@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.)  The
476 -parameter @var{string-index} specifies which argument is the format
477 -string argument (starting from 1), while @var{first-to-check} is the
478 -number of the first argument to check against the format string.  For
479 -functions where the arguments are not available to be checked (such as
480 +interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
481 +@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
482 +@code{strfmon}.  (You can also use @code{__printf__},
483 +@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.)  On
484 +MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
485 +@code{ms_strftime} are also present.
486 +@var{archtype} values such as @code{printf} refer to the formats accepted
487 +by the system's C run-time library, while @code{gnu_} values always refer
488 +to the formats accepted by the GNU C Library.  On Microsoft Windows
489 +targets, @code{ms_} values refer to the formats accepted by the
490 +@file{msvcrt.dll} library.
491 +The parameter @var{string-index}
492 +specifies which argument is the format string argument (starting
493 +from 1), while @var{first-to-check} is the number of the first
494 +argument to check against the format string.  For functions
495 +where the arguments are not available to be checked (such as
496  @code{vprintf}), specify the third parameter as zero.  In this case the
497  compiler only checks the format string for consistency.  For
498  @code{strftime} formats, the third parameter is required to be zero.
499 diff -r ddadaee88373 gcc/doc/tm.texi
500 --- a/gcc/doc/tm.texi   Thu May 29 20:27:38 2008 -0600
501 +++ b/gcc/doc/tm.texi   Mon Jun 02 08:07:22 2008 -0600
502 @@ -10319,6 +10319,18 @@
503  @code{TARGET_FORMAT_TYPES}.
504  @end defmac
505  
506 +@defmac TARGET_OVERRIDES_FORMAT_ATTRIBUTES
507 +If defined, this macro is the name of a global variable containing
508 +target-specific format overrides for the @option{-Wformat} option. The
509 +default is to have no target-specific format overrides. If defined,
510 +@code{TARGET_FORMAT_TYPES} must be defined, too.
511 +@end defmac
512 +
513 +@defmac TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
514 +If defined, this macro specifies the number of entries in
515 +@code{TARGET_OVERRIDES_FORMAT_ATTRIBUTES}.
516 +@end defmac
517 +
518  @deftypefn {Target Hook} bool TARGET_RELAXED_ORDERING
519  If set to @code{true}, means that the target's memory model does not
520  guarantee that loads which do not depend on one another will access
521 diff -r ddadaee88373 gcc/pretty-print.c
522 --- a/gcc/pretty-print.c        Thu May 29 20:27:38 2008 -0600
523 +++ b/gcc/pretty-print.c        Mon Jun 02 08:07:22 2008 -0600
524 @@ -50,7 +50,7 @@
525          break;                                               \
526                                                               \
527        case 2:                                                \
528 -        pp_scalar (PP, "%ll" F, va_arg (ARG, long long T));  \
529 +        pp_scalar (PP, "%" HOST_LONG_LONG_FORMAT F, va_arg (ARG, long long T));  \
530          break;                                               \
531                                                               \
532        default:                                               \
533 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/attr-1.c
534 --- a/gcc/testsuite/gcc.dg/format/attr-1.c      Thu May 29 20:27:38 2008 -0600
535 +++ b/gcc/testsuite/gcc.dg/format/attr-1.c      Mon Jun 02 08:07:22 2008 -0600
536 @@ -3,7 +3,8 @@
537  /* { dg-do compile } */
538  /* { dg-options "-std=gnu99 -Wformat" } */
539  
540 +#define DONT_GNU_PROTOTYPE
541  #include "format.h"
542  
543 -extern void foo0 (const char *) __attribute__((__format__(__strftime__, 1, 0)));
544 -extern void foo1 (const char *, ...) __attribute__((__format__(__strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
545 +extern void foo0 (const char *) __attribute__((__format__(gnu_attr___strftime__, 1, 0)));
546 +extern void foo1 (const char *, ...) __attribute__((__format__(gnu_attr___strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
547 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/attr-2.c
548 --- a/gcc/testsuite/gcc.dg/format/attr-2.c      Thu May 29 20:27:38 2008 -0600
549 +++ b/gcc/testsuite/gcc.dg/format/attr-2.c      Mon Jun 02 08:07:22 2008 -0600
550 @@ -3,22 +3,23 @@
551  /* { dg-do compile } */
552  /* { dg-options "-std=gnu99 -Wformat" } */
553  
554 +#define DONT_GNU_PROTOTYPE
555  #include "format.h"
556  
557 -extern void tformatprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
558 -extern void tformat__printf__ (const char *, ...) __attribute__((format(__printf__, 1, 2)));
559 -extern void tformatscanf (const char *, ...) __attribute__((format(scanf, 1, 2)));
560 -extern void tformat__scanf__ (const char *, ...) __attribute__((format(__scanf__, 1, 2)));
561 -extern void tformatstrftime (const char *) __attribute__((format(strftime, 1, 0)));
562 -extern void tformat__strftime__ (const char *) __attribute__((format(__strftime__, 1, 0)));
563 +extern void tformatprintf (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
564 +extern void tformat__printf__ (const char *, ...) __attribute__((format(gnu_attr___printf__, 1, 2)));
565 +extern void tformatscanf (const char *, ...) __attribute__((format(gnu_attr_scanf, 1, 2)));
566 +extern void tformat__scanf__ (const char *, ...) __attribute__((format(gnu_attr___scanf__, 1, 2)));
567 +extern void tformatstrftime (const char *) __attribute__((format(gnu_attr_strftime, 1, 0)));
568 +extern void tformat__strftime__ (const char *) __attribute__((format(gnu_attr___strftime__, 1, 0)));
569  extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2)));
570  extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2)));
571 -extern void t__format__printf (const char *, ...) __attribute__((__format__(printf, 1, 2)));
572 -extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__printf__, 1, 2)));
573 -extern void t__format__scanf (const char *, ...) __attribute__((__format__(scanf, 1, 2)));
574 -extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__scanf__, 1, 2)));
575 -extern void t__format__strftime (const char *) __attribute__((__format__(strftime, 1, 0)));
576 -extern void t__format____strftime__ (const char *) __attribute__((__format__(__strftime__, 1, 0)));
577 +extern void t__format__printf (const char *, ...) __attribute__((__format__(gnu_attr_printf, 1, 2)));
578 +extern void t__format____printf__ (const char *, ...) __attribute__((__format__(gnu_attr___printf__, 1, 2)));
579 +extern void t__format__scanf (const char *, ...) __attribute__((__format__(gnu_attr_scanf, 1, 2)));
580 +extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(gnu_attr___scanf__, 1, 2)));
581 +extern void t__format__strftime (const char *) __attribute__((__format__(gnu_attr_strftime, 1, 0)));
582 +extern void t__format____strftime__ (const char *) __attribute__((__format__(gnu_attr___strftime__, 1, 0)));
583  extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2)));
584  extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2)));
585  
586 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/attr-3.c
587 --- a/gcc/testsuite/gcc.dg/format/attr-3.c      Thu May 29 20:27:38 2008 -0600
588 +++ b/gcc/testsuite/gcc.dg/format/attr-3.c      Mon Jun 02 08:07:22 2008 -0600
589 @@ -3,20 +3,21 @@
590  /* { dg-do compile } */
591  /* { dg-options "-std=gnu99 -Wformat" } */
592  
593 +#define DONT_GNU_PROTOTYPE
594  #include "format.h"
595  
596  /* Proper uses of the attributes.  */
597 -extern void fa0 (const char *, ...) __attribute__((format(printf, 1, 2)));
598 -extern void fa1 (char *, ...) __attribute__((format(printf, 1, 2)));
599 +extern void fa0 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
600 +extern void fa1 (char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
601  extern char *fa2 (const char *) __attribute__((format_arg(1)));
602  extern char *fa3 (char *) __attribute__((format_arg(1)));
603  
604  /* Uses with too few or too many arguments.  */
605  extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */
606  extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */
607 -extern void fb2 (const char *, ...) __attribute__((format(printf))); /* { dg-error "wrong number of arguments" "bad format" } */
608 -extern void fb3 (const char *, ...) __attribute__((format(printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
609 -extern void fb4 (const char *, ...) __attribute__((format(printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
610 +extern void fb2 (const char *, ...) __attribute__((format(gnu_attr_printf))); /* { dg-error "wrong number of arguments" "bad format" } */
611 +extern void fb3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
612 +extern void fb4 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
613  
614  extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */
615  extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */
616 @@ -25,9 +26,9 @@
617  /* These attributes presently only apply to declarations, not to types.
618     Eventually, they should be usable with declarators for function types
619     anywhere, but still not with structure/union/enum types.  */
620 -struct s0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
621 -union u0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
622 -enum e0 { E0V0 } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
623 +struct s0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
624 +union u0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
625 +enum e0 { E0V0 } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
626  
627  struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */
628  union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */
629 @@ -38,28 +39,28 @@
630  extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */
631  
632  /* Both the numbers must be integer constant expressions.  */
633 -extern void ff0 (const char *, ...) __attribute__((format(printf, 3-2, (long long)(10/5))));
634 +extern void ff0 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, (long long)(10/5))));
635  int foo;
636 -extern void ff1 (const char *, ...) __attribute__((format(printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
637 -extern void ff2 (const char *, ...) __attribute__((format(printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
638 +extern void ff1 (const char *, ...) __attribute__((format(gnu_attr_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
639 +extern void ff2 (const char *, ...) __attribute__((format(gnu_attr_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
640  extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
641  extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
642  
643  /* The format string argument must precede the arguments to be formatted.
644     This includes if no parameter types are specified (which is not valid ISO
645     C for variadic functions).  */
646 -extern void fg0 () __attribute__((format(printf, 1, 2)));
647 -extern void fg1 () __attribute__((format(printf, 1, 0)));
648 -extern void fg2 () __attribute__((format(printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
649 -extern void fg3 () __attribute__((format(printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
650 +extern void fg0 () __attribute__((format(gnu_attr_printf, 1, 2)));
651 +extern void fg1 () __attribute__((format(gnu_attr_printf, 1, 0)));
652 +extern void fg2 () __attribute__((format(gnu_attr_printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
653 +extern void fg3 () __attribute__((format(gnu_attr_printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
654  
655  /* The format string argument must be a string type, and the arguments to
656     be formatted must be the "...".  */
657 -extern void fh0 (int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
658 -extern void fh1 (signed char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
659 -extern void fh2 (unsigned char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
660 -extern void fh3 (const char *, ...) __attribute__((format(printf, 1, 3))); /* { dg-error "is not" "not ..." } */
661 -extern void fh4 (const char *, int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "is not" "not ..." } */
662 +extern void fh0 (int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
663 +extern void fh1 (signed char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
664 +extern void fh2 (unsigned char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
665 +extern void fh3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
666 +extern void fh4 (const char *, int, ...) __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
667  
668  /* format_arg formats must take and return a string.  */
669  extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
670 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/attr-4.c
671 --- a/gcc/testsuite/gcc.dg/format/attr-4.c      Thu May 29 20:27:38 2008 -0600
672 +++ b/gcc/testsuite/gcc.dg/format/attr-4.c      Mon Jun 02 08:07:22 2008 -0600
673 @@ -4,12 +4,13 @@
674  /* { dg-do compile } */
675  /* { dg-options "-std=gnu99 -Wformat" } */
676  
677 +#define DONT_GNU_PROTOTYPE
678  #include "format.h"
679  
680 -extern __attribute__((format(printf, 1, 2))) void tformatprintf0 (const char *, ...);
681 -extern void __attribute__((format(printf, 1, 2))) tformatprintf1 (const char *, ...);
682 -extern void foo (void), __attribute__((format(printf, 1, 2))) tformatprintf2 (const char *, ...);
683 -extern __attribute__((noreturn)) void bar (void), __attribute__((format(printf, 1, 2))) tformatprintf3 (const char *, ...);
684 +extern __attribute__((format(gnu_attr_printf, 1, 2))) void tformatprintf0 (const char *, ...);
685 +extern void __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf1 (const char *, ...);
686 +extern void foo (void), __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf2 (const char *, ...);
687 +extern __attribute__((noreturn)) void bar (void), __attribute__((format(gnu_attr_printf, 1, 2))) tformatprintf3 (const char *, ...);
688  
689  void
690  baz (int i, int *ip, double d)
691 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/attr-7.c
692 --- a/gcc/testsuite/gcc.dg/format/attr-7.c      Thu May 29 20:27:38 2008 -0600
693 +++ b/gcc/testsuite/gcc.dg/format/attr-7.c      Mon Jun 02 08:07:23 2008 -0600
694 @@ -3,12 +3,13 @@
695  /* { dg-do compile } */
696  /* { dg-options "-std=gnu99 -Wformat" } */
697  
698 +#define DONT_GNU_PROTOTYPE
699  #include "format.h"
700  
701 -__attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
702 -void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2)));
703 -void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...);
704 -void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...);
705 +__attribute__((format(gnu_attr_printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
706 +void (*tformatprintf1) (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2)));
707 +void (__attribute__((format(gnu_attr_printf, 1, 2))) *tformatprintf2) (const char *, ...);
708 +void (__attribute__((format(gnu_attr_printf, 1, 2))) ****tformatprintf3) (const char *, ...);
709  
710  char * (__attribute__((format_arg(1))) *tformat_arg) (const char *);
711  
712 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/c90-printf-3.c
713 --- a/gcc/testsuite/gcc.dg/format/c90-printf-3.c        Thu May 29 20:27:38 2008 -0600
714 +++ b/gcc/testsuite/gcc.dg/format/c90-printf-3.c        Mon Jun 02 08:07:23 2008 -0600
715 @@ -3,7 +3,7 @@
716     do not.
717  */
718  /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
719 -/* { dg-do compile } */
720 +/* { dg-do compile { target { ! *-*-mingw* } } } */
721  /* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
722  
723  #include "format.h"
724 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/c90-scanf-4.c
725 --- a/gcc/testsuite/gcc.dg/format/c90-scanf-4.c Thu May 29 20:27:38 2008 -0600
726 +++ b/gcc/testsuite/gcc.dg/format/c90-scanf-4.c Mon Jun 02 08:07:23 2008 -0600
727 @@ -3,7 +3,7 @@
728     do not.
729  */
730  /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
731 -/* { dg-do compile } */
732 +/* { dg-do compile { target { ! *-*-mingw* } } } */
733  /* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
734  
735  #include "format.h"
736 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/c99-printf-3.c
737 --- a/gcc/testsuite/gcc.dg/format/c99-printf-3.c        Thu May 29 20:27:38 2008 -0600
738 +++ b/gcc/testsuite/gcc.dg/format/c99-printf-3.c        Mon Jun 02 08:07:23 2008 -0600
739 @@ -2,7 +2,7 @@
740     attributes in strict C99 mode, but the gettext functions do not.
741  */
742  /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
743 -/* { dg-do compile } */
744 +/* { dg-do compile { target { ! *-*-mingw* } } } */
745  /* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
746  
747  #include "format.h"
748 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/format.h
749 --- a/gcc/testsuite/gcc.dg/format/format.h      Thu May 29 20:27:38 2008 -0600
750 +++ b/gcc/testsuite/gcc.dg/format/format.h      Mon Jun 02 08:07:23 2008 -0600
751 @@ -1,5 +1,36 @@
752  /* Format checking tests: common header.  */
753  /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
754 +
755 +/* DONT_GNU_PROTOTYPE */
756 +#if defined (_WIN32) && !defined (__CYGWIN__)
757 +#if !defined (USE_SYSTEM_FORMATS)
758 +#define gnu_attr_printf        gnu_printf
759 +#define gnu_attr___printf__ __gnu_printf__
760 +#define gnu_attr_scanf gnu_scanf
761 +#define gnu_attr___scanf__ __gnu_scanf__
762 +#define gnu_attr_strftime gnu_strftime
763 +#define gnu_attr___strftime__ __gnu_strftime__
764 +#endif
765 +#endif
766 +
767 +#ifndef gnu_attr_printf
768 +#define gnu_attr_printf        printf
769 +#define gnu_attr___printf__ __printf__
770 +#define gnu_attr_scanf scanf
771 +#define gnu_attr___scanf__ __scanf__
772 +#define gnu_attr_strftime strftime
773 +#define gnu_attr___strftime__ __strftime__
774 +#endif
775 +
776 +#if !defined (USE_SYSTEM_FORMATS)
777 +#define USE_PRINTF(FMTPOS, WILDARG) __attribute__((format(gnu_printf, FMTPOS, WILDARG))) __attribute__((nonnull (FMTPOS)))
778 +#define USE_SCANF(FMTPOS, WILDARG) __attribute__((format(gnu_scanf, FMTPOS, WILDARG))) __attribute__((nonnull (FMTPOS)))
779 +#define USE_STRFTIME(FMTPOS) __attribute__((__format__(gnu_strftime, FMTPOS, 0))) __attribute__((nonnull (FMTPOS)))
780 +#else
781 +#define USE_PRINTF(FMTPOS, WILDARG)
782 +#define USE_SCANF(FMTPOS, WILDARG)
783 +#define USE_STRFTIME(FMTPOS)
784 +#endif
785  
786  #include <stdarg.h>
787  #include <stddef.h>
788 @@ -11,6 +42,20 @@
789  typedef __WINT_TYPE__ wint_t;
790  #endif
791  
792 +#ifdef _WIN64
793 +/* Kludges to get types corresponding to size_t and ptrdiff_t.  */
794 +#define unsigned signed
795 +typedef signed int signed_size_t __attribute__ ((mode (DI)));
796 +/* We also use this type to approximate ssize_t.  */
797 +typedef signed int ssize_t __attribute__ ((mode (DI)));
798 +#undef unsigned
799 +#define signed /* Type might or might not have explicit 'signed'.  */
800 +typedef unsigned int unsigned_ptrdiff_t __attribute__ ((mode (DI)));
801 +#undef signed
802 +
803 +__extension__ typedef int llong  __attribute__ ((mode (DI)));
804 +__extension__ typedef unsigned int ullong  __attribute__ ((mode (DI)));
805 +#else
806  /* Kludges to get types corresponding to size_t and ptrdiff_t.  */
807  #define unsigned signed
808  typedef __SIZE_TYPE__ signed_size_t;
809 @@ -23,6 +68,7 @@
810  
811  __extension__ typedef long long int llong;
812  __extension__ typedef unsigned long long int ullong;
813 +#endif
814  
815  /* %q formats want a "quad"; GCC considers this to be a long long.  */
816  typedef llong quad_t;
817 @@ -70,3 +116,77 @@
818                         const struct tm *restrict);
819  
820  extern ssize_t strfmon (char *restrict, size_t, const char *restrict, ...);
821 +
822 +/* Mingw specific part.  */
823 +#if !defined (USE_SYSTEM_FORMATS) && defined(_WIN32) && !defined(DONT_GNU_PROTOTYPE)
824 +
825 +extern USE_PRINTF(2,3) int fprintf_gnu (FILE *restrict, const char *restrict, ...);
826 +#undef fprintf
827 +#define fprintf fprintf_gnu
828 +
829 +extern USE_PRINTF(1,2) int printf_gnu (const char *restrict, ...);
830 +#undef printf
831 +#define printf printf_gnu
832 +
833 +extern USE_PRINTF(2,3) int fprintf_unlocked_gnu (FILE *restrict, const char *restrict, ...);
834 +#undef fprintf_unlocked
835 +#define fprintf_unlocked fprintf_unlocked_gnu
836 +
837 +extern USE_PRINTF(1,2)int printf_unlocked_gnu (const char *restrict, ...);
838 +#undef printf_unlocked
839 +#define printf_unlocked printf_unlocked_gnu
840 +
841 +extern USE_PRINTF(2,3) int sprintf_gnu (char *restrict, const char *restrict, ...);
842 +#undef sprintf
843 +#define sprintf sprintf_gnu
844 +
845 +extern USE_PRINTF(2,0) int vfprintf_gnu (FILE *restrict, const char *restrict, va_list);
846 +#undef vsprintf
847 +#define vsprintf vsprintf_gnu
848 +
849 +extern USE_PRINTF(1,0) int vprintf_gnu (const char *restrict, va_list);
850 +#undef vprintf
851 +#define vprintf vprintf_gnu
852 +
853 +extern USE_PRINTF(2,0) int vsprintf_gnu (char *restrict, const char *restrict, va_list);
854 +#undef vsprintf
855 +#define vsprintf vsprintf_gnu
856 +
857 +extern USE_PRINTF(3,4) int snprintf_gnu (char *restrict, size_t, const char *restrict, ...);
858 +#undef snprintf
859 +#define snprintf snprintf_gnu
860 +
861 +extern USE_PRINTF(3,0) int vsnprintf_gnu (char *restrict, size_t, const char *restrict, va_list);
862 +#undef vsnprintf
863 +#define vsnprintf vsnprintf_gnu
864 +
865 +extern USE_SCANF(2,3) int fscanf_gnu (FILE *restrict, const char *restrict, ...);
866 +#undef fscanf
867 +#define fscanf fscanf_gnu
868 +
869 +extern USE_SCANF(1,2) int scanf_gnu (const char *restrict, ...);
870 +#undef scanf
871 +#define scanf scanf_gnu
872 +
873 +extern USE_SCANF(2,3) int sscanf_gnu (const char *restrict, const char *restrict, ...);
874 +#undef sscanf
875 +#define sscanf sscanf_gnu
876 +
877 +extern USE_SCANF(2,0) int vfscanf_gnu (FILE *restrict, const char *restrict, va_list);
878 +#undef vfscanf
879 +#define vfscanf vfscanf_gnu
880 +
881 +extern USE_SCANF(1,0) int vscanf_gnu (const char *restrict, va_list);
882 +#undef vscanf
883 +#define vscanf vscanf_gnu
884 +
885 +extern USE_SCANF(2,0) int vsscanf_gnu (const char *restrict, const char *restrict, va_list);
886 +#undef vsscanf
887 +#define vsscanf vsscanf_gnu
888 +
889 +extern USE_STRFTIME(3) size_t strftime_gnu (char *restrict, size_t, const char *restrict,
890 +                       const struct tm *restrict);
891 +#undef strftime
892 +#define strftime strftime_gnu
893 +
894 +#endif
895 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/miss-1.c
896 --- a/gcc/testsuite/gcc.dg/format/miss-1.c      Thu May 29 20:27:38 2008 -0600
897 +++ b/gcc/testsuite/gcc.dg/format/miss-1.c      Mon Jun 02 08:07:23 2008 -0600
898 @@ -23,7 +23,7 @@
899    va_end (ap);
900  }
901  
902 -__attribute__((__format__(__printf__, 1, 2))) void
903 +__attribute__((__format__(gnu_attr___printf__, 1, 2))) void
904  foo2 (const char *fmt, ...)
905  {
906    va_list ap;
907 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/miss-3.c
908 --- a/gcc/testsuite/gcc.dg/format/miss-3.c      Thu May 29 20:27:38 2008 -0600
909 +++ b/gcc/testsuite/gcc.dg/format/miss-3.c      Mon Jun 02 08:07:23 2008 -0600
910 @@ -3,13 +3,14 @@
911  /* { dg-do compile } */
912  /* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
913  
914 +#define DONT_GNU_PROTOTYPE
915  #include "format.h"
916  
917  typedef void (*noattr_t) (const char *, ...);
918 -typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
919 +typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
920  
921  typedef void (*vnoattr_t) (const char *, va_list);
922 -typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
923 +typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
924  
925  void
926  foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
927 @@ -18,7 +19,7 @@
928    noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */
929    attr_t a1 = na;
930    attr_t a2 = a;
931 -  
932 +
933    vnoattr_t vna1 = vna;
934    vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */
935    vattr_t va1 = vna;
936 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/miss-4.c
937 --- a/gcc/testsuite/gcc.dg/format/miss-4.c      Thu May 29 20:27:38 2008 -0600
938 +++ b/gcc/testsuite/gcc.dg/format/miss-4.c      Mon Jun 02 08:07:23 2008 -0600
939 @@ -3,20 +3,21 @@
940  /* { dg-do compile } */
941  /* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
942  
943 +#define DONT_GNU_PROTOTYPE
944  #include "format.h"
945  
946  typedef void (*noattr_t) (const char *, ...);
947 -typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
948 +typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
949  
950  typedef void (*vnoattr_t) (const char *, va_list);
951 -typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
952 +typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
953  
954  void
955  foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
956  {
957    noattr_t na1, na2;
958    attr_t a1, a2;
959 -  
960 +
961    vnoattr_t vna1, vna2;
962    vattr_t va1, va2;
963  
964 @@ -24,7 +25,7 @@
965    na2 = a; /* { dg-warning "candidate" "assignment warning" } */
966    a1 = na;
967    a2 = a;
968 -  
969 +
970    vna1 = vna;
971    vna2 = va; /* { dg-warning "candidate" "assignment warning" } */
972    va1 = vna;
973 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/miss-5.c
974 --- a/gcc/testsuite/gcc.dg/format/miss-5.c      Thu May 29 20:27:38 2008 -0600
975 +++ b/gcc/testsuite/gcc.dg/format/miss-5.c      Mon Jun 02 08:07:23 2008 -0600
976 @@ -3,13 +3,14 @@
977  /* { dg-do compile } */
978  /* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
979  
980 +#define DONT_GNU_PROTOTYPE
981  #include "format.h"
982  
983  typedef void (*noattr_t) (const char *, ...);
984 -typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
985 +typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
986  
987  typedef void (*vnoattr_t) (const char *, va_list);
988 -typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
989 +typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
990  
991  noattr_t
992  foo1 (noattr_t na, attr_t a, int i)
993 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/miss-6.c
994 --- a/gcc/testsuite/gcc.dg/format/miss-6.c      Thu May 29 20:27:38 2008 -0600
995 +++ b/gcc/testsuite/gcc.dg/format/miss-6.c      Mon Jun 02 08:07:23 2008 -0600
996 @@ -3,13 +3,14 @@
997  /* { dg-do compile } */
998  /* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
999  
1000 +#define DONT_GNU_PROTOTYPE
1001  #include "format.h"
1002  
1003  typedef void (*noattr_t) (const char *, ...);
1004 -typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t;
1005 +typedef noattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 2))) attr_t;
1006  
1007  typedef void (*vnoattr_t) (const char *, va_list);
1008 -typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t;
1009 +typedef vnoattr_t __attribute__ ((__format__(gnu_attr___printf__, 1, 0))) vattr_t;
1010  
1011  extern void foo1 (noattr_t);
1012  extern void foo2 (attr_t);
1013 @@ -23,7 +24,7 @@
1014    foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */
1015    foo2 (na);
1016    foo2 (a);
1017 -  
1018 +
1019    foo3 (vna);
1020    foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */
1021    foo4 (vna);
1022 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_array-1.c
1023 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1024 +++ b/gcc/testsuite/gcc.dg/format/ms_array-1.c  Mon Jun 02 08:07:23 2008 -0600
1025 @@ -0,0 +1,42 @@
1026 +/* Test for format checking of constant arrays.  */
1027 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1028 +/* { dg-do compile { target { *-*-mingw* } } } */
1029 +/* { dg-options "-std=gnu99 -Wformat=2" } */
1030 +
1031 +#define USE_SYSTEM_FORMATS
1032 +#include "format.h"
1033 +
1034 +const char a1[] = "foo";
1035 +const char a2[] = "foo%d";
1036 +const char b1[3] = "foo";
1037 +const char b2[1] = "1";
1038 +static const char c1[] = "foo";
1039 +static const char c2[] = "foo%d";
1040 +char d[] = "foo";
1041 +volatile const char e[] = "foo";
1042 +
1043 +void
1044 +foo (int i, long l)
1045 +{
1046 +  const char p1[] = "bar";
1047 +  const char p2[] = "bar%d";
1048 +  static const char q1[] = "bar";
1049 +  static const char q2[] = "bar%d";
1050 +  printf (a1);
1051 +  printf (a2, i);
1052 +  printf (a2, l); /* { dg-warning "format" "wrong type with array" } */
1053 +  printf (b1); /* { dg-warning "unterminated" "unterminated array" } */
1054 +  printf (b2); /* { dg-warning "unterminated" "unterminated array" } */
1055 +  printf (c1);
1056 +  printf (c2, i);
1057 +  printf (c2, l); /* { dg-warning "format" "wrong type with array" } */
1058 +  printf (p1);
1059 +  printf (p2, i);
1060 +  printf (p2, l); /* { dg-warning "format" "wrong type with array" } */
1061 +  printf (q1);
1062 +  printf (q2, i);
1063 +  printf (q2, l); /* { dg-warning "format" "wrong type with array" } */
1064 +  /* Volatile or non-constant arrays must not be checked.  */
1065 +  printf (d); /* { dg-warning "not a string literal" "non-const" } */
1066 +  printf ((const char *)e); /* { dg-warning "not a string literal" "volatile" } */
1067 +}
1068 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_attr-1.c
1069 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1070 +++ b/gcc/testsuite/gcc.dg/format/ms_attr-1.c   Mon Jun 02 08:07:23 2008 -0600
1071 @@ -0,0 +1,10 @@
1072 +/* Test for strftime format attributes: can't have first_arg_num != 0.  */
1073 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1074 +/* { dg-do compile { target { *-*-mingw* } } } */
1075 +/* { dg-options "-std=gnu99 -Wformat" } */
1076 +
1077 +#define DONT_GNU_PROTOTYPE
1078 +#include "format.h"
1079 +
1080 +extern void foo0 (const char *) __attribute__((__format__(__ms_strftime__, 1, 0)));
1081 +extern void foo1 (const char *, ...) __attribute__((__format__(__ms_strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
1082 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_attr-2.c
1083 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1084 +++ b/gcc/testsuite/gcc.dg/format/ms_attr-2.c   Mon Jun 02 08:07:23 2008 -0600
1085 @@ -0,0 +1,68 @@
1086 +/* Test for format attributes: test use of __attribute__.  */
1087 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1088 +/* { dg-do compile { target { *-*-mingw* } } } */
1089 +/* { dg-options "-std=gnu99 -Wformat" } */
1090 +
1091 +#define DONT_GNU_PROTOTYPE
1092 +#include "format.h"
1093 +
1094 +extern void tformatprintf (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
1095 +extern void tformat__printf__ (const char *, ...) __attribute__((format(__ms_printf__, 1, 2)));
1096 +extern void tformatscanf (const char *, ...) __attribute__((format(ms_scanf, 1, 2)));
1097 +extern void tformat__scanf__ (const char *, ...) __attribute__((format(__ms_scanf__, 1, 2)));
1098 +extern void tformatstrftime (const char *) __attribute__((format(ms_strftime, 1, 0)));
1099 +extern void tformat__strftime__ (const char *) __attribute__((format(__ms_strftime__, 1, 0)));
1100 +extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2)));
1101 +extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2)));
1102 +extern void t__format__printf (const char *, ...) __attribute__((__format__(ms_printf, 1, 2)));
1103 +extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__ms_printf__, 1, 2)));
1104 +extern void t__format__scanf (const char *, ...) __attribute__((__format__(ms_scanf, 1, 2)));
1105 +extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__ms_scanf__, 1, 2)));
1106 +extern void t__format__strftime (const char *) __attribute__((__format__(ms_strftime, 1, 0)));
1107 +extern void t__format____strftime__ (const char *) __attribute__((__format__(__ms_strftime__, 1, 0)));
1108 +extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2)));
1109 +extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2)));
1110 +
1111 +extern char *tformat_arg (const char *) __attribute__((format_arg(1)));
1112 +extern char *t__format_arg__ (const char *) __attribute__((__format_arg__(1)));
1113 +
1114 +void
1115 +foo (int i, int *ip, double d)
1116 +{
1117 +  tformatprintf ("%d", i);
1118 +  tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */
1119 +  tformat__printf__ ("%d", i);
1120 +  tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */
1121 +  tformatscanf ("%d", ip);
1122 +  tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */
1123 +  tformat__scanf__ ("%d", ip);
1124 +  tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */
1125 +  tformatstrftime ("%a");
1126 +  tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */
1127 +  tformat__strftime__ ("%a");
1128 +  tformat__strftime__ ("%"); /* { dg-warning "format" "attribute format __strftime__" } */
1129 +  tformatstrfmon ("%n", d);
1130 +  tformatstrfmon ("%"); /* { dg-warning "format" "attribute format strfmon" } */
1131 +  tformat__strfmon__ ("%n", d);
1132 +  tformat__strfmon__ ("%"); /* { dg-warning "format" "attribute format __strfmon__" } */
1133 +  t__format__printf ("%d", i);
1134 +  t__format__printf ("%"); /* { dg-warning "format" "attribute __format__ printf" } */
1135 +  t__format____printf__ ("%d", i);
1136 +  t__format____printf__ ("%"); /* { dg-warning "format" "attribute __format__ __printf__" } */
1137 +  t__format__scanf ("%d", ip);
1138 +  t__format__scanf ("%"); /* { dg-warning "format" "attribute __format__ scanf" } */
1139 +  t__format____scanf__ ("%d", ip);
1140 +  t__format____scanf__ ("%"); /* { dg-warning "format" "attribute __format__ __scanf__" } */
1141 +  t__format__strftime ("%a");
1142 +  t__format__strftime ("%"); /* { dg-warning "format" "attribute __format__ strftime" } */
1143 +  t__format____strftime__ ("%a");
1144 +  t__format____strftime__ ("%"); /* { dg-warning "format" "attribute __format__ __strftime__" } */
1145 +  t__format__strfmon ("%n", d);
1146 +  t__format__strfmon ("%"); /* { dg-warning "format" "attribute __format__ strfmon" } */
1147 +  t__format____strfmon__ ("%n", d);
1148 +  t__format____strfmon__ ("%"); /* { dg-warning "format" "attribute __format__ __strfmon__" } */
1149 +  tformatprintf (tformat_arg ("%d"), i);
1150 +  tformatprintf (tformat_arg ("%")); /* { dg-warning "format" "attribute format_arg" } */
1151 +  tformatprintf (t__format_arg__ ("%d"), i);
1152 +  tformatprintf (t__format_arg__ ("%")); /* { dg-warning "format" "attribute __format_arg__" } */
1153 +}
1154 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_attr-3.c
1155 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1156 +++ b/gcc/testsuite/gcc.dg/format/ms_attr-3.c   Mon Jun 02 08:07:23 2008 -0600
1157 @@ -0,0 +1,71 @@
1158 +/* Test for format attributes: test bad uses of __attribute__.  */
1159 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1160 +/* { dg-do compile { target { *-*-mingw* } } } */
1161 +/* { dg-options "-std=gnu99 -Wformat" } */
1162 +
1163 +#define USE_SYSTEM_FORMATS
1164 +#include "format.h"
1165 +
1166 +/* Proper uses of the attributes.  */
1167 +extern void fa0 (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
1168 +extern void fa1 (char *, ...) __attribute__((format(ms_printf, 1, 2)));
1169 +extern char *fa2 (const char *) __attribute__((format_arg(1)));
1170 +extern char *fa3 (char *) __attribute__((format_arg(1)));
1171 +
1172 +/* Uses with too few or too many arguments.  */
1173 +extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */
1174 +extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */
1175 +extern void fb2 (const char *, ...) __attribute__((format(ms_printf))); /* { dg-error "wrong number of arguments" "bad format" } */
1176 +extern void fb3 (const char *, ...) __attribute__((format(ms_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */
1177 +extern void fb4 (const char *, ...) __attribute__((format(ms_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */
1178 +
1179 +extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */
1180 +extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */
1181 +extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error "wrong number of arguments" "bad format_arg" } */
1182 +
1183 +/* These attributes presently only apply to declarations, not to types.
1184 +   Eventually, they should be usable with declarators for function types
1185 +   anywhere, but still not with structure/union/enum types.  */
1186 +struct s0 { int i; } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */
1187 +union u0 { int i; } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */
1188 +enum e0 { E0V0 } __attribute__((format(ms_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
1189 +
1190 +struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */
1191 +union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */
1192 +enum e1 { E1V0 } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on enum" } */
1193 +
1194 +/* The format type must be an identifier, one of those recognized.  */
1195 +extern void fe0 (const char *, ...) __attribute__((format(12345, 1, 2))); /* { dg-error "format specifier" "non-id format" } */
1196 +extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */
1197 +
1198 +/* Both the numbers must be integer constant expressions.  */
1199 +extern void ff0 (const char *, ...) __attribute__((format(ms_printf, 3-2, (long long)(10/5))));
1200 +int foo;
1201 +extern void ff1 (const char *, ...) __attribute__((format(ms_printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */
1202 +extern void ff2 (const char *, ...) __attribute__((format(ms_printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */
1203 +extern char *ff3 (const char *) __attribute__((format_arg(3-2)));
1204 +extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */
1205 +
1206 +/* The format string argument must precede the arguments to be formatted.
1207 +   This includes if no parameter types are specified (which is not valid ISO
1208 +   C for variadic functions).  */
1209 +extern void fg0 () __attribute__((format(ms_printf, 1, 2)));
1210 +extern void fg1 () __attribute__((format(ms_printf, 1, 0)));
1211 +extern void fg2 () __attribute__((format(ms_printf, 1, 1))); /* { dg-error "follows" "bad number order" } */
1212 +extern void fg3 () __attribute__((format(ms_printf, 2, 1))); /* { dg-error "follows" "bad number order" } */
1213 +
1214 +/* The format string argument must be a string type, and the arguments to
1215 +   be formatted must be the "...".  */
1216 +extern void fh0 (int, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "format int string" } */
1217 +extern void fh1 (signed char *, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */
1218 +extern void fh2 (unsigned char *, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */
1219 +extern void fh3 (const char *, ...) __attribute__((format(ms_printf, 1, 3))); /* { dg-error "is not" "not ..." } */
1220 +extern void fh4 (const char *, int, ...) __attribute__((format(ms_printf, 1, 2))); /* { dg-error "is not" "not ..." } */
1221 +
1222 +/* format_arg formats must take and return a string.  */
1223 +extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */
1224 +extern char *fi1 (signed char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg signed char string" } */
1225 +extern char *fi2 (unsigned char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg unsigned char string" } */
1226 +extern int fi3 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret int string" } */
1227 +extern signed char *fi4 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret signed char string" } */
1228 +extern unsigned char *fi5 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret unsigned char string" } */
1229 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_attr-4.c
1230 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1231 +++ b/gcc/testsuite/gcc.dg/format/ms_attr-4.c   Mon Jun 02 08:07:23 2008 -0600
1232 @@ -0,0 +1,26 @@
1233 +/* Test for format attributes: test use of __attribute__
1234 +   in prefix attributes.  */
1235 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1236 +/* { dg-do compile { target { *-*-mingw* } } } */
1237 +/* { dg-options "-std=gnu99 -Wformat" } */
1238 +
1239 +#define USE_SYSTEM_FORMATS
1240 +#include "format.h"
1241 +
1242 +extern __attribute__((format(ms_printf, 1, 2))) void tformatprintf0 (const char *, ...);
1243 +extern void __attribute__((format(ms_printf, 1, 2))) tformatprintf1 (const char *, ...);
1244 +extern void foo (void), __attribute__((format(ms_printf, 1, 2))) tformatprintf2 (const char *, ...);
1245 +extern __attribute__((noreturn)) void bar (void), __attribute__((format(ms_printf, 1, 2))) tformatprintf3 (const char *, ...);
1246 +
1247 +void
1248 +baz (int i, int *ip, double d)
1249 +{
1250 +  tformatprintf0 ("%d", i);
1251 +  tformatprintf0 ("%"); /* { dg-warning "format" "attribute format printf case 0" } */
1252 +  tformatprintf1 ("%d", i);
1253 +  tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */
1254 +  tformatprintf2 ("%d", i);
1255 +  tformatprintf2 ("%"); /* { dg-warning "format" "attribute format printf case 2" } */
1256 +  tformatprintf3 ("%d", i);
1257 +  tformatprintf3 ("%"); /* { dg-warning "format" "attribute format printf case 3" } */
1258 +}
1259 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_attr-7.c
1260 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1261 +++ b/gcc/testsuite/gcc.dg/format/ms_attr-7.c   Mon Jun 02 08:07:23 2008 -0600
1262 @@ -0,0 +1,35 @@
1263 +/* Test for format attributes: test applying them to types.  */
1264 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1265 +/* { dg-do compile { target { *-*-mingw* } } } */
1266 +/* { dg-options "-std=gnu99 -Wformat" } */
1267 +
1268 +#define DONT_GNU_PROTOTYPE
1269 +#include "format.h"
1270 +
1271 +__attribute__((format(ms_printf, 1, 2))) void (*tformatprintf0) (const char *, ...);
1272 +void (*tformatprintf1) (const char *, ...) __attribute__((format(ms_printf, 1, 2)));
1273 +void (__attribute__((format(ms_printf, 1, 2))) *tformatprintf2) (const char *, ...);
1274 +void (__attribute__((format(ms_printf, 1, 2))) ****tformatprintf3) (const char *, ...);
1275 +
1276 +char * (__attribute__((format_arg(1))) *tformat_arg) (const char *);
1277 +
1278 +void
1279 +baz (int i)
1280 +{
1281 +  (*tformatprintf0) ("%d", i);
1282 +  (*tformatprintf0) ((*tformat_arg) ("%d"), i);
1283 +  (*tformatprintf0) ("%"); /* { dg-warning "format" "prefix" } */
1284 +  (*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */
1285 +  (*tformatprintf1) ("%d", i);
1286 +  (*tformatprintf1) ((*tformat_arg) ("%d"), i);
1287 +  (*tformatprintf1) ("%"); /* { dg-warning "format" "postfix" } */
1288 +  (*tformatprintf1) ((*tformat_arg) ("%")); /* { dg-warning "format" "postfix" } */
1289 +  (*tformatprintf2) ("%d", i);
1290 +  (*tformatprintf2) ((*tformat_arg) ("%d"), i);
1291 +  (*tformatprintf2) ("%"); /* { dg-warning "format" "nested" } */
1292 +  (*tformatprintf2) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested" } */
1293 +  (****tformatprintf3) ("%d", i);
1294 +  (****tformatprintf3) ((*tformat_arg) ("%d"), i);
1295 +  (****tformatprintf3) ("%"); /* { dg-warning "format" "nested 2" } */
1296 +  (****tformatprintf3) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested 2" } */
1297 +}
1298 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_bitfld-1.c
1299 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1300 +++ b/gcc/testsuite/gcc.dg/format/ms_bitfld-1.c Mon Jun 02 08:07:23 2008 -0600
1301 @@ -0,0 +1,52 @@
1302 +/* Test for printf formats and bit-fields: bug 22421.  */
1303 +/* Origin: Joseph Myers <joseph@codesourcery.com> */
1304 +/* { dg-do compile { target { *-*-mingw* } } } */
1305 +/* { dg-options "-std=gnu99 -Wformat" } */
1306 +/* { dg-require-effective-target int32plus } */
1307 +
1308 +#define USE_SYSTEM_FORMATS
1309 +#include "format.h"
1310 +
1311 +struct s {
1312 +  unsigned int u1 : 1;
1313 +  signed int s1 : 1;
1314 +  unsigned int u15 : 15;
1315 +  signed int s15 : 15;
1316 +  unsigned int u16 : 16;
1317 +  signed int s16 : 16;
1318 +  unsigned long u31 : 31;
1319 +  signed long s31 : 31;
1320 +  unsigned long u32 : 32;
1321 +  signed long s32 : 32;
1322 +  unsigned long long u48 : 48;
1323 +} x;
1324 +
1325 +void
1326 +foo (void)
1327 +{
1328 +  printf ("%d%u", x.u1, x.u1);
1329 +  printf ("%d%u", x.s1, x.s1);
1330 +  printf ("%d%u", x.u15, x.u15);
1331 +  printf ("%d%u", x.s15, x.s15);
1332 +  printf ("%d%u", x.u16, x.u16);
1333 +  printf ("%d%u", x.s16, x.s16);
1334 +#if __INT_MAX__ > 32767
1335 +  /* If integers are 16 bits, there doesn't seem to be a way of
1336 +     printing these without getting an error.  */
1337 +  printf ("%d%u", x.u31, x.u31);
1338 +  printf ("%d%u", x.s31, x.s31);
1339 +#endif
1340 +#if __LONG_MAX__ > 2147483647 && __INT_MAX__ >= 2147483647
1341 +  /* If long is wider than 32 bits, the 32-bit bit-fields are int or
1342 +     unsigned int or promote to those types.  Otherwise, long is 32
1343 +     bits and the bit-fields are of type plain long or unsigned
1344 +     long.  */
1345 +  printf ("%d%u", x.u32, x.u32);
1346 +  printf ("%d%u", x.s32, x.s32);
1347 +#else
1348 +  printf ("%ld%lu", x.u32, x.u32);
1349 +  printf ("%ld%lu", x.s32, x.s32);
1350 +#endif
1351 +  printf ("%I64u", x.u48); /* { dg-warning "has type '.*unsigned int:48'" } */
1352 +  printf ("%I64u", (unsigned long long)x.u48);
1353 +}
1354 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_branch-1.c
1355 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1356 +++ b/gcc/testsuite/gcc.dg/format/ms_branch-1.c Mon Jun 02 08:07:23 2008 -0600
1357 @@ -0,0 +1,28 @@
1358 +/* Test for format checking of conditional expressions.  */
1359 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1360 +/* { dg-do compile { target { *-*-mingw* } } } */
1361 +/* { dg-options "-std=gnu99 -Wformat" } */
1362 +
1363 +#define USE_SYSTEM_FORMATS
1364 +#include "format.h"
1365 +
1366 +void
1367 +foo (long l, int nfoo)
1368 +{
1369 +  printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
1370 +  printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
1371 +  printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
1372 +  printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
1373 +  /* Should allow one case to have extra arguments.  */
1374 +  printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
1375 +  printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */
1376 +  printf ((nfoo > 1) ? "%d foos" : "", nfoo);
1377 +  printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
1378 +  printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
1379 +  printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
1380 +  printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
1381 +  printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
1382 +  /* Extra arguments to NULL should be complained about.  */
1383 +  printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */
1384 +  /* { dg-warning "null" "null format arg" { target *-*-* } 26 } */
1385 +}
1386 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c
1387 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1388 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-1.c     Mon Jun 02 08:07:23 2008 -0600
1389 @@ -0,0 +1,184 @@
1390 +/* Test for printf formats.  Formats using C90 features, including cases
1391 +   where C90 specifies some aspect of the format to be ignored or where
1392 +   the behavior is undefined.
1393 +*/
1394 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1395 +/* { dg-do compile { target { *-*-mingw* } } } */
1396 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1397 +
1398 +#define USE_SYSTEM_FORMATS
1399 +#include "format.h"
1400 +
1401 +void
1402 +foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
1403 +     int *n, short int *hn, long int l, unsigned long int ul,
1404 +     long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll,
1405 +     ullong ull, unsigned int *un, const int *cn, signed char *ss,
1406 +     unsigned char *us, const signed char *css, unsigned int u1,
1407 +     unsigned int u2)
1408 +{
1409 +  /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134).  */
1410 +  /* Basic sanity checks for the different components of a format.  */
1411 +  printf ("%d\n", i);
1412 +  printf ("%+d\n", i);
1413 +  printf ("%3d\n", i);
1414 +  printf ("%-3d\n", i);
1415 +  printf ("%*d\n", i1, i);
1416 +  printf ("%d %lu\n", i, ul);
1417 +  /* Bogus use of width.  */
1418 +  printf ("%5n\n", n); /* { dg-warning "width" "width with %n" } */
1419 +  /* Valid and invalid %% constructions.  Some of the warning messages
1420 +     are non-optimal, but they do detect the errorneous nature of the
1421 +     format string.
1422 +  */
1423 +  printf ("%%");
1424 +  printf ("%-%"); /* { dg-warning "format" "bogus %%" } */
1425 +  printf ("%-%\n"); /* { dg-warning "format" "bogus %%" } */
1426 +  printf ("%5%\n"); /* { dg-warning "format" "bogus %%" } */
1427 +  printf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */
1428 +  /* Valid and invalid %h, %l, %L constructions.  */
1429 +  printf ("%hd", i);
1430 +  printf ("%hi", i);
1431 +  /* Strictly, these parameters should be int or unsigned int according to
1432 +     what unsigned short promotes to.  However, GCC ignores sign
1433 +     differences in format checking here, and this is relied on to get the
1434 +     correct checking without print_char_table needing to know whether
1435 +     int and short are the same size.
1436 +  */
1437 +  printf ("%ho%hu%hx%hX", u, u, u, u);
1438 +  printf ("%hn", hn);
1439 +  printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */
1440 +  printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */
1441 +  printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */
1442 +  printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */
1443 +  printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */
1444 +  printf ("%hc", i);
1445 +  printf ("%hs", hn);
1446 +  printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */
1447 +  printf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */
1448 +  printf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul);
1449 +  printf ("%ln", ln);
1450 +  printf ("%lf", d); /* { dg-warning "length|C" "bad use of %l" } */
1451 +  printf ("%le", d); /* { dg-warning "length|C" "bad use of %l" } */
1452 +  printf ("%lE", d); /* { dg-warning "length|C" "bad use of %l" } */
1453 +  printf ("%lg", d); /* { dg-warning "length|C" "bad use of %l" } */
1454 +  printf ("%lG", d); /* { dg-warning "length|C" "bad use of %l" } */
1455 +  printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */
1456 +  /* These next two were added in C94, but should be objected to in C90.
1457 +     For the first one, GCC has wanted wchar_t instead of the correct C94
1458 +     and C99 wint_t.
1459 +  */
1460 +  printf ("%lc", lc); /* { dg-warning "length|C" "C90 bad use of %l" } */
1461 +  printf ("%ls", ls); /* { dg-warning "length|C" "C90 bad use of %l" } */
1462 +  /* Valid uses of each bare conversion.  */
1463 +  printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u, d, d, d, d, d,
1464 +         i, s, p, n);
1465 +  /* Uses of the - flag (valid on all non-%, non-n conversions).  */
1466 +  printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i, u, u, u, u,
1467 +         d, d, d, d, d, i, s, p);
1468 +  printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */
1469 +  /* Uses of the + flag (valid on signed conversions only).  */
1470 +  printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d);
1471 +  printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */
1472 +  printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */
1473 +  printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */
1474 +  printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */
1475 +  printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */
1476 +  printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */
1477 +  printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */
1478 +  printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */
1479 +  /* Uses of the space flag (valid on signed conversions only, and ignored
1480 +     with +).
1481 +  */
1482 +  printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
1483 +  printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
1484 +  printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d);
1485 +  printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */
1486 +  printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */
1487 +  printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */
1488 +  printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */
1489 +  printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */
1490 +  printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */
1491 +  printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */
1492 +  printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */
1493 +  /* Uses of the # flag.  */
1494 +  printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d, d, d);
1495 +  printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */
1496 +  printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */
1497 +  printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */
1498 +  printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */
1499 +  printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */
1500 +  printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */
1501 +  printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */
1502 +  /* Uses of the 0 flag.  */
1503 +  printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i, u, u, u, u,
1504 +         d, d, d, d, d);
1505 +  printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */
1506 +  printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */
1507 +  printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */
1508 +  printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */
1509 +  /* 0 flag ignored with - flag.  */
1510 +  printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1511 +  printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1512 +  printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1513 +  printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1514 +  printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1515 +  printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1516 +  printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1517 +  printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1518 +  printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1519 +  printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1520 +  printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
1521 +  /* Various tests of bad argument types.  */
1522 +  printf ("%d", l); /* { dg-warning "format" "bad argument types" } */
1523 +  printf ("%ld", i); /* { dg-warning "format" "bad argument types" } */
1524 +  printf ("%s", n); /* { dg-warning "format" "bad argument types" } */
1525 +  printf ("%p", i); /* { dg-warning "format" "bad argument types" } */
1526 +  printf ("%n", p); /* { dg-warning "format" "bad argument types" } */
1527 +  /* With -pedantic, we want some further checks for pointer targets:
1528 +     %p should allow only pointers to void (possibly qualified) and
1529 +     to character types (possibly qualified), but not function pointers
1530 +     or pointers to other types.  (Whether, in fact, character types are
1531 +     allowed here is unclear; see thread on comp.std.c, July 2000 for
1532 +     discussion of the requirements of rules on identical representation,
1533 +     and of the application of the as if rule with the new va_arg
1534 +     allowances in C99 to printf.)  Likewise, we should warn if
1535 +     pointer targets differ in signedness, except in some circumstances
1536 +     for character pointers.  (In C99 we should consider warning for
1537 +     char * or unsigned char * being passed to %hhn, even if strictly
1538 +     legitimate by the standard.)
1539 +  */
1540 +  printf ("%p", foo); /* { dg-warning "format" "bad argument types" } */
1541 +  printf ("%n", un); /* { dg-warning "format" "bad argument types" } */
1542 +  printf ("%p", n); /* { dg-warning "format" "bad argument types" } */
1543 +  /* Allow character pointers with %p.  */
1544 +  printf ("%p%p%p%p", s, ss, us, css);
1545 +  /* %s allows any character type.  */
1546 +  printf ("%s%s%s%s", s, ss, us, css);
1547 +  /* Warning for void * arguments for %s is GCC's historical behavior,
1548 +     and seems useful to keep, even if some standard versions might be
1549 +     read to permit it.
1550 +  */
1551 +  printf ("%s", p); /* { dg-warning "format" "bad argument types" } */
1552 +  /* The historical behavior is to allow signed / unsigned types
1553 +     interchangably as arguments.  For values representable in both types,
1554 +     such usage may be correct.  For now preserve the behavior of GCC
1555 +     in such cases.
1556 +  */
1557 +  printf ("%d", u);
1558 +  /* Wrong number of arguments.  */
1559 +  printf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */
1560 +  printf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */
1561 +  /* Miscellaneous bogus constructions.  */
1562 +  printf (""); /* { dg-warning "zero-length" "warning for empty format" } */
1563 +  printf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */
1564 +  printf ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */
1565 +  printf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
1566 +  printf (NULL); /* { dg-warning "null" "null format string warning" } */
1567 +  printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
1568 +  printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
1569 +  printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
1570 +  printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */
1571 +  printf ("%n", (int *)0); /* { dg-warning "null" "%n with NULL" } */
1572 +  printf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */
1573 +}
1574 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c
1575 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1576 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-2.c     Mon Jun 02 08:07:23 2008 -0600
1577 @@ -0,0 +1,25 @@
1578 +/* Test for printf formats.  Formats using C99 features should be rejected
1579 +   outside of C99 mode.
1580 +*/
1581 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1582 +/* { dg-do compile { target { *-*-mingw* } } } */
1583 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1584 +
1585 +#define USE_SYSTEM_FORMATS
1586 +#include "format.h"
1587 +
1588 +void
1589 +foo (int i, double d, llong ll, intmax_t j, size_t z, ptrdiff_t t)
1590 +{
1591 +  /* Some tests already in c90-printf-1.c, e.g. %lf.  */
1592 +  /* The widths hh, ll, j, z, t are new.  */
1593 +  printf ("%hhd", i); /* { dg-warning "unknown|format" "%hh is unsupported" } */
1594 +  printf ("%I64d", ll); /* { dg-warning "length|C" "%I64 in C90" } */
1595 +  printf ("%jd", j); /* { dg-warning "unknown|format" "%j is unsupported" } */
1596 +  printf ("%zu", z); /* { dg-warning "unknown|format" "%z is unsupported" } */
1597 +  printf ("%td", t); /* { dg-warning "unknown|format" "%t is unsupported" } */
1598 +  /* The formats F, a, A are new.  */
1599 +  printf ("%F", d); /* { dg-warning "unknown|format" "%F is unsupported" } */
1600 +  printf ("%a", d); /* { dg-warning "unknown|format" "%a is unsupported" } */
1601 +  printf ("%A", d); /* { dg-warning "unknown|format" "%A is unsupported" } */
1602 +}
1603 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c
1604 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1605 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-printf-3.c     Mon Jun 02 08:07:23 2008 -0600
1606 @@ -0,0 +1,43 @@
1607 +/* Test for printf formats.  Test that the C90 functions get their default
1608 +   attributes in strict C90 mode, but the C99 and gettext functions
1609 +   do not.
1610 +*/
1611 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1612 +/* { dg-do compile { target { *-*-mingw* } } } */
1613 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1614 +
1615 +#define USE_SYSTEM_FORMATS
1616 +#include "format.h"
1617 +
1618 +void
1619 +foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3,
1620 +     va_list v4, va_list v5, va_list v6, va_list v7, va_list v8)
1621 +{
1622 +  fprintf (stdout, "%d", i);
1623 +  fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */
1624 +  printf ("%d", i);
1625 +  printf ("%ld", i); /* { dg-warning "format" "printf" } */
1626 +  /* The "unlocked" functions shouldn't warn in c90 mode.  */
1627 +  fprintf_unlocked (stdout, "%ld", i);
1628 +  printf_unlocked ("%ld", i);
1629 +  sprintf (s, "%d", i);
1630 +  sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */
1631 +  vfprintf (stdout, "%d", v0);
1632 +  vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */
1633 +  vprintf ("%d", v2);
1634 +  vprintf ("%Y", v3); /* { dg-warning "format" "vprintf" } */
1635 +  /* The following used to give a bogus warning.  */
1636 +  vprintf ("%*.*d", v8);   /* { dg-bogus "format" "vprintf" } */
1637 +  vsprintf (s, "%d", v4);
1638 +  vsprintf (s, "%Y", v5); /* { dg-warning "format" "Y is invalid" } */
1639 +  snprintf (s, n, "%d", i);
1640 +  snprintf (s, n, "%ld", i);
1641 +  vsnprintf (s, n, "%d", v6);
1642 +  vsnprintf (s, n, "%Y", v7);
1643 +  printf (gettext ("%d"), i);
1644 +  printf (gettext ("%ld"), i);
1645 +  printf (dgettext ("", "%d"), i);
1646 +  printf (dgettext ("", "%ld"), i);
1647 +  printf (dcgettext ("", "%d", 0), i);
1648 +  printf (dcgettext ("", "%ld", 0), i);
1649 +}
1650 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c
1651 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1652 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-1.c      Mon Jun 02 08:07:23 2008 -0600
1653 @@ -0,0 +1,119 @@
1654 +/* Test for scanf formats.  Formats using C90 features, including cases
1655 +   where C90 specifies some aspect of the format to be ignored or where
1656 +   the behavior is undefined.
1657 +*/
1658 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1659 +/* { dg-do compile { target { *-*-mingw* } } } */
1660 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1661 +
1662 +#define USE_SYSTEM_FORMATS
1663 +#include "format.h"
1664 +
1665 +void
1666 +foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
1667 +     long int *lp, unsigned long int *ulp, float *fp, double *dp,
1668 +     long double *ldp, char *s, signed char *ss, unsigned char *us,
1669 +     void **pp, int *n, llong *llp, ullong *ullp, wchar_t *ls,
1670 +     const int *cip, const int *cn, const char *cs, const void **ppc,
1671 +     void *const *pcp, short int *hn, long int *ln, void *p, char **sp,
1672 +     volatile void *ppv)
1673 +{
1674 +  /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138).  */
1675 +  /* Basic sanity checks for the different components of a format.  */
1676 +  scanf ("%d", ip);
1677 +  scanf ("%*d");
1678 +  scanf ("%3d", ip);
1679 +  scanf ("%hd", hp);
1680 +  scanf ("%3ld", lp);
1681 +  scanf ("%*3d");
1682 +  scanf ("%d %ld", ip, lp);
1683 +  /* Valid and invalid %% constructions.  */
1684 +  scanf ("%%");
1685 +  scanf ("%*%"); /* { dg-warning "format" "bogus %%" } */
1686 +  scanf ("%*%\n"); /* { dg-warning "format" "bogus %%" } */
1687 +  scanf ("%4%"); /* { dg-warning "format" "bogus %%" } */
1688 +  scanf ("%4%\n"); /* { dg-warning "format" "bogus %%" } */
1689 +  scanf ("%h%"); /* { dg-warning "format" "bogus %%" } */
1690 +  scanf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */
1691 +  /* Valid, invalid and silly assignment-suppression constructions.  */
1692 +  scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
1693 +  scanf ("%*2d%*8s%*3c");
1694 +  scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
1695 +  scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
1696 +  /* Valid, invalid and silly width constructions.  */
1697 +  scanf ("%2d%3i%4o%5u%6x%7X%8e%9E%10f%11g%12G%13s%14[abc]%15c%16p",
1698 +        ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, s, s, s, pp);
1699 +  scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
1700 +  scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
1701 +  /* Valid and invalid %h, %l, %L constructions.  */
1702 +  scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
1703 +  scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
1704 +  scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
1705 +  scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
1706 +  scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
1707 +  scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
1708 +  scanf ("%hs", hp);
1709 +  scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
1710 +  scanf ("%hc", hp);
1711 +  scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
1712 +  scanf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */
1713 +  scanf ("%h."); /* { dg-warning "conversion" "bogus %h" } */
1714 +  scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
1715 +  scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
1716 +  scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
1717 +  /* These next three formats were added in C94.  */
1718 +  scanf ("%ls", ls); /* { dg-warning "length|C" "bad use of %l" } */
1719 +  scanf ("%l[ac]", ls); /* { dg-warning "length|C" "bad use of %l" } */
1720 +  scanf ("%lc", ls); /* { dg-warning "length|C" "bad use of %l" } */
1721 +  scanf ("%Ld", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1722 +  scanf ("%Li", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1723 +  scanf ("%Lo", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1724 +  scanf ("%Lu", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1725 +  scanf ("%Lx", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1726 +  scanf ("%LX", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1727 +  scanf ("%Ls", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
1728 +  scanf ("%L[ac]", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
1729 +  scanf ("%Lc", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
1730 +  scanf ("%Lp", pp); /* { dg-warning "unknown|format" "%L is unsupported" } */
1731 +  scanf ("%Ln", n); /* { dg-warning "unknown|format" "%L is unsupported" } */
1732 +  /* Valid uses of each bare conversion.  */
1733 +  scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
1734 +        uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
1735 +  /* Allow other character pointers with %s, %c, %[].  */
1736 +  scanf ("%2s%3s%4c%5c%6[abc]%7[abc]", ss, us, ss, us, ss, us);
1737 +  /* Further tests for %[].  */
1738 +  scanf ("%[%d]%d", s, ip);
1739 +  scanf ("%[^%d]%d", s, ip);
1740 +  scanf ("%[]%d]%d", s, ip);
1741 +  scanf ("%[^]%d]%d", s, ip);
1742 +  scanf ("%[%d]%d", s, ip);
1743 +  scanf ("%[]abcd", s); /* { dg-warning "no closing" "incomplete scanset" } */
1744 +  /* Various tests of bad argument types.  Some of these are only pedantic
1745 +     warnings.
1746 +  */
1747 +  scanf ("%d", lp); /* { dg-warning "format" "bad argument types" } */
1748 +  scanf ("%d", uip); /* { dg-warning "format" "bad argument types" } */
1749 +  scanf ("%d", pp); /* { dg-warning "format" "bad argument types" } */
1750 +  scanf ("%p", ppc); /* { dg-warning "format" "bad argument types" } */
1751 +  scanf ("%p", ppv); /* { dg-warning "format" "bad argument types" } */
1752 +  scanf ("%s", n); /* { dg-warning "format" "bad argument types" } */
1753 +  scanf ("%s", p); /* { dg-warning "format" "bad argument types" } */
1754 +  scanf ("%p", p); /* { dg-warning "format" "bad argument types" } */
1755 +  scanf ("%p", sp); /* { dg-warning "format" "bad argument types" } */
1756 +  /* Tests for writing into constant values.  */
1757 +  scanf ("%d", cip); /* { dg-warning "constant" "%d writing into const" } */
1758 +  scanf ("%n", cn); /* { dg-warning "constant" "%n writing into const" } */
1759 +  scanf ("%s", cs); /* { dg-warning "constant" "%s writing into const" } */
1760 +  scanf ("%p", pcp); /* { dg-warning "constant" "%p writing into const" } */
1761 +  /* Wrong number of arguments.  */
1762 +  scanf ("%d%d", ip); /* { dg-warning "arguments" "wrong number of args" } */
1763 +  scanf ("%d", ip, ip); /* { dg-warning "arguments" "wrong number of args" } */
1764 +  /* Miscellaneous bogus constructions.  */
1765 +  scanf (""); /* { dg-warning "zero-length" "warning for empty format" } */
1766 +  scanf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */
1767 +  scanf ("%d\0", ip); /* { dg-warning "embedded" "warning for embedded NUL" } */
1768 +  scanf ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
1769 +  scanf (NULL); /* { dg-warning "null" "null format string warning" } */
1770 +  scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
1771 +  scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */
1772 +}
1773 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c
1774 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1775 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-2.c      Mon Jun 02 08:07:23 2008 -0600
1776 @@ -0,0 +1,26 @@
1777 +/* Test for scanf formats.  Formats using C99 features should be rejected
1778 +   outside of C99 mode.
1779 +*/
1780 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1781 +/* { dg-do compile { target { *-*-mingw* } } } */
1782 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1783 +
1784 +#define USE_SYSTEM_FORMATS
1785 +#include "format.h"
1786 +
1787 +void
1788 +foo (signed char *hhp, float *fp, llong *llp, intmax_t *jp,
1789 +     size_t *zp, ptrdiff_t *tp)
1790 +{
1791 +  /* Some tests already in c90-scanf-1.c.  */
1792 +  /* The widths hh, ll, j, z, t are new.  */
1793 +  scanf ("%hhd", hhp); /* { dg-warning "unknown|format" "%hh is unsupported" } */
1794 +  scanf ("%I64d", llp); /* { dg-warning "length|C" "%I64 in C90" } */
1795 +  scanf ("%jd", jp); /* { dg-warning "unknown|format" "%j is unsupported" } */
1796 +  scanf ("%zu", zp); /* { dg-warning "unknown|format" "%z is unsupported" } */
1797 +  scanf ("%td", tp); /* { dg-warning "unknown|format" "%t is unsupported" } */
1798 +  /* The formats F, a, A are new.  */
1799 +  scanf ("%F", fp); /* { dg-warning "unknown|format" "%F is unsupported" } */
1800 +  scanf ("%a", fp); /* { dg-warning "unknown|format" "%a is unsupported" } */
1801 +  scanf ("%A", fp); /* { dg-warning "unknown|format" "%A is unsupported" } */
1802 +}
1803 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c
1804 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1805 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-3.c      Mon Jun 02 08:07:23 2008 -0600
1806 @@ -0,0 +1,20 @@
1807 +/* Test for scanf formats.  Formats using extensions to the standard
1808 +   should be rejected in strict pedantic mode.
1809 +*/
1810 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1811 +/* { dg-do compile { target { *-*-mingw* } } } */
1812 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1813 +
1814 +#define USE_SYSTEM_FORMATS
1815 +#include "format.h"
1816 +
1817 +void
1818 +foo (char **sp, wchar_t **lsp)
1819 +{
1820 +  /* %a formats for allocation, only recognized in C90 mode, are a
1821 +     GNU extension.
1822 +  */
1823 +  scanf ("%as", sp); /* { dg-warning "flag" "%as is unsupported" } */
1824 +  scanf ("%aS", lsp); /* { dg-warning "format|flag" "%aS is unsupported" } */
1825 +  scanf ("%a[bcd]", sp); /* { dg-warning "flag" "%a[] is unsupported" } */
1826 +}
1827 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c
1828 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1829 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-4.c      Mon Jun 02 08:07:23 2008 -0600
1830 @@ -0,0 +1,31 @@
1831 +/* Test for scanf formats.  Test that the C90 functions get their default
1832 +   attributes in strict C90 mode, but the C99 and gettext functions
1833 +   do not.
1834 +*/
1835 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1836 +/* { dg-do compile { target { *-*-mingw* } } } */
1837 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1838 +
1839 +#define USE_SYSTEM_FORMATS
1840 +#include "format.h"
1841 +
1842 +void
1843 +foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3,
1844 +     va_list v4, va_list v5)
1845 +{
1846 +  fscanf (stdin, "%d", ip);
1847 +  fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */
1848 +  scanf ("%d", ip);
1849 +  scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */
1850 +  sscanf (s, "%d", ip);
1851 +  sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */
1852 +  vfscanf (stdin, "%d", v0);
1853 +  vscanf ("%d", v2);
1854 +  vsscanf (s, "%d", v4);
1855 +  scanf (gettext ("%d"), ip);
1856 +  scanf (gettext ("%ld"), ip);
1857 +  scanf (dgettext ("", "%d"), ip);
1858 +  scanf (dgettext ("", "%ld"), ip);
1859 +  scanf (dcgettext ("", "%d", 0), ip);
1860 +  scanf (dcgettext ("", "%ld", 0), ip);
1861 +}
1862 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c
1863 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1864 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-scanf-5.c      Mon Jun 02 08:07:23 2008 -0600
1865 @@ -0,0 +1,20 @@
1866 +/* Test for scanf formats.  Formats using extensions to the standard
1867 +   should be rejected in strict pedantic mode.
1868 +*/
1869 +/* { dg-do compile { target { *-*-mingw* } } } */
1870 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
1871 +
1872 +#define USE_SYSTEM_FORMATS
1873 +#include "format.h"
1874 +
1875 +void
1876 +foo (char **sp, wchar_t **lsp)
1877 +{
1878 +  /* m assignment-allocation modifier, recognized in both C90
1879 +     and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension.  */
1880 +  scanf ("%ms", sp); /* { dg-warning "unknown|format" "%ms is unsupported" } */
1881 +  scanf ("%mS", lsp); /* { dg-warning "unknown|format" "%mS is unsupported" } */
1882 +  scanf ("%mls", lsp); /* { dg-warning "unknown|format" "%mls is unsupported" } */
1883 +  scanf ("%m[bcd]", sp); /* { dg-warning "unknown|format" "%m[] is unsupported" } */
1884 +  scanf ("%ml[bcd]", lsp); /* { dg-warning "unknown|format" "%ml[] is unsupported" } */
1885 +}
1886 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c
1887 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1888 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-1.c   Mon Jun 02 08:07:23 2008 -0600
1889 @@ -0,0 +1,20 @@
1890 +/* Test for strftime formats.  Formats using C90 features.  */
1891 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1892 +/* { dg-do compile { target { *-*-mingw* } } } */
1893 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */
1894 +
1895 +#define USE_SYSTEM_FORMATS
1896 +#include "format.h"
1897 +
1898 +void
1899 +foo (char *s, size_t m, const struct tm *tp)
1900 +{
1901 +  /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175).  */
1902 +  /* Formats which are Y2K-compliant (no 2-digit years).  */
1903 +  strftime (s, m, "%a%A%b%B%d%H%I%j%m%M%p%S%U%w%W%X%Y%Z%%", tp);
1904 +  /* Formats with 2-digit years.  */
1905 +  strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */
1906 +  /* Formats with 2-digit years in some locales.  */
1907 +  strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */
1908 +  strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */
1909 +}
1910 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c
1911 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1912 +++ b/gcc/testsuite/gcc.dg/format/ms_c90-strftime-2.c   Mon Jun 02 08:07:23 2008 -0600
1913 @@ -0,0 +1,28 @@
1914 +/* Test for strftime formats.  Rejection of formats using C99 features in
1915 +   pedantic C90 mode.  */
1916 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1917 +/* { dg-do compile { target { *-*-mingw* } } } */
1918 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */
1919 +
1920 +#define USE_SYSTEM_FORMATS
1921 +#include "format.h"
1922 +
1923 +void
1924 +foo (char *s, size_t m, const struct tm *tp)
1925 +{
1926 +  strftime (s, m, "%C", tp); /* { dg-warning "format" "%C is unsupported" } */
1927 +  strftime (s, m, "%D", tp); /* { dg-warning "format" "%D is unsupported" } */
1928 +  strftime (s, m, "%e", tp); /* { dg-warning "format" "%e is unsupported" } */
1929 +  strftime (s, m, "%F", tp); /* { dg-warning "format" "%F is unsupported" } */
1930 +  strftime (s, m, "%g", tp); /* { dg-warning "format" "%g is unsupported" } */
1931 +  strftime (s, m, "%G", tp); /* { dg-warning "format" "%G is unsupported" } */
1932 +  strftime (s, m, "%h", tp); /* { dg-warning "format" "%h is unsupported" } */
1933 +  strftime (s, m, "%n", tp); /* { dg-warning "format" "%n is unsupported" } */
1934 +  strftime (s, m, "%r", tp); /* { dg-warning "format" "%r is unsupported" } */
1935 +  strftime (s, m, "%R", tp); /* { dg-warning "format" "%R is unsupported" } */
1936 +  strftime (s, m, "%t", tp); /* { dg-warning "format" "%t is unsupported" } */
1937 +  strftime (s, m, "%T", tp); /* { dg-warning "format" "%T is unsupported" } */
1938 +  strftime (s, m, "%u", tp); /* { dg-warning "format" "%u is unsupported" } */
1939 +  strftime (s, m, "%V", tp); /* { dg-warning "format" "%V is unsupported" } */
1940 +  strftime (s, m, "%z", tp); /* { dg-warning "C" "%z not in C90" } */
1941 +}
1942 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c
1943 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1944 +++ b/gcc/testsuite/gcc.dg/format/ms_c94-printf-1.c     Mon Jun 02 08:07:23 2008 -0600
1945 @@ -0,0 +1,19 @@
1946 +/* Test for printf formats.  Changes in C94 to C90.  */
1947 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1948 +/* { dg-do compile { target { *-*-mingw* } } } */
1949 +/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */
1950 +
1951 +#define USE_SYSTEM_FORMATS
1952 +#include "format.h"
1953 +
1954 +void
1955 +foo (wint_t lc, wchar_t *ls)
1956 +{
1957 +  /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134),
1958 +     as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 4-5).
1959 +     We do not repeat here all the C90 format checks, but just verify
1960 +     that %ls and %lc are accepted without warning.
1961 +  */
1962 +  printf ("%lc", lc);
1963 +  printf ("%ls", ls);
1964 +}
1965 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c
1966 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1967 +++ b/gcc/testsuite/gcc.dg/format/ms_c94-scanf-1.c      Mon Jun 02 08:07:23 2008 -0600
1968 @@ -0,0 +1,18 @@
1969 +/* Test for scanf formats.  Changes in C94 to C90.  */
1970 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1971 +/* { dg-do compile { target { *-*-mingw* } } } */
1972 +/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */
1973 +
1974 +#define USE_SYSTEM_FORMATS
1975 +#include "format.h"
1976 +
1977 +void
1978 +foo (wchar_t *ls)
1979 +{
1980 +  /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138),
1981 +     as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 5-6).
1982 +     We do not repeat here all the C90 format checks, but just verify
1983 +     that %ls, %lc, %l[] are accepted without warning.
1984 +  */
1985 +  scanf ("%lc%ls%l[abc]", ls, ls, ls);
1986 +}
1987 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c
1988 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
1989 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-1.c     Mon Jun 02 08:07:23 2008 -0600
1990 @@ -0,0 +1,109 @@
1991 +/* Test for printf formats.  Formats using C99 features, including cases
1992 +   where C99 specifies some aspect of the format to be ignored or where
1993 +   the behavior is undefined.
1994 +*/
1995 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
1996 +/* { dg-do compile { target { *-*-mingw* } } } */
1997 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
1998 +
1999 +#define USE_SYSTEM_FORMATS
2000 +#include "format.h"
2001 +
2002 +void
2003 +foo (int i, unsigned int u, double d, char *s, void *p, int *n,
2004 +     long double ld, wint_t lc, wchar_t *ls, long long int ll,
2005 +     unsigned long long int ull, signed char *ss, unsigned char *us,
2006 +     long long int *lln, intmax_t j, uintmax_t uj, intmax_t *jn,
2007 +     size_t z, signed_size_t sz, signed_size_t *zn,
2008 +     ptrdiff_t t, ptrdiff_t *tn)
2009 +{
2010 +  /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.1 (pages 273-281).
2011 +     We do not repeat here most of the checks for correct C90 formats
2012 +     or completely broken formats.
2013 +  */
2014 +  /* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions.  */
2015 +  printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */
2016 +  printf ("%hF", d); /* { dg-warning "unknown|format" "bad use of %hF" } */
2017 +  printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */
2018 +  printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */
2019 +  printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */
2020 +  printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */
2021 +  printf ("%ha", d); /* { dg-warning "unknown|format" "bad use of %ha" } */
2022 +  printf ("%hA", d); /* { dg-warning "unknown|format" "bad use of %hA" } */
2023 +  printf ("%hc", i);
2024 +  printf ("%hs", (short *)s);
2025 +  printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */
2026 +  printf ("%lc", lc);
2027 +  printf ("%ls", ls);
2028 +  printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */
2029 +  /* Valid uses of each bare conversion.  */
2030 +  printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u,
2031 +         d, d, d, d, d, i, s, p, n);
2032 +  /* Uses of the - flag (valid on all non-%, non-n conversions).  */
2033 +  printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i,
2034 +         u, u, u, u, d, d, d, d, d, i, s, p);
2035 +  printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */
2036 +  /* Uses of the + flag (valid on signed conversions only).  */
2037 +  printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d);
2038 +  printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */
2039 +  printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */
2040 +  printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */
2041 +  printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */
2042 +  printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */
2043 +  printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */
2044 +  printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */
2045 +  printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */
2046 +  /* Uses of the space flag (valid on signed conversions only, and ignored
2047 +     with +).
2048 +  */
2049 +  printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
2050 +  printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
2051 +  printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d);
2052 +  printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */
2053 +  printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */
2054 +  printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */
2055 +  printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */
2056 +  printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */
2057 +  printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */
2058 +  printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */
2059 +  printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */
2060 +  /* Uses of the # flag.  */
2061 +  printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d,
2062 +         d, d);
2063 +  printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */
2064 +  printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */
2065 +  printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */
2066 +  printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */
2067 +  printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */
2068 +  printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */
2069 +  printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */
2070 +  /* Uses of the 0 flag.  */
2071 +  printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i,
2072 +         u, u, u, u, d, d, d, d, d);
2073 +  printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */
2074 +  printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */
2075 +  printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */
2076 +  printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */
2077 +  /* 0 flag ignored with - flag.  */
2078 +  printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2079 +  printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2080 +  printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2081 +  printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2082 +  printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2083 +  printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2084 +  printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2085 +  printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2086 +  printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2087 +  printf ("%-08F", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
2088 +  printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2089 +  printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
2090 +  printf ("%-08a", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
2091 +  printf ("%-08A", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
2092 +  /* Various tests of bad argument types.  Mostly covered in c90-printf-1.c;
2093 +     here just test for pointer target sign with %hhn.  (Probably allowed
2094 +     by the standard, but a bad idea, so GCC should diagnose if what
2095 +     is used is not signed char *.)
2096 +  */
2097 +  printf ("%hhn", s); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
2098 +  printf ("%hhn", us); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
2099 +}
2100 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c
2101 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2102 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-2.c     Mon Jun 02 08:07:23 2008 -0600
2103 @@ -0,0 +1,32 @@
2104 +/* Test for printf formats.  Formats using extensions to the standard
2105 +   should be rejected in strict pedantic mode.
2106 +*/
2107 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2108 +/* { dg-do compile { target { *-*-mingw* } } } */
2109 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2110 +
2111 +#define USE_SYSTEM_FORMATS
2112 +#include "format.h"
2113 +
2114 +void
2115 +foo (int i, long long ll, size_t z, wint_t lc, wchar_t *ls)
2116 +{
2117 +  /* The length modifiers q, Z and L as applied to integer formats are
2118 +     extensions.
2119 +  */
2120 +  printf ("%qd", ll); /* { dg-warning "unknown|format" "%q length is unsupported" } */
2121 +  printf ("%Ld", ll); /* { dg-warning "unknown|format" "%L length is unsupported" } */
2122 +  printf ("%Zd", z); /* { dg-warning "unknown|format" "%Z length is unsupported" } */
2123 +  /* The conversion specifiers C and S are X/Open extensions; the
2124 +     conversion specifier m is a GNU extension.
2125 +  */
2126 +  printf ("%m"); /* { dg-warning "unknown" "printf %m is unsupported" } */
2127 +  printf ("%C", lc); /* { dg-warning "C" "printf %C" } */
2128 +  printf ("%S", ls); /* { dg-warning "C" "printf %S" } */
2129 +  /* The flag character ', and the use of operand number $ formats, are
2130 +     X/Open extensions.
2131 +  */
2132 +  printf ("%'d", i); /* { dg-warning "C" "printf ' flag" } */
2133 +  printf ("%1$d", i); /* { dg-warning "C" "printf $ format" } */
2134 +  printf ("%Ix", z); /* { dg-warning "C" "printf I format" } */
2135 +}
2136 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c
2137 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2138 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-printf-3.c     Mon Jun 02 08:07:23 2008 -0600
2139 @@ -0,0 +1,40 @@
2140 +/* Test for printf formats.  Test that the C99 functions get their default
2141 +   attributes in strict C99 mode, but the gettext functions do not.
2142 +*/
2143 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2144 +/* { dg-do compile { target { *-*-mingw* } } } */
2145 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2146 +
2147 +#define USE_SYSTEM_FORMATS
2148 +#include "format.h"
2149 +
2150 +void
2151 +foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3,
2152 +     va_list v4, va_list v5, va_list v6, va_list v7)
2153 +{
2154 +  fprintf (stdout, "%d", i);
2155 +  fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */
2156 +  printf ("%d", i);
2157 +  printf ("%ld", i); /* { dg-warning "format" "printf" } */
2158 +  /* The "unlocked" functions shouldn't warn in c99 mode.  */
2159 +  fprintf_unlocked (stdout, "%ld", i);
2160 +  printf_unlocked ("%ld", i);
2161 +  sprintf (s, "%d", i);
2162 +  sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */
2163 +  snprintf (s, n, "%d", i);
2164 +  snprintf (s, n, "%ld", i); /* { dg-warning "format" "snprintf" } */
2165 +  vfprintf (stdout, "%d", v0);
2166 +  vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */
2167 +  vprintf ("%d", v0);
2168 +  vprintf ("%Y", v1); /* { dg-warning "format" "vprintf" } */
2169 +  vsprintf (s, "%d", v0);
2170 +  vsprintf (s, "%Y", v1); /* { dg-warning "format" "vsprintf" } */
2171 +  vsnprintf (s, n, "%d", v0);
2172 +  vsnprintf (s, n, "%Y", v1); /* { dg-warning "format" "vsnprintf" } */
2173 +  printf (gettext ("%d"), i);
2174 +  printf (gettext ("%ld"), (long) i);
2175 +  printf (dgettext ("", "%d"), i);
2176 +  printf (dgettext ("", "%ld"), (long) i);
2177 +  printf (dcgettext ("", "%d", 0), i);
2178 +  printf (dcgettext ("", "%ld", 0), (long) i);
2179 +}
2180 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c
2181 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2182 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-1.c      Mon Jun 02 08:07:23 2008 -0600
2183 @@ -0,0 +1,63 @@
2184 +/* Test for scanf formats.  Formats using C99 features, including cases
2185 +   where C99 specifies some aspect of the format to be ignored or where
2186 +   the behavior is undefined.
2187 +*/
2188 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2189 +/* { dg-do compile { target { *-*-mingw* } } } */
2190 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2191 +
2192 +#define USE_SYSTEM_FORMATS
2193 +#include "format.h"
2194 +
2195 +void
2196 +foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
2197 +     signed char *hhp, unsigned char *uhhp, long int *lp,
2198 +     unsigned long int *ulp, float *fp, double *dp, long double *ldp, char *s,
2199 +     void **pp, int *n, long long *llp, unsigned long long *ullp, wchar_t *ls,
2200 +     short int *hn, signed char *hhn, long int *ln, long long int *lln,
2201 +     intmax_t *jp, uintmax_t *ujp, intmax_t *jn, size_t *zp,
2202 +     signed_size_t *szp, signed_size_t *zn, ptrdiff_t *tp,
2203 +     unsigned_ptrdiff_t *utp, ptrdiff_t *tn)
2204 +{
2205 +  /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.2 (pages 281-288).
2206 +     We do not repeat here most of the checks for correct C90 formats
2207 +     or completely broken formats.
2208 +  */
2209 +  /* Valid, invalid and silly assignment-suppression
2210 +     and width constructions.
2211 +  */
2212 +  scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
2213 +  scanf ("%*2d%*8s%*3c");
2214 +  scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
2215 +  scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
2216 +  scanf ("%2d%3i%4o%5u%6x%7X%10e%11E%12f%14g%15G%16s%3[abc]%4c%5p",
2217 +        ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp,
2218 +        s, s, s, pp);
2219 +  scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
2220 +  scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
2221 +  /* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions.  */
2222 +  scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
2223 +  scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
2224 +  scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
2225 +  scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
2226 +  scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
2227 +  scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
2228 +  scanf ("%hs", hp);
2229 +  scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
2230 +  scanf ("%hc", (short *)s);
2231 +  scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
2232 +  scanf ("%hhd", hhp); /* { dg-warning "unknown|format" "%hh is unsupported" } */
2233 +  scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
2234 +  scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
2235 +  scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
2236 +  scanf ("%ls", ls);
2237 +  scanf ("%l[ac]", ls);
2238 +  scanf ("%lc", ls);
2239 +  scanf ("%jd", jp); /* { dg-warning "unknown|format" "%j not supported" } */
2240 +  scanf ("%zd", zp); /* { dg-warning "unknown|format" "%z not supported" } */
2241 +  scanf ("%td", tp); /* { dg-warning "unknown|format" "%t not supported" } */
2242 +  scanf ("%Lf", llp); /* { dg-warning "unknown|format" "bad use of %L is not supported" } */
2243 +  /* Valid uses of each bare conversion.  */
2244 +  scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
2245 +         uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
2246 +}
2247 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c
2248 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2249 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-2.c      Mon Jun 02 08:07:23 2008 -0600
2250 @@ -0,0 +1,27 @@
2251 +/* Test for scanf formats.  Formats using extensions to the standard
2252 +   should be rejected in strict pedantic mode.
2253 +*/
2254 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2255 +/* { dg-do compile { target { *-*-mingw* } } } */
2256 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2257 +
2258 +#define USE_SYSTEM_FORMATS
2259 +#include "format.h"
2260 +
2261 +void
2262 +foo (int *ip, long long int *llp, wchar_t *ls)
2263 +{
2264 +  /* The length modifiers q and L as applied to integer formats are
2265 +     extensions.
2266 +  */
2267 +  scanf ("%qd", llp); /* { dg-warning "unknown|format" "%q is unsupported" } */
2268 +  scanf ("%Ld", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
2269 +  /* The conversion specifiers C and S are X/Open extensions.  */
2270 +  scanf ("%C", ls); /* { dg-warning "C" "scanf %C" } */
2271 +  scanf ("%S", ls); /* { dg-warning "C" "scanf %S" } */
2272 +  /* The use of operand number $ formats is an X/Open extension.  */
2273 +  scanf ("%1$d", ip); /* { dg-warning "C" "scanf $ format" } */
2274 +  /* glibc also supports flags ' and I on scanf formats as an extension.  */
2275 +  scanf ("%'d", ip); /* { dg-warning "C" "scanf ' flag" } */
2276 +  scanf ("%Id", (ssize_t *)ip); /* { dg-warning "C" "scanf I flag" } */
2277 +}
2278 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c
2279 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2280 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-3.c      Mon Jun 02 08:07:23 2008 -0600
2281 @@ -0,0 +1,33 @@
2282 +/* Test for scanf formats.  Test that the C99 functions get their default
2283 +   attributes in strict C99 mode, but the gettext functions do not.
2284 +*/
2285 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2286 +/* { dg-do compile { target { *-*-mingw* } } } */
2287 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2288 +
2289 +#define USE_SYSTEM_FORMATS
2290 +#include "format.h"
2291 +
2292 +void
2293 +foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3,
2294 +     va_list v4, va_list v5)
2295 +{
2296 +  fscanf (stdin, "%d", ip);
2297 +  fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */
2298 +  scanf ("%d", ip);
2299 +  scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */
2300 +  sscanf (s, "%d", ip);
2301 +  sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */
2302 +  vfscanf (stdin, "%d", v0);
2303 +  vfscanf (stdin, "%Y", v1); /* { dg-warning "format" "vfscanf" } */
2304 +  vscanf ("%d", v2);
2305 +  vscanf ("%Y", v3); /* { dg-warning "format" "vscanf" } */
2306 +  vsscanf (s, "%d", v4);
2307 +  vsscanf (s, "%Y", v5); /* { dg-warning "format" "vsscanf" } */
2308 +  scanf (gettext ("%d"), ip);
2309 +  scanf (gettext ("%ld"), ip);
2310 +  scanf (dgettext ("", "%d"), ip);
2311 +  scanf (dgettext ("", "%ld"), ip);
2312 +  scanf (dcgettext ("", "%d", 0), ip);
2313 +  scanf (dcgettext ("", "%ld", 0), ip);
2314 +}
2315 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c
2316 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2317 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-scanf-4.c      Mon Jun 02 08:07:23 2008 -0600
2318 @@ -0,0 +1,20 @@
2319 +/* Test for scanf formats.  Formats using extensions to the standard
2320 +   should be rejected in strict pedantic mode.
2321 +*/
2322 +/* { dg-do compile { target { *-*-mingw* } } } */
2323 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2324 +
2325 +#define USE_SYSTEM_FORMATS
2326 +#include "format.h"
2327 +
2328 +void
2329 +foo (char **sp, wchar_t **lsp)
2330 +{
2331 +  /* m assignment-allocation modifier, recognized in both C90
2332 +     and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension.  */
2333 +  scanf ("%ms", sp); /* { dg-warning "unknown|format" "%ms is unsupported" } */
2334 +  scanf ("%mS", lsp); /* { dg-warning "unknown|format" "%mS is unsupported" } */
2335 +  scanf ("%mls", lsp); /* { dg-warning "unknown|format" "%mls is unsupported" } */
2336 +  scanf ("%m[bcd]", sp); /* { dg-warning "unknown|format" "%m[] is unsupported" } */
2337 +  scanf ("%ml[bcd]", lsp); /* { dg-warning "unknown|format" "%ml[] is unsupported" } */
2338 +}
2339 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c
2340 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2341 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-1.c   Mon Jun 02 08:07:23 2008 -0600
2342 @@ -0,0 +1,20 @@
2343 +/* Test for strftime formats.  Formats using C99 features.  */
2344 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2345 +/* { dg-do compile { target { *-*-mingw* } } } */
2346 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat -Wformat-y2k" } */
2347 +
2348 +#define USE_SYSTEM_FORMATS
2349 +#include "format.h"
2350 +
2351 +void
2352 +foo (char *s, size_t m, const struct tm *tp)
2353 +{
2354 +  /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175).  */
2355 +  /* Formats which are Y2K-compliant (no 2-digit years).  */
2356 +  strftime (s, m, "%a%A%b%B%d%H%I%j%m%M%p%S%U%w%W%X%Y%z%Z%%", tp);
2357 +  /* Formats with 2-digit years.  */
2358 +  strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */
2359 +  /* Formats with 2-digit years in some locales.  */
2360 +  strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */
2361 +  strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */
2362 +}
2363 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c
2364 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2365 +++ b/gcc/testsuite/gcc.dg/format/ms_c99-strftime-2.c   Mon Jun 02 08:07:23 2008 -0600
2366 @@ -0,0 +1,20 @@
2367 +/* Test for strftime formats.  Rejection of extensions in pedantic mode.  */
2368 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2369 +/* { dg-do compile { target { *-*-mingw* } } } */
2370 +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
2371 +
2372 +#define USE_SYSTEM_FORMATS
2373 +#include "format.h"
2374 +
2375 +void
2376 +foo (char *s, size_t m, const struct tm *tp)
2377 +{
2378 +  /* %P is a lowercase version of %p.  */
2379 +  strftime (s, m, "%P", tp); /* { dg-warning "unknown" "strftime %P" } */
2380 +  /* %k is %H but padded with a space rather than 0 if necessary.  */
2381 +  strftime (s, m, "%k", tp); /* { dg-warning "unknown" "strftime %k" } */
2382 +  /* %l is %I but padded with a space rather than 0 if necessary.  */
2383 +  strftime (s, m, "%l", tp); /* { dg-warning "unknown" "strftime %l" } */
2384 +  /* %s is the number of seconds since the Epoch.  */
2385 +  strftime (s, m, "%s", tp); /* { dg-warning "unknown" "strftime %s" } */
2386 +}
2387 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_cast-1.c
2388 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2389 +++ b/gcc/testsuite/gcc.dg/format/ms_cast-1.c   Mon Jun 02 08:07:23 2008 -0600
2390 @@ -0,0 +1,17 @@
2391 +/* Test for strings cast through integer types: should not be treated
2392 +   as format strings unless the types are of the same width as
2393 +   pointers (intptr_t or similar).  */
2394 +/* Origin: Joseph Myers <joseph@codesourcery.com> */
2395 +/* { dg-do compile { target { *-*-mingw* } } } */
2396 +/* { dg-options "-Wformat" } */
2397 +
2398 +#define USE_SYSTEM_FORMATS
2399 +#include "format.h"
2400 +
2401 +void
2402 +f (int x)
2403 +{
2404 +  printf("%s", x); /* { dg-warning "format" } */
2405 +  printf((char *)(size_t)"%s", x); /* { dg-warning "format" } */
2406 +  printf((char *)(char)"%s", x); /* { dg-warning "cast from pointer to integer of different size" } */
2407 +}
2408 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-1.c
2409 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2410 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-1.c   Mon Jun 02 08:07:23 2008 -0600
2411 @@ -0,0 +1,40 @@
2412 +/* Test for warnings for missing format attributes.  */
2413 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2414 +/* { dg-do compile { target { *-*-mingw* } } } */
2415 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2416 +
2417 +#define USE_SYSTEM_FORMATS
2418 +#include "format.h"
2419 +
2420 +void
2421 +foo (const char *fmt, ...)
2422 +{
2423 +  va_list ap;
2424 +  va_start (ap, fmt);
2425 +  vprintf (fmt, ap); /* { dg-warning "candidate" "printf attribute warning" } */
2426 +  va_end (ap);
2427 +}
2428 +
2429 +void
2430 +bar (const char *fmt, ...)
2431 +{
2432 +  va_list ap;
2433 +  va_start (ap, fmt);
2434 +  vscanf (fmt, ap); /* { dg-warning "candidate" "scanf attribute warning" } */
2435 +  va_end (ap);
2436 +}
2437 +
2438 +__attribute__((__format__(__ms_printf__, 1, 2))) void
2439 +foo2 (const char *fmt, ...)
2440 +{
2441 +  va_list ap;
2442 +  va_start (ap, fmt);
2443 +  vprintf (fmt, ap);
2444 +  va_end (ap);
2445 +}
2446 +
2447 +void
2448 +vfoo (const char *fmt, va_list arg)
2449 +{
2450 +  vprintf (fmt, arg); /* { dg-warning "candidate" "printf attribute warning 2" } */
2451 +}
2452 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-2.c
2453 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2454 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-2.c   Mon Jun 02 08:07:23 2008 -0600
2455 @@ -0,0 +1,17 @@
2456 +/* Test for warnings for missing format attributes.  Don't warn if no
2457 +   relevant parameters for a format attribute; see c/1017.  */
2458 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2459 +/* { dg-do compile { target { *-*-mingw* } } } */
2460 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2461 +
2462 +#define USE_SYSTEM_FORMATS
2463 +#include "format.h"
2464 +
2465 +void
2466 +foo (int i, ...)
2467 +{
2468 +  va_list ap;
2469 +  va_start (ap, i);
2470 +  vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */
2471 +  va_end (ap);
2472 +}
2473 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-3.c
2474 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2475 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-3.c   Mon Jun 02 08:07:23 2008 -0600
2476 @@ -0,0 +1,27 @@
2477 +/* Test warnings for missing format attributes on function pointers.  */
2478 +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
2479 +/* { dg-do compile { target { *-*-mingw* } } } */
2480 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2481 +
2482 +#define USE_SYSTEM_FORMATS
2483 +#include "format.h"
2484 +
2485 +typedef void (*noattr_t) (const char *, ...);
2486 +typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
2487 +
2488 +typedef void (*vnoattr_t) (const char *, va_list);
2489 +typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
2490 +
2491 +void
2492 +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
2493 +{
2494 +  noattr_t na1 = na;
2495 +  noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */
2496 +  attr_t a1 = na;
2497 +  attr_t a2 = a;
2498 +
2499 +  vnoattr_t vna1 = vna;
2500 +  vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */
2501 +  vattr_t va1 = vna;
2502 +  vattr_t va2 = va;
2503 +}
2504 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-4.c
2505 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2506 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-4.c   Mon Jun 02 08:07:23 2008 -0600
2507 @@ -0,0 +1,33 @@
2508 +/* Test warnings for missing format attributes on function pointers.  */
2509 +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
2510 +/* { dg-do compile { target { *-*-mingw* } } } */
2511 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2512 +
2513 +#define USE_SYSTEM_FORMATS
2514 +#include "format.h"
2515 +
2516 +typedef void (*noattr_t) (const char *, ...);
2517 +typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
2518 +
2519 +typedef void (*vnoattr_t) (const char *, va_list);
2520 +typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
2521 +
2522 +void
2523 +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
2524 +{
2525 +  noattr_t na1, na2;
2526 +  attr_t a1, a2;
2527 +
2528 +  vnoattr_t vna1, vna2;
2529 +  vattr_t va1, va2;
2530 +
2531 +  na1 = na;
2532 +  na2 = a; /* { dg-warning "candidate" "assignment warning" } */
2533 +  a1 = na;
2534 +  a2 = a;
2535 +
2536 +  vna1 = vna;
2537 +  vna2 = va; /* { dg-warning "candidate" "assignment warning" } */
2538 +  va1 = vna;
2539 +  va1 = va;
2540 +}
2541 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-5.c
2542 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2543 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-5.c   Mon Jun 02 08:07:23 2008 -0600
2544 @@ -0,0 +1,49 @@
2545 +/* Test warnings for missing format attributes on function pointers.  */
2546 +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
2547 +/* { dg-do compile { target { *-*-mingw* } } } */
2548 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2549 +
2550 +#define USE_SYSTEM_FORMATS
2551 +#include "format.h"
2552 +
2553 +typedef void (*noattr_t) (const char *, ...);
2554 +typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
2555 +
2556 +typedef void (*vnoattr_t) (const char *, va_list);
2557 +typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
2558 +
2559 +noattr_t
2560 +foo1 (noattr_t na, attr_t a, int i)
2561 +{
2562 +  if (i)
2563 +    return na;
2564 +  else
2565 +    return a; /* { dg-warning "candidate" "return type warning" } */
2566 +}
2567 +
2568 +attr_t
2569 +foo2 (noattr_t na, attr_t a, int i)
2570 +{
2571 +  if (i)
2572 +    return na;
2573 +  else
2574 +    return a;
2575 +}
2576 +
2577 +vnoattr_t
2578 +foo3 (vnoattr_t vna, vattr_t va, int i)
2579 +{
2580 +  if (i)
2581 +    return vna;
2582 +  else
2583 +    return va; /* { dg-warning "candidate" "return type warning" } */
2584 +}
2585 +
2586 +vattr_t
2587 +foo4 (vnoattr_t vna, vattr_t va, int i)
2588 +{
2589 +  if (i)
2590 +    return vna;
2591 +  else
2592 +    return va;
2593 +}
2594 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_miss-6.c
2595 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2596 +++ b/gcc/testsuite/gcc.dg/format/ms_miss-6.c   Mon Jun 02 08:07:23 2008 -0600
2597 @@ -0,0 +1,32 @@
2598 +/* Test warnings for missing format attributes on function pointers.  */
2599 +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
2600 +/* { dg-do compile { target { *-*-mingw* } } } */
2601 +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */
2602 +
2603 +#define USE_SYSTEM_FORMATS
2604 +#include "format.h"
2605 +
2606 +typedef void (*noattr_t) (const char *, ...);
2607 +typedef noattr_t __attribute__ ((__format__(__ms_printf__, 1, 2))) attr_t;
2608 +
2609 +typedef void (*vnoattr_t) (const char *, va_list);
2610 +typedef vnoattr_t __attribute__ ((__format__(__ms_printf__, 1, 0))) vattr_t;
2611 +
2612 +extern void foo1 (noattr_t);
2613 +extern void foo2 (attr_t);
2614 +extern void foo3 (vnoattr_t);
2615 +extern void foo4 (vattr_t);
2616 +
2617 +void
2618 +foo (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va)
2619 +{
2620 +  foo1 (na);
2621 +  foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */
2622 +  foo2 (na);
2623 +  foo2 (a);
2624 +
2625 +  foo3 (vna);
2626 +  foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */
2627 +  foo4 (vna);
2628 +  foo4 (va);
2629 +}
2630 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_multattr-1.c
2631 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2632 +++ b/gcc/testsuite/gcc.dg/format/ms_multattr-1.c       Mon Jun 02 08:07:23 2008 -0600
2633 @@ -0,0 +1,51 @@
2634 +/* Test for multiple format attributes.  Test for printf and scanf attributes
2635 +   together.  */
2636 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2637 +/* { dg-do compile { target { *-*-mingw* } } } */
2638 +/* { dg-options "-std=gnu99 -Wformat" } */
2639 +
2640 +#define USE_SYSTEM_FORMATS
2641 +#include "format.h"
2642 +
2643 +/* If we specify multiple attributes for a single function, they should
2644 +   all apply.  This should apply whether they are on the same declaration
2645 +   or on different declarations.  */
2646 +
2647 +extern void my_vprintf_scanf (const char *, va_list, const char *, ...)
2648 +     __attribute__((__format__(__ms_printf__, 1, 0)))
2649 +     __attribute__((__format__(__ms_scanf__, 3, 4)));
2650 +
2651 +extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...)
2652 +     __attribute__((__format__(__ms_scanf__, 3, 4)))
2653 +     __attribute__((__format__(__ms_printf__, 1, 0)));
2654 +
2655 +extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
2656 +     __attribute__((__format__(__ms_printf__, 1, 0)));
2657 +extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
2658 +     __attribute__((__format__(__ms_scanf__, 3, 4)));
2659 +
2660 +extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
2661 +     __attribute__((__format__(__ms_scanf__, 3, 4)));
2662 +extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
2663 +     __attribute__((__format__(__ms_printf__, 1, 0)));
2664 +
2665 +void
2666 +foo (va_list ap, int *ip, long *lp)
2667 +{
2668 +  my_vprintf_scanf ("%d", ap, "%d", ip);
2669 +  my_vprintf_scanf ("%d", ap, "%ld", lp);
2670 +  my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2671 +  my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2672 +  my_vprintf_scanf2 ("%d", ap, "%d", ip);
2673 +  my_vprintf_scanf2 ("%d", ap, "%ld", lp);
2674 +  my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2675 +  my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2676 +  my_vprintf_scanf3 ("%d", ap, "%d", ip);
2677 +  my_vprintf_scanf3 ("%d", ap, "%ld", lp);
2678 +  my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2679 +  my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2680 +  my_vprintf_scanf4 ("%d", ap, "%d", ip);
2681 +  my_vprintf_scanf4 ("%d", ap, "%ld", lp);
2682 +  my_vprintf_scanf4 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2683 +  my_vprintf_scanf4 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2684 +}
2685 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_multattr-2.c
2686 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2687 +++ b/gcc/testsuite/gcc.dg/format/ms_multattr-2.c       Mon Jun 02 08:07:23 2008 -0600
2688 @@ -0,0 +1,40 @@
2689 +/* Test for multiple format attributes.  Test for printf and scanf attributes
2690 +   together, in different places on the declarations.  */
2691 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2692 +/* { dg-do compile { target { *-*-mingw* } } } */
2693 +/* { dg-options "-std=gnu99 -Wformat" } */
2694 +
2695 +#define USE_SYSTEM_FORMATS
2696 +#include "format.h"
2697 +
2698 +/* If we specify multiple attributes for a single function, they should
2699 +   all apply, wherever they are placed on the declarations.  */
2700 +
2701 +extern __attribute__((__format__(__ms_printf__, 1, 0))) void
2702 +     my_vprintf_scanf (const char *, va_list, const char *, ...)
2703 +     __attribute__((__format__(__ms_scanf__, 3, 4)));
2704 +
2705 +extern void (__attribute__((__format__(__ms_printf__, 1, 0))) my_vprintf_scanf2)
2706 +     (const char *, va_list, const char *, ...)
2707 +     __attribute__((__format__(__ms_scanf__, 3, 4)));
2708 +
2709 +extern __attribute__((__format__(__ms_scanf__, 3, 4))) void
2710 +     (__attribute__((__format__(__ms_printf__, 1, 0))) my_vprintf_scanf3)
2711 +     (const char *, va_list, const char *, ...);
2712 +
2713 +void
2714 +foo (va_list ap, int *ip, long *lp)
2715 +{
2716 +  my_vprintf_scanf ("%d", ap, "%d", ip);
2717 +  my_vprintf_scanf ("%d", ap, "%ld", lp);
2718 +  my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2719 +  my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2720 +  my_vprintf_scanf2 ("%d", ap, "%d", ip);
2721 +  my_vprintf_scanf2 ("%d", ap, "%ld", lp);
2722 +  my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2723 +  my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2724 +  my_vprintf_scanf3 ("%d", ap, "%d", ip);
2725 +  my_vprintf_scanf3 ("%d", ap, "%ld", lp);
2726 +  my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */
2727 +  my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */
2728 +}
2729 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_multattr-3.c
2730 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2731 +++ b/gcc/testsuite/gcc.dg/format/ms_multattr-3.c       Mon Jun 02 08:07:23 2008 -0600
2732 @@ -0,0 +1,29 @@
2733 +/* Test for multiple format_arg attributes.  Test for both branches
2734 +   getting checked.  */
2735 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2736 +/* { dg-do compile { target { *-*-mingw* } } } */
2737 +/* { dg-options "-std=gnu99 -Wformat" } */
2738 +
2739 +#define USE_SYSTEM_FORMATS
2740 +#include "format.h"
2741 +
2742 +extern char *ngettext (const char *, const char *, unsigned long int)
2743 +     __attribute__((__format_arg__(1))) __attribute__((__format_arg__(2)));
2744 +
2745 +void
2746 +foo (long l, int nfoo)
2747 +{
2748 +  printf (ngettext ("%d foo", "%d foos", nfoo), nfoo);
2749 +  printf (ngettext ("%d foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
2750 +  printf (ngettext ("%d foo", "%ld foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
2751 +  printf (ngettext ("%ld foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
2752 +  /* Should allow one case to have extra arguments.  */
2753 +  printf (ngettext ("1 foo", "%d foos", nfoo), nfoo);
2754 +  printf (ngettext ("1 foo", "many foos", nfoo), nfoo); /* { dg-warning "too many" "too many args in all branches" } */
2755 +  printf (ngettext ("", "%d foos", nfoo), nfoo);
2756 +  printf (ngettext ("1 foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
2757 +  printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
2758 +  printf (ngettext ("%ld foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
2759 +  printf (ngettext ("%d foo", (nfoo > 0) ? "%ld foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
2760 +  printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "%ld foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
2761 +}
2762 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c
2763 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2764 +++ b/gcc/testsuite/gcc.dg/format/ms_no-exargs-1.c      Mon Jun 02 08:07:23 2008 -0600
2765 @@ -0,0 +1,15 @@
2766 +/* Test for warnings for extra format arguments being disabled by
2767 +   -Wno-format-extra-args.  */
2768 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2769 +/* { dg-do compile { target { *-*-mingw* } } } */
2770 +/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */
2771 +
2772 +#define USE_SYSTEM_FORMATS
2773 +#include "format.h"
2774 +
2775 +void
2776 +foo (int i)
2777 +{
2778 +  printf ("foo", i);
2779 +  printf ("%1$d", i, i);
2780 +}
2781 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c
2782 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2783 +++ b/gcc/testsuite/gcc.dg/format/ms_no-exargs-2.c      Mon Jun 02 08:07:23 2008 -0600
2784 @@ -0,0 +1,28 @@
2785 +/* Test for warnings for extra format arguments being disabled by
2786 +   -Wno-format-extra-args.  Test which warnings still apply with $
2787 +   operand numbers.  */
2788 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2789 +/* { dg-do compile { target { *-*-mingw* } } } */
2790 +/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */
2791 +
2792 +#define USE_SYSTEM_FORMATS
2793 +#include "format.h"
2794 +
2795 +void
2796 +foo (int i, int *ip, va_list va)
2797 +{
2798 +  printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */
2799 +  printf ("%2$d%1$d", i, i, i);
2800 +  vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */
2801 +  /* With scanf formats, gaps in the used arguments are allowed only if the
2802 +     arguments are all pointers.  In such a case, should only give the lesser
2803 +     warning about unused arguments rather than the more serious one about
2804 +     argument gaps.  */
2805 +  scanf ("%3$d%1$d", ip, ip, ip);
2806 +  /* If there are non-pointer arguments unused at the end, this is also OK.  */
2807 +  scanf ("%3$d%1$d", ip, ip, ip, i);
2808 +  scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */
2809 +  /* Can't check the arguments in the vscanf case, so should suppose the
2810 +     lesser problem.  */
2811 +  vscanf ("%3$d%1$d", va);
2812 +}
2813 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c
2814 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2815 +++ b/gcc/testsuite/gcc.dg/format/ms_no-y2k-1.c Mon Jun 02 08:07:23 2008 -0600
2816 @@ -0,0 +1,13 @@
2817 +/* Test for warnings for Y2K problems not being on by default.  */
2818 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2819 +/* { dg-do compile { target { *-*-mingw* } } } */
2820 +/* { dg-options "-std=gnu99 -Wformat" } */
2821 +
2822 +#define USE_SYSTEM_FORMATS
2823 +#include "format.h"
2824 +
2825 +void
2826 +foo (char *s, size_t m, const struct tm *tp)
2827 +{
2828 +  strftime (s, m, "%y%c%x", tp);
2829 +}
2830 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_nonlit-1.c
2831 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2832 +++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-1.c Mon Jun 02 08:07:23 2008 -0600
2833 @@ -0,0 +1,14 @@
2834 +/* Test for warnings for non-string-literal formats.  */
2835 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2836 +/* { dg-do compile { target { *-*-mingw* } } } */
2837 +/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
2838 +
2839 +#define USE_SYSTEM_FORMATS
2840 +#include "format.h"
2841 +
2842 +void
2843 +foo (char *s, size_t i)
2844 +{
2845 +  printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */
2846 +  printf (s, i); /* { dg-warning "argument types" "non-literal" } */
2847 +}
2848 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_nonlit-2.c
2849 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2850 +++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-2.c Mon Jun 02 08:07:23 2008 -0600
2851 @@ -0,0 +1,14 @@
2852 +/* Test for warnings for non-string-literal formats.  Test with -Wformat=2.  */
2853 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2854 +/* { dg-do compile { target { *-*-mingw* } } } */
2855 +/* { dg-options "-std=gnu99 -Wformat=2" } */
2856 +
2857 +#define USE_SYSTEM_FORMATS
2858 +#include "format.h"
2859 +
2860 +void
2861 +foo (char *s, size_t i)
2862 +{
2863 +  printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */
2864 +  printf (s, i); /* { dg-warning "argument types" "non-literal" } */
2865 +}
2866 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_nonlit-3.c
2867 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2868 +++ b/gcc/testsuite/gcc.dg/format/ms_nonlit-3.c Mon Jun 02 08:07:23 2008 -0600
2869 @@ -0,0 +1,13 @@
2870 +/* Test for warnings for non-string-literal formats.  Test for strftime formats.  */
2871 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2872 +/* { dg-do compile { target { *-*-mingw* } } } */
2873 +/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
2874 +
2875 +#define USE_SYSTEM_FORMATS
2876 +#include "format.h"
2877 +
2878 +void
2879 +foo (char *s, size_t m, const struct tm *tp, char *fmt)
2880 +{
2881 +  strftime (s, m, fmt, tp); /* { dg-warning "format string" "non-literal" } */
2882 +}
2883 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_nul-1.c
2884 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2885 +++ b/gcc/testsuite/gcc.dg/format/ms_nul-1.c    Mon Jun 02 08:07:23 2008 -0600
2886 @@ -0,0 +1,15 @@
2887 +/* Test diagnostics for suppressing contains nul
2888 +   -Wformat.  -Wformat.  */
2889 +/* Origin: Bruce Korb <bkorb@gnu.org> */
2890 +/* { dg-do compile { target { *-*-mingw* } } } */
2891 +/* { dg-options "-Wformat -Wno-format-contains-nul" } */
2892 +
2893 +#define USE_SYSTEM_FORMATS
2894 +#include "format.h"
2895 +
2896 +void
2897 +foo (void)
2898 +{
2899 +  static char const fmt[] = "x%s\0%s\n\0abc";
2900 +  printf (fmt+4, fmt+8); /* { dg-bogus "embedded.*in format" "bogus embed warning" } */
2901 +}
2902 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_nul-2.c
2903 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2904 +++ b/gcc/testsuite/gcc.dg/format/ms_nul-2.c    Mon Jun 02 08:07:23 2008 -0600
2905 @@ -0,0 +1,17 @@
2906 +/* Test diagnostics for options used on their own without
2907 +   -Wformat.  -Wformat-.  */
2908 +/* Origin: Bruce Korb <bkorb@gnu.org> */
2909 +/* { dg-do compile { target { *-*-mingw* } } } */
2910 +/* { dg-options "-Wformat" } */
2911 +
2912 +/* { dg-warning "embedded .* in format" "ignored" { target *-*-* } 0 } */
2913 +
2914 +#define USE_SYSTEM_FORMATS
2915 +#include "format.h"
2916 +
2917 +void
2918 +fumble (void)
2919 +{
2920 +  static char const fmt[] = "x%s\0%s\n\0abc";
2921 +  printf (fmt+4, fmt+8);
2922 +}
2923 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_null-1.c
2924 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2925 +++ b/gcc/testsuite/gcc.dg/format/ms_null-1.c   Mon Jun 02 08:07:23 2008 -0600
2926 @@ -0,0 +1,28 @@
2927 +/* Test for some aspects of null format string handling.  */
2928 +/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
2929 +/* { dg-do compile { target { *-*-mingw* } } } */
2930 +/* { dg-options "-std=gnu99 -Wformat" } */
2931 +
2932 +#define USE_SYSTEM_FORMATS
2933 +#include "format.h"
2934 +
2935 +extern void my_printf (const char *, ...) __attribute__((format(ms_printf,1,2)));
2936 +extern const char *my_format (const char *, const char *)
2937 +  __attribute__((format_arg(2)));
2938 +
2939 +void
2940 +foo (int i1)
2941 +{
2942 +  /* Warning about a null format string has been decoupled from the actual
2943 +     format check.  However, we still expect to be warned about any excess
2944 +     arguments after a null format string.  */
2945 +  my_printf (NULL);
2946 +  my_printf (NULL, i1); /* { dg-warning "too many" "null format with arguments" } */
2947 +
2948 +  my_printf (my_format ("", NULL));
2949 +  my_printf (my_format ("", NULL), i1); /* { dg-warning "too many" "null format_arg with arguments" } */
2950 +
2951 +  /* While my_printf allows a null argument, dgettext does not, so we expect
2952 +     a null argument warning here.  */
2953 +  my_printf (dgettext ("", NULL)); /* { dg-warning "null" "null format with dgettext" } */
2954 +}
2955 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_plus-1.c
2956 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2957 +++ b/gcc/testsuite/gcc.dg/format/ms_plus-1.c   Mon Jun 02 08:07:23 2008 -0600
2958 @@ -0,0 +1,21 @@
2959 +/* Test for printf formats using string literal plus constant.
2960 + */
2961 +/* Origin: Jakub Jelinek <jakub@redhat.com> */
2962 +/* { dg-do compile { target { *-*-mingw* } } } */
2963 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat=2" } */
2964 +
2965 +#define USE_SYSTEM_FORMATS
2966 +#include "format.h"
2967 +
2968 +void
2969 +foo (int i)
2970 +{
2971 +  printf ("%%d\n" + 1, i);
2972 +  printf (5 + "%.-*d%3d\n", i);
2973 +  printf ("%d%d" + 2, i, i);   /* { dg-warning "arguments" "wrong number of args" } */
2974 +  printf (3 + "%d\n");         /* { dg-warning "zero-length" "zero-length string" } */
2975 +  printf ("%d\n" + i, i);      /* { dg-warning "not a string" "non-constant addend" } */
2976 +  printf ("%d\n" + 10);                /* { dg-warning "not a string" "too large addend" } */
2977 +  printf ("%d\n" - 1, i);      /* { dg-warning "not a string" "minus constant" } */
2978 +  printf ("%d\n" + -1, i);     /* { dg-warning "not a string" "negative addend" } */
2979 +}
2980 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_sec-1.c
2981 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2982 +++ b/gcc/testsuite/gcc.dg/format/ms_sec-1.c    Mon Jun 02 08:07:23 2008 -0600
2983 @@ -0,0 +1,13 @@
2984 +/* Test for security warning when non-literal format has no arguments.  */
2985 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
2986 +/* { dg-do compile { target { *-*-mingw* } } } */
2987 +/* { dg-options "-std=gnu99 -Wformat -Wformat-security" } */
2988 +
2989 +#define USE_SYSTEM_FORMATS
2990 +#include "format.h"
2991 +
2992 +void
2993 +foo (char *s)
2994 +{
2995 +  printf (s); /* { dg-warning "no format arguments" "security warning" } */
2996 +}
2997 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_unnamed-1.c
2998 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
2999 +++ b/gcc/testsuite/gcc.dg/format/ms_unnamed-1.c        Mon Jun 02 08:07:23 2008 -0600
3000 @@ -0,0 +1,24 @@
3001 +/* Test for warnings with possibly unnamed integer types.  Bug 24329.  */
3002 +/* Origin: Joseph Myers <joseph@codesourcery.com> */
3003 +/* { dg-do compile { target { *-*-mingw* } } } */
3004 +/* { dg-options "-Wformat" } */
3005 +/* { dg-options "-Wformat -msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
3006 +
3007 +#define USE_SYSTEM_FORMATS
3008 +#include "format.h"
3009 +
3010 +/* Definition of TItype follows same logic as in gcc.dg/titype-1.c,
3011 +   but must be a #define to avoid giving the type a name.  */
3012 +#if defined(__LP64__) && !defined(__hppa__)
3013 +#define TItype int __attribute__ ((mode (TI)))
3014 +#else
3015 +#define TItype long
3016 +#endif
3017 +
3018 +void
3019 +f (TItype x)
3020 +{
3021 +  printf("%d", x); /* { dg-warning "expects type" } */
3022 +  printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */
3023 +  /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 22 } */
3024 +}
3025 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_va-1.c
3026 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
3027 +++ b/gcc/testsuite/gcc.dg/format/ms_va-1.c     Mon Jun 02 08:07:23 2008 -0600
3028 @@ -0,0 +1,14 @@
3029 +/* Test for strange warning in format checking.  */
3030 +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3031 +/* { dg-do compile { target { *-*-mingw* } } } */
3032 +/* { dg-options "-Wformat" } */
3033 +
3034 +#define USE_SYSTEM_FORMATS
3035 +#include "format.h"
3036 +
3037 +void
3038 +foo (void *p)
3039 +{
3040 +  printf ("%d", p); /* { dg-bogus "va_list" "wrong type in format warning" } */
3041 +  /* { dg-warning "format" "format error" { target *-*-* } 12 } */
3042 +}
3043 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/ms_zero-length-1.c
3044 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
3045 +++ b/gcc/testsuite/gcc.dg/format/ms_zero-length-1.c    Mon Jun 02 08:07:23 2008 -0600
3046 @@ -0,0 +1,16 @@
3047 +/* Test the -Wno-format-zero-length option, which suppresses warnings
3048 +   about zero-length formats.  */
3049 +/* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
3050 +/* { dg-do compile { target { *-*-mingw* } } } */
3051 +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-format-zero-length" } */
3052 +
3053 +#define USE_SYSTEM_FORMATS
3054 +#include "format.h"
3055 +
3056 +void
3057 +foo (void)
3058 +{
3059 +  /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134).  */
3060 +  /* Zero-length format strings are allowed.  */
3061 +  printf ("");
3062 +}
3063 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/multattr-1.c
3064 --- a/gcc/testsuite/gcc.dg/format/multattr-1.c  Thu May 29 20:27:38 2008 -0600
3065 +++ b/gcc/testsuite/gcc.dg/format/multattr-1.c  Mon Jun 02 08:07:23 2008 -0600
3066 @@ -4,6 +4,7 @@
3067  /* { dg-do compile } */
3068  /* { dg-options "-std=gnu99 -Wformat" } */
3069  
3070 +#define DONT_GNU_PROTOTYPE
3071  #include "format.h"
3072  
3073  /* If we specify multiple attributes for a single function, they should
3074 @@ -11,22 +12,22 @@
3075     or on different declarations.  */
3076  
3077  extern void my_vprintf_scanf (const char *, va_list, const char *, ...)
3078 -     __attribute__((__format__(__printf__, 1, 0)))
3079 -     __attribute__((__format__(__scanf__, 3, 4)));
3080 +     __attribute__((__format__(gnu_attr___printf__, 1, 0)))
3081 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
3082  
3083  extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...)
3084 -     __attribute__((__format__(__scanf__, 3, 4)))
3085 -     __attribute__((__format__(__printf__, 1, 0)));
3086 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)))
3087 +     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
3088  
3089  extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
3090 -     __attribute__((__format__(__printf__, 1, 0)));
3091 +     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
3092  extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...)
3093 -     __attribute__((__format__(__scanf__, 3, 4)));
3094 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
3095  
3096  extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
3097 -     __attribute__((__format__(__scanf__, 3, 4)));
3098 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
3099  extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...)
3100 -     __attribute__((__format__(__printf__, 1, 0)));
3101 +     __attribute__((__format__(gnu_attr___printf__, 1, 0)));
3102  
3103  void
3104  foo (va_list ap, int *ip, long *lp)
3105 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/multattr-2.c
3106 --- a/gcc/testsuite/gcc.dg/format/multattr-2.c  Thu May 29 20:27:38 2008 -0600
3107 +++ b/gcc/testsuite/gcc.dg/format/multattr-2.c  Mon Jun 02 08:07:23 2008 -0600
3108 @@ -4,21 +4,22 @@
3109  /* { dg-do compile } */
3110  /* { dg-options "-std=gnu99 -Wformat" } */
3111  
3112 +#define DONT_GNU_PROTOTYPE
3113  #include "format.h"
3114  
3115  /* If we specify multiple attributes for a single function, they should
3116     all apply, wherever they are placed on the declarations.  */
3117  
3118 -extern __attribute__((__format__(__printf__, 1, 0))) void
3119 +extern __attribute__((__format__(gnu_attr___printf__, 1, 0))) void
3120       my_vprintf_scanf (const char *, va_list, const char *, ...)
3121 -     __attribute__((__format__(__scanf__, 3, 4)));
3122 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
3123  
3124 -extern void (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf2)
3125 +extern void (__attribute__((__format__(gnu_attr___printf__, 1, 0))) my_vprintf_scanf2)
3126       (const char *, va_list, const char *, ...)
3127 -     __attribute__((__format__(__scanf__, 3, 4)));
3128 +     __attribute__((__format__(gnu_attr___scanf__, 3, 4)));
3129  
3130 -extern __attribute__((__format__(__scanf__, 3, 4))) void
3131 -     (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf3)
3132 +extern __attribute__((__format__(gnu_attr___scanf__, 3, 4))) void
3133 +     (__attribute__((__format__(gnu_attr___printf__, 1, 0))) my_vprintf_scanf3)
3134       (const char *, va_list, const char *, ...);
3135  
3136  void
3137 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/null-1.c
3138 --- a/gcc/testsuite/gcc.dg/format/null-1.c      Thu May 29 20:27:38 2008 -0600
3139 +++ b/gcc/testsuite/gcc.dg/format/null-1.c      Mon Jun 02 08:07:23 2008 -0600
3140 @@ -3,9 +3,10 @@
3141  /* { dg-do compile } */
3142  /* { dg-options "-std=gnu99 -Wformat" } */
3143  
3144 +#define DONT_GNU_PROTOTYPE
3145  #include "format.h"
3146  
3147 -extern void my_printf (const char *, ...) __attribute__((format(printf,1,2)));
3148 +extern void my_printf (const char *, ...) __attribute__((format(gnu_attr_printf,1,2)));
3149  extern const char *my_format (const char *, const char *)
3150    __attribute__((format_arg(2)));
3151  
3152 diff -r ddadaee88373 gcc/testsuite/gcc.dg/format/sys_format.c
3153 --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
3154 +++ b/gcc/testsuite/gcc.dg/format/sys_format.c  Mon Jun 02 08:07:23 2008 -0600
3155 @@ -0,0 +1,14 @@
3156 +/* Test system default printf formatter specifiers.  */
3157 +/* Origin: Kai Tietz <KaiTietz.@onevision.com> */
3158 +/* { dg-do compile { target { *-*-mingw* } } } */
3159 +/* { dg-options "-std=gnu89" } */
3160 +
3161 +#define USE_SYSTEM_FORMATS
3162 +#include "format.h"
3163 +
3164 +__attribute__((format(printf, 1, 2))) void foo (const char *, ...);
3165 +
3166 +void bar (long long v1, long v2, int v3)
3167 +{
3168 +  foo ("%I64d %I32d %ld %d\n", v1, v2, v2, v3);
3169 +}
This page took 0.531939 seconds and 3 git commands to generate.