aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKai Tietz <kai.tietz@onevision.com>2008-10-13 10:32:07 +0000
committerKai Tietz <ktietz@gcc.gnu.org>2008-10-13 12:32:07 +0200
commit945648261c44e52fb0a02ee9233382248edf9896 (patch)
tree6b5e20bdfb092f077651b8c498e3001d78912b1e /gcc
parent36c713e04cb642a9bfbf4ddbad9ef7024dd6f05a (diff)
downloadgcc-945648261c44e52fb0a02ee9233382248edf9896.zip
gcc-945648261c44e52fb0a02ee9233382248edf9896.tar.gz
gcc-945648261c44e52fb0a02ee9233382248edf9896.tar.bz2
Fix PR/25502
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. * testsuite/gcc.dg/format/ms-format1.c: New. From-SVN: r141087
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/c-format.c6
-rw-r--r--gcc/config.gcc2
-rw-r--r--gcc/config/i386/mingw.opt23
-rw-r--r--gcc/config/i386/mingw32.h4
-rw-r--r--gcc/config/i386/msformat-c.c24
-rw-r--r--gcc/doc/invoke.texi11
-rw-r--r--gcc/doc/tm.texi6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/format/ms-format1.c17
10 files changed, 107 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8838c41..ff7533a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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.
diff --git a/gcc/c-format.c b/gcc/c-format.c
index fa28763..2f1370e 100644
--- a/gcc/c-format.c
+++ b/gcc/c-format.c
@@ -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. */
diff --git a/gcc/config.gcc b/gcc/config.gcc
index 8f31bde..c10e7f9 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -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
index 0000000..6be904e
--- /dev/null
+++ b/gcc/config/i386/mingw.opt
@@ -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
diff --git a/gcc/config/i386/mingw32.h b/gcc/config/i386/mingw32.h
index b4137ea..2526665 100644
--- a/gcc/config/i386/mingw32.h
+++ b/gcc/config/i386/mingw32.h
@@ -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
diff --git a/gcc/config/i386/msformat-c.c b/gcc/config/i386/msformat-c.c
index 9036555..44e080d 100644
--- a/gcc/config/i386/msformat-c.c
+++ b/gcc/config/i386/msformat-c.c
@@ -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
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index c5c47fe..d17ef60 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 2b85f90..28f3d7f 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a3f7738..592dc58 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..81c21d9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ms-format1.c
@@ -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);
+}