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/testsuite/c-c++-common/analyzer | |
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/testsuite/c-c++-common/analyzer')
-rw-r--r-- | gcc/testsuite/c-c++-common/analyzer/escaping-1.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/gcc/testsuite/c-c++-common/analyzer/escaping-1.c b/gcc/testsuite/c-c++-common/analyzer/escaping-1.c index b389656..0d3949b 100644 --- a/gcc/testsuite/c-c++-common/analyzer/escaping-1.c +++ b/gcc/testsuite/c-c++-common/analyzer/escaping-1.c @@ -13,16 +13,13 @@ static void test_1 (void) __analyzer_dump_escaped (); /* { dg-warning "escaped: 0: " } */ unknown_fn (&local_1); - __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" "" { target c } } */ - /* { dg-warning "escaped: 1: 'int local_1'" "" { target c++ } .-1 } */ + __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" } */ /* Should be idempotent. */ unknown_fn (&local_1); - __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" "" { target c } } */ - /* { dg-warning "escaped: 1: 'int local_1'" "" { target c++ } .-1 } */ + __analyzer_dump_escaped (); /* { dg-warning "escaped: 1: 'local_1'" } */ /* Escape a static global. */ unknown_fn (&only_used_by_test_1); - __analyzer_dump_escaped (); /* { dg-warning "escaped: 2: 'local_1', 'only_used_by_test_1'" "" { target c } } */ - /* { dg-warning "escaped: 2: 'int local_1', 'int only_used_by_test_1'" "" { target c++ } .-1 } */ + __analyzer_dump_escaped (); /* { dg-warning "escaped: 2: 'local_1', 'only_used_by_test_1'" } */ } |