From ca23341b28cd3af7985b83a6479107d9ea145a90 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 25 Nov 2020 14:05:01 -0700 Subject: [PATCH] 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 * config/i386/i386-options.c (ix86_valid_target_attribute_inner_p): Avoid -Wformat-diag. * digraph.cc (struct test_edge): Same. * 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. --- gcc/c-family/c-attribs.c | 4 ++-- gcc/config/i386/i386-options.c | 4 ++-- gcc/cp/constraint.cc | 4 ++-- gcc/cp/error.c | 21 ++++++++++++++++--- gcc/cp/logic.cc | 5 +++-- gcc/cp/name-lookup.c | 3 ++- gcc/cp/parser.c | 6 ++++-- gcc/cp/typeck.c | 3 ++- gcc/digraph.cc | 2 +- gcc/dumpfile.c | 18 +++++++++++++++- gcc/edit-context.c | 14 +++++++++---- gcc/jit/jit-recording.c | 20 ++++++++++++++---- gcc/json.cc | 5 ++++- gcc/lto-wrapper.c | 3 ++- gcc/reload.c | 2 +- .../patchable_function_entry-error-3.c | 6 +++--- gcc/tree-diagnostic-path.cc | 13 +++++++++++- gcc/ubsan.c | 13 +++++++----- 18 files changed, 109 insertions(+), 37 deletions(-) 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/config/i386/i386-options.c b/gcc/config/i386/i386-options.c index 467bed82f47..dc07697f622 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -1209,7 +1209,7 @@ ix86_valid_target_attribute_inner_p (tree fndecl, tree args, char *p_strings[], { if (!opt_set_p) { - error_at (loc, "pragma or attribute % " + error_at (loc, "pragma or attribute % " "does not allow a negated form", p); return false; } @@ -2077,7 +2077,7 @@ ix86_option_override_internal (bool main_args_p, && (!TARGET_64BIT_P (opts->x_ix86_isa_flags) || opts->x_ix86_abi != SYSV_ABI)) { - error (G_("%<%s%> architecture level is only defined" + error (G_("%qs architecture level is only defined" " for the x86-64 psABI"), opts->x_ix86_arch_string); return false; } 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..ff701fc789d 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 and PEER is map, @@ -4152,9 +4164,12 @@ add_quotes (const char *content, bool show_color) pretty_printer tmp_pp; pp_show_color (&tmp_pp) = show_color; - /* We have to use "%<%s%>" rather than "%qs" here in order to avoid - quoting colorization bytes within the results. */ - pp_printf (&tmp_pp, "%<%s%>", content); + /* We use pp_quote & pp_string rather than pp_printf with "%<%s%>" + or "%qs" here in order to avoid quoting colorization bytes within + the results, and to avoid -Wformat-diag. */ + pp_quote (&tmp_pp); + pp_string (&tmp_pp, content); + pp_quote (&tmp_pp); return pp_ggc_formatted_text (&tmp_pp); } 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 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..80a65fe1ec3 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,12 @@ 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", "===", name, "==="); + pp_newline (&pp); 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..a237d574fe5 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); } @@ -4479,6 +4479,14 @@ recording::block::write_reproducer (reproducer &r) m_name ? m_name->get_debug_string () : "NULL"); } +/* 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 + /* Dump a block in graphviz form into PP, capturing the block name (if any) and the statements. */ @@ -4507,7 +4515,7 @@ 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); } @@ -4527,6 +4535,10 @@ recording::block::dump_edges_to_dot (pretty_printer *pp) successors.release (); } +#if __GNUC__ >= 10 +# pragma GCC diagnostic pop +#endif + /* The implementation of class gcc::jit::recording::global. */ /* Implementation of pure virtual hook recording::memento::replay_into 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 ((*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 % " "with outputs in %"); 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..b4fef2bea6f 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); } @@ -520,6 +520,13 @@ default_tree_make_json_for_path (diagnostic_context *context, #if CHECKING_P +/* Disable warnings about missing quoting in GCC diagnostics for the print + calls in the tests below. */ +#if __GNUC__ >= 10 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wformat-diag" +#endif + namespace selftest { /* A subclass of simple_diagnostic_path that adds member functions @@ -814,4 +821,8 @@ tree_diagnostic_path_cc_tests () } // namespace selftest +#if __GNUC__ >= 10 +# pragma GCC diagnostic pop +#endif + #endif /* #if CHECKING_P */ diff --git a/gcc/ubsan.c b/gcc/ubsan.c index acd8a0b92b9..4c14a386a0e 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 = ""; + 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,14 @@ 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_string (&pretty_name, tname); + pp_space (&pretty_name); while (deref_depth-- > 0) pp_star (&pretty_name); while (TREE_CODE (t) == ARRAY_TYPE) @@ -453,13 +455,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)) { -- 2.30.2