From patchwork Wed Dec 6 17:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 174683 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4269908vqy; Wed, 6 Dec 2023 09:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFs95I23w6XYPbwKmaeE8vUjsNg6he/wx+8euTbYuy5tCBAtNXXcGe9alrXdZ6t3OaFf0ri X-Received: by 2002:a05:622a:44c:b0:425:4043:419b with SMTP id o12-20020a05622a044c00b004254043419bmr1690633qtx.71.1701884599196; Wed, 06 Dec 2023 09:43:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701884599; cv=pass; d=google.com; s=arc-20160816; b=Fsvx/I4uccemKHmdQpkHAk4EzM0LhXLxLqeVIzx3WuIGmEJIk2eNhSlMl2hA152Of5 XK3i+A9t0N+7DtKhNFVMHh/fD+821wO+ZBOXFAiAFZDpeyOOcEgEePtQzu9kDKX/Q+jD bSGpsVSsfLdeCauMe8DaGGh5rXdIfQ/CwgpO3mev9ZmCl26kky+zhbsQZQWXMZAiGkVE ykyYm73RZ4aPKV7Na4PuWHcuxrbhc/BXdhtDA+wXNHeYwZFfKcQxlXLRSCAtbE0cvCua NPQlVALJE51lUyMSpWffpyOAfdNYoIqDHa81YRx58ixLVHoqrxwJMJfyNHZ0oHnxTaii OA0A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=+0C1FF/W1Y62c8u37mN9cBkPfddBroA1hu1PWmv4B+U=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=DfEujt0kq3wNBiRMPer++FIUriKBVQ+Xyig+aakG+9Mo++L1J3RVCmNeIIyCWd87Ko PZoPTfe8r3EBaDcZbA4tOtaSFGo7lEFKVR++ciPLqrn6lghQRyuQ+wK7Xzn9UeoqZwM/ SUz3rlT5RAWw+Kn9hVHwsMdiujFLMaFJ7PJfsu6CuPyw73xSPl17i9HiKFc4NXa9nJ4Z LCfpw9ZBbIvtBPDKYoH3Qj6Rrg6Y8krRULyKQNXJ570HF95hWE41Mh8IuUd31TZlrpgl vncfVJoLGTYnFvkvb3ZGI2C7xlLlUmWleEU19hlzUAVptsxQO2yCWrD77igcS0hLiflF N0Fw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bz0L++mR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fw13-20020a05622a4a8d00b0042380ba6e47si373894qtb.326.2023.12.06.09.43.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 09:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bz0L++mR; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E403B3857357 for ; Wed, 6 Dec 2023 17:43:18 +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 ESMTPS id A858B3858D3C for ; Wed, 6 Dec 2023 17:42:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A858B3858D3C 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 A858B3858D3C 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=1701884575; cv=none; b=sl9qfpwVoCPOSaAqNi2f/Z5Ju66wB8lkLvsQq1ZwOX4En8Mdhkz/5jFlvUF2n2Q5+HLKUjQzFQ4b+u6fXuzsBgOwl0ryxt2KQDDf+CHM+zUkhvCBw33hfnBA3sZeNxf0DhMBU6V9TgQPHviqthp9qmGnRIaFDtrN7pFsfRd238o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701884575; c=relaxed/simple; bh=fnMuu5Poj+MSDgQxh+1KIyYYaMt6r1H4cQbjvr082HU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=IEtSSDjYfglV3Z5j1dMMdu5GTIabHSYk2ULrm4gqUeuuO03MdwNF3Ml0VDEK2TRCKUqRCtc44QJDKRk4tFyUtYfW3Nj7emYerZYl5yGM7WXlRDyvSCHGlheJN4lwsTjIjAnJQoc4gge3+c2aLLfy/jI4vukhkBypSKEPmaL+3zM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701884570; 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=+0C1FF/W1Y62c8u37mN9cBkPfddBroA1hu1PWmv4B+U=; b=Bz0L++mR6G9ZKfusksAXSX1+aqqoSZ05DhkkJHSB4V7hsLcHqinb6NmPOjV6O+h0jihEv+ i926qBDeFmdYU2BaWzKNT4afQDGn0bLfmInqUb4SJYoEMvG0hX8Irqa/iIlK6fSe0ueDPh 1hifLg/xo82n7rxhfkZ8331cr3SGu+s= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-geK-zx4eN4qSmBBnSFnQ6g-1; Wed, 06 Dec 2023 12:42:48 -0500 X-MC-Unique: geK-zx4eN4qSmBBnSFnQ6g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7FB98185A780 for ; Wed, 6 Dec 2023 17:42:48 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.33.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01401492BE6; Wed, 6 Dec 2023 17:42:47 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] diagnostics: use const and references for diagnostic_info Date: Wed, 6 Dec 2023 12:42:45 -0500 Message-Id: <20231206174245.2462114-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784555345483259291 X-GMAIL-MSGID: 1784555345483259291 No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-6227-g8fc4e6c397e1ce. gcc/c-family/ChangeLog: * c-opts.cc (c_diagnostic_finalizer): Make "diagnostic" param const. gcc/cp/ChangeLog: * cp-tree.h (cxx_print_error_function): Make diagnostic_info param const. * error.cc (cxx_print_error_function): Likewise. (cp_diagnostic_starter): Likewise. (cp_print_error_function): Likewise. gcc/ChangeLog: * diagnostic-format-json.cc (on_begin_diagnostic): Convert param to const reference. (on_end_diagnostic): Likewise. (json_output_format::on_end_diagnostic): Likewise. * diagnostic-format-sarif.cc (sarif_invocation::add_notification_for_ice): Likewise. (sarif_result::on_nested_diagnostic): Likewise. (sarif_ice_notification::sarif_ice_notification): Likewise. (sarif_builder::end_diagnostic): Likewise. (sarif_builder::make_result_object): Likewise. (make_reporting_descriptor_object_for_warning): Likewise. (sarif_builder::make_locations_arr): Likewise. (sarif_output_format::on_begin_diagnostic): Likewise. (sarif_output_format::on_end_diagnostic): Likewise. * diagnostic.cc (default_diagnostic_starter): Make diagnostic_info param const. (default_diagnostic_finalizer): Likewise. (diagnostic_context::report_diagnostic): Pass diagnostic by reference to on_{begin,end}_diagnostic. (diagnostic_text_output_format::on_begin_diagnostic): Convert param to const reference. (diagnostic_text_output_format::on_end_diagnostic): Likewise. * diagnostic.h (diagnostic_starter_fn): Make diagnostic_info param const. (diagnostic_finalizer_fn): Likeewise. (diagnostic_output_format::on_begin_diagnostic): Convert param to const reference. (diagnostic_output_format::on_end_diagnostic): Likewise. (diagnostic_text_output_format::on_begin_diagnostic): Likewise. (diagnostic_text_output_format::on_end_diagnostic): Likewise. (default_diagnostic_starter): Make diagnostic_info param const. (default_diagnostic_finalizer): Likewise. * langhooks-def.h (lhd_print_error_function): Make diagnostic_info param const. * langhooks.cc (lhd_print_error_function): Likewise. * langhooks.h (lang_hooks::print_error_function): Likewise. * tree-diagnostic.cc (diagnostic_report_current_function): Likewise. (default_tree_diagnostic_starter): Likewise. (virt_loc_aware_diagnostic_finalizer): Likewise. * tree-diagnostic.h (diagnostic_report_current_function): Likewise. (virt_loc_aware_diagnostic_finalizer): Likewise. gcc/fortran/ChangeLog: * error.cc (gfc_diagnostic_starter): Make diagnostic_info param const. (gfc_diagnostic_finalizer): Likewise. gcc/jit/ChangeLog: * dummy-frontend.cc (jit_begin_diagnostic): Make diagnostic_info param const. (jit_end_diagnostic): Likewise. Pass to add_diagnostic by reference. * jit-playback.cc (jit::playback::context::add_diagnostic): Convert diagnostic_info to const reference. * jit-playback.h (jit::playback::context::add_diagnostic): Likewise. gcc/testsuite/ChangeLog: * g++.dg/plugin/show_template_tree_color_plugin.c (noop_starter_fn): Make diagnostic_info param const. * gcc.dg/plugin/diagnostic_group_plugin.c (test_diagnostic_starter): Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (custom_diagnostic_finalizer): Likewise. * gcc.dg/plugin/location_overflow_plugin.c (verify_unpacked_ranges): Likewise. (verify_no_columns): Likewise. libcc1/ChangeLog: * context.cc (plugin_print_error_function): Make diagnostic_info param const. Signed-off-by: David Malcolm --- gcc/c-family/c-opts.cc | 2 +- gcc/cp/cp-tree.h | 2 +- gcc/cp/error.cc | 12 ++-- gcc/diagnostic-format-json.cc | 20 +++---- gcc/diagnostic-format-sarif.cc | 57 ++++++++++--------- gcc/diagnostic.cc | 17 +++--- gcc/diagnostic.h | 17 +++--- gcc/fortran/error.cc | 4 +- gcc/jit/dummy-frontend.cc | 7 ++- gcc/jit/jit-playback.cc | 4 +- gcc/jit/jit-playback.h | 2 +- gcc/langhooks-def.h | 3 +- gcc/langhooks.cc | 2 +- gcc/langhooks.h | 2 +- .../plugin/show_template_tree_color_plugin.c | 2 +- .../gcc.dg/plugin/diagnostic_group_plugin.c | 2 +- .../diagnostic_plugin_test_show_locus.c | 2 +- .../gcc.dg/plugin/location_overflow_plugin.c | 4 +- gcc/tree-diagnostic.cc | 6 +- gcc/tree-diagnostic.h | 4 +- libcc1/context.cc | 2 +- 21 files changed, 90 insertions(+), 83 deletions(-) diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index d7faff10d66..b68ea5e7006 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -168,7 +168,7 @@ c_common_option_lang_mask (void) /* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */ static void c_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t) { char *saved_prefix = pp_take_prefix (context->printer); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 6b3ce9d87da..3aa235262b6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8071,7 +8071,7 @@ extern void cxx_print_type (FILE *, tree, int); extern void cxx_print_identifier (FILE *, tree, int); extern void cxx_print_error_function (diagnostic_context *, const char *, - struct diagnostic_info *); + const diagnostic_info *); /* in typeck.cc */ /* Says how we should behave when comparing two arrays one of which diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 785909c362a..8e9dda33afd 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -101,8 +101,10 @@ static void print_instantiation_partial_context (diagnostic_context *, struct tinst_level *, location_t); static void maybe_print_constraint_context (diagnostic_context *); -static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *); -static void cp_print_error_function (diagnostic_context *, diagnostic_info *); +static void cp_diagnostic_starter (diagnostic_context *, + const diagnostic_info *); +static void cp_print_error_function (diagnostic_context *, + const diagnostic_info *); static bool cp_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool, bool *, const char **); @@ -3530,7 +3532,7 @@ eh_spec_to_string (tree p, int /*v*/) /* Langhook for print_error_function. */ void cxx_print_error_function (diagnostic_context *context, const char *file, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { char *prefix; if (file) @@ -3544,7 +3546,7 @@ cxx_print_error_function (diagnostic_context *context, const char *file, static void cp_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { diagnostic_report_current_module (context, diagnostic_location (diagnostic)); cp_print_error_function (context, diagnostic); @@ -3559,7 +3561,7 @@ cp_diagnostic_starter (diagnostic_context *context, a diagnostic message. Called from cp_diagnostic_starter. */ static void cp_print_error_function (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { /* If we are in an instantiation context, current_function_decl is likely to be wrong, so just rely on print_instantiation_full_context. */ diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc index 141075b7dee..418db74522d 100644 --- a/gcc/diagnostic-format-json.cc +++ b/gcc/diagnostic-format-json.cc @@ -43,12 +43,12 @@ public: m_cur_children_array = nullptr; } void - on_begin_diagnostic (diagnostic_info *) final override + on_begin_diagnostic (const diagnostic_info &) final override { /* No-op. */ } void - on_end_diagnostic (diagnostic_info *diagnostic, + on_end_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) final override; void on_diagram (const diagnostic_diagram &) final override { @@ -188,7 +188,7 @@ json_from_metadata (const diagnostic_metadata *metadata) within current diagnostic group. */ void -json_output_format::on_end_diagnostic (diagnostic_info *diagnostic, +json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { json::object *diag_obj = new json::object (); @@ -202,7 +202,7 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic, "must-not-happen" }; /* Lose the trailing ": ". */ - const char *kind_text = diagnostic_kind_text[diagnostic->kind]; + const char *kind_text = diagnostic_kind_text[diagnostic.kind]; size_t len = strlen (kind_text); gcc_assert (len > 2); gcc_assert (kind_text[len - 2] == ':'); @@ -217,15 +217,15 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic, diag_obj->set_string ("message", pp_formatted_text (m_context.printer)); pp_clear_output_area (m_context.printer); - if (char *option_text = m_context.make_option_name (diagnostic->option_index, + if (char *option_text = m_context.make_option_name (diagnostic.option_index, orig_diag_kind, - diagnostic->kind)) + diagnostic.kind)) { diag_obj->set_string ("option", option_text); free (option_text); } - if (char *option_url = m_context.make_option_url (diagnostic->option_index)) + if (char *option_url = m_context.make_option_url (diagnostic.option_index)) { diag_obj->set_string ("option_url", option_url); free (option_url); @@ -249,7 +249,7 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic, diag_obj->set_integer ("column-origin", m_context.m_column_origin); } - const rich_location *richloc = diagnostic->richloc; + const rich_location *richloc = diagnostic.richloc; json::array *loc_array = new json::array (); diag_obj->set ("locations", loc_array); @@ -280,9 +280,9 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic, TODO: inlining information TODO: macro expansion information. */ - if (diagnostic->metadata) + if (diagnostic.metadata) { - json::object *metadata_obj = json_from_metadata (diagnostic->metadata); + json::object *metadata_obj = json_from_metadata (diagnostic.metadata); diag_obj->set ("metadata", metadata_obj); } diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index 67775929f85..941fd0f5f74 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -48,7 +48,7 @@ public: {} void add_notification_for_ice (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, sarif_builder *builder); void prepare_to_flush (diagnostic_context *context); @@ -67,7 +67,7 @@ public: void on_nested_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, sarif_builder *builder); void on_diagram (diagnostic_context *context, @@ -90,7 +90,7 @@ class sarif_ice_notification : public sarif_object { public: sarif_ice_notification (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, sarif_builder *builder); }; @@ -159,7 +159,8 @@ class sarif_builder public: sarif_builder (diagnostic_context *context); - void end_diagnostic (diagnostic_context *context, diagnostic_info *diagnostic, + void end_diagnostic (diagnostic_context *context, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind); void emit_diagram (diagnostic_context *context, const diagnostic_diagram &diagram); @@ -167,7 +168,7 @@ public: void flush_to_file (FILE *outf); - json::array *make_locations_arr (diagnostic_info *diagnostic); + json::array *make_locations_arr (const diagnostic_info &diagnostic); json::object *make_location_object (const rich_location &rich_loc, const logical_location *logical_loc); json::object *make_message_object (const char *msg) const; @@ -177,7 +178,7 @@ public: private: sarif_result *make_result_object (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind); void set_any_logical_locs_arr (json::object *location_obj, const logical_location *logical_loc); @@ -208,7 +209,7 @@ private: json::object *make_tool_component_reference_object_for_cwe () const; json::object * make_reporting_descriptor_object_for_warning (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind, const char *option_text); json::object *make_reporting_descriptor_object_for_cwe_id (int cwe_id) const; @@ -275,7 +276,7 @@ sarif_object::get_or_create_properties () void sarif_invocation::add_notification_for_ice (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, sarif_builder *builder) { m_success = false; @@ -310,7 +311,7 @@ sarif_invocation::prepare_to_flush (diagnostic_context *context) void sarif_result::on_nested_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t /*orig_diag_kind*/, sarif_builder *builder) { @@ -318,7 +319,7 @@ sarif_result::on_nested_diagnostic (diagnostic_context *context, sometimes these will related to current_function_decl, but often they won't. */ json::object *location_obj - = builder->make_location_object (*diagnostic->richloc, NULL); + = builder->make_location_object (*diagnostic.richloc, NULL); json::object *message_obj = builder->make_message_object (pp_formatted_text (context->printer)); pp_clear_output_area (context->printer); @@ -366,7 +367,7 @@ sarif_result::add_related_location (json::object *location_obj) DIAGNOSTIC is an internal compiler error. */ sarif_ice_notification::sarif_ice_notification (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, sarif_builder *builder) { /* "locations" property (SARIF v2.1.0 section 3.58.4). */ @@ -416,10 +417,10 @@ sarif_builder::sarif_builder (diagnostic_context *context) void sarif_builder::end_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { - if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT) + if (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT) { m_invocation_obj->add_notification_for_ice (context, diagnostic, this); return; @@ -528,7 +529,7 @@ make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind) sarif_result * sarif_builder::make_result_object (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { sarif_result *result_obj = new sarif_result (); @@ -536,8 +537,8 @@ sarif_builder::make_result_object (diagnostic_context *context, /* "ruleId" property (SARIF v2.1.0 section 3.27.5). */ /* Ideally we'd have an option_name for these. */ if (char *option_text - = context->make_option_name (diagnostic->option_index, - orig_diag_kind, diagnostic->kind)) + = context->make_option_name (diagnostic.option_index, + orig_diag_kind, diagnostic.kind)) { /* Lazily create reportingDescriptor objects for and add to m_rules_arr. Set ruleId referencing them. */ @@ -569,10 +570,10 @@ sarif_builder::make_result_object (diagnostic_context *context, free (rule_id); } - if (diagnostic->metadata) + if (diagnostic.metadata) { /* "taxa" property (SARIF v2.1.0 section 3.27.8). */ - if (int cwe_id = diagnostic->metadata->get_cwe ()) + if (int cwe_id = diagnostic.metadata->get_cwe ()) { json::array *taxa_arr = new json::array (); json::object *cwe_id_obj @@ -581,11 +582,11 @@ sarif_builder::make_result_object (diagnostic_context *context, result_obj->set ("taxa", taxa_arr); } - diagnostic->metadata->maybe_add_sarif_properties (*result_obj); + diagnostic.metadata->maybe_add_sarif_properties (*result_obj); } /* "level" property (SARIF v2.1.0 section 3.27.10). */ - if (const char *sarif_level = maybe_get_sarif_level (diagnostic->kind)) + if (const char *sarif_level = maybe_get_sarif_level (diagnostic.kind)) result_obj->set_string ("level", sarif_level); /* "message" property (SARIF v2.1.0 section 3.27.11). */ @@ -599,7 +600,7 @@ sarif_builder::make_result_object (diagnostic_context *context, result_obj->set ("locations", locations_arr); /* "codeFlows" property (SARIF v2.1.0 section 3.27.18). */ - if (const diagnostic_path *path = diagnostic->richloc->get_path ()) + if (const diagnostic_path *path = diagnostic.richloc->get_path ()) { json::array *code_flows_arr = new json::array (); json::object *code_flow_obj = make_code_flow_object (*path); @@ -612,7 +613,7 @@ sarif_builder::make_result_object (diagnostic_context *context, group. */ /* "fixes" property (SARIF v2.1.0 section 3.27.30). */ - const rich_location *richloc = diagnostic->richloc; + const rich_location *richloc = diagnostic.richloc; if (richloc->get_num_fixit_hints ()) { json::array *fix_arr = new json::array (); @@ -630,7 +631,7 @@ sarif_builder::make_result_object (diagnostic_context *context, json::object * sarif_builder:: make_reporting_descriptor_object_for_warning (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info &diagnostic, diagnostic_t /*orig_diag_kind*/, const char *option_text) { @@ -643,7 +644,7 @@ make_reporting_descriptor_object_for_warning (diagnostic_context *context, it seems redundant compared to "id". */ /* "helpUri" property (SARIF v2.1.0 section 3.49.12). */ - if (char *option_url = context->make_option_url (diagnostic->option_index)) + if (char *option_url = context->make_option_url (diagnostic.option_index)) { reporting_desc->set_string ("helpUri", option_url); free (option_url); @@ -725,7 +726,7 @@ make_tool_component_reference_object_for_cwe () const - a "notification" object (SARIF v2.1.0 section 3.58.4). */ json::array * -sarif_builder::make_locations_arr (diagnostic_info *diagnostic) +sarif_builder::make_locations_arr (const diagnostic_info &diagnostic) { json::array *locations_arr = new json::array (); const logical_location *logical_loc = NULL; @@ -733,7 +734,7 @@ sarif_builder::make_locations_arr (diagnostic_info *diagnostic) logical_loc = client_data_hooks->get_current_logical_location (); json::object *location_obj - = make_location_object (*diagnostic->richloc, logical_loc); + = make_location_object (*diagnostic.richloc, logical_loc); locations_arr->append (location_obj); return locations_arr; } @@ -1704,12 +1705,12 @@ public: m_builder.end_group (); } void - on_begin_diagnostic (diagnostic_info *) final override + on_begin_diagnostic (const diagnostic_info &) final override { /* No-op, */ } void - on_end_diagnostic (diagnostic_info *diagnostic, + on_end_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) final override { m_builder.end_diagnostic (&m_context, diagnostic, orig_diag_kind); diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index 2e3d37b04cc..5854c89a387 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -1077,7 +1077,7 @@ diagnostic_path::interprocedural_p () const void default_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { diagnostic_report_current_module (context, diagnostic_location (diagnostic)); pp_set_prefix (context->printer, diagnostic_build_prefix (context, @@ -1095,7 +1095,7 @@ default_diagnostic_start_span_fn (diagnostic_context *context, void default_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t) { char *saved_prefix = pp_take_prefix (context->printer); @@ -1602,7 +1602,7 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) m_diagnostic_groups.m_emission_count++; pp_format (this->printer, &diagnostic->message, m_urlifier); - m_output_format->on_begin_diagnostic (diagnostic); + m_output_format->on_begin_diagnostic (*diagnostic); pp_output_formatted_text (this->printer); if (m_show_cwe) print_any_cwe (*diagnostic); @@ -1610,7 +1610,7 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) print_any_rules (*diagnostic); if (m_show_option_requested) print_option_information (*diagnostic, orig_diag_kind); - m_output_format->on_end_diagnostic (diagnostic, orig_diag_kind); + m_output_format->on_end_diagnostic (*diagnostic, orig_diag_kind); switch (m_extra_output_kind) { default: @@ -2396,16 +2396,17 @@ diagnostic_text_output_format::~diagnostic_text_output_format () } void -diagnostic_text_output_format::on_begin_diagnostic (diagnostic_info *diagnostic) +diagnostic_text_output_format::on_begin_diagnostic (const diagnostic_info &diagnostic) { - (*diagnostic_starter (&m_context)) (&m_context, diagnostic); + (*diagnostic_starter (&m_context)) (&m_context, &diagnostic); } void -diagnostic_text_output_format::on_end_diagnostic (diagnostic_info *diagnostic, +diagnostic_text_output_format::on_end_diagnostic (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind) { - (*diagnostic_finalizer (&m_context)) (&m_context, diagnostic, orig_diag_kind); + (*diagnostic_finalizer (&m_context)) (&m_context, &diagnostic, + orig_diag_kind); } void diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index b57556f9759..4fc31438b16 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -171,13 +171,13 @@ struct diagnostic_info /* Forward declarations. */ typedef void (*diagnostic_starter_fn) (diagnostic_context *, - diagnostic_info *); + const diagnostic_info *); typedef void (*diagnostic_start_span_fn) (diagnostic_context *, expanded_location); typedef void (*diagnostic_finalizer_fn) (diagnostic_context *, - diagnostic_info *, + const diagnostic_info *, diagnostic_t); typedef int (*diagnostic_option_enabled_cb) (int, unsigned, void *); @@ -205,8 +205,8 @@ public: virtual void on_begin_group () = 0; virtual void on_end_group () = 0; - virtual void on_begin_diagnostic (diagnostic_info *) = 0; - virtual void on_end_diagnostic (diagnostic_info *, + virtual void on_begin_diagnostic (const diagnostic_info &) = 0; + virtual void on_end_diagnostic (const diagnostic_info &, diagnostic_t orig_diag_kind) = 0; virtual void on_diagram (const diagnostic_diagram &diagram) = 0; @@ -233,8 +233,8 @@ public: ~diagnostic_text_output_format (); void on_begin_group () override {} void on_end_group () override {} - void on_begin_diagnostic (diagnostic_info *) override; - void on_end_diagnostic (diagnostic_info *, + void on_begin_diagnostic (const diagnostic_info &) override; + void on_end_diagnostic (const diagnostic_info &, diagnostic_t orig_diag_kind) override; void on_diagram (const diagnostic_diagram &diagram) override; }; @@ -985,10 +985,11 @@ extern void diagnostic_append_note (diagnostic_context *, location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(3,4); #endif extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *); -void default_diagnostic_starter (diagnostic_context *, diagnostic_info *); +void default_diagnostic_starter (diagnostic_context *, const diagnostic_info *); void default_diagnostic_start_span_fn (diagnostic_context *, expanded_location); -void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *, +void default_diagnostic_finalizer (diagnostic_context *, + const diagnostic_info *, diagnostic_t); void diagnostic_set_caret_max_width (diagnostic_context *context, int value); diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc index 56d2e63622d..76113def7c8 100644 --- a/gcc/fortran/error.cc +++ b/gcc/fortran/error.cc @@ -1207,7 +1207,7 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context, */ static void gfc_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { char * kind_prefix = gfc_diagnostic_build_kind_prefix (context, diagnostic); @@ -1283,7 +1283,7 @@ gfc_diagnostic_start_span (diagnostic_context *context, static void gfc_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic ATTRIBUTE_UNUSED, + const diagnostic_info *diagnostic ATTRIBUTE_UNUSED, diagnostic_t orig_diag_kind ATTRIBUTE_UNUSED) { pp_destroy_prefix (context->printer); diff --git a/gcc/jit/dummy-frontend.cc b/gcc/jit/dummy-frontend.cc index 61cc0e1ae66..f5fb40178c2 100644 --- a/gcc/jit/dummy-frontend.cc +++ b/gcc/jit/dummy-frontend.cc @@ -563,7 +563,7 @@ struct ggc_root_tab jit_root_tab[] = static void jit_begin_diagnostic (diagnostic_context */*context*/, - diagnostic_info */*diagnostic*/) + const diagnostic_info */*diagnostic*/) { gcc_assert (gcc::jit::active_playback_ctxt); JIT_LOG_SCOPE (gcc::jit::active_playback_ctxt->get_logger ()); @@ -576,7 +576,7 @@ jit_begin_diagnostic (diagnostic_context */*context*/, static void jit_end_diagnostic (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t) { gcc_assert (gcc::jit::active_playback_ctxt); @@ -584,7 +584,8 @@ jit_end_diagnostic (diagnostic_context *context, /* Delegate to the playback context (and thence to the recording context). */ - gcc::jit::active_playback_ctxt->add_diagnostic (context, diagnostic); + gcc_assert (diagnostic); + gcc::jit::active_playback_ctxt->add_diagnostic (context, *diagnostic); } /* Language hooks. */ diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc index 18cc4da25b8..dddd537f3b1 100644 --- a/gcc/jit/jit-playback.cc +++ b/gcc/jit/jit-playback.cc @@ -3513,7 +3513,7 @@ add_error_va (location *loc, const char *fmt, va_list ap) void playback::context:: add_diagnostic (diagnostic_context *diag_context, - struct diagnostic_info *diagnostic) + const diagnostic_info &diagnostic) { /* At this point the text has been formatted into the pretty-printer's output buffer. */ @@ -3526,7 +3526,7 @@ add_diagnostic (diagnostic_context *diag_context, from the file/line/column since any playback location instances may have been garbage-collected away by now, so instead we create another recording::location directly. */ - location_t gcc_loc = diagnostic_location (diagnostic); + location_t gcc_loc = diagnostic_location (&diagnostic); recording::location *rec_loc = NULL; if (gcc_loc) { diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index f9e29d0baec..b0166f8f6ce 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -248,7 +248,7 @@ public: void add_diagnostic (diagnostic_context *context, - struct diagnostic_info *diagnostic); + const diagnostic_info &diagnostic); void set_tree_location (tree t, location *loc); diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index c9cb65759c2..cedc8fd85fc 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -50,7 +50,8 @@ extern const char *lhd_decl_printable_name (tree, int); extern const char *lhd_dwarf_name (tree, int); extern int lhd_types_compatible_p (tree, tree); extern void lhd_print_error_function (diagnostic_context *, - const char *, struct diagnostic_info *); + const char *, + const struct diagnostic_info *); extern void lhd_set_decl_assembler_name (tree decl); extern void lhd_overwrite_decl_assembler_name (tree decl, tree name); extern bool lhd_warn_unused_global_decl (const_tree); diff --git a/gcc/langhooks.cc b/gcc/langhooks.cc index cf047d9e530..bc3fd3531b0 100644 --- a/gcc/langhooks.cc +++ b/gcc/langhooks.cc @@ -369,7 +369,7 @@ lhd_handle_option (size_t code ATTRIBUTE_UNUSED, an error. */ void lhd_print_error_function (diagnostic_context *context, const char *file, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { if (diagnostic_last_function_changed (context, diagnostic)) { diff --git a/gcc/langhooks.h b/gcc/langhooks.h index 2785a0070fc..bba64d1412a 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -516,7 +516,7 @@ struct lang_hooks /* Called by report_error_function to print out function name. */ void (*print_error_function) (diagnostic_context *, const char *, - struct diagnostic_info *); + const struct diagnostic_info *); /* Convert a character from the host's to the target's character set. The character should be in what C calls the "basic source diff --git a/gcc/testsuite/g++.dg/plugin/show_template_tree_color_plugin.c b/gcc/testsuite/g++.dg/plugin/show_template_tree_color_plugin.c index af568bf622a..e1af2cf25a4 100644 --- a/gcc/testsuite/g++.dg/plugin/show_template_tree_color_plugin.c +++ b/gcc/testsuite/g++.dg/plugin/show_template_tree_color_plugin.c @@ -21,7 +21,7 @@ int plugin_is_GPL_compatible; void -noop_starter_fn (diagnostic_context *, diagnostic_info *) +noop_starter_fn (diagnostic_context *, const diagnostic_info *) { } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c index ce0b3225dfc..e9d4b7276cc 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.c @@ -165,7 +165,7 @@ pass_test_groups::execute (function *fun) void test_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { pp_set_prefix (context->printer, xstrdup ("PREFIX: ")); } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c index 6cc661b026d..3bd8cab8c7f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @@ -129,7 +129,7 @@ static bool force_show_locus_color = false; static void custom_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t) { bool old_show_color = pp_show_color (context->printer); diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c index 09bac50d2af..d0a6b075564 100644 --- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c @@ -42,7 +42,7 @@ static diagnostic_finalizer_fn original_finalizer = NULL; static void verify_unpacked_ranges (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t orig_diag_kind) { /* Verify that the locations are ad-hoc, not packed. */ @@ -56,7 +56,7 @@ verify_unpacked_ranges (diagnostic_context *context, static void verify_no_columns (diagnostic_context *context, - diagnostic_info *diagnostic, + const diagnostic_info *diagnostic, diagnostic_t orig_diag_kind) { /* Verify that the locations have no columns. */ diff --git a/gcc/tree-diagnostic.cc b/gcc/tree-diagnostic.cc index de853bc4fd7..dae8a42b8bc 100644 --- a/gcc/tree-diagnostic.cc +++ b/gcc/tree-diagnostic.cc @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see that caused an error. Called from all error and warning functions. */ void diagnostic_report_current_function (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { location_t loc = diagnostic_location (diagnostic); diagnostic_report_current_module (context, loc); @@ -44,7 +44,7 @@ diagnostic_report_current_function (diagnostic_context *context, static void default_tree_diagnostic_starter (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { diagnostic_report_current_function (context, diagnostic); pp_set_prefix (context->printer, diagnostic_build_prefix (context, @@ -241,7 +241,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context, template instantiation contexts. */ void virt_loc_aware_diagnostic_finalizer (diagnostic_context *context, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { maybe_unwind_expanded_macro_loc (context, diagnostic_location (diagnostic)); } diff --git a/gcc/tree-diagnostic.h b/gcc/tree-diagnostic.h index 9089f2ded1e..a3ea18ca61b 100644 --- a/gcc/tree-diagnostic.h +++ b/gcc/tree-diagnostic.h @@ -49,9 +49,9 @@ along with GCC; see the file COPYING3. If not see : current_function_decl) void diagnostic_report_current_function (diagnostic_context *, - diagnostic_info *); + const diagnostic_info *); void virt_loc_aware_diagnostic_finalizer (diagnostic_context *, - diagnostic_info *); + const diagnostic_info *); void tree_diagnostics_defaults (diagnostic_context *context); bool default_tree_printer (pretty_printer *, text_info *, const char *, diff --git a/libcc1/context.cc b/libcc1/context.cc index 3263c167ff2..fbe468f0286 100644 --- a/libcc1/context.cc +++ b/libcc1/context.cc @@ -63,7 +63,7 @@ cc1_plugin::plugin_context *cc1_plugin::current_context; static void plugin_print_error_function (diagnostic_context *context, const char *file, - diagnostic_info *diagnostic) + const diagnostic_info *diagnostic) { if (current_function_decl != NULL_TREE && DECL_NAME (current_function_decl) != NULL_TREE