Patch to re-enable format checking for warning, error etc.

Joseph S. Myers joseph@codesourcery.com
Sat Jul 2 23:49:00 GMT 2005


As a further piece of followup to
<http://gcc.gnu.org/ml/gcc-patches/2005-07/msg00077.html> and
<http://gcc.gnu.org/ml/gcc-patches/2005-07/msg00087.html>, it became
apparent that there were various format errors in GCC not being caught
because of format checking being disabled for various format functions
in the middle-end.  This patch re-enables that format checking.  There
are now four format attributes for GCC-internal formats based on the
pretty-printing infrastructure:

gcc_diag - core formats supported by pretty-print.c only

gcc_tdiag - middle-end formats (those supported by
default_tree_printer in toplev.c and by the front ends with their own
printers, i.e. C/C++/ObjC/ObjC++) - gcc_diag plus %D %F %T

gcc_cdiag - C formats - gcc_tdiag plus %E

gcc_cxxdiag - C++ formats - gcc_cdiag plus various others

Not much presently uses gcc_diag (pp_printf and pp_verbatim are
declared that way), since %D %F %T are always available with the
pretty-printing infrastructure.  However, it would be desirable for
the pretty-printing and diagnostic infrastructure to be available for
the the various programs (e.g. the "gcc" driver) not linking with
toplev.c and having no knowledge of the type "tree".  Such programs
would use warning/error/... with the plain gcc_diag format type.  (It
would be necessary for the %J format, with its knowledge of "tree", to
become a shared middle-end/front-end format rather than being in the
core pretty-printer.)

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  I also
configured cross-compilers to one target for each CPU directory and
fixed any format warnings building the <cpu>.o file - many of which
would have shown up without the patch (subject in some cases to
building with a sufficiently recent compiler, for non-bootstrap
builds).  OK to commit?

(Various targets had other warnings which I didn't try to fix.  This may 
be because of cross-compilers not getting built with -Werror - which does 
need a sufficiently recent bootstrap compiler to be doable reliably - or 
because of compilers to some targets only being regularly built from 
32-bit hosts and not from 64-bit hosts.)

NB: it's possible some of the format fixes would apply to 4.0 branch as 
well, but I haven't checked for this.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2005-07-02  Joseph S. Myers  <joseph@codesourcery.com>

	* c-common.h (GCC_DIAG_STYLE): Define.
	* c-tree.h (GCC_DIAG_STYLE): Do not define.  Change minimum GCC
	version for format checking to 4.1.
	* c-format.c: Include toplev.h after c-common.h.
	(enum format_type): Add gcc_tdiag_format_type.
	(gcc_tdiag_length_specs, gcc_tdiag_flag_pairs,
	gcc_tdiag_flag_specs, gcc_tdiag_char_table): New.
	(format_types_orig): Add gcc_tdiag.
	(init_dynamic_diag_info): Support gcc_tdiag formats.
	(handle_format_attribute): Likewise.
	* toplev.h (NO_FRONT_END_DIAG, ATTRIBUTE_GCC_FE_DIAG): Remove.
	(GCC_DIAG_STYLE): Default to __gcc_tdiag__.  Change minimum GCC
	version for format checking to 4.1.
	(warning0, warning, error, pedwarn, sorry): Use
	ATTRIBUTE_GCC_DIAG.
	* config/rs6000/rs6000.c (altivec_expand_builtin), varasm.c
	(finish_aliases_1): Do not use %qE.
	* config/arm/arm.c, config/i386/i386.c, config/mmix/mmix.c,
	config/pdp11/pdp11.c, stor-layout.c, tree-eh.c, tree-ssa.c:
	Correct format bugs.
	* config/v850/v850-protos.h (v850_output_aligned_bss): Change size
	parameter to unsigned HOST_WIDE_INT.
	* config/v850/v850.c (v850_output_aligned_bss): Likewise.

cp:
2005-07-02  Joseph S. Myers  <joseph@codesourcery.com>

	* cp-tree.h (GCC_DIAG_STYLE): #undef before defining.  Change
	minimum GCC version for format checking to 4.1.

testsuite:
2005-07-02  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/format/gcc_diag-1.c: Update.

