From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 69FB138303C0 for ; Wed, 22 Jun 2022 22:34:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69FB138303C0 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-ZNflUyk2MI6y9LvcHdpgZg-1; Wed, 22 Jun 2022 18:34:51 -0400 X-MC-Unique: ZNflUyk2MI6y9LvcHdpgZg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C0E2018188A2 for ; Wed, 22 Jun 2022 22:34:50 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E50E1121314; Wed, 22 Jun 2022 22:34:50 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Subject: [PATCH 11/12] Fixups to diagnostic-format-sarif.cc Date: Wed, 22 Jun 2022 18:34:46 -0400 Message-Id: <20220622223447.2462880-12-dmalcolm@redhat.com> In-Reply-To: <20220622223447.2462880-1-dmalcolm@redhat.com> References: <20220622223447.2462880-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.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_LOW, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2022 22:34:56 -0000 I believe these are needed by one of the rule-handling patches. gcc/ChangeLog: * diagnostic-format-sarif.cc (sarif_builder::sarif_builder): Defer population of m_driver_obj until... (sarif_builder::make_tool_object): ...here. (sarif_builder::make_driver_tool_component_object): Replace with... (sarif_builder::populate_driver_object): ...this. Signed-off-by: David Malcolm --- gcc/diagnostic-format-sarif.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/gcc/diagnostic-format-sarif.cc b/gcc/diagnostic-format-sarif.cc index a409abf648b..9c304fd8e49 100644 --- a/gcc/diagnostic-format-sarif.cc +++ b/gcc/diagnostic-format-sarif.cc @@ -158,7 +158,7 @@ private: json::object *make_top_level_object (json::array *results); json::object *make_run_object (json::array *results); json::object *make_tool_object (); - sarif_tool_component *make_driver_tool_component_object () const; + void populate_driver_object () const; json::array *maybe_make_taxonomies_array () const; json::object *maybe_make_cwe_taxonomy_object () const; json::object *make_tool_component_reference_object_for_cwe () const; @@ -289,7 +289,7 @@ sarif_builder::sarif_builder (diagnostic_context *context) m_extensions_arr (NULL), m_tabstop (context->tabstop) { - m_driver_obj = make_driver_tool_component_object (); + m_driver_obj = new sarif_tool_component (); m_extensions_arr = new json::array (); } @@ -1256,6 +1256,7 @@ sarif_builder::make_tool_object () /* "driver" property (SARIF v2.1.0 section 3.18.2). */ tool_obj->set ("driver", m_driver_obj); + populate_driver_object (); /* Report plugins via the "extensions" property (SARIF v2.1.0 section 3.18.3). */ @@ -1288,42 +1289,40 @@ sarif_builder::make_tool_object () return tool_obj; } -/* Make a toolComponent object (SARIF v2.1.0 section 3.19) for what SARIF - calls the "driver" (see SARIF v2.1.0 section 3.18.1). */ +/* Populate the toolComponent object (SARIF v2.1.0 section 3.19) for what SARIF + calls the "driver" (see SARIF v2.1.0 section 3.18.1). + We delay this to ensure that the m_client_data_hooks is set up (e.g. for + roundtripping from SARIF to SARIF). */ -sarif_tool_component * -sarif_builder::make_driver_tool_component_object () const +void +sarif_builder::populate_driver_object () const { - sarif_tool_component *driver_obj = new sarif_tool_component (); - if (m_context->m_client_data_hooks) if (const client_version_info *vinfo = m_context->m_client_data_hooks->get_any_version_info ()) { /* "name" property (SARIF v2.1.0 section 3.19.8). */ if (const char *name = vinfo->get_tool_name ()) - driver_obj->set ("name", new json::string (name)); + m_driver_obj->set ("name", new json::string (name)); /* "fullName" property (SARIF v2.1.0 section 3.19.9). */ if (char *full_name = vinfo->maybe_make_full_name ()) { - driver_obj->set ("fullName", new json::string (full_name)); + m_driver_obj->set ("fullName", new json::string (full_name)); free (full_name); } /* "version" property (SARIF v2.1.0 section 3.19.13). */ if (const char *version = vinfo->get_version_string ()) - driver_obj->set ("version", new json::string (version)); + m_driver_obj->set ("version", new json::string (version)); /* "informationUri" property (SARIF v2.1.0 section 3.19.17). */ if (char *version_url = vinfo->maybe_make_version_url ()) { - driver_obj->set ("informationUri", new json::string (version_url)); + m_driver_obj->set ("informationUri", new json::string (version_url)); free (version_url); } } - - return driver_obj; } /* If we've seen any CWE IDs, make an array for the "taxonomies" property -- 2.26.3