diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-09-30 11:48:29 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-09-30 11:48:29 -0400 |
commit | 3d3d20ccd8365970f34002bfe0a632f2868bc95b (patch) | |
tree | b6815ac2fbf9e0a50b88a41799388ee6bd1901de /gcc/cp | |
parent | 4c7a58ac2617e24069c9ad3d469a7f87dc96091d (diff) | |
download | gcc-3d3d20ccd8365970f34002bfe0a632f2868bc95b.zip gcc-3d3d20ccd8365970f34002bfe0a632f2868bc95b.tar.gz gcc-3d3d20ccd8365970f34002bfe0a632f2868bc95b.tar.bz2 |
diagnostics: use "%e" to avoid intermediate strings [PR116613]
Various diagnostics build an intermediate string, potentially with
colorization, and then use this in a diagnostic message.
This won't work if we have multiple diagnostic sinks, where some might
be colorized and some not.
This patch reworks such places using "%e" and pp_element subclasses, so
that any colorization happens within report_diagnostic's call to
pp_format.
gcc/analyzer/ChangeLog:
PR other/116613
* kf-analyzer.cc: Include "pretty-print-markup.h".
(kf_analyzer_dump_escaped::impl_call_pre): Defer colorization
choices by eliminating the construction of a intermediate string,
replacing it with a new pp_element subclass via "%e".
gcc/ChangeLog:
PR other/116613
* attribs.cc: Include "pretty-print-markup.h".
(decls_mismatched_attributes): Defer colorization choices by
replacing printing to a pretty_printer * param with appending
to a vec of strings.
(maybe_diag_alias_attributes): As above, replacing pretty_printer
with usage of pp_markup::comma_separated_quoted_strings and "%e"
in two places.
* attribs.h (decls_mismatched_attributes): Update decl.
* gimple-ssa-warn-access.cc: Include "pretty-print-markup.h".
(pass_waccess::maybe_warn_memmodel): Defer colorization choices by
replacing printing to a pretty_printer * param with use of
pp_markup::comma_separated_quoted_strings and "%e".
(pass_waccess::maybe_warn_memmodel): Likewise, replacing printing
to a temporary buffer.
* pretty-print-markup.h
(class pp_markup::comma_separated_quoted_strings): New.
* pretty-print.cc
(pp_markup::comma_separated_quoted_strings::add_to_phase_2): New.
(selftest::test_pp_printf_within_pp_element): New.
(selftest::test_comma_separated_quoted_strings): New.
(selftest::pretty_print_cc_tests): Call the new tests.
gcc/cp/ChangeLog:
PR other/116613
* pt.cc: Include "pretty-print-markup.h".
(warn_spec_missing_attributes): Defer colorization choices by
replacing printing to a pretty_printer * param with appending
to a vec of strings. Replace pretty_printer with usage of
pp_markup::comma_separated_quoted_strings and "%e".
gcc/testsuite/ChangeLog:
PR other/116613
* c-c++-common/analyzer/escaping-1.c: Update expected results to
remove type information from C++ results. Previously we were
using %qD with default_tree_printer, which used
lang_hooks.decl_printable_name, whereas now we're using %qD with
a clone of the cxx_pretty_printer.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/pt.cc | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index a3a697d..43468e5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "builtins.h" #include "omp-general.h" +#include "pretty-print-markup.h" /* The type of functions taking a tree, and some additional data, and returning an int. */ @@ -2764,9 +2765,9 @@ warn_spec_missing_attributes (tree tmpl, tree spec, tree attrlist) /* Put together a list of the black listed attributes that the primary template is declared with that the specialization is not, in case it's not apparent from the most recent declaration of the primary. */ - pretty_printer str; + auto_vec<const char *> mismatches; unsigned nattrs = decls_mismatched_attributes (tmpl, spec, attrlist, - blacklist, &str); + blacklist, mismatches); if (!nattrs) return; @@ -2775,11 +2776,14 @@ warn_spec_missing_attributes (tree tmpl, tree spec, tree attrlist) if (warning_at (DECL_SOURCE_LOCATION (spec), OPT_Wmissing_attributes, "explicit specialization %q#D may be missing attributes", spec)) - inform (DECL_SOURCE_LOCATION (tmpl), - nattrs > 1 - ? G_("missing primary template attributes %s") - : G_("missing primary template attribute %s"), - pp_formatted_text (&str)); + { + pp_markup::comma_separated_quoted_strings e (mismatches); + inform (DECL_SOURCE_LOCATION (tmpl), + nattrs > 1 + ? G_("missing primary template attributes %e") + : G_("missing primary template attribute %e"), + &e); + } } /* Check to see if the function just declared, as indicated in |