The attached patch cleans up most remaining -Wformat-diag instances
in an x86_64-build.  I tried to minimize using #pragma diagnostic
so I tweaked the code instead.  A preferable solution might be to
introduce a new format attribute and used it to exempt the pp_printf()
and verbatim() functions from some of the -Wformat-diag checks but that
would require more surgery on the warning code than I think is called
for at this point.

Tested by bootstrapping all of the languages below (same set I test
all my patches with) and regtesting:
  ada,brig,c,c++,d,fortran,jit,lto,objc,obj-c++

Martin
Clean up -Wformat-diag warnings (PR bootstrap/97622, PR bootstrap/94982)

gcc/c-family/ChangeLog:

	PR bootstrap/94982
	* c-attribs.c (handle_patchable_function_entry_attribute): Avoid
	-Wformat-diag.

gcc/cp/ChangeLog:

	PR bootstrap/94982
	* constraint.cc (debug_argument_list): Avoid -Wformat-diag.
	* error.c (function_category): Same.
	(print_template_differences): Same.
	* logic.cc (debug): Same.
	* name-lookup.c (lookup_using_decl): Same.
	* parser.c (maybe_add_cast_fixit): Same.
	(cp_parser_template_introduction): Same.
	* typeck.c (access_failure_info::add_fixit_hint): Same.

gcc/ChangeLog:

	PR bootstrap/97622
	PR bootstrap/94982
	* digraph.cc (struct test_edge): Avoid -Wformat-diag.
	* dumpfile.c (dump_loc): Same.
	(dump_context::begin_scope): Same.
	* edit-context.c (edited_file::print_diff): Same.
	(edited_file::print_diff_hunk): Same.
	* json.cc (object::print): Same.
	* lto-wrapper.c (merge_and_complain): Same.
	* reload.c (find_reloads): Same.
	* tree-diagnostic-path.cc (print_path_summary_as_text): Same.
	* ubsan.c (ubsan_type_descriptor): Same.

gcc/jit/ChangeLog:

	PR bootstrap/94982
	* jit-recording.c (recording::function::dump_to_dot): Avoid
	-Wformat-diag.
	(recording::block::dump_to_dot): Same.

gcc/testsuite/ChangeLog:

	PR bootstrap/94982
	* c-c++-common/patchable_function_entry-error-3.c: Adjust text
	of expected warning.

diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 6d515dca05a..99b663085f2 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -5191,8 +5191,8 @@ handle_patchable_function_entry_attribute (tree *, tree name, tree args,
       if (tree_to_uhwi (val) > USHRT_MAX)
 	{
 	  warning (OPT_Wattributes,
-		   "%qE attribute argument %qE is out of range (> 65535)",
-		   name, val);
+		   "%qE attribute argument %qE exceeds %u",
+		   name, val, USHRT_MAX);
 	  *no_add_attrs = true;
 	  return NULL_TREE;
 	}
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 8691281d5f1..00d2f2ea9a8 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -533,9 +533,9 @@ debug_argument_list (tree args)
     {
       tree arg = TREE_VEC_ELT (args, i);
       if (TYPE_P (arg))
-	verbatim ("ARG %qT", arg);
+	verbatim ("argument %qT", arg);
       else
-	verbatim ("ARG %qE", arg);
+	verbatim ("argument %qE", arg);
     }
 }
 
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index d27545d1223..85249f4a539 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -3553,6 +3553,14 @@ function_category (tree fn)
     return _("In function %qs");
 }
 
+/* Disable warnings about missing quoting in GCC diagnostics for
+   the pp_verbatim calls.  Their format strings deliberately don't
+   follow GCC diagnostic conventions.  */
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wformat-diag"
+#endif
+
 /* Report the full context of a current template instantiation,
    onto BUFFER.  */
 static void
@@ -4053,6 +4061,10 @@ print_template_differences (pretty_printer *pp, tree type_a, tree type_b,
   pp_printf (pp, ">");
 }
 
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic pop
+#endif
+
 /* As type_to_string, but for a template, potentially colorizing/eliding
    in comparison with PEER.
    For example, if TYPE is map<int,double> and PEER is map<int,int>,
diff --git a/gcc/cp/logic.cc b/gcc/cp/logic.cc
index 6701488bc1c..5592680b08e 100644
--- a/gcc/cp/logic.cc
+++ b/gcc/cp/logic.cc
@@ -303,9 +303,10 @@ debug (formula& f)
 {
   for (formula::iterator i = f.begin(); i != f.end(); ++i)
     {
-      verbatim ("(((");
+      /* Format punctuators via %s to avoid -Wformat-diag.  */
+      verbatim ("%s", "(((");
       debug (*i);