diff -rupN GCC.orig/gcc/c-common.h GCC/gcc/c-common.h
--- GCC.orig/gcc/c-common.h	2005-06-29 09:44:30.000000000 +0000
+++ GCC/gcc/c-common.h	2005-07-02 19:35:17.000000000 +0000
@@ -926,4 +926,13 @@ extern void preprocess_file (cpp_reader 
 extern void pp_file_change (const struct line_map *);
 extern void pp_dir_change (cpp_reader *, const char *);
 
+/* In order for the format checking to accept the C frontend
+   diagnostic framework extensions, you must include this file before
+   toplev.h, not after.  The C front end formats are a subset of those
+   for C++, so they are the appropriate set to use in common code;
+   cp-tree.h overrides this for C++.  */
+#ifndef GCC_DIAG_STYLE
+#define GCC_DIAG_STYLE __gcc_cdiag__
+#endif
+
 #endif /* ! GCC_C_COMMON_H */
diff -rupN GCC.orig/gcc/c-format.c GCC/gcc/c-format.c
--- GCC.orig/gcc/c-format.c	2005-07-02 10:46:13.000000000 +0000
+++ GCC/gcc/c-format.c	2005-07-02 19:36:46.000000000 +0000
@@ -25,8 +25,8 @@ Software Foundation, 51 Franklin Street,
 #include "tm.h"
 #include "tree.h"
 #include "flags.h"
-#include "toplev.h"
 #include "c-common.h"
+#include "toplev.h"
 #include "intl.h"
 #include "diagnostic.h"
 #include "langhooks.h"
@@ -58,7 +58,8 @@ set_Wformat (int setting)
    format_type_error.  Target-specific format types do not have
    matching enum values.  */
 enum format_type { printf_format_type, asm_fprintf_format_type,
-		   gcc_diag_format_type, gcc_cdiag_format_type,
+		   gcc_diag_format_type, gcc_tdiag_format_type,
+		   gcc_cdiag_format_type,
 		   gcc_cxxdiag_format_type,
 		   scanf_format_type, strftime_format_type,
 		   strfmon_format_type, format_type_error = -1};
@@ -310,6 +311,7 @@ static const format_length_info gcc_diag
 };
 
 /* The custom diagnostics all accept the same length specifiers.  */
+#define gcc_tdiag_length_specs gcc_diag_length_specs
 #define gcc_cdiag_length_specs gcc_diag_length_specs
 #define gcc_cxxdiag_length_specs gcc_diag_length_specs
 
@@ -386,6 +388,7 @@ static const format_flag_pair gcc_diag_f
   { 0, 0, 0, 0 }
 };
 
+#define gcc_tdiag_flag_pairs gcc_diag_flag_pairs
 #define gcc_cdiag_flag_pairs gcc_diag_flag_pairs
 #define gcc_cxxdiag_flag_pairs gcc_diag_flag_pairs
 
@@ -398,6 +401,7 @@ static const format_flag_spec gcc_diag_f
   { 0, 0, 0, NULL, NULL, 0 }
 };
 
+#define gcc_tdiag_flag_specs gcc_diag_flag_specs
 #define gcc_cdiag_flag_specs gcc_diag_flag_specs
 
 static const format_flag_spec gcc_cxxdiag_flag_specs[] =
@@ -543,6 +547,29 @@ static const format_char_info gcc_diag_c
   { NULL,  0, 0, NOLENGTHS, NULL, NULL, NULL }
 };
 
