aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2024-09-30 11:48:30 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2024-09-30 11:48:30 -0400
commite7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7 (patch)
tree57804a7bfba3023b89bbce8ce1cb42a7b973b014
parentbe02253af810348be689cfa6f235af96c8cc5802 (diff)
downloadgcc-e7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7.zip
gcc-e7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7.tar.gz
gcc-e7a8fbe2fed83b5ce6e2bdb6fd66d9bf47f74db7.tar.bz2
diagnostics: require callers of diagnostic_show_locus to be explicit about the printer [PR116613]
As work towards supporting multiple diagnostic outputs (where each output has its own pretty_printer), update diagnostic_show_locus so that the pretty_printer must always be explicitly passed in. No functional change intended. gcc/c-family/ChangeLog: PR other/116613 * c-format.cc (selftest::test_type_mismatch_range_labels): Explicitly pass in dc.m_printer to diagnostic_show_locus. gcc/ChangeLog: PR other/116613 * diagnostic-show-locus.cc (diagnostic_context::maybe_show_locus): Convert param "pp" from * to &. Drop logic for using the context's m_printer when the param is null. * diagnostic.h (diagnostic_context::maybe_show_locus): Convert param "pp" from * to &. (diagnostic_show_locus): Drop default "nullptr" value for pp param. Assert that it and context are nonnull. Pass pp by reference to maybe_show_locus. gcc/testsuite/ChangeLog: PR other/116613 * gcc.dg/plugin/expensive_selftests_plugin.c (test_richloc): Explicitly pass in dc.m_printer to diagnostic_show_locus. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r--gcc/c-family/c-format.cc2
-rw-r--r--gcc/diagnostic-show-locus.cc8
-rw-r--r--gcc/diagnostic.h8
-rw-r--r--gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c2
4 files changed, 9 insertions, 11 deletions
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 614b432..f4a65a5 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -5578,7 +5578,7 @@ test_type_mismatch_range_labels ()
richloc.add_range (param, SHOW_RANGE_WITHOUT_CARET, &param_label);
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, &richloc, DK_ERROR);
+ diagnostic_show_locus (&dc, &richloc, DK_ERROR, dc.m_printer);
if (c_dialect_cxx ())
/* "char*", without a space. */
ASSERT_STREQ (" printf (\"msg: %i\\n\", msg);\n"
diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc
index a1d66cf..b575dc5 100644
--- a/gcc/diagnostic-show-locus.cc
+++ b/gcc/diagnostic-show-locus.cc
@@ -3265,7 +3265,7 @@ add_location_if_nearby (const diagnostic_context &dc,
void
diagnostic_context::maybe_show_locus (const rich_location &richloc,
diagnostic_t diagnostic_kind,
- pretty_printer *pp,
+ pretty_printer &pp,
diagnostic_source_effect_info *effects)
{
const location_t loc = richloc.get_loc ();
@@ -3287,12 +3287,8 @@ diagnostic_context::maybe_show_locus (const rich_location &richloc,
m_last_location = loc;
- if (!pp)
- pp = m_printer;
- gcc_assert (pp);
-
diagnostic_source_print_policy source_policy (*this);
- source_policy.print (*pp, richloc, diagnostic_kind, effects);
+ source_policy.print (pp, richloc, diagnostic_kind, effects);
}
diagnostic_source_print_policy::
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index bc0e67c..23a9a1b 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -528,7 +528,7 @@ public:
void maybe_show_locus (const rich_location &richloc,
diagnostic_t diagnostic_kind,
- pretty_printer *pp,
+ pretty_printer &pp,
diagnostic_source_effect_info *effect_info);
void emit_diagram (const diagnostic_diagram &diagram);
@@ -981,11 +981,13 @@ inline void
diagnostic_show_locus (diagnostic_context *context,
rich_location *richloc,
diagnostic_t diagnostic_kind,
- pretty_printer *pp = nullptr,
+ pretty_printer *pp,
diagnostic_source_effect_info *effect_info = nullptr)
{
+ gcc_assert (context);
gcc_assert (richloc);
- context->maybe_show_locus (*richloc, diagnostic_kind, pp, effect_info);
+ gcc_assert (pp);
+ context->maybe_show_locus (*richloc, diagnostic_kind, *pp, effect_info);
}
/* Because we read source files a second time after the frontend did it the
diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
index 3c53400..554dad6 100644
--- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
+++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c
@@ -48,7 +48,7 @@ test_richloc (rich_location *richloc)
{
/* Run the diagnostic and fix-it printing code. */
test_diagnostic_context dc;
- diagnostic_show_locus (&dc, richloc, DK_ERROR);
+ diagnostic_show_locus (&dc, richloc, DK_ERROR, dc.m_printer);
/* Generate a diff. */
edit_context ec (global_dc->get_file_cache ());