public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kai Tietz <Kai.Tietz@onevision.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: Danny Smith <dansmister@gmail.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	        NightStrike <nightstrike@gmail.com>
Subject: Re: Ping - old patch from April - mingw support for I32/I64 MS printf    formatters to c-format.c
Date: Mon, 07 Jan 2008 13:56:00 -0000	[thread overview]
Message-ID: <OFD8E09BCD.E7899FFC-ONC12573C9.0037DD89-C12573C9.003A2D35@onevision.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0712211316490.2090@digraph.polyomino.org.uk>

[-- Attachment #1: Type: text/plain, Size: 3559 bytes --]

Hi Joseph,

"Joseph S. Myers" wrote on 21.12.2007 14:19:57:

> On Fri, 21 Dec 2007, Kai Tietz wrote:
> 
> > There is a problem with the fortran compiler and this patch. The 
fortran 
> > compiler inherits i386.c as target, but does not have the 
c_global_trees 
> > symbol, which is referenced by the formatter tables. So this patch 
will 
> > fail for it. To solve this, I suggest, that the tables should be 
placed 
> > within c-format.c. Is this ok for you ?
> 
> No, you should put it in a new *-c.c file listed in c_target_objs and 
> cxx_target_objs in config.gcc and add the necessary rule to the 
associated 
> t-* file to build this object.  sol2-c.c has an existing example of 
> target-specific formats.

Thanks for you hint. I moved the formatter rules for the ms style in 
/config/i386/msformat-c.c and added the rules in config.gcc for it.

Ok, while running the testsuite I noticed, that at some places the 
formatter "%ld" is used together with an "int" type, which isn't marked to 
produce a warning. Which is at least for x86_64 linux targets a problem. I 
see on my tests that it got warned correctly as it should be a long.
Just for "printf/scanf/strftime" formatters, there are some problems, the 
other formatters seems to work as before.

I needed to add a special prefix to the format char definition to allow 
multi-charaters here. I choose the \0, but may you have an better idea for 
that?

The ChangeLog so far:

2008-01-07      Kai Tietz  <kai.tietz@onevision.com>

        * gcc/c-format.c: (replace_formatter_name_to_system_name): New.
        (compare_tofa): New.
        (decode_format_attr): Use of 
replace_formatter_name_to_system_name.
        (format_types_orig): Add gnu_ prefix to names.
        (check_format_info_main): Special treating of \0 escaped names for
        supporting multi-character formatters as I32, I64.
        (TARGET_OVERRIDES_FORMAT_ATTRIBUTES): Use of user defined 
attributes.
        (gnu_target_overrides_format_attributes): New.
        * gcc/c-format.h: Add structure target_ovr_attr to hold
        system specific formatter names.
        * gcc/config.gcc: Add for x86&x86_64 cygwin and mingw32 targets 
the
        msformat-c.o file to c_target_objs and cxx_target_objs.
        * gcc/config/i386/mingw32.h: (TARGET_OVERRIDES_FORMAT_ATTRIBUTES): 
New.
        (TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT): New.
        (TARGET_N_FORMAT_TYPES): New.
        * gcc/config/i386/msformat-c.c: New.
        * gcc/config/i386/t-cygming: Add build rule for msformat-c.o.
        * gcc/doc/extend.texi: Add new format names gnu_* and ms_*.
        * gcc/doc/tm.texi: (TARGET_OVERRIDES_FORMAT_ATTRIBUTES): New.
        * gcc/testsuite/gcc.dg/format/sys_formatter.c: New.

Cheers,
 i.A. Kai Tietz



|  (\_/)  This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-Straße 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  Komplementärin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-Straße 9 – 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - Geschäftsführer: 
Ulrike Döhler, Manuela Kluger



[-- Attachment #2: mingw-msformat.txt --]
[-- Type: text/plain, Size: 23433 bytes --]

Index: gcc/gcc/c-format.c
===================================================================
--- gcc.orig/gcc/c-format.c
+++ gcc/gcc/c-format.c
@@ -80,7 +80,8 @@ static bool check_format_string (tree ar
 				 int flags, bool *no_add_attrs);
 static bool get_constant (tree expr, unsigned HOST_WIDE_INT *value,
 			  int validated_p);
-
+static const char *replace_formatter_name_to_system_name (const char *attr_name);
+static int compare_tofa (const char *tattr_name, const char *attr_name);
 
 /* Handle a "format_arg" attribute; arguments as in
    struct attribute_spec.handler.  */
@@ -191,6 +192,8 @@ decode_format_attr (tree args, function_
     {
       const char *p = IDENTIFIER_POINTER (format_type_id);
 
+      p = replace_formatter_name_to_system_name (p);
+
       info->format_type = decode_format_type (p);
 
       if (info->format_type == format_type_error)
@@ -715,7 +718,7 @@ static const format_char_info monetary_c
 /* This must be in the same order as enum format_type.  */
 static const format_kind_info format_types_orig[] =
 {
-  { "printf",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
+  { "gnu_printf",   printf_length_specs,  print_char_table, " +#0-'I", NULL,
     printf_flag_specs, printf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
     'w', 0, 'p', 0, 'L', 0,
@@ -757,18 +760,18 @@ static const format_kind_info format_typ
     0, 0, 0, 0, 0, 0,
     NULL, NULL
   },
-  { "scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
+  { "gnu_scanf",    scanf_length_specs,   scan_char_table,  "*'I", NULL,
     scanf_flag_specs, scanf_flag_pairs,
     FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
     'w', 0, 0, '*', 'L', 'm',
     NULL, NULL
   },
-  { "strftime", NULL,                 time_char_table,  "_-0^#", "EO",
+  { "gnu_strftime", NULL,                 time_char_table,  "_-0^#", "EO",
     strftime_flag_specs, strftime_flag_pairs,
     FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0, 0,
     NULL, NULL
   },
-  { "strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
+  { "gnu_strfmon",  strfmon_length_specs, monetary_char_table, "=^+(!-", NULL,
     strfmon_flag_specs, strfmon_flag_pairs,
     FMT_FLAG_ARG_CONVERT, 'w', '#', 'p', 0, 'L', 0,
     NULL, NULL
@@ -847,6 +850,7 @@ decode_format_type (const char *s)
 {
   int i;
   int slen;
+  s = replace_formatter_name_to_system_name (s);
   slen = strlen (s);
   for (i = 0; i < n_format_types; i++)
     {
@@ -1776,7 +1780,22 @@ check_format_info_main (format_check_res
       if (fli)
 	{
 	  while (fli->name != 0 && fli->name[0] != *format_chars)
-	    fli++;
+	    {
+	      if (fli->name[0] == '\0')
+		{
+		  int si  = strlen (fli->name + 1) + 1;
+		  int i = 1;
+		  while (fli->name[i] != 0 && fli->name[i] == format_chars [i - 1])
+		    ++i;
+		 if (si == i)
+		   {
+		     if (si > 2)
+		       format_chars += si - 2;
+		     break;
+		   }
+	       }
+	      fli++;
+	    }
 	  if (fli->name != 0)
 	    {
 	      format_chars++;
@@ -2703,6 +2722,72 @@ init_dynamic_diag_info (void)
 extern const format_kind_info TARGET_FORMAT_TYPES[];
 #endif
 
+#ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
+extern const target_ovr_attr TARGET_OVERRIDES_FORMAT_ATTRIBUTES[];
+#endif
+
+/* Description of gnu specific format attributes reflected to
+   system format attribute types, as printf, scanf, strftime, and
+   strfmon.  */
+const target_ovr_attr gnu_target_overrides_format_attributes[] =
+{
+  { "gnu_printf",   "printf" },
+  { "gnu_scanf",    "scanf" },
+  { "gnu_strftime", "strftime" },
+  { "gnu_strfmon",  "strfmon" },
+  { NULL,           NULL }
+};
+
+static const char *
+replace_formatter_name_to_system_name (const char *attr_name)
+{
+  int i;
+
+  if (attr_name == NULL || *attr_name == 0 || strncmp (attr_name, "gcc_", 4) == 0)
+    return attr_name;
+
+#ifdef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
+  /* Check if format attribute is overridden by target.  */
+  if (TARGET_OVERRIDES_FORMAT_ATTRIBUTES != NULL && TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT > 0)
+    {
+      for (i = 0; i < TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT; ++i)
+        {
+          if (compare_tofa (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src, attr_name))
+            return attr_name;
+          if (compare_tofa (TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_dst, attr_name))
+            return TARGET_OVERRIDES_FORMAT_ATTRIBUTES[i].named_attr_src;
+        }
+    }
+#endif
+  /* Otherwise default to gnu formatter.  */
+  for (i = 0; gnu_target_overrides_format_attributes[i].named_attr_src != NULL; ++i)
+    {
+      if (compare_tofa (gnu_target_overrides_format_attributes[i].named_attr_src, attr_name))
+        return attr_name;
+      if (compare_tofa (gnu_target_overrides_format_attributes[i].named_attr_dst, attr_name))
+        return gnu_target_overrides_format_attributes[i].named_attr_src;
+    }
+
+  return attr_name;
+}
+
+/* Compare the target override format attribute by treating double underscore syntax.  */
+static int
+compare_tofa (const char *tattr_name, const char *attr_name)
+{
+  int alen = strlen (attr_name);
+  int slen = (tattr_name ? strlen (tattr_name) : 0);
+  if (alen > 4 && attr_name[0] == '_' && attr_name[1] == '_'
+      && attr_name[alen - 1] == '_' && attr_name[alen - 2] == '_')
+    {
+      attr_name += 2;
+      alen -= 4;
+    }
+  if (alen != slen || strncmp (tattr_name, attr_name, alen) != 0)
+    return 0;
+  return 1;
+}
+
 /* Handle a "format" attribute; arguments as in
    struct attribute_spec.handler.  */
 tree
Index: gcc/gcc/c-format.h
===================================================================
--- gcc.orig/gcc/c-format.h
+++ gcc/gcc/c-format.h
@@ -306,4 +306,18 @@ typedef struct
 #define T_D128  &dfloat128_type_node
 #define TEX_D128 { STD_EXT, "_Decimal128", T_D128 }
 
+/* Structure describing the target specific to be override formatter
+   attributes, e.g. printf, scanf, etc.  This allows to support different
+   runtime-library specific formatter attributes to co-exist and defining
+   a default system version.
+   This type is used for the pointer variable TARGET_OVERRIDES_FORMAT_ATTRIBUTES
+   refers to.  */
+typedef struct
+{
+  /* The name of the to be copied formatter attribute. */
+  const char *named_attr_src;
+  /* The name of the to be overridden formatter attribute. */
+  const char *named_attr_dst;
+} target_ovr_attr;
+
 #endif /* GCC_C_FORMAT_H */
Index: gcc/gcc/config.gcc
===================================================================
--- gcc.orig/gcc/config.gcc
+++ gcc/gcc/config.gcc
@@ -1359,8 +1359,8 @@ i[34567]86-*-pe | i[34567]86-*-cygwin*)
 	target_gtfiles="\$(srcdir)/config/i386/winnt.c"
 	extra_options="${extra_options} i386/cygming.opt"
 	extra_objs="winnt.o winnt-stubs.o"
-	c_target_objs=cygwin2.o
-	cxx_target_objs="cygwin2.o winnt-cxx.o"
+	c_target_objs="cygwin2.o msformat-c.o"
+	cxx_target_objs="cygwin2.o winnt-cxx.o msformat-c.o"
 	extra_gcc_objs=cygwin1.o
 	if test x$enable_threads = xyes; then
 		thread_file='posix'
@@ -1373,7 +1373,8 @@ i[34567]86-*-mingw32* | x86_64-*-mingw32
 	target_gtfiles="\$(srcdir)/config/i386/winnt.c"
 	extra_options="${extra_options} i386/cygming.opt"
 	extra_objs="winnt.o winnt-stubs.o"
-	cxx_target_objs=winnt-cxx.o
+	c_target_objs="msformat-c.o"
+	cxx_target_objs="winnt-cxx.o msformat-c.o"
 	default_use_cxa_atexit=yes
 	case ${enable_threads} in
 	  "" | yes | win32)
Index: gcc/gcc/config/i386/mingw32.h
===================================================================
--- gcc.orig/gcc/config/i386/mingw32.h
+++ gcc/gcc/config/i386/mingw32.h
@@ -143,6 +143,22 @@ do {						         \
    to register C++ static destructors.  */
 #define TARGET_CXX_USE_ATEXIT_FOR_CXA_ATEXIT hook_bool_void_true
 
+/* Contains a pointer to type target_ovr_attr defining the target specific
+   overrides of formatter attributs.  See format.h for structure definition.  */
+#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES
+#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES mingw_formatter_attribute_overrides
+
+/* Specify the count of elements in TARGET_OVERRIDES_ATTRIBUTE.  */
+#undef TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
+#define TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT 3
+
+/* MS specific format attributes for ms_printf, ms_scanf, ms_strftime.  */
+#undef TARGET_FORMAT_TYPES
+#define TARGET_FORMAT_TYPES mingw_formatter_attributes
+
+#undef TARGET_N_FORMAT_TYPES
+#define TARGET_N_FORMAT_TYPES 3
+
 /* JCR_SECTION works on mingw32.  */
 #undef TARGET_USE_JCR_SECTION
 #define TARGET_USE_JCR_SECTION 1
Index: gcc/gcc/config/i386/msformat-c.c
===================================================================
--- /dev/null
+++ gcc/gcc/config/i386/msformat-c.c
@@ -0,0 +1,189 @@
+/* Check calls to formatted I/O functions (-Wformat).
+   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001, 2002, 2003, 2004, 2005, 2007 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/>.  */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "flags.h"
+#include "c-common.h"
+#include "toplev.h"
+#include "intl.h"
+#include "diagnostic.h"
+#include "langhooks.h"
+#include "c-format.h"
+#include "alloc-pool.h"
+
+/* Mingw specific format attributes ms_printf, ms_scanf, and ms_strftime.  */
+
+static const 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 },
+  { "\0I32", FMT_LEN_l, STD_C89, NULL, 0, 0 },
+  { "\0I64", FMT_LEN_ll, STD_C9L, NULL, 0, 0 },
+  { "I", FMT_LEN_L, STD_C89, NULL, 0, 0 },
+  { NULL, 0, 0, NULL, 0, 0 }
+};
+
+static const format_flag_spec ms_printf_flag_specs[] =
+{
+  { ' ',  0, 0, N_("' ' flag"),        N_("the ' ' printf flag"),              STD_C89 },
+  { '+',  0, 0, N_("'+' flag"),        N_("the '+' printf flag"),              STD_C89 },
+  { '#',  0, 0, N_("'#' flag"),        N_("the '#' printf flag"),              STD_C89 },
+  { '0',  0, 0, N_("'0' flag"),        N_("the '0' printf flag"),              STD_C89 },
+  { '-',  0, 0, N_("'-' flag"),        N_("the '-' printf flag"),              STD_C89 },
+  { '\'', 0, 0, N_("''' flag"),        N_("the ''' printf flag"),              STD_EXT },
+  { 'w',  0, 0, N_("field width"),     N_("field width in printf format"),     STD_C89 },
+  { '.',  0, 0, N_("precision"),       N_("precision in printf format"),       STD_C89 },
+  { 'L',  0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
+  { 0, 0, 0, NULL, NULL, 0 }
+};
+
+static const format_flag_pair ms_printf_flag_pairs[] =
+{
+  { ' ', '+', 1, 0   },
+  { '0', '-', 1, 0   },
+  { 0, 0, 0, 0 }
+};
+
+static const format_flag_spec ms_scanf_flag_specs[] =
+{
+  { '*',  0, 0, N_("assignment suppression"), N_("the assignment suppression scanf feature"), STD_C89 },
+  { 'a',  0, 0, N_("'a' flag"),               N_("the 'a' scanf flag"),                       STD_EXT },
+  { 'w',  0, 0, N_("field width"),            N_("field width in scanf format"),              STD_C89 },
+  { 'L',  0, 0, N_("length modifier"),        N_("length modifier in scanf format"),          STD_C89 },
+  { '\'', 0, 0, N_("''' flag"),               N_("the ''' scanf flag"),                       STD_EXT },
+  { 0, 0, 0, NULL, NULL, 0 }
+};
+
+static const format_flag_pair ms_scanf_flag_pairs[] =
+{
+  { '*', 'L', 0, 0 },
+  { 0, 0, 0, 0 }
+};
+
+static const format_flag_spec ms_strftime_flag_specs[] =
+{
+  { '_', 0,   0, N_("'_' flag"),     N_("the '_' strftime flag"),          STD_EXT },
+  { '-', 0,   0, N_("'-' flag"),     N_("the '-' strftime flag"),          STD_EXT },
+  { '0', 0,   0, N_("'0' flag"),     N_("the '0' strftime flag"),          STD_EXT },
+  { '^', 0,   0, N_("'^' flag"),     N_("the '^' strftime flag"),          STD_EXT },
+  { '#', 0,   0, N_("'#' flag"),     N_("the '#' strftime flag"),          STD_EXT },
+  { 'w', 0,   0, N_("field width"),  N_("field width in strftime format"), STD_EXT },
+  { 'E', 0,   0, N_("'E' modifier"), N_("the 'E' strftime modifier"),      STD_C99 },
+  { 'O', 0,   0, N_("'O' modifier"), N_("the 'O' strftime modifier"),      STD_C99 },
+  { 'O', 'o', 0, NULL,               N_("the 'O' modifier"),               STD_EXT },
+  { 0, 0, 0, NULL, NULL, 0 }
+};
+
+
+static const format_flag_pair ms_strftime_flag_pairs[] =
+{
+  { 'E', 'O', 0, 0 },
+  { '_', '-', 0, 0 },
+  { '_', '0', 0, 0 },
+  { '-', '0', 0, 0 },
+  { '^', '#', 0, 0 },
+  { 0, 0, 0, 0 }
+};
+
+static const format_char_info ms_print_char_table[] =
+{
+  /* C89 conversion specifiers.  */
+  { "di",  0, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  T89_V,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +'",  "i",  NULL },
+  { "oxX", 0, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T89_V, BADLEN, BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "-wp0#",     "i",  NULL },
+  { "u",   0, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T89_V, BADLEN, BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "-wp0'",    "i",  NULL },
+  { "fgG", 0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "-wp0 +#'", "",   NULL },
+  { "eE",  0, STD_C89, { T89_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "-wp0 +#",  "",   NULL },
+  { "c",   0, STD_C89, { T89_I,   BADLEN,  T89_S,  T94_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
+  { "s",   1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "cR", NULL },
+  { "p",   1, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "c",  NULL },
+  { "n",   1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  BADLEN,  BADLEN, BADLEN,  T99_IM,  BADLEN,  BADLEN,  BADLEN }, "",          "W",  NULL },
+  /* X/Open conversion specifiers.  */
+  { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-w",        "",   NULL },
+  { "S",   1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "-wp",       "R",  NULL },
+  { NULL,  0, 0, NOLENGTHS, NULL, NULL, NULL }
+};
+
+static const format_char_info ms_scan_char_table[] =
+{
+  /* C89 conversion specifiers.  */
+  { "di",    1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  T89_V,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w'", "W",   NULL },
+  { "u",     1, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T89_V, BADLEN,  BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "*w'", "W",   NULL },
+  { "oxX",   1, STD_C89, { T89_UI,  BADLEN,  T89_US,  T89_UL,  T9L_ULL, T89_V, BADLEN,  BADLEN, BADLEN, BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
+  { "efgEG", 1, STD_C89, { T89_F,   BADLEN,  BADLEN,  T89_D,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN, BADLEN, BADLEN }, "*w'",  "W",   NULL },
+  { "c",     1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "cW",  NULL },
+  { "s",     1, STD_C89, { T89_C,   BADLEN,  T89_S,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "cW",  NULL },
+  { "[",     1, STD_C89, { T89_C,   BADLEN,  BADLEN,  T94_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "cW[", NULL },
+  { "p",     2, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
+  { "n",     1, STD_C89, { T89_I,   BADLEN,  T89_S,   T89_L,   T9L_LL,  BADLEN,  BADLEN, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "",     "W",   NULL },
+  /* X/Open conversion specifiers.  */
+  { "C",     1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*w",   "W",   NULL },
+  { "S",     1, STD_EXT, { TEX_W,   BADLEN,  T89_S,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN }, "*aw",  "W",   NULL },
+  { NULL, 0, 0, NOLENGTHS, NULL, NULL, NULL }
+};
+
+static const format_char_info ms_time_char_table[] =
+{
+  /* C89 conversion specifiers.  */
+  { "ABZab",		0, STD_C89, NOLENGTHS, "^#",     "",   NULL },
+  { "cx",		0, STD_C89, NOLENGTHS, "E",      "3",  NULL },
+  { "HIMSUWdmw",	0, STD_C89, NOLENGTHS, "-_0Ow",  "",   NULL },
+  { "j",		0, STD_C89, NOLENGTHS, "-_0Ow",  "o",  NULL },
+  { "p",		0, STD_C89, NOLENGTHS, "#",      "",   NULL },
+  { "X",		0, STD_C89, NOLENGTHS, "E",      "",   NULL },
+  { "y",		0, STD_C89, NOLENGTHS, "EO-_0w", "4",  NULL },
+  { "Y",		0, STD_C89, NOLENGTHS, "-_0EOw", "o",  NULL },
+  { "%",		0, STD_C89, NOLENGTHS, "",       "",   NULL },
+  /* C99 conversion specifiers.  */
+  { "z",		0, STD_C99, NOLENGTHS, "O",      "o",  NULL },
+  { NULL,		0, 0, NOLENGTHS, NULL, NULL, NULL }
+};
+
+const format_kind_info mingw_formatter_attributes[3] =
+{
+  { "ms_printf",   ms_printf_length_specs,  ms_print_char_table, " +#0-'", NULL,
+    ms_printf_flag_specs, ms_printf_flag_pairs,
+    FMT_FLAG_ARG_CONVERT|FMT_FLAG_DOLLAR_MULTIPLE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_EMPTY_PREC_OK,
+    'w', 0, 0, 0, 'L', 0,
+    &integer_type_node, &integer_type_node
+  },
+  { "ms_scanf",    ms_printf_length_specs,   ms_scan_char_table,  "*'", NULL,
+    ms_scanf_flag_specs, ms_scanf_flag_pairs,
+    FMT_FLAG_ARG_CONVERT|FMT_FLAG_SCANF_A_KLUDGE|FMT_FLAG_USE_DOLLAR|FMT_FLAG_ZERO_WIDTH_BAD|FMT_FLAG_DOLLAR_GAP_POINTER_OK,
+    'w', 0, 0, '*', 'L', 'm',
+    NULL, NULL
+  },
+  { "ms_strftime", NULL,                 ms_time_char_table,  "_-0^#", "EO",
+    ms_strftime_flag_specs, ms_strftime_flag_pairs,
+    FMT_FLAG_FANCY_PERCENT_OK, 'w', 0, 0, 0, 0, 0,
+    NULL, NULL
+  }
+};
+
+/* Default overrides for printf, scanf and strftime.  */
+const target_ovr_attr mingw_formatter_attribute_overrides[4] =
+{
+  { "ms_printf", "printf" },
+  { "ms_scanf", "scanf" },
+  { "ms_strftime", "strftime" }
+};
Index: gcc/gcc/config/i386/t-cygming
===================================================================
--- gcc.orig/gcc/config/i386/t-cygming
+++ gcc/gcc/config/i386/t-cygming
@@ -29,4 +29,10 @@ winnt-stubs.o: $(srcdir)/config/i386/win
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	$(srcdir)/config/i386/winnt-stubs.c
 
+msformat-c.o: $(srcdir)/config/i386/msformat-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
+  $(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	$(srcdir)/config/i386/msformat-c.c
+
 STMP_FIXINC=stmp-fixinc
Index: gcc/gcc/doc/extend.texi
===================================================================
--- gcc.orig/gcc/doc/extend.texi
+++ gcc/gcc/doc/extend.texi
@@ -2204,13 +2204,17 @@ for consistency with the @code{printf} s
 @code{my_format}.
 
 The parameter @var{archetype} determines how the format string is
-interpreted, and should be @code{printf}, @code{scanf}, @code{strftime}
-or @code{strfmon}.  (You can also use @code{__printf__},
-@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.)  The
-parameter @var{string-index} specifies which argument is the format
-string argument (starting from 1), while @var{first-to-check} is the
-number of the first argument to check against the format string.  For
-functions where the arguments are not available to be checked (such as
+interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
+@code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
+@code{strfmon}.  (You can also use @code{__printf__},
+@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.)  On
+mingw targets there is also @code{ms_printf}, @code{ms_scanf}, and
+@code{ms_strftime} present. The none target specific formatters are
+always the variant of the system.  The parameter @var{string-index}
+specifies which argument is the format string argument (starting
+from 1), while @var{first-to-check} is the number of the first
+argument to check against the format string.  For functions
+where the arguments are not available to be checked (such as
 @code{vprintf}), specify the third parameter as zero.  In this case the
 compiler only checks the format string for consistency.  For
 @code{strftime} formats, the third parameter is required to be zero.
Index: gcc/gcc/doc/tm.texi
===================================================================
--- gcc.orig/gcc/doc/tm.texi
+++ gcc/gcc/doc/tm.texi
@@ -10311,6 +10311,18 @@ If defined, this macro is the number of 
 @code{TARGET_FORMAT_TYPES}.
 @end defmac
 
+@defmac TARGET_OVERRIDES_FORMAT_ATTRIBUTES
+If defined, this macro is the name of a global variable containg
+target-specific format overrides for the @option{-Wformat} option. The
+default is to have no target-specific format overrides. This depends, that
+@code{TARGET_FORMAT_TYPES} is defined too.
+@end defmac
+
+@defmac TARGET_OVERRIDES_FORMAT_ATTRIBUTES_COUNT
+If defined, this macro is the number of entries in
+@code{}.
+@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: gcc/gcc/testsuite/gcc.dg/format/sys_formatter.c
===================================================================
--- /dev/null
+++ gcc/gcc/testsuite/gcc.dg/format/sys_formatter.c
@@ -0,0 +1,19 @@
+/* Test system default printf formatter specifiers.  */
+/* Origin: Kai Tietz <KaiTietz.@onevision.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89" } */
+
+#include <format.h>
+
+__attribute__((format(printf, 1, 2))) void foo (const char *, ...);
+
+#ifdef _WIN32
+#define FORMATTER_TEXT	"%I64d %I32d %ld %d\n"
+#else
+#define FORMATTER_TEXT	"%lld %ld %ld %d"
+#endif
+
+void bar (long long v1, long v2, int v3)
+{
+  foo (FORMATTER_TEXT, v1, v2, v2, v3);
+}
=

  reply	other threads:[~2008-01-07 10:36 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-04 17:55 NightStrike
2007-12-04 18:32 ` Joseph S. Myers
2007-12-05 21:35   ` NightStrike
2007-12-05 22:53     ` Joseph S. Myers
2007-12-18 14:06       ` Kai Tietz
2007-12-18 16:30         ` Joseph S. Myers
2007-12-18 21:14         ` Danny Smith
2007-12-20 13:00           ` Kai Tietz
2007-12-20 14:16             ` Joseph S. Myers
2007-12-20 14:30               ` Kai Tietz
2007-12-21 14:03               ` Kai Tietz
2007-12-21 14:38                 ` Joseph S. Myers
2008-01-07 13:56                   ` Kai Tietz [this message]
2008-01-07 14:44                     ` Joseph S. Myers
2008-01-07 16:26                       ` Kai Tietz
2008-01-08 14:37                       ` Kai Tietz
2008-01-08 18:18                         ` Joseph S. Myers
2008-01-15 16:45                           ` Kai Tietz
2008-01-16 16:14 Kai Tietz
     [not found] <Pine.LNX.4.64.0801312346090.5937@digraph.polyomino.org.uk>
2008-02-01 11:04 ` Kai Tietz
2008-02-01 15:52   ` Joseph S. Myers
2008-02-04 14:23     ` Kai Tietz
2008-02-13 18:32       ` Joseph S. Myers
2008-02-19  9:22         ` Kai Tietz
2008-02-19 12:38           ` Joseph S. Myers
2008-02-19 13:30             ` Kai Tietz
2008-02-19 14:10               ` Joseph S. Myers
2008-02-19 15:16                 ` Kai Tietz
2008-02-25 16:46                   ` NightStrike
2008-02-25 16:58                     ` Joseph S. Myers
2008-02-25 17:42                       ` NightStrike
2008-02-25 18:53                   ` Joseph S. Myers
2008-03-04 19:25                     ` Joseph S. Myers
2008-03-10 11:06                     ` Kai Tietz
2008-03-10 22:29                       ` Joseph S. Myers
2008-03-13  0:03                         ` Danny Smith
2008-03-13  8:43                           ` Kai Tietz
2008-03-13  9:29                           ` Kai Tietz
2008-03-13 19:24                             ` Ralf Wildenhues
2008-03-14  9:32                               ` Kai Tietz
2008-03-13 20:52                             ` Danny Smith
2008-03-14 11:00                               ` Kai Tietz
2008-03-16  5:54                                 ` Danny Smith
2008-03-16 12:16                                   ` Kai Tietz
2008-03-18 13:20                                   ` Kai Tietz
2008-03-18 13:44                                     ` NightStrike
2008-03-18 13:51                                       ` Kai Tietz
2008-03-18 15:07                                       ` Kai Tietz
2008-03-19  5:01                                         ` NightStrike
2008-03-19  6:22                                         ` Danny Smith
2008-03-19  9:42                                           ` Kai Tietz
2008-03-19 13:43                                             ` NightStrike
2008-03-19 13:51                                             ` NightStrike
2008-03-20  1:18                                             ` Danny Smith
2008-03-20  1:18                                               ` NightStrike
2008-03-20  9:54                                               ` Kai Tietz
2008-02-13 21:27       ` Danny Smith
2008-02-19  9:17         ` Kai Tietz
2008-03-13 22:38 FX Coudert
2008-03-14  1:33 ` Joseph S. Myers
2008-03-16  7:58 ` Danny Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OFD8E09BCD.E7899FFC-ONC12573C9.0037DD89-C12573C9.003A2D35@onevision.de \
    --to=kai.tietz@onevision.com \
    --cc=dansmister@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=nightstrike@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).