+static const format_char_info gcc_tdiag_char_table[] =
+{
+  /* C89 conversion specifiers.  */
+  { "di",  0, STD_C89, { T89_I,   BADLEN,  BADLEN,  T89_L,   T9L_LL,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "",   NULL },
+  { "ox",  0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  T9L_ULL, BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "",   NULL },
+  { "u",   0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  T9L_ULL, BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "",   NULL },
+  { "c",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "",   NULL },
+  { "s",   1, STD_C89, { T89_C,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "pq", "cR", NULL },
+  { "p",   1, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "c",  NULL },
+
+  /* Custom conversion specifiers.  */
+
+  /* %H will require "location_t" at runtime.  */
+  { "H",   0, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q",  "",   NULL },
+
+  /* These will require a "tree" at runtime.  */
+  { "DFJT", 0, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
+
+  { "<>'", 0, STD_C89, NOARGUMENTS, "",      "",   NULL },
+  { "m",   0, STD_C89, NOARGUMENTS, "q",     "",   NULL },
+  { NULL,  0, 0, NOLENGTHS, NULL, NULL, NULL }
+};
+
 static const format_char_info gcc_cdiag_char_table[] =
 {
   /* C89 conversion specifiers.  */
@@ -666,6 +693,12 @@ static const format_kind_info format_typ
     0, 0, 'p', 0, 'L',
     NULL, &integer_type_node
   },
+  { "gcc_tdiag",   gcc_tdiag_length_specs,  gcc_tdiag_char_table, "q+", NULL, 
+    gcc_tdiag_flag_specs, gcc_tdiag_flag_pairs,
+    FMT_FLAG_ARG_CONVERT,
+    0, 0, 'p', 0, 'L',
+    NULL, &integer_type_node
+  },
   { "gcc_cdiag",   gcc_cdiag_length_specs,  gcc_cdiag_char_table, "q+", NULL, 
     gcc_cdiag_flag_specs, gcc_cdiag_flag_pairs,
     FMT_FLAG_ARG_CONVERT,
@@ -2360,7 +2393,7 @@ init_dynamic_diag_info (void)
 
   if (!loc || !t || !hwi)
     {
-      static format_char_info *diag_fci, *cdiag_fci, *cxxdiag_fci;
+      static format_char_info *diag_fci, *tdiag_fci, *cdiag_fci, *cxxdiag_fci;
       static format_length_info *diag_ls;
       unsigned int i;
 
@@ -2441,6 +2474,7 @@ init_dynamic_diag_info (void)
       /* All the GCC diag formats use the same length specs.  */
       if (!diag_ls)
 	dynamic_format_types[gcc_diag_format_type].length_char_specs =
+	  dynamic_format_types[gcc_tdiag_format_type].length_char_specs =
 	  dynamic_format_types[gcc_cdiag_format_type].length_char_specs =
 	  dynamic_format_types[gcc_cxxdiag_format_type].length_char_specs =
 	  diag_ls = (format_length_info *)
@@ -2479,6 +2513,30 @@ init_dynamic_diag_info (void)
 	  diag_fci[i].pointer_count = 1;
 	}
 
+      /* Handle the __gcc_tdiag__ format specifics.  */
+      if (!tdiag_fci)
+	dynamic_format_types[gcc_tdiag_format_type].conversion_specs =
+	  tdiag_fci = (format_char_info *)
+		      xmemdup (gcc_tdiag_char_table,
+			       sizeof (gcc_tdiag_char_table),
+			       sizeof (gcc_tdiag_char_table));
+      if (loc)
+        {
+	  i = find_char_info_specifier_index (tdiag_fci, 'H');
+	  tdiag_fci[i].types[0].type = &loc;
+	  tdiag_fci[i].pointer_count = 1;
+	}
+      if (t)
+        {
+	  /* All specifiers taking a tree share the same struct.  */
+	  i = find_char_info_specifier_index (tdiag_fci, 'D');
+	  tdiag_fci[i].types[0].type = &t;
+	  tdiag_fci[i].pointer_count = 1;
+	  i = find_char_info_specifier_index (tdiag_fci, 'J');
+	  tdiag_fci[i].types[0].type = &t;
+	  tdiag_fci[i].pointer_count = 1;
+	}
+
       /* Handle the __gcc_cdiag__ format specifics.  */
       if (!cdiag_fci)
 	dynamic_format_types[gcc_cdiag_format_type].conversion_specs =
@@ -2603,6 +2661,7 @@ handle_format_attribute (tree *node, tre
      initialize certain bits a runtime.  */
   if (info.format_type == asm_fprintf_format_type
       || info.format_type == gcc_diag_format_type
+      || info.format_type == gcc_tdiag_format_type
       || info.format_type == gcc_cdiag_format_type
       || info.format_type == gcc_cxxdiag_format_type)
     {
@@ -2620,6 +2679,7 @@ handle_format_attribute (tree *node, tre
       /* If this is one of the diagnostic attributes, then we have to
          initialize 'location_t' and 'tree' at runtime.  */
       else if (info.format_type == gcc_diag_format_type
+	       || info.format_type == gcc_tdiag_format_type
 	       || info.format_type == gcc_cdiag_format_type
 	       || info.format_type == gcc_cxxdiag_format_type)
 	init_dynamic_diag_info ();
diff -rupN GCC.orig/gcc/c-tree.h GCC/gcc/c-tree.h
--- GCC.orig/gcc/c-tree.h	2005-06-29 22:09:40.000000000 +0000
+++ GCC/gcc/c-tree.h	2005-07-02 19:35:40.000000000 +0000
@@ -608,8 +608,7 @@ extern void c_write_global_declarations 
 /* In order for the format checking to accept the C frontend
    diagnostic framework extensions, you must include this file before
    toplev.h, not after.  */
-#define GCC_DIAG_STYLE __gcc_cdiag__
-#if GCC_VERSION >= 3005
+#if GCC_VERSION >= 4001
 #define ATTRIBUTE_GCC_CDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m ,n))) ATTRIBUTE_NONNULL(m)
 #else
 #define ATTRIBUTE_GCC_CDIAG(m, n) ATTRIBUTE_NONNULL(m)
diff -rupN GCC.orig/gcc/config/arm/arm.c GCC/gcc/config/arm/arm.c
--- GCC.orig/gcc/config/arm/arm.c	2005-06-28 21:46:45.000000000 +0000
+++ GCC/gcc/config/arm/arm.c	2005-07-02 22:01:11.000000000 +0000
@@ -14750,7 +14750,7 @@ arm_unwind_emit_stm (FILE * asm_out_file
   else if (reg >= FIRST_FPA_REGNUM && reg <= LAST_FPA_REGNUM)
     {
       /* FPA registers are done differently.  */
-      asm_fprintf (asm_out_file, "\t.save %r, %d\n", reg, nregs);
+      asm_fprintf (asm_out_file, "\t.save %r, %wd\n", reg, nregs);
       return;
     }
   else
@@ -14848,7 +14848,7 @@ arm_unwind_emit_set (FILE * asm_out_file
 	      || GET_CODE (XEXP (e1, 1)) != CONST_INT)
 	    abort ();
 
-	  asm_fprintf (asm_out_file, "\t.pad #%d\n",
+	  asm_fprintf (asm_out_file, "\t.pad #%wd\n",
 		       -INTVAL (XEXP (e1, 1)));
 	}
       else if (REGNO (e0) == HARD_FRAME_POINTER_REGNUM)
@@ -14863,7 +14863,7 @@ arm_unwind_emit_set (FILE * asm_out_file
 		abort ();
 	      reg = REGNO (XEXP (e1, 0));
 	      offset = INTVAL (XEXP (e1, 1));
-	      asm_fprintf (asm_out_file, "\t.setfp %r, %r, #%d\n",
+	      asm_fprintf (asm_out_file, "\t.setfp %r, %r, #%wd\n",
 			   HARD_FRAME_POINTER_REGNUM, reg,
 			   INTVAL (XEXP (e1, 1)));
 	    }
diff -rupN GCC.orig/gcc/config/i386/i386.c GCC/gcc/config/i386/i386.c
--- GCC.orig/gcc/config/i386/i386.c	2005-06-29 22:09:19.000000000 +0000
+++ GCC/gcc/config/i386/i386.c	2005-07-02 20:56:52.000000000 +0000
@@ -14659,7 +14659,7 @@ get_element_number (tree vec_type, tree 
   if (!host_integerp (arg, 1)
       || (elt = tree_low_cst (arg, 1), elt > max))
     {
-      error ("selector must be an integer constant in the range 0..%i", max);
+      error ("selector must be an integer constant in the range 0..%wi", max);
       return 0;
     }
 
diff -rupN GCC.orig/gcc/config/mmix/mmix.c GCC/gcc/config/mmix/mmix.c
--- GCC.orig/gcc/config/mmix/mmix.c	2005-06-25 09:54:34.000000000 +0000
+++ GCC/gcc/config/mmix/mmix.c	2005-07-02 22:36:41.000000000 +0000
@@ -1891,7 +1891,7 @@ mmix_expand_prologue (void)
 
   /* Make sure we don't get an unaligned stack.  */
   if ((stack_space_to_allocate % 8) != 0)
-    internal_error ("stack frame not a multiple of 8 bytes: %d",
+    internal_error ("stack frame not a multiple of 8 bytes: %wd",
 		    stack_space_to_allocate);
 
   if (current_function_pretend_args_size)
@@ -2127,7 +2127,7 @@ mmix_expand_epilogue (void)
 
   /* Make sure we don't get an unaligned stack.  */
   if ((stack_space_to_deallocate % 8) != 0)
-    internal_error ("stack frame not a multiple of octabyte: %d",
+    internal_error ("stack frame not a multiple of octabyte: %wd",
 		    stack_space_to_deallocate);
 
   /* We will add back small offsets to the stack pointer as we go.
diff -rupN GCC.orig/gcc/config/pdp11/pdp11.c GCC/gcc/config/pdp11/pdp11.c
--- GCC.orig/gcc/config/pdp11/pdp11.c	2005-06-25 09:54:35.000000000 +0000
+++ GCC/gcc/config/pdp11/pdp11.c	2005-07-02 22:49:24.000000000 +0000
@@ -245,7 +245,7 @@ pdp11_output_function_prologue (FILE *st
     {
       fprintf (stream, "\t/*abuse empty parameter slot for locals!*/\n");
       if (size > 2)
-	fprintf(stream, "\tsub $%#o, sp\n", size - 2);
+	asm_fprintf (stream, "\tsub $%#wo, sp\n", size - 2);
 
     }
 }
@@ -285,7 +285,7 @@ pdp11_output_function_prologue (FILE *st
 
     /* make frame */
     if (fsize)							
-	fprintf (stream, "\tsub $%#o, sp\n", fsize);			
+	asm_fprintf (stream, "\tsub $%#wo, sp\n", fsize);
 
     /* save CPU registers  */
     for (regno = 0; regno < 8; regno++)				
diff -rupN GCC.orig/gcc/config/rs6000/rs6000.c GCC/gcc/config/rs6000/rs6000.c
--- GCC.orig/gcc/config/rs6000/rs6000.c	2005-07-02 13:13:43.000000000 +0000
+++ GCC/gcc/config/rs6000/rs6000.c	2005-07-02 22:53:24.000000000 +0000
@@ -6826,7 +6826,7 @@ altivec_expand_builtin (tree exp, rtx ta
       && fcode <= ALTIVEC_BUILTIN_OVERLOADED_LAST)
     {
       *expandedp = true;
-      error ("unresolved overload for Altivec builtin %qE", fndecl);
+      error ("unresolved overload for Altivec builtin %qF", fndecl);
       return const0_rtx;
     }
 
diff -rupN GCC.orig/gcc/config/v850/v850-protos.h GCC/gcc/config/v850/v850-protos.h
--- GCC.orig/gcc/config/v850/v850-protos.h	2005-06-25 09:54:42.000000000 +0000
+++ GCC/gcc/config/v850/v850-protos.h	2005-07-02 23:06:02.000000000 +0000
@@ -61,7 +61,7 @@ extern rtx    function_arg              
 
 #ifdef TREE_CODE
 extern int    v850_interrupt_function_p     (tree);
-extern void   v850_output_aligned_bss       (FILE *, tree, const char *, int, int);
+extern void   v850_output_aligned_bss       (FILE *, tree, const char *, unsigned HOST_WIDE_INT, int);
 extern void   v850_output_common            (FILE *, tree, const char *, int, int);
 extern void   v850_output_local             (FILE *, tree, const char *, int, int);
 extern v850_data_area v850_get_data_area    (tree);
diff -rupN GCC.orig/gcc/config/v850/v850.c GCC/gcc/config/v850/v850.c
--- GCC.orig/gcc/config/v850/v850.c	2005-07-02 10:46:13.000000000 +0000
+++ GCC/gcc/config/v850/v850.c	2005-07-02 23:05:51.000000000 +0000
@@ -2485,7 +2485,7 @@ void
 v850_output_aligned_bss (FILE * file,
                          tree decl,
                          const char * name,
-                         int size,
+                         unsigned HOST_WIDE_INT size,
                          int align)
 {
   switch (v850_get_data_area (decl))
diff -rupN GCC.orig/gcc/cp/cp-tree.h GCC/gcc/cp/cp-tree.h
--- GCC.orig/gcc/cp/cp-tree.h	2005-07-02 10:46:13.000000000 +0000
+++ GCC/gcc/cp/cp-tree.h	2005-07-02 19:36:25.000000000 +0000
@@ -4367,9 +4367,11 @@ extern void cp_genericize			(tree);
 
 /* In order for the format checking to accept the C++ frontend
    diagnostic framework extensions, you must include this file before
-   toplev.h, not after.  */
+   toplev.h, not after.  We override the definition of GCC_DIAG_STYLE
+   in c-common.h.  */
+#undef GCC_DIAG_STYLE
 #define GCC_DIAG_STYLE __gcc_cxxdiag__
-#if GCC_VERSION >= 3004
+#if GCC_VERSION >= 4001
 #define ATTRIBUTE_GCC_CXXDIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
 #else
 #define ATTRIBUTE_GCC_CXXDIAG(m, n) ATTRIBUTE_NONNULL(m)
diff -rupN GCC.orig/gcc/stor-layout.c GCC/gcc/stor-layout.c
--- GCC.orig/gcc/stor-layout.c	2005-07-02 10:46:14.000000000 +0000
+++ GCC/gcc/stor-layout.c	2005-07-02 20:13:32.000000000 +0000
@@ -30,6 +30,7 @@ Software Foundation, 51 Franklin Street,
 #include "flags.h"
 #include "function.h"
 #include "expr.h"
+#include "output.h"
 #include "toplev.h"
 #include "ggc.h"
 #include "target.h"
@@ -453,7 +454,7 @@ layout_decl (tree decl, unsigned int kno
 	  if (compare_tree_int (size, size_as_int) == 0)
 	    warning (0, "size of %q+D is %d bytes", decl, size_as_int);
 	  else
-	    warning (0, "size of %q+D is larger than %d bytes",
+	    warning (0, "size of %q+D is larger than %wd bytes",
                      decl, larger_than_size);
 	}
     }
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/format/gcc_diag-1.c GCC/gcc/testsuite/gcc.dg/format/gcc_diag-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/format/gcc_diag-1.c	2005-07-02 10:46:14.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/format/gcc_diag-1.c	2005-07-02 19:22:34.000000000 +0000
@@ -21,6 +21,7 @@ union tree_node;
 typedef union tree_node *tree;
 
 extern int diag (const char *, ...) ATTRIBUTE_DIAG(__gcc_diag__);
+extern int tdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_tdiag__);
 extern int cdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cdiag__);
 extern int cxxdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cxxdiag__);
 
@@ -35,42 +36,57 @@ foo (int i, int i1, int i2, unsigned int
 {
   /* Acceptable C90 specifiers, flags and modifiers.  */
   diag ("%%");
+  tdiag ("%%");
   cdiag ("%%");
   cxxdiag ("%%");
   diag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p);
+  tdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p);
   cdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p);
   cxxdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p);
   diag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p);
+  tdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p);
   cdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p);
   cxxdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p);
   diag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul);
+  tdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul);
   cdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul);
   cxxdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul);
   diag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull);