-      verbatim (")))");
+      verbatim ("%s", ")))");
     }
 }
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index bf05e7bbcd1..837c0ea89af 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4613,7 +4613,8 @@ lookup_using_decl (tree scope, name_lookup &lookup)
 	{
 	  if (!TYPE_P (current))
 	    {
-	      error ("non-member using-decl names constructor of %qT", scope);
+	      error ("non-member using-declaration names constructor of %qT",
+		     scope);
 	      return NULL_TREE;
 	    }
 	  maybe_warn_cpp0x (CPP0X_INHERITING_CTORS);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 88021243ee4..d11900a7dd5 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -9382,7 +9382,8 @@ maybe_add_cast_fixit (rich_location *rich_loc, location_t open_paren_loc,
 
   /* Replace the open paren with "CAST_SUGGESTION<".  */
   pretty_printer pp;
-  pp_printf (&pp, "%s<", cast_suggestion);
+  pp_string (&pp, cast_suggestion);
+  pp_less (&pp);
   rich_loc->add_fixit_replace (open_paren_loc, pp_formatted_text (&pp));
 
   /* Replace the close paren with "> (".  */
@@ -29750,7 +29751,8 @@ cp_parser_template_introduction (cp_parser* parser, bool member_p)
     {
       if (!flag_concepts_ts)
 	pedwarn (introduction_loc, 0, "template-introductions"
-		 " are not part of C++20 concepts [-fconcepts-ts]");
+		 " are not part of C++20 concepts; use %qs to enable",
+		 "-fconcepts-ts");
 
       cp_parser_template_declaration_after_parameters (parser, parms,
 						       member_p);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 729c7069c4f..267b284ea40 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2901,7 +2901,8 @@ access_failure_info::add_fixit_hint (rich_location *richloc,
 				     tree accessor_decl)
 {
   pretty_printer pp;
-  pp_printf (&pp, "%s()", IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
+  pp_string (&pp, IDENTIFIER_POINTER (DECL_NAME (accessor_decl)));
+  pp_string (&pp, "()");
   richloc->add_fixit_replace (pp_formatted_text (&pp));
 }
 
diff --git a/gcc/digraph.cc b/gcc/digraph.cc
index 31b3e19851f..cd376ba1873 100644
--- a/gcc/digraph.cc
+++ b/gcc/digraph.cc
@@ -67,7 +67,7 @@ struct test_edge : public dedge<test_graph_traits>
 
   void dump_dot (graphviz_out *gv, const dump_args_t &) const OVERRIDE
   {
-    gv->println ("%s -> %s;", m_src->m_name, m_dest->m_name);
+    gv->println ("%s %s %s%c", m_src->m_name, "->", m_dest->m_name, ';');
   }
 };
 
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 8e53aeff340..19985324a4c 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -492,6 +492,14 @@ dump_loc (dump_flags_t dump_kind, FILE *dfile, location_t loc)
 static void
 dump_loc (dump_flags_t dump_kind, pretty_printer *pp, location_t loc)
 {
+  /* Disable warnings about missing quoting in GCC diagnostics for
+     the pp_printf calls.  Their format strings aren't used to format
+     diagnostics so don't need to follow GCC diagnostic conventions.  */
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wformat-diag"
+#endif
+
   if (dump_kind)
     {
       if (LOCATION_LOCUS (loc) > BUILTINS_LOCATION)
@@ -507,6 +515,10 @@ dump_loc (dump_flags_t dump_kind, pretty_printer *pp, location_t loc)
       for (unsigned i = 0; i < get_dump_scope_depth (); i++)
 	pp_character (pp, ' ');
     }
+
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic pop
+#endif
 }
 
 /* Implementation of dump_context member functions.  */
@@ -1118,8 +1130,11 @@ dump_context::begin_scope (const char *name,
   if (m_test_pp && apply_dump_filter_p (MSG_NOTE, m_test_pp_flags))
     ::dump_loc (MSG_NOTE, m_test_pp, src_loc);
 
+  /* Format multiple consecutive punctuation characters via %s to
+     avoid -Wformat-diag in the pp_printf call below whose output
+     isn't used for diagnostic output.  */
   pretty_printer pp;
-  pp_printf (&pp, "=== %s ===\n", name);
+  pp_printf (&pp, "%s %s %s\n", "===", name, "===");
   optinfo_item *item
     = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
 			xstrdup (pp_formatted_text (&pp)));
diff --git a/gcc/edit-context.c b/gcc/edit-context.c
index 97897d69a10..80641c2843b 100644
--- a/gcc/edit-context.c
+++ b/gcc/edit-context.c
@@ -447,8 +447,13 @@ edited_file::print_diff (pretty_printer *pp, bool show_filenames)
   if (show_filenames)
     {
       pp_string (pp, colorize_start (pp_show_color (pp), "diff-filename"));
-      pp_printf (pp, "--- %s\n", m_filename);
-      pp_printf (pp, "+++ %s\n", m_filename);
+      /* Avoid -Wformat-diag in non-diagnostic output.  */
+      pp_string (pp, "--- ");
+      pp_string (pp, m_filename);
+      pp_newline (pp);
+      pp_string (pp, "+++ ");
+      pp_string (pp, m_filename);
+      pp_newline (pp);
       pp_string (pp, colorize_stop (pp_show_color (pp)));
     }
 
@@ -519,8 +524,9 @@ edited_file::print_diff_hunk (pretty_printer *pp, int old_start_of_hunk,
     = get_effective_line_count (old_start_of_hunk, old_end_of_hunk);
 
   pp_string (pp, colorize_start (pp_show_color (pp), "diff-hunk"));
-  pp_printf (pp, "@@ -%i,%i +%i,%i @@\n", old_start_of_hunk, old_num_lines,
-	     new_start_of_hunk, new_num_lines);
+  pp_printf (pp, "%s -%i,%i +%i,%i %s",
+	     "@@", old_start_of_hunk, old_num_lines,
+	     new_start_of_hunk, new_num_lines, "@@\n");
   pp_string (pp, colorize_stop (pp_show_color (pp)));
 
   int line_num = old_start_of_hunk;
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index 1b0f8bc7db3..9af3c52d1b1 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -4038,8 +4038,8 @@ recording::function::dump_to_dot (const char *path)
 
   pretty_printer *pp = &the_pp;
 
-  pp_printf (pp,
-	     "digraph %s {\n", get_debug_string ());
+  pp_printf (pp, "digraph %s", get_debug_string ());
+  pp_string (pp, " {\n");
 
   /* Blocks: */
   {
@@ -4057,7 +4057,7 @@ recording::function::dump_to_dot (const char *path)
       b->dump_edges_to_dot (pp);
   }
 
-  pp_printf (pp, "}\n");
+  pp_string (pp, "}\n");
   pp_flush (pp);
   fclose (fp);
 }
@@ -4485,6 +4485,14 @@ recording::block::write_reproducer (reproducer &r)
 void
 recording::block::dump_to_dot (pretty_printer *pp)
 {
+  /* Disable warnings about missing quoting in GCC diagnostics for
+     the pp_printf calls.  Their format strings deliberately don't
+     follow GCC diagnostic conventions.  */
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Wformat-diag"
+#endif
+
   pp_printf (pp,
 	     ("\tblock_%d "
 	      "[shape=record,style=filled,fillcolor=white,label=\"{"),
@@ -4507,9 +4515,13 @@ recording::block::dump_to_dot (pretty_printer *pp)
       pp_write_text_as_dot_label_to_stream (pp, true /*for_record*/);
     }
 
-  pp_printf (pp,
+  pp_string (pp,
 	     "}\"];\n\n");
   pp_flush (pp);
+
+#if __GNUC__ >= 10
+#  pragma GCC diagnostic pop
+#endif
 }
 
 /* Dump the out-edges of the block in graphviz form into PP.  */
diff --git a/gcc/json.cc b/gcc/json.cc
index 627741db7f0..70775d1c0af 100644
--- a/gcc/json.cc
+++ b/gcc/json.cc
@@ -70,7 +70,10 @@ object::print (pretty_printer *pp) const
 	pp_string (pp, ", ");
       const char *key = const_cast <char *>((*it).first);
       value *value = (*it).second;
-      pp_printf (pp, "\"%s\": ", key); // FIXME: escaping?
+      pp_doublequote (pp);
+      pp_string (pp, key); // FIXME: escaping?
+      pp_doublequote (pp);
+      pp_string (pp, ": ");
       value->print (pp);
     }
   pp_character (pp, '}');
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index fe10f4f4fbb..68ccb156521 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -323,8 +323,9 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
 		  if (cf_protection_option
 		      && cf_protection_option->value == CF_CHECK)
 		    fatal_error (input_location,
-				 "option -fcf-protection with mismatching values"
+				 "option %qs with mismatching values"
 				 " (%s, %s)",
+				 "-fcf-protection",
 				 (*decoded_options)[j].arg, foption->arg);
 		  else
 		    {
diff --git a/gcc/reload.c b/gcc/reload.c
index 445f9bdca43..a63cc02d4b3 100644
--- a/gcc/reload.c
+++ b/gcc/reload.c
@@ -2665,7 +2665,7 @@ find_reloads (rtx_insn *insn, int replace, int ind_levels, int live_known,
       if (i < recog_data.n_operands)
 	{
 	  error_for_asm (insn,
-			 "the target does not support asm goto "
+			 "the target does not support %<asm goto%> "
 			 "with outputs in %<asm%>");
 	  ira_nullify_asm_goto (insn);
 	  return 0;
diff --git a/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c b/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c
index 4490e5c15ca..c3ef54d3207 100644
--- a/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c
+++ b/gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c
@@ -3,15 +3,15 @@
 
 void
  __attribute__((patchable_function_entry(65536)))
-foo1 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' is out of range" } */
+foo1 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' exceeds 65535" } */
 }
 
 void
  __attribute__((patchable_function_entry(65536,1)))
-foo2 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' is out of range" } */
+foo2 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' exceeds 65535" } */
 }
 
 void
  __attribute__((patchable_function_entry(65536,65536)))
-foo3 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' is out of range" } */
+foo3 (void) { /* { dg-warning "'patchable_function_entry' attribute argument '65536' exceeds 65535" } */
 }
diff --git a/gcc/tree-diagnostic-path.cc b/gcc/tree-diagnostic-path.cc
index 164df86037e..222e44497a5 100644
--- a/gcc/tree-diagnostic-path.cc
+++ b/gcc/tree-diagnostic-path.cc
@@ -411,7 +411,7 @@ print_path_summary_as_text (const path_summary *ps, diagnostic_context *dc,
 
 		  write_indent (pp, vbar_for_next_frame);
 		  pp_string (pp, start_line_color);
-		  pp_printf (pp, "|");
+		  pp_character (pp, '|');
 		  pp_string (pp, end_line_color);
 		  pp_newline (pp);
 		}
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index acd8a0b92b9..1a2a71299d5 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -405,10 +405,12 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
     /* We weren't able to determine the type name.  */
     tname = "<unknown>";
 
+  pp_quote (&pretty_name);
+
   tree eltype = type;
   if (pstyle == UBSAN_PRINT_POINTER)
     {
-      pp_printf (&pretty_name, "'%s%s%s%s%s%s%s",
+      pp_printf (&pretty_name, "%s%s%s%s%s%s%s",
 		 TYPE_VOLATILE (type2) ? "volatile " : "",
 		 TYPE_READONLY (type2) ? "const " : "",
 		 TYPE_RESTRICT (type2) ? "restrict " : "",
@@ -420,14 +422,13 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
 		 deref_depth == 0 ? "" : " ");
       while (deref_depth-- > 0)
 	pp_star (&pretty_name);
-      pp_quote (&pretty_name);
     }
   else if (pstyle == UBSAN_PRINT_ARRAY)
     {
       /* Pretty print the array dimensions.  */
       gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
       tree t = type;
-      pp_printf (&pretty_name, "'%s ", tname);
+      pp_printf (&pretty_name, "%s ", tname);
       while (deref_depth-- > 0)
 	pp_star (&pretty_name);
       while (TREE_CODE (t) == ARRAY_TYPE)
@@ -453,13 +454,14 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
 	  pp_right_bracket (&pretty_name);
 	  t = TREE_TYPE (t);
 	}
-      pp_quote (&pretty_name);
 
       /* Save the tree with stripped types.  */
       eltype = t;
     }
   else
-    pp_printf (&pretty_name, "'%s'", tname);
+    pp_string (&pretty_name, tname);
+
+  pp_quote (&pretty_name);
 
   switch (TREE_CODE (eltype))
     {

Reply via email to