From: ktietz Date: Mon, 13 Oct 2008 10:32:07 +0000 (+0000) Subject: 2008-10-13 Kai Tietz X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78e16ab5562671ddce186cccf332c0c9fedbc3b9;p=thirdparty%2Fgcc.git 2008-10-13 Kai Tietz 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8838c4144838..ff7533ade005 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2008-10-13 Kai Tietz + + 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 * builtins.c: Remove MPFR_VERSION_NUM(2,3,0) conditionals. diff --git a/gcc/c-format.c b/gcc/c-format.c index fa28763028f9..2f1370e44fe7 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 8f31bdef144b..c10e7f9fdacf 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 000000000000..6be904e968a2 --- /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 +; . + +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 b4137ea13940..25266653042d 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 90365557a69e..44e080d45573 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 c5c47fed86fe..d17ef6009181 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 2b85f909d759..28f3d7ffa751 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 a3f773803bf5..592dc585d5cb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-10-13 Kai Tietz + + * testsuite/gcc.dg/format/ms-format1.c: New. + 2008-10-12 Daniel Kraft 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 000000000000..81c21d911e58 --- /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 */ +/* { 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); +}