+  tdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull);
   cdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull);
   cxxdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull);
   diag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull);
+  tdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull);
   cdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull);
   cxxdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull);
   diag ("%.*s", i, s);
+  tdiag ("%.*s", i, s);
   cdiag ("%.*s", i, s);
   cxxdiag ("%.*s", i, s);
 
   /* Extensions provided in the diagnostic framework.  */
   diag ("%m");
+  tdiag ("%m");
   cdiag ("%m");
   cxxdiag ("%m");
   diag ("%H", loc);
+  tdiag ("%H", loc);
   cdiag ("%H", loc);
   cxxdiag ("%H", loc);
   diag ("%J", t1);
+  tdiag ("%J", t1);
   cdiag ("%J", t1);
   cxxdiag ("%J", t1);
 
+  tdiag ("%D%F%T", t1, t1, t1);
+  tdiag ("%+D%+F%+T", t1, t1, t1);
+  tdiag ("%q+D%q+F%q+T", t1, t1, t1);
+  tdiag ("%D%D%D%D", t1, t2, *t3, t4[5]);
   cdiag ("%D%F%T", t1, t1, t1);
   cdiag ("%+D%+F%+T", t1, t1, t1);
   cdiag ("%q+D%q+F%q+T", t1, t1, t1);
   cdiag ("%D%D%D%D", t1, t2, *t3, t4[5]);
+  cdiag ("%E", t1);
   cxxdiag ("%A%D%E%F%T%V", t1, t1, t1, t1, t1, t1);
   cxxdiag ("%D%D%D%D", t1, t2, *t3, t4[5]);
   cxxdiag ("%#A%#D%#E%#F%#T%#V", t1, t1, t1, t1, t1, t1);
@@ -80,36 +96,49 @@ foo (int i, int i1, int i2, unsigned int
 
   /* Bad stuff with extensions.  */
   diag ("%m", i); /* { dg-warning "format" "extra arg" } */
+  tdiag ("%m", i); /* { dg-warning "format" "extra arg" } */
   cdiag ("%m", i); /* { dg-warning "format" "extra arg" } */
   cxxdiag ("%m", i); /* { dg-warning "format" "extra arg" } */
   diag ("%#m"); /* { dg-warning "format" "bogus modifier" } */
+  tdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */
   cxxdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */
   diag ("%+m"); /* { dg-warning "format" "bogus modifier" } */
+  tdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */
   cxxdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */
   diag ("%H"); /* { dg-warning "format" "missing arg" } */
+  tdiag ("%H"); /* { dg-warning "format" "missing arg" } */
   cdiag ("%H"); /* { dg-warning "format" "missing arg" } */
   cxxdiag ("%H"); /* { dg-warning "format" "missing arg" } */
   diag ("%J"); /* { dg-warning "format" "missing arg" } */
+  tdiag ("%J"); /* { dg-warning "format" "missing arg" } */
   cdiag ("%J"); /* { dg-warning "format" "missing arg" } */
   cxxdiag ("%J"); /* { dg-warning "format" "missing arg" } */
   diag ("%H", i); /* { dg-warning "format" "wrong arg" } */
+  tdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */
   cdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */
   cxxdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */
   diag ("%H", p); /* { dg-warning "format" "wrong arg" } */
+  tdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */
   cdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */
   cxxdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */
   diag ("%J", loc); /* { dg-warning "format" "wrong arg" } */
+  tdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */
   cdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */
   cxxdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */
   diag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */
+  tdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */
   cxxdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */
   diag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */
+  tdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */
   cxxdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */
   diag ("%D", t1); /* { dg-warning "format" "bogus tree" } */
+  tdiag ("%A", t1); /* { dg-warning "format" "bogus tree" } */
+  tdiag ("%E", t1); /* { dg-warning "format" "bogus tree" } */
+  tdiag ("%#D", t1); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%A", t1); /* { dg-warning "format" "bogus tree" } */
   cdiag ("%#D", t1); /* { dg-warning "format" "bogus modifier" } */
   cdiag ("%+D", t1);
@@ -118,10 +147,13 @@ foo (int i, int i1, int i2, unsigned int
   cxxdiag ("%C", i, i); /* { dg-warning "format" "extra arg" } */
   cxxdiag ("%#C", i); /* { dg-warning "format" "bogus modifier" } */
   cxxdiag ("%+C", i); /* { dg-warning "format" "bogus modifier" } */
+  tdiag ("%D"); /* { dg-warning "format" "missing arg" } */
   cdiag ("%D"); /* { dg-warning "format" "missing arg" } */
   cxxdiag ("%D"); /* { dg-warning "format" "missing arg" } */
+  tdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */
   cdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */
   cxxdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */
+  tdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */
   cdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */
   cxxdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */
 
@@ -137,36 +169,47 @@ foo (int i, int i1, int i2, unsigned int
 
   /* Various tests of bad argument types.  */
   diag ("%-d", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */
   diag ("% d", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("% d", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("% d", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("% d", i); /* { dg-warning "format" "bad flag" } */
   diag ("%#o", u); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */
   cdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */
   diag ("%0d", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */
   diag ("%08d", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */
   diag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */
   diag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */
   diag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */
   diag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */
   diag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */
   cdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */
   diag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */
+  tdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */
   cdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */
   cxxdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */
   diag ("%d %lu\n", i, ul);
diff -rupN GCC.orig/gcc/toplev.h GCC/gcc/toplev.h
--- GCC.orig/gcc/toplev.h	2005-06-25 09:54:07.000000000 +0000
+++ GCC/gcc/toplev.h	2005-07-02 19:17:36.000000000 +0000
@@ -44,34 +44,25 @@ extern void _fatal_insn (const char *, r
 /* If we haven't already defined a frontend specific diagnostics
    style, use the generic one.  */
 #ifndef GCC_DIAG_STYLE
-#define GCC_DIAG_STYLE __gcc_diag__
-#define NO_FRONT_END_DIAG
+#define GCC_DIAG_STYLE __gcc_tdiag__
 #endif
 /* None of these functions are suitable for ATTRIBUTE_PRINTF, because
    each language front end can extend them with its own set of format
-   specifiers.  We must use custom format checks.  Note that at present
-   the front-end %D specifier is used in non-front-end code with some
-   functions, and those formats can only be checked in front-end code.  */
-#if GCC_VERSION >= 3005
+   specifiers.  We must use custom format checks.  */
+#if GCC_VERSION >= 4001
 #define ATTRIBUTE_GCC_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
-#ifdef NO_FRONT_END_DIAG
-#define ATTRIBUTE_GCC_FE_DIAG(m, n) ATTRIBUTE_NONNULL(m)
-#else
-#define ATTRIBUTE_GCC_FE_DIAG(m, n) __attribute__ ((__format__ (GCC_DIAG_STYLE, m, n))) ATTRIBUTE_NONNULL(m)
-#endif
 #else
 #define ATTRIBUTE_GCC_DIAG(m, n) ATTRIBUTE_NONNULL(m)
-#define ATTRIBUTE_GCC_FE_DIAG(m, n) ATTRIBUTE_NONNULL(m)
 #endif
 extern void internal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
-extern void warning0 (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
-extern void warning (int, const char *, ...) ATTRIBUTE_GCC_FE_DIAG(2,3);
-extern void error (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
+extern void warning0 (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
+extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
      ATTRIBUTE_NORETURN;
-extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
-extern void sorry (const char *, ...) ATTRIBUTE_GCC_FE_DIAG(1,2);
+extern void pedwarn (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void sorry (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void inform (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
 
diff -rupN GCC.orig/gcc/tree-eh.c GCC/gcc/tree-eh.c
--- GCC.orig/gcc/tree-eh.c	2005-06-25 09:54:07.000000000 +0000
+++ GCC/gcc/tree-eh.c	2005-07-02 19:48:55.000000000 +0000
@@ -1764,7 +1764,7 @@ mark_eh_edge (struct eh_region *region, 
   e = find_edge (src, dst);
   if (!e)
     {
-      error ("EH edge %i->%i is missing %i %i.", src->index, dst->index, src, dst);
+      error ("EH edge %i->%i is missing.", src->index, dst->index);
       mark_eh_edge_found_error = true;
     }
   else if (!(e->flags & EDGE_EH))
diff -rupN GCC.orig/gcc/tree-ssa.c GCC/gcc/tree-ssa.c
--- GCC.orig/gcc/tree-ssa.c	2005-07-01 19:24:45.000000000 +0000
+++ GCC/gcc/tree-ssa.c	2005-07-02 19:47:22.000000000 +0000
@@ -346,7 +346,7 @@ verify_phi_args (tree phi, basic_block b
       if (e->dest != bb)
 	{
 	  error ("Wrong edge %d->%d for PHI argument\n",
-	         e->src->index, e->dest->index, bb->index);
+	         e->src->index, e->dest->index);
 	  err = true;
 	}
 
diff -rupN GCC.orig/gcc/varasm.c GCC/gcc/varasm.c
--- GCC.orig/gcc/varasm.c	2005-07-02 10:46:14.000000000 +0000
+++ GCC/gcc/varasm.c	2005-07-02 20:46:05.000000000 +0000
@@ -4583,11 +4583,11 @@ finish_aliases_1 (void)
 
       target_decl = find_decl_and_mark_needed (p->decl, p->target);
       if (target_decl == NULL)
-	error ("%q+D aliased to undefined symbol %qE",
-	       p->decl, p->target);
+	error ("%q+D aliased to undefined symbol %qs",
+	       p->decl, IDENTIFIER_POINTER (p->target));
       else if (DECL_EXTERNAL (target_decl))
-	error ("%q+D aliased to external symbol %qE",
-	       p->decl, p->target);
+	error ("%q+D aliased to external symbol %qs",
+	       p->decl, IDENTIFIER_POINTER (p->target));
     }
 }
 



More information about the Gcc-patches mailing list