OSDN Git Service

2008-10-13 Kai Tietz <kai.tietz@onevision.com>
authorktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 Oct 2008 10:32:07 +0000 (10:32 +0000)
committerktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 13 Oct 2008 10:32:07 +0000 (10:32 +0000)
Fix PR/25502
* c-format.c (convert_format_name_to_system_name): Use
TARGET_OVERRIDES_FORMAT_INIT.
* config.gcc (extra_options): Add for mingw targets mingw.opt.
* config/i386/mingw.opt: New.
* config/i386/mingw32.h (TARGET_OVERRIDES_FORMAT_INIT): New.
* config/i386/msformat-c.c (TARGET_OVERRIDES_FORMAT_INIT): New.
(ms_printf_length_specs): Removed const specifier.
* doc/tm.texi (TARGET_OVERRIDES_FORMAT_INIT): New.
* doc/invoke.texi (Wno-pedantic-ms-format): New.
* testsuite/gcc.dg/format/ms-format1.c: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@141087 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-format.c
gcc/config.gcc
gcc/config/i386/mingw.opt [new file with mode: 0644]
gcc/config/i386/mingw32.h
gcc/config/i386/msformat-c.c
gcc/doc/invoke.texi
gcc/doc/tm.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/format/ms-format1.c [new file with mode: 0644]

index 8838c41..ff7533a 100644 (file)
@@ -1,3 +1,16 @@
+2008-10-13  Kai Tietz  <kai.tietz@onevision.com>
+
+       Fix PR/25502
+       * c-format.c (convert_format_name_to_system_name): Use
+       TARGET_OVERRIDES_FORMAT_INIT.
+       * config.gcc (extra_options): Add for mingw targets mingw.opt.
+       * config/i386/mingw.opt: New.
+       * config/i386/mingw32.h (TARGET_OVERRIDES_FORMAT_INIT): New.
+       * config/i386/msformat-c.c (TARGET_OVERRIDES_FORMAT_INIT): New.
+       (ms_printf_length_specs): Removed const specifier.
+       * doc/tm.texi (TARGET_OVERRIDES_FORMAT_INIT): New.
+       * doc/invoke.texi (Wno-pedantic-ms-format): New.
+
 2008-10-13  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * builtins.c: Remove MPFR_VERSION_NUM(2,3,0) conditionals.
index fa28763..2f1370e 100644 (file)
@@ -2714,6 +2714,9 @@ extern const format_kind_info TARGET_FORMAT_TYPES[];
 #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
 extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[];
 #endif
+#ifdef TARGET_OVERRIDES_FORMAT_INIT
+  extern void TARGET_OVERRIDES_FORMAT_INIT (void);
+#endif
 
 /* Attributes such as "printf" are equivalent to those such as
    "gnu_printf" unless this is overridden by a target.  */
@@ -2738,6 +2741,9 @@ convert_format_name_to_system_name (const char *attr_name)
   if (attr_name == NULL || *attr_name == 0
       || strncmp (attr_name, "gcc_", 4) == 0)
     return attr_name;
+#ifdef TARGET_OVERRIDES_FORMAT_INIT
+  TARGET_OVERRIDES_FORMAT_INIT ();
+#endif
 
 #ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
   /* Check if format attribute is overridden by target.  */
index 8f31bde..c10e7f9 100644 (file)
@@ -1270,7 +1270,7 @@ i[34567]86-*-mingw* | x86_64-*-mingw*)
        xm_file=i386/xm-mingw32.h
        tmake_file="${tmake_file} i386/t-cygming i386/t-mingw32"
        target_gtfiles="\$(srcdir)/config/i386/winnt.c"
-       extra_options="${extra_options} i386/cygming.opt"
+       extra_options="${extra_options} i386/cygming.opt i386/mingw.opt"
        extra_objs="winnt.o winnt-stubs.o"
        c_target_objs="${c_target_objs} msformat-c.o"
        cxx_target_objs="${cxx_target_objs} winnt-cxx.o msformat-c.o"
diff --git a/gcc/config/i386/mingw.opt b/gcc/config/i386/mingw.opt
new file mode 100644 (file)
index 0000000..6be904e
--- /dev/null
@@ -0,0 +1,23 @@
+; MinGW-specific options.
+
+; Copyright (C) 2008 Free Software Foundation, Inc.
+;
+; This file is part of GCC.
+;
+; GCC is free software; you can redistribute it and/or modify it under
+; the terms of the GNU General Public License as published by the Free
+; Software Foundation; either version 3, or (at your option) any later
+; version.
+;
+; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+; WARRANTY; without even the implied warranty of MERCHANTABILITY or
+; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+; for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with GCC; see the file COPYING3.  If not see
+; <http://www.gnu.org/licenses/>.
+
+Wpedantic-ms-format
+C ObjC C++ ObjC++ Var(warn_pedantic_ms_format) Init(1) Warning
+Warn about none ISO msvcrt scanf/printf width extensions
index b4137ea..2526665 100644 (file)
@@ -169,6 +169,10 @@ do {                                                        \
 #undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
 #define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3
 
+/* Custom initialization for warning -Wpedantic-ms-format for c-format.  */
+#undef TARGET_OVERRIDES_FORMAT_INIT
+#define TARGET_OVERRIDES_FORMAT_INIT msformat_init
+
 /* MS specific format attributes for ms_printf, ms_scanf, ms_strftime.  */
 #undef TARGET_FORMAT_TYPES
 #define TARGET_FORMAT_TYPES mingw_format_attributes
index 9036555..44e080d 100644 (file)
@@ -34,7 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Mingw specific format attributes ms_printf, ms_scanf, and ms_strftime.  */
 
-static const format_length_info ms_printf_length_specs[] =
+static format_length_info ms_printf_length_specs[] =
 {
   { "h", FMT_LEN_h, STD_C89, NULL, 0, 0 },
   { "l", FMT_LEN_l, STD_C89, NULL, 0, 0 },
@@ -173,3 +173,25 @@ const target_ovr_attr mingw_format_attribute_overrides[4] =
   { "ms_scanf", "scanf" },
   { "ms_strftime", "strftime" }
 };
+
+/* Setup for option Wpedantic-ms-format.  */
+
+#ifdef TARGET_OVERRIDES_FORMAT_INIT
+
+/* Make sure TARGET_OVERRIDES_FORMAT_INIT is prototyped.  */
+extern void TARGET_OVERRIDES_FORMAT_INIT (void);
+
+/* Helper.  */
+#define C89_OR_EXT (warn_pedantic_ms_format ? STD_EXT : STD_C89)
+
+void
+TARGET_OVERRIDES_FORMAT_INIT (void)
+{
+  ms_printf_length_specs[2].std = C89_OR_EXT; /* I32 */
+  ms_printf_length_specs[3].std = C89_OR_EXT; /* I64 */
+  ms_printf_length_specs[4].std = C89_OR_EXT; /* I */
+}
+
+#undef C89_OR_EXT
+
+#endif
index c5c47fe..d17ef60 100644 (file)
@@ -250,7 +250,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wmissing-noreturn  -Wno-mudflap @gol
 -Wno-multichar  -Wnonnull  -Wno-overflow @gol
 -Woverlength-strings  -Wpacked  -Wpadded @gol
--Wparentheses  -Wpointer-arith  -Wno-pointer-to-int-cast @gol
+-Wparentheses  -Wpedantic-ms-format -Wno-pedantic-ms-format @gol
+-Wpointer-arith  -Wno-pointer-to-int-cast @gol
 -Wredundant-decls @gol
 -Wreturn-type  -Wsequence-point  -Wshadow @gol
 -Wsign-compare  -Wsign-conversion  -Wstack-protector @gol
@@ -3572,6 +3573,14 @@ assume anything on the bounds of the loop indices.  With
 @option{-funsafe-loop-optimizations} warn if the compiler made
 such assumptions.
 
+@item -Wno-pedantic-ms-format
+@opindex Wno-pedantic-ms-format
+@opindex Wpedantic-ms-format
+Disables the warnings about non-ISO @code{printf} / @code{scanf} format
+width specifiers @code{I32}, @code{I64}, and @code{I} used on Windows targets
+depending on the MS runtime, when you are using the options @option{-Wformat}
+and @option{-pedantic} without gnu-extensions.
+
 @item -Wpointer-arith
 @opindex Wpointer-arith
 @opindex Wno-pointer-arith
index 2b85f90..28f3d7f 100644 (file)
@@ -10539,6 +10539,12 @@ If defined, this macro specifies the number of entries in
 @code{TARGET_OVERRIDES_FORMAT_ATTRIBUTES}.
 @end defmac
 
+@defmac TARGET_OVERRIDES_FORMAT_INIT
+If defined, this macro specifies the optional initialization
+routine for target specific customizations of the system printf
+and scanf formatter settings.
+@end defmac
+
 @deftypefn {Target Hook} bool TARGET_RELAXED_ORDERING
 If set to @code{true}, means that the target's memory model does not
 guarantee that loads which do not depend on one another will access
index a3f7738..592dc58 100644 (file)
@@ -1,3 +1,7 @@
+2008-10-13  Kai Tietz  <kai.tietz@onevision.com>
+
+       * testsuite/gcc.dg/format/ms-format1.c: New.
+
 2008-10-12  Daniel Kraft  <d@domob.eu>
 
        PR fortran/37688
diff --git a/gcc/testsuite/gcc.dg/format/ms-format1.c b/gcc/testsuite/gcc.dg/format/ms-format1.c
new file mode 100644 (file)
index 0000000..81c21d9
--- /dev/null
@@ -0,0 +1,17 @@
+/* Test for printf formats.  Formats using extensions to the standard
+   should be rejected in strict pedantic mode. But allowed by -Wno-pedantic-ms-format.
+*/
+/* Origin: Kai Tietz <kai.tietz@onevision.com> */
+/* { dg-do compile { target { *-*-mingw* } } } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat -Wno-pedantic-ms-format" } */
+
+#define USE_SYSTEM_FORMATS
+#include "format.h"
+
+void
+foo (int i, long long ll, size_t z)
+{
+  printf ("%I32d", i);
+  printf ("%I64x", ll);
+  printf ("%Ix", z);
+}