This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Warn for each missing printf argument


Right now if there are too few arguments to printf, -Wformat will print
a single generic warning.  This patch makes it print separate warnings
for each missing argument.

In addition, I noticed that sometimes warnings are not 100% correct
in that for example `%.*p' is reported to expect a pointer, while
as printed the specifier obviously doesn't require only a pointer.
For this reason, and to avoid excessive proliferation of warning
messages in format_type_warning, this patch changes it to strip
the field widths and precisions when warning about format specifiers.

Bootstrapped/regtested x86_64-pc-linux-gnu, ok?
Paolo


c-family:
2010-10-28  Paolo Bonzini  <bonzini@gnu.org>

	* c-format.c (enum format_specifier_kind, kind_descriptions): New.
        (struct format_wanted_type): Replace field "name" with "kind", add
        "format_start" and "format_length".
        (check_format_info_main): Fill in new fields.  Fill in
        FORMAT_WANTED_TYPES even for missing arguments.  Move checks
        after the final NUL outside the while loop.  Do not include
        width and precision modifiers in the format_start/format_length
        of the main format.
        (check_format_types): Remove FORMAT_START and FORMAT_LENGTH
        arguments.  Compute WANTED_TYPE first so that format_type_warning
        can be called for missing arguments.  Adjust calls to
        format_type_warning.
        (format_type_warning): Fetch as much information as possible
        from format_wanted_type.  Adjust printing now that every
        warning has a "descr", as well as for missing argument warnings
        and to include % sign for format specifiers.

testsuite:
2010-10-28  Paolo Bonzini  <bonzini@gnu.org>

	* gcc.dg/format/gcc_diag-1.c: Adjust.
	* gcc.dg/format/dfp-scanf-1.c: Adjust.
	* gcc.dg/format/cmn-err-1.c: Adjust.
	* gcc.dg/format/dfp-printf-1.c: Adjust.
	* gcc.dg/format/c90-scanf-1.c: Adjust.
	* gcc.dg/format/unnamed-1.c: Adjust.
	* gcc.dg/format/strfmon-1.c: Adjust.
	* gcc.dg/format/xopen-2.c: Adjust.
	* gcc.dg/format/asm_fprintf-1.c: Adjust.
	* gcc.dg/format/c90-printf-1.c: Adjust.
	* gcc.dg/format/ms_unnamed-1.c: Adjust.
        * gcc.dg/format/few-1.c: New.

Index: gcc/c-family/c-format.c
===================================================================
--- gcc/c-family/c-format.c	(branch diag)
+++ gcc/c-family/c-format.c	(working copy)
@@ -252,6 +252,20 @@ decode_format_attr (tree args, function_
 				       ? (warn_long_long ? STD_C99 : STD_C89) \
 				       : (VER)))
 
+/* Enum describing the kind of specifiers present in the format and
+   requiring an argument.  */
+enum format_specifier_kind {
+  CF_KIND_FORMAT,
+  CF_KIND_FIELD_WIDTH,
+  CF_KIND_FIELD_PRECISION
+};
+
+static const char *kind_descriptions[] = {
+  N_("format"),
+  N_("field width specifier"),
+  N_("field precision specifier")
+};
+
 /* Structure describing details of a type expected in format checking,
    and the type to check against it.  */
 typedef struct format_wanted_type
@@ -273,11 +287,13 @@ typedef struct format_wanted_type
   /* Whether the argument, dereferenced once, is read from and so
      must not be a NULL pointer.  */
   int reading_from_flag;
-  /* If warnings should be of the form "field precision should have
-     type 'int'", the name to use (in this case "field precision"),
-     otherwise NULL, for "format expects type 'long'" type
-     messages.  */
-  const char *name;
+  /* The kind of specifier that this type is used for.  */
+  enum format_specifier_kind kind;
+  /* The starting character of the specifier.  This never includes the
+     initial percent sign.  */
+  const char *format_start;
+  /* The length of the specifier.  */
+  int format_length;
   /* The actual parameter to check against the wanted type.  */
   tree param;
   /* The argument number of that parameter.  */
@@ -828,9 +844,8 @@ static void finish_dollar_format_checkin
 static const format_flag_spec *get_flag_spec (const format_flag_spec *,
 					      int, const char *);
 
-static void check_format_types (format_wanted_type *, const char *, int);
-static void format_type_warning (const char *, const char *, int, tree,
-				 int, const char *, tree, int);
+static void check_format_types (format_wanted_type *);
+static void format_type_warning (format_wanted_type *, tree, tree);
 
 /* Decode a format type from a string, returning the type, or
    format_type_error if not valid, in which case the caller should print an
@@ -1457,7 +1472,7 @@ check_format_info_main (format_check_res
 
   init_dollar_format_checking (info->first_arg_num, first_fillin_param);
 
-  while (1)
+  while (*format_chars != 0)
     {
       int i;
       int suppressed = FALSE;
@@ -1481,21 +1496,8 @@ check_format_info_main (format_check_res
       char flag_chars[256];
       int alloc_flag = 0;
       int scalar_identity_flag = 0;
-      const char *format_start = format_chars;
-      if (*format_chars == 0)
-	{
-	  if (format_chars - orig_format_chars != format_length)
-	    warning (OPT_Wformat_contains_nul, "embedded %<\\0%> in format");
-	  if (info->first_arg_num != 0 && params != 0
-	      && has_operand_number <= 0)
-	    {
-	      res->number_other--;
-	      res->number_extra_args++;
-	    }
-	  if (has_operand_number > 0)
-	    finish_dollar_format_checking (res, fki->flags & (int) FMT_FLAG_DOLLAR_GAP_POINTER_OK);
-	  return;
-	}
+      const char *format_start;
+
       if (*format_chars++ != '%')
 	continue;
       if (*format_chars == 0)
@@ -1600,16 +1602,16 @@ check_format_info_main (format_check_res
 	      if (info->first_arg_num != 0)
 		{
 		  if (params == 0)
-		    {
-		      warning (OPT_Wformat, "too few arguments for format");
-		      return;
-		    }
-		  cur_param = TREE_VALUE (params);
-		  if (has_operand_number <= 0)
-		    {
-		      params = TREE_CHAIN (params);
-		      ++arg_num;
-		    }
+	            cur_param = NULL;
+	          else
+	            {
+	              cur_param = TREE_VALUE (params);
+	              if (has_operand_number <= 0)
+	                {
+	                  params = TREE_CHAIN (params);
+	                  ++arg_num;
+	                }
+	            }
 		  width_wanted_type.wanted_type = *fki->width_type;
 		  width_wanted_type.wanted_type_name = NULL;
 		  width_wanted_type.pointer_count = 0;
@@ -1617,7 +1619,9 @@ check_format_info_main (format_check_res
 		  width_wanted_type.scalar_identity_flag = 0;
 		  width_wanted_type.writing_in_flag = 0;
 		  width_wanted_type.reading_from_flag = 0;
-		  width_wanted_type.name = _("field width");
+	          width_wanted_type.kind = CF_KIND_FIELD_WIDTH;
+		  width_wanted_type.format_start = format_chars - 1;
+		  width_wanted_type.format_length = 1;
 		  width_wanted_type.param = cur_param;
 		  width_wanted_type.arg_num = arg_num;
 		  width_wanted_type.next = NULL;
@@ -1703,16 +1707,16 @@ check_format_info_main (format_check_res
 	      if (info->first_arg_num != 0)
 		{
 		  if (params == 0)
-		    {
-		      warning (OPT_Wformat, "too few arguments for format");
-		      return;
-		    }
-		  cur_param = TREE_VALUE (params);
-		  if (has_operand_number <= 0)
-		    {
-		      params = TREE_CHAIN (params);
-		      ++arg_num;
-		    }
+	            cur_param = NULL;
+	          else
+	            {
+	              cur_param = TREE_VALUE (params);
+	              if (has_operand_number <= 0)
+	                {
+	                  params = TREE_CHAIN (params);
+	                  ++arg_num;
+	                }
+	            }
 		  precision_wanted_type.wanted_type = *fki->precision_type;
 		  precision_wanted_type.wanted_type_name = NULL;
 		  precision_wanted_type.pointer_count = 0;
@@ -1720,8 +1724,10 @@ check_format_info_main (format_check_res
 		  precision_wanted_type.scalar_identity_flag = 0;
 		  precision_wanted_type.writing_in_flag = 0;
 		  precision_wanted_type.reading_from_flag = 0;
-		  precision_wanted_type.name = _("field precision");
+	          precision_wanted_type.kind = CF_KIND_FIELD_PRECISION;
 		  precision_wanted_type.param = cur_param;
+		  precision_wanted_type.format_start = format_chars - 2;
+		  precision_wanted_type.format_length = 2;
 		  precision_wanted_type.arg_num = arg_num;
 		  precision_wanted_type.next = NULL;
 		  if (last_wanted_type != 0)
@@ -1741,6 +1747,7 @@ check_format_info_main (format_check_res
 	    }
 	}
 
+      format_start = format_chars;
       if (fki->alloc_char && fki->alloc_char == *format_chars)
 	{
 	  i = strlen (flag_chars);
@@ -2001,12 +2008,8 @@ check_format_info_main (format_check_res
 	      /* Heuristic: skip one argument when an invalid length/type
 		 combination is encountered.  */
 	      arg_num++;
-	      if (params == 0)
-		{
-		  warning (OPT_Wformat, "too few arguments for format");
-		  return;
-		}
-	      params = TREE_CHAIN (params);
+	      if (params != 0)
+	        params = TREE_CHAIN (params);
 	      continue;
 	    }
 	  else if (pedantic
@@ -2067,13 +2070,12 @@ check_format_info_main (format_check_res
 	  while (fci)
 	    {
 	      if (params == 0)
-		{
-		  warning (OPT_Wformat, "too few arguments for format");
-		  return;
-		}
-
-	      cur_param = TREE_VALUE (params);
-	      params = TREE_CHAIN (params);
+	        cur_param = NULL;
+	      else
+	        {
+	          cur_param = TREE_VALUE (params);
+	          params = TREE_CHAIN (params);
+	        }
 
 	      wanted_type_ptr->wanted_type = wanted_type;
 	      wanted_type_ptr->wanted_type_name = wanted_type_name;
@@ -2095,9 +2097,11 @@ check_format_info_main (format_check_res
 		  if (strchr (fci->flags2, 'R') != 0)
 		    wanted_type_ptr->reading_from_flag = 1;
 		}
-	      wanted_type_ptr->name = NULL;
+	      wanted_type_ptr->kind = CF_KIND_FORMAT;
 	      wanted_type_ptr->param = cur_param;
 	      wanted_type_ptr->arg_num = arg_num;
+	      wanted_type_ptr->format_start = format_start;
+	      wanted_type_ptr->format_length = format_chars - format_start;
 	      wanted_type_ptr->next = NULL;
 	      if (last_wanted_type != 0)
 		last_wanted_type->next = wanted_type_ptr;
@@ -2118,17 +2122,26 @@ check_format_info_main (format_check_res
 	}
 
       if (first_wanted_type != 0)
-	check_format_types (first_wanted_type, format_start,
-			    format_chars - format_start);
+	check_format_types (first_wanted_type);
+    }
+
+  if (format_chars - orig_format_chars != format_length)
+    warning (OPT_Wformat_contains_nul, "embedded %<\\0%> in format");
+  if (info->first_arg_num != 0 && params != 0
+      && has_operand_number <= 0)
+    {
+      res->number_other--;
+      res->number_extra_args++;
     }
+  if (has_operand_number > 0)
+    finish_dollar_format_checking (res, fki->flags & (int) FMT_FLAG_DOLLAR_GAP_POINTER_OK);
 }
 
 
 /* Check the argument types from a single format conversion (possibly
    including width and precision arguments).  */
 static void
-check_format_types (format_wanted_type *types, const char *format_start,
-		    int format_length)
+check_format_types (format_wanted_type *types)
 {
   for (; types != 0; types = types->next)
     {
@@ -2139,12 +2152,7 @@ check_format_types (format_wanted_type *
       int arg_num;
       int i;
       int char_type_flag;
-      cur_param = types->param;
-      cur_type = TREE_TYPE (cur_param);
-      if (cur_type == error_mark_node)
-	continue;
-      orig_cur_type = cur_type;
-      char_type_flag = 0;
+
       wanted_type = types->wanted_type;
       arg_num = types->arg_num;
 
@@ -2157,6 +2165,19 @@ check_format_types (format_wanted_type *
 
       wanted_type = TYPE_MAIN_VARIANT (wanted_type);
 
+      cur_param = types->param;
+      if (!cur_param)
+	{
+	  format_type_warning (types, wanted_type, NULL);
+	  continue;
+	}
+
+      cur_type = TREE_TYPE (cur_param);
+      if (cur_type == error_mark_node)
+	continue;
+      orig_cur_type = cur_type;
+      char_type_flag = 0;
+
       STRIP_NOPS (cur_param);
 
       /* Check the types of any additional pointer arguments
@@ -2220,10 +2241,7 @@ check_format_types (format_wanted_type *
 	    }
 	  else
 	    {
-	      format_type_warning (types->name, format_start, format_length,
-				   wanted_type, types->pointer_count,
-				   types->wanted_type_name, orig_cur_type,
-				   arg_num);
+	      format_type_warning (types, wanted_type, orig_cur_type);
 	      break;
 	    }
 	}
@@ -2275,33 +2293,34 @@ check_format_types (format_wanted_type *
 	  && TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type))
 	continue;
       /* Now we have a type mismatch.  */
-      format_type_warning (types->name, format_start, format_length,
-			   wanted_type, types->pointer_count,
-			   types->wanted_type_name, orig_cur_type, arg_num);
+      format_type_warning (types, wanted_type, orig_cur_type);
     }
 }
 
 
 /* Give a warning about a format argument of different type from that
-   expected.  DESCR is a description such as "field precision", or
-   NULL for an ordinary format.  For an ordinary format, FORMAT_START
-   points to where the format starts in the format string and
-   FORMAT_LENGTH is its length.  WANTED_TYPE is the type the argument
-   should have after POINTER_COUNT pointer dereferences.
-   WANTED_NAME_NAME is a possibly more friendly name of WANTED_TYPE,
-   or NULL if the ordinary name of the type should be used.  ARG_TYPE
-   is the type of the actual argument.  ARG_NUM is the number of that
-   argument.  */
+   expected.  WANTED_TYPE is the type the argument should have, possibly
+   stripped of pointer dereferences.  The description (such as "field
+   precision"), the placement in the format string, a possibly more
+   friendly name of WANTED_TYPE, and the number of pointer dereferences
+   are taken from TYPE.  ARG_TYPE is the type of the actual argument,
+   or NULL if it is missing.  */
 static void
-format_type_warning (const char *descr, const char *format_start,
-		     int format_length, tree wanted_type, int pointer_count,
-		     const char *wanted_type_name, tree arg_type, int arg_num)
+format_type_warning (format_wanted_type *type, tree wanted_type, tree arg_type)
 {
+  int kind = type->kind;
+  const char *wanted_type_name = type->wanted_type_name;
+  const char *format_start = type->format_start;
+  int format_length = type->format_length;
+  int pointer_count = type->pointer_count;
+  int arg_num = type->arg_num;
+
   char *p;
   /* If ARG_TYPE is a typedef with a misleading name (for example,
      size_t but not the standard size_t expected by printf %zu), avoid
      printing the typedef name.  */
   if (wanted_type_name
+      && arg_type
       && TYPE_NAME (arg_type)
       && TREE_CODE (TYPE_NAME (arg_type)) == TYPE_DECL
       && DECL_NAME (TYPE_NAME (arg_type))
@@ -2327,28 +2346,36 @@ format_type_warning (const char *descr, 
       memset (p + 1, '*', pointer_count);
       p[pointer_count + 1] = 0;
     }
+
   if (wanted_type_name)
     {
-      if (descr)
-	warning (OPT_Wformat, "%s should have type %<%s%s%>, "
-		 "but argument %d has type %qT",
-		 descr, wanted_type_name, p, arg_num, arg_type);
+      if (arg_type)
+	warning (OPT_Wformat, "%s %<%s%.*s%> expects argument of type %<%s%s%>, "
+	         "but argument %d has type %qT",
+	         gettext (kind_descriptions[kind]),
+	         (kind == CF_KIND_FORMAT ? "%" : ""),
+	         format_length, format_start, 
+	         wanted_type_name, p, arg_num, arg_type);
       else
-	warning (OPT_Wformat, "format %q.*s expects type %<%s%s%>, "
-		 "but argument %d has type %qT",
-		 format_length, format_start, wanted_type_name, p,
-		 arg_num, arg_type);
+	warning (OPT_Wformat, "%s %<%s%.*s%> expects a matching %<%s%s%> argument",
+	         gettext (kind_descriptions[kind]),
+	         (kind == CF_KIND_FORMAT ? "%" : ""),
+	         format_length, format_start, wanted_type_name, p);
     }
   else
     {
-      if (descr)
-	warning (OPT_Wformat, "%s should have type %<%T%s%>, "
-		 "but argument %d has type %qT",
-		 descr, wanted_type, p, arg_num, arg_type);
+      if (arg_type)
+	warning (OPT_Wformat, "%s %<%s%.*s%> expects argument of type %<%T%s%>, "
+	         "but argument %d has type %qT",
+	         gettext (kind_descriptions[kind]),
+	         (kind == CF_KIND_FORMAT ? "%" : ""),
+	         format_length, format_start, 
+	         wanted_type, p, arg_num, arg_type);
       else
-	warning (OPT_Wformat, "format %q.*s expects type %<%T%s%>, "
-		 "but argument %d has type %qT",
-		 format_length, format_start, wanted_type, p, arg_num, arg_type);
+	warning (OPT_Wformat, "%s %<%s%.*s%> expects a matching %<%T%s%> argument",
+	         gettext (kind_descriptions[kind]),
+	         (kind == CF_KIND_FORMAT ? "%" : ""),
+	         format_length, format_start, wanted_type, p);
     }
 }
 
Index: gcc/testsuite/gcc.dg/format/gcc_diag-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/gcc_diag-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/gcc_diag-1.c	(working copy)
@@ -201,7 +201,7 @@ foo (int i, int i1, int i2, unsigned int
   diag ("%s", n); /* { dg-warning "format" "bad argument types" } */
 
   /* Wrong number of arguments.  */
-  diag ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */
+  diag ("%d%d", i); /* { dg-warning "matching" "wrong number of args" } */
   diag ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */
   /* Miscellaneous bogus constructions.  */
   diag (""); /* { dg-warning "zero-length" "warning for empty format" } */
Index: gcc/testsuite/gcc.dg/format/dfp-scanf-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/dfp-scanf-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/dfp-scanf-1.c	(working copy)
@@ -43,44 +43,44 @@ voo (_Decimal32 *x, _Decimal64 *y, _Deci
 
   /* Check warnings for type mismatches.  */
 
-  scanf ("%Hf", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HF", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%He", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HE", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%Hg", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HG", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%Hf", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HF", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%He", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HE", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%Hg", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  scanf ("%HG", z);	/* { dg-warning "expects type" "bad use of %H" } */
-
-  scanf ("%Df", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DF", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%De", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DE", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%Dg", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DG", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%Df", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DF", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%De", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DE", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%Dg", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  scanf ("%DG", z);	/* { dg-warning "expects type" "bad use of %D" } */
-
-  scanf ("%DDf", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDF", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDe", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDE", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDg", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDG", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDf", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDF", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDe", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDE", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDg", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  scanf ("%DDG", y);	/* { dg-warning "expects type" "bad use of %DD" } */
+  scanf ("%Hf", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HF", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%He", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HE", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%Hg", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HG", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%Hf", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HF", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%He", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HE", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%Hg", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  scanf ("%HG", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+
+  scanf ("%Df", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DF", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%De", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DE", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%Dg", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DG", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%Df", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DF", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%De", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DE", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%Dg", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  scanf ("%DG", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+
+  scanf ("%DDf", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDF", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDe", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDE", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDg", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDG", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDf", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDF", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDe", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDE", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDg", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  scanf ("%DDG", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
 
   /* Check for warnings for bad use of H, D, and DD length specifiers.  */
 
Index: gcc/testsuite/gcc.dg/format/cmn-err-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/cmn-err-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/cmn-err-1.c	(working copy)
@@ -28,11 +28,12 @@ int main()
   cmn_err_func (0, "%16b", i, "\01Foo");
 
   cmn_err_func (0, "%i", i);		/* { dg-warning "unknown|too many" } */
-  cmn_err_func (0, "%d", l);		/* { dg-warning "expects type" } */
-  cmn_err_func (0, "%b");		/* { dg-warning "too few" } */
-  cmn_err_func (0, "%b", i);		/* { dg-warning "too few" } */
-  cmn_err_func (0, "%b", i, i);		/* { dg-warning "expects type" } */
-  cmn_err_func (0, "%b", string, i);	/* { dg-warning "expects type" } */
-  cmn_err_func (0, "%p", 3);		/* { dg-warning "expects type" } */
+  cmn_err_func (0, "%d", l);		/* { dg-warning "expects argument" } */
+  cmn_err_func (0, "%b");		/* { dg-warning "'int'" } */
+/* { dg-warning "'char \\*'" "" { target *-*-solaris2.* } 32 } */
+  cmn_err_func (0, "%b", i);		/* { dg-warning "matching" } */
+  cmn_err_func (0, "%b", i, i);		/* { dg-warning "expects argument" } */
+  cmn_err_func (0, "%b", string, i);	/* { dg-warning "expects argument" } */
+  cmn_err_func (0, "%p", 3);		/* { dg-warning "expects argument" } */
   return 0;
 }
Index: gcc/testsuite/gcc.dg/format/dfp-printf-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/dfp-printf-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/dfp-printf-1.c	(working copy)
@@ -43,44 +43,44 @@ foo (_Decimal32 x, _Decimal64 y, _Decima
 
   /* Check warnings for type mismatches.  */
 
-  printf ("%Hf\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HF\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%He\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HE\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%Hg\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HG\n", y);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%Hf\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HF\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%He\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HE\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%Hg\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-  printf ("%HG\n", z);	/* { dg-warning "expects type" "bad use of %H" } */
-
-  printf ("%Df\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DF\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%De\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DE\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%Dg\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DG\n", x);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%Df\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DF\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%De\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DE\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%Dg\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-  printf ("%DG\n", z);	/* { dg-warning "expects type" "bad use of %D" } */
-
-  printf ("%DDf\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDF\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDe\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDE\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDg\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDG\n", x);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDf\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDF\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDe\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDE\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDg\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
-  printf ("%DDG\n", y);	/* { dg-warning "expects type" "bad use of %DD" } */
+  printf ("%Hf\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HF\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%He\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HE\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%Hg\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HG\n", y);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%Hf\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HF\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%He\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HE\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%Hg\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+  printf ("%HG\n", z);	/* { dg-warning "expects argument" "bad use of %H" } */
+
+  printf ("%Df\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DF\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%De\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DE\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%Dg\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DG\n", x);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%Df\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DF\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%De\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DE\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%Dg\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+  printf ("%DG\n", z);	/* { dg-warning "expects argument" "bad use of %D" } */
+
+  printf ("%DDf\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDF\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDe\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDE\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDg\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDG\n", x);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDf\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDF\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDe\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDE\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDg\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
+  printf ("%DDG\n", y);	/* { dg-warning "expects argument" "bad use of %DD" } */
 
   /* Check for warnings for bad use of H, D, and DD length specifiers.  */
 
Index: gcc/testsuite/gcc.dg/format/c90-scanf-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/c90-scanf-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/c90-scanf-1.c	(working copy)
@@ -106,7 +106,7 @@ foo (int *ip, unsigned int *uip, short i
   scanf ("%s", cs); /* { dg-warning "constant" "%s writing into const" } */
   scanf ("%p", pcp); /* { dg-warning "constant" "%p writing into const" } */
   /* Wrong number of arguments.  */
-  scanf ("%d%d", ip); /* { dg-warning "arguments" "wrong number of args" } */
+  scanf ("%d%d", ip); /* { dg-warning "matching" "wrong number of args" } */
   scanf ("%d", ip, ip); /* { dg-warning "arguments" "wrong number of args" } */
   /* Miscellaneous bogus constructions.  */
   scanf (""); /* { dg-warning "zero-length" "warning for empty format" } */
Index: gcc/testsuite/gcc.dg/format/unnamed-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/unnamed-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/unnamed-1.c	(working copy)
@@ -19,7 +19,7 @@
 void
 f (TItype x)
 {
-  printf("%d", x); /* { dg-warning "expects type" } */
-  printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */
+  printf("%d", x); /* { dg-warning "expects argument" } */
+  printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects argument" } */
   /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 23 } */
 }
Index: gcc/testsuite/gcc.dg/format/strfmon-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/strfmon-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/strfmon-1.c	(working copy)
@@ -54,7 +54,7 @@ foo (char *s, size_t m, double d, long d
   strfmon (s, m, "%.5%\n"); /* { dg-warning "format" "bogus %%" } */
   strfmon (s, m, "%#5%\n"); /* { dg-warning "format" "bogus %%" } */
   /* Miscellaneous bogus formats.  */
-  strfmon (s, m, "%n%n", d); /* { dg-warning "arguments" "too few args" } */
+  strfmon (s, m, "%n%n", d); /* { dg-warning "matching" "too few args" } */
   strfmon (s, m, ""); /* { dg-warning "zero-length" "empty" } */
   strfmon (s, m, NULL); /* { dg-warning "null" "null format string" } */
   strfmon (s, m, "%"); /* { dg-warning "trailing" "tailing %" } */
Index: gcc/testsuite/gcc.dg/format/xopen-2.c
===================================================================
--- gcc/testsuite/gcc.dg/format/xopen-2.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/xopen-2.c	(working copy)
@@ -16,6 +16,6 @@ void
 foo (int i, int j, va_list va)
 {
   printf("%2$*1$c", i, j);
-  printf("%2$*1$c %2$*1$c", i, j); /* { dg-bogus "too few" "bogus too few dollar" } */
-  vbar(va, "%*s"); /* { dg-bogus "too few" "bogus too few vprintf" } */
+  printf("%2$*1$c %2$*1$c", i, j); /* { dg-bogus "matching" "bogus too few dollar" } */
+  vbar(va, "%*s"); /* { dg-bogus "matching" "bogus too few vprintf" } */
 }
Index: gcc/testsuite/gcc.dg/format/asm_fprintf-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/asm_fprintf-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/asm_fprintf-1.c	(working copy)
@@ -62,7 +62,7 @@ foo (int i, int i1, int i2, unsigned int
   asm_fprintf ("%s", n); /* { dg-warning "format" "bad argument types" } */
 
   /* Wrong number of arguments.  */
-  asm_fprintf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */
+  asm_fprintf ("%d%d", i); /* { dg-warning "matching" "wrong number of args" } */
   asm_fprintf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */
   /* Miscellaneous bogus constructions.  */
   asm_fprintf (""); /* { dg-warning "zero-length" "warning for empty format" } */
Index: gcc/testsuite/gcc.dg/format/c90-printf-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/c90-printf-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/c90-printf-1.c	(working copy)
@@ -220,7 +220,7 @@ foo (int i, int i1, int i2, unsigned int
   */
   printf ("%*.*d", u1, u2, i);
   /* Wrong number of arguments.  */
-  printf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */
+  printf ("%d%d", i); /* { dg-warning "matching" "wrong number of args" } */
   printf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */
   /* Miscellaneous bogus constructions.  */
   printf (""); /* { dg-warning "zero-length" "warning for empty format" } */
Index: gcc/testsuite/gcc.dg/format/ms_unnamed-1.c
===================================================================
--- gcc/testsuite/gcc.dg/format/ms_unnamed-1.c	(branch diag)
+++ gcc/testsuite/gcc.dg/format/ms_unnamed-1.c	(working copy)
@@ -19,7 +19,7 @@
 void
 f (TItype x)
 {
-  printf("%d", x); /* { dg-warning "expects type" } */
-  printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */
+  printf("%d", x); /* { dg-warning "expects argument" } */
+  printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects argument" } */
   /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 23 } */
 }




/* { dg-do compile } */
/* { dg-options "-std=gnu89 -Wformat" } */

int f(int *ip, char *cp)
{
	__builtin_printf ("%*.*s");
/* { dg-warning "field width specifier '\\*' expects a matching 'int' argument" "" { target *-*-* } 6 } */
/* { dg-warning "field precision specifier '\\.\\*' expects a matching 'int' argument" "" { target *-*-* } 6 } */
/* { dg-warning "format '%s' expects a matching 'char \\*' argument" "" { target *-*-* } 6 } */
	__builtin_printf ("%*.*s", ip, *cp);
/* { dg-warning "field width specifier '\\*' expects argument of type 'int'" "" { target *-*-* } 10 } */
/* { dg-warning "format '%s' expects a matching 'char \\*' argument" "" { target *-*-* } 10 } */
	__builtin_printf ("%s %i", ip, ip);
/* { dg-warning "format '%s' expects argument of type 'char \\*'" "" { target *-*-* } 13 } */
/* { dg-warning "format '%i' expects argument of type 'int'" "" { target *-*-* } 13 } */
	__builtin_printf ("%s %i", cp);
/* { dg-warning "format '%i' expects a matching 'int' argument" "" { target *-*-* } 16 } */
	__builtin_printf ("%lc");
/* { dg-warning "format '%lc' expects a matching 'wint_t' argument" "" { target *-*-* } 18 } */
	__builtin_printf ("%lc", cp);
/* { dg-warning "format '%lc' expects argument of type 'wint_t'" "" { target *-*-* } 20 } */
	__builtin_scanf ("%s");
/* { dg-warning "format '%s' expects a matching 'char \\*' argument" "" { target *-*-* } 22 } */
	__builtin_scanf ("%i", cp);
/* { dg-warning "format '%i' expects argument of type 'int \\*'" "" { target *-*-* } 24 } */
	__builtin_scanf ("%lc");
/* { dg-warning "format '%lc' expects a matching 'wchar_t \\*' argument" "" { target *-*-* } 26 } */
	__builtin_scanf ("%lc", cp);
/* { dg-warning "format '%lc' expects argument of type 'wchar_t \\*'" "" { target *-*-* } 28 } */
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]