From patchwork Wed Oct 16 17:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1998177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AIQZ9yOZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XTHkg0sFlz1xv6 for ; Thu, 17 Oct 2024 04:19:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1277385841E for ; Wed, 16 Oct 2024 17:19:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EF9893858D20 for ; Wed, 16 Oct 2024 17:18:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EF9893858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EF9893858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729099118; cv=none; b=xmOdtv9hamVuREUfg/SZC1Xi/Jt39EQ510xTifsJt++X2DXvVJst+POwVHp2tGvCm6jLKSD6N8XPmtZdcLdGpHJkvJh6V4MdTLy2tw3Z/YBPdXo2x3WySdx2CfJlAtoeOKqRQfRYOm9w5WMm6NcGmi0UW6fk1VstNL3b7gNVeHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729099118; c=relaxed/simple; bh=wMsos559KPk4dby21qTt2RDUaY93DWQ7bLfu6zlvaA0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GSN86U+Dj5QEb9y6SRC3p21EgwgXhreCeDkiJWvi/iwXYXwVrLOZ/ipdOepffTngKD8KpXa0mt8aijSHb5e1GU0Snc95zEfgWd2HV+oeLhE9XprL5VFGFakIDHgx+jWbPQ4UtRl2r9AJICscvZ6Sxv6llZ2YX5T4Z0CT4mIFzVo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729099115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vcGcxdkjeee7MFvSwmlevlicMva3Y395K19zZeQLTg8=; b=AIQZ9yOZjabJ0j+iKNtDDWLlqZlqfmbxZ5/DxeHSjIld3ZwzO+8phnoSU0CC3Yq/rhrDyk /Lv2aCyF2WrN4JdzzoV2R4nrnweUkzNozorOKgwXg8CBgyY175Fw42/8vEepu7jH33PvGo jgF350TyhM6LrPENgpObjjk+7xOwZ1w= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-XMTZx9cHNC2MNtOuUdJeYA-1; Wed, 16 Oct 2024 13:18:28 -0400 X-MC-Unique: XMTZx9cHNC2MNtOuUdJeYA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A3FDB1956077 for ; Wed, 16 Oct 2024 17:18:27 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.64.110]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C112E1956086; Wed, 16 Oct 2024 17:18:26 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed: r15-4392] diagnostics: eliminate m_ice_handler_cb [PR116613] Date: Wed, 16 Oct 2024 13:18:23 -0400 Message-ID: <20241016171823.733602-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org More preliminary cleanup work for supporting multiple diagnostic output sinks. No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r15-4392-gd826b6389d9605. 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 --- gcc/diagnostic-format-sarif.cc | 28 +++++------------ gcc/diagnostic.cc | 16 +++++----- gcc/diagnostic.h | 8 ----- .../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 70832513b6d9..0ab2b83bff9a 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 41656a607b81..4a1e347776e9 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 83d73d2c4b70..dbb3803ffb19 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 2ce8cc29660c..c74ecb018efa 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 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);