diff options
author | David Malcolm <dmalcolm@redhat.com> | 2024-10-16 13:10:07 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2024-10-16 13:10:07 -0400 |
commit | d826b6389d9605944ce2261c07d2c9515992bccf (patch) | |
tree | 1119f57811dfe0b390249c681207afe7b2654cfe | |
parent | 9fb5348e3021021e82d75e4ca4e6f8d51a34c24f (diff) | |
download | gcc-d826b6389d9605944ce2261c07d2c9515992bccf.zip gcc-d826b6389d9605944ce2261c07d2c9515992bccf.tar.gz gcc-d826b6389d9605944ce2261c07d2c9515992bccf.tar.bz2 |
diagnostics: eliminate m_ice_handler_cb [PR116613]
No functional change intended.
gcc/ChangeLog:
PR other/116613
* diagnostic-format-sarif.cc
(sarif_builder::on_report_diagnostic): Move the fnotice here from
sarif_ice_handler.
(sarif_ice_handler): Delete.
(diagnostic_output_format_init_sarif): Drop setting of ice handler
callback.
* diagnostic.cc (diagnostic_context::initialize): Likewise.
(diagnostic_context::action_after_output): Rather than call
m_ice_handler_cb, instead call finish on this context.
* diagnostic.h (ice_handler_callback_t): Delete typedef.
(diagnostic_context::set_ice_handler_callback): Delete.
(diagnostic_context::m_ice_handler_cb): Delete.
gcc/testsuite/ChangeLog:
PR other/116613
* gcc.dg/plugin/diagnostic_plugin_xhtml_format.c: Update for
removal of ICE callback.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
-rw-r--r-- | gcc/diagnostic-format-sarif.cc | 28 | ||||
-rw-r--r-- | gcc/diagnostic.cc | 16 | ||||
-rw-r--r-- | gcc/diagnostic.h | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c | 30 |
4 files changed, 24 insertions, 58 deletions
diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 7083251..0ab2b83 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -1539,6 +1539,14 @@ sarif_builder::on_report_diagnostic (const diagnostic_info &diagnostic, if (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT) { m_invocation_obj->add_notification_for_ice (diagnostic, *this); + + /* Print a header for the remaining output to stderr, and + return, attempting to print the usual ICE messages to + stderr. Hopefully this will be helpful to the user in + indicating what's gone wrong (also for DejaGnu, for pruning + those messages). */ + fnotice (stderr, "Internal compiler error:\n"); + return; } @@ -3138,23 +3146,6 @@ sarif_builder::make_artifact_content_object (const char *text) const return content_obj; } -/* Callback for diagnostic_context::ice_handler_cb for when an ICE - occurs. */ - -static void -sarif_ice_handler (diagnostic_context *context) -{ - /* Attempt to ensure that a .sarif file is written out. */ - diagnostic_finish (context); - - /* Print a header for the remaining output to stderr, and - return, attempting to print the usual ICE messages to - stderr. Hopefully this will be helpful to the user in - indicating what's gone wrong (also for DejaGnu, for pruning - those messages). */ - fnotice (stderr, "Internal compiler error:\n"); -} - class sarif_output_format : public diagnostic_output_format { public: @@ -3387,9 +3378,6 @@ diagnostic_output_format_init_sarif (diagnostic_context &context, /* Suppress normal textual path output. */ context.set_path_format (DPF_NONE); - /* Override callbacks. */ - context.set_ice_handler_callback (sarif_ice_handler); - /* Don't colorize the text. */ pp_show_color (fmt->get_printer ()) = false; context.set_show_highlight_colors (false); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 5e092cc..9793df6 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -284,7 +284,6 @@ diagnostic_context::initialize (int n_opts) m_diagnostic_groups.m_emission_count = 0; m_output_format = new diagnostic_text_output_format (*this); m_set_locations_cb = nullptr; - m_ice_handler_cb = nullptr; m_client_data_hooks = nullptr; m_diagrams.m_theme = nullptr; m_original_argv = nullptr; @@ -782,16 +781,15 @@ diagnostic_context::action_after_output (diagnostic_t diag_kind) case DK_ICE: case DK_ICE_NOBT: { - /* Optional callback for attempting to handle ICEs gracefully. */ - if (void (*ice_handler_cb) (diagnostic_context *) = m_ice_handler_cb) + /* Attempt to ensure that any outputs are flushed e.g. that .sarif + files are written out. + Only do it once. */ + static bool finishing_due_to_ice = false; + if (!finishing_due_to_ice) { - /* Clear the callback, to avoid potentially re-entering - the routine if there's a crash within the handler. */ - m_ice_handler_cb = NULL; - ice_handler_cb (this); + finishing_due_to_ice = true; + finish (); } - /* The context might have had diagnostic_finish called on - it at this point. */ struct backtrace_state *state = NULL; if (diag_kind == DK_ICE) diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 83d73d2..dbb3803 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -468,7 +468,6 @@ public: friend class diagnostic_source_print_policy; friend class diagnostic_text_output_format; - typedef void (*ice_handler_callback_t) (diagnostic_context *); typedef void (*set_locations_callback_t) (diagnostic_context *, diagnostic_info *); @@ -587,10 +586,6 @@ public: { m_escape_format = val; } - void set_ice_handler_callback (ice_handler_callback_t cb) - { - m_ice_handler_cb = cb; - } /* Various accessors. */ bool warning_as_error_requested_p () const @@ -859,9 +854,6 @@ private: of a diagnostic's location. */ set_locations_callback_t m_set_locations_cb; - /* Optional callback for attempting to handle ICEs gracefully. */ - ice_handler_callback_t m_ice_handler_cb; - /* A bundle of hooks for providing data to the context about its client e.g. version information, plugins, etc. Used by SARIF output to give metadata about the client that's diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c index 2ce8cc2..c74ecb0 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_xhtml_format.c @@ -362,7 +362,15 @@ void xhtml_builder::on_report_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { - // TODO: handle (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT) + if (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT) + { + /* Print a header for the remaining output to stderr, and + return, attempting to print the usual ICE messages to + stderr. Hopefully this will be helpful to the user in + indicating what's gone wrong (also for DejaGnu, for pruning + those messages). */ + fnotice (stderr, "Internal compiler error:\n"); + } auto diag_element = make_element_for_diagnostic (diagnostic, orig_diag_kind); @@ -573,23 +581,6 @@ xhtml_builder::flush_to_file (FILE *outf) fprintf (outf, "\n"); } -/* Callback for diagnostic_context::ice_handler_cb for when an ICE - occurs. */ - -static void -xhtml_ice_handler (diagnostic_context *context) -{ - /* Attempt to ensure that a .xhtml file is written out. */ - diagnostic_finish (context); - - /* Print a header for the remaining output to stderr, and - return, attempting to print the usual ICE messages to - stderr. Hopefully this will be helpful to the user in - indicating what's gone wrong (also for DejaGnu, for pruning - those messages). */ - fnotice (stderr, "Internal compiler error:\n"); -} - class xhtml_output_format : public diagnostic_output_format { public: @@ -707,9 +698,6 @@ static void diagnostic_output_format_init_xhtml (diagnostic_context &context, std::unique_ptr<xhtml_output_format> fmt) { - /* Override callbacks. */ - context.set_ice_handler_callback (xhtml_ice_handler); - /* Don't colorize the text. */ pp_show_color (fmt->get_printer ()) = false; context.set_show_highlight_colors (false); |