From patchwork Fri Jun 18 15:22:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1494321 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=KzHpTqJB; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G62kG2MyKz9sCD for ; Sat, 19 Jun 2021 01:23:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA7BD3AA9C5D for ; Fri, 18 Jun 2021 15:23:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CA7BD3AA9C5D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624029792; bh=iSBn7KqehPLVf3LW+AdbWqmv11cXMfXn4phjTMH/zyE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KzHpTqJBaBzq7SExZdBY6UE115ftWHvHsXBPbNeH/iM6R4xC2NoWHWQNpQyfoUf1w fQHQ+zwq/A+0JW8wGDP1uczArcO3E2tlkBDdOM3WrV8riXpHUD8htVJ6eKv8+C22HH lzO857lHO0JKMYRqajGnsFoeSzyja8YRtULcaF/E= 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 94D07383B834 for ; Fri, 18 Jun 2021 15:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 94D07383B834 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-68-1Y5EdiLoMRKv9hSTuT7JGQ-1; Fri, 18 Jun 2021 11:22:13 -0400 X-MC-Unique: 1Y5EdiLoMRKv9hSTuT7JGQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9217E100C66F for ; Fri, 18 Jun 2021 15:22:10 +0000 (UTC) Received: from t14s.localdomain.com (ovpn-112-247.phx2.redhat.com [10.3.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2237C10074FD; Fri, 18 Jun 2021 15:22:09 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: refactor custom_event, introducing precanned_custom_event class Date: Fri, 18 Jun 2021 11:22:08 -0400 Message-Id: <20210618152208.636023-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" I have followup work where a custom event's description would be better handled via a vfunc rather that a precanned string, hence this refactoring to make it easy to add custom_event subclasses. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as 86606d2ab731a4b8dbbe1e5318a1920210abd65d. gcc/analyzer/ChangeLog: * checker-path.cc (class custom_event): Make abstract to allow for custom vfuncs, splitting existing implementation into... (class precanned_custom_event): New subclass. (custom_event::get_desc): Move to... (precanned_custom_event::get_desc): ...subclass. * checker-path.h (class custom_event): Make abstract to allow for custom vfuncs, splitting existing implementation into... (class precanned_custom_event): New subclass. * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge): Use precanned_custom_event. * engine.cc (stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise. * sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path): Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/checker-path.cc | 6 +++--- gcc/analyzer/checker-path.h | 22 +++++++++++++++++----- gcc/analyzer/diagnostic-manager.cc | 2 +- gcc/analyzer/engine.cc | 2 +- gcc/analyzer/sm-signal.cc | 7 ++++--- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index e6f838b7d52..e10c8e2bb7c 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -162,14 +162,14 @@ debug_event::get_desc (bool) const return label_text::borrow (m_desc); } -/* class custom_event : public checker_event. */ +/* class precanned_custom_event : public custom_event. */ /* Implementation of diagnostic_event::get_desc vfunc for - custom_event. + precanned_custom_event. Use the saved string as the event's description. */ label_text -custom_event::get_desc (bool) const +precanned_custom_event::get_desc (bool) const { return label_text::borrow (m_desc); } diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index f76bb94e7cc..1843c4bc7b4 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -56,6 +56,7 @@ extern const char *event_kind_to_string (enum event_kind ek); checker_event debug_event (EK_DEBUG) custom_event (EK_CUSTOM) + precanned_custom_event statement_event (EK_STMT) function_entry_event (EK_FUNCTION_ENTRY) state_change_event (EK_STATE_CHANGE) @@ -144,19 +145,30 @@ private: char *m_desc; }; -/* A concrete event subclass for custom events. These are not filtered, +/* An abstract event subclass for custom events. These are not filtered, as they are likely to be pertinent to the diagnostic. */ class custom_event : public checker_event { +protected: + custom_event (location_t loc, tree fndecl, int depth) + : checker_event (EK_CUSTOM, loc, fndecl, depth) + { + } +}; + +/* A concrete custom_event subclass with a precanned message. */ + +class precanned_custom_event : public custom_event +{ public: - custom_event (location_t loc, tree fndecl, int depth, - const char *desc) - : checker_event (EK_CUSTOM, loc, fndecl, depth), + precanned_custom_event (location_t loc, tree fndecl, int depth, + const char *desc) + : custom_event (loc, fndecl, depth), m_desc (xstrdup (desc)) { } - ~custom_event () + ~precanned_custom_event () { free (m_desc); } diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 443ff058f65..7eb4ed8a4f2 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -1587,7 +1587,7 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb, "this path would have been rejected as infeasible" " at this edge: "); pb.get_feasibility_problem ()->dump_to_pp (&pp); - emission_path->add_event (new custom_event + emission_path->add_event (new precanned_custom_event (dst_point.get_location (), dst_point.get_fndecl (), dst_stack_depth, diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 529965af187..f322fdb6497 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -1395,7 +1395,7 @@ public: { /* Compare with diagnostic_manager::add_events_for_superedge. */ const int src_stack_depth = src_point.get_stack_depth (); - m_stack_pop_event = new custom_event + m_stack_pop_event = new precanned_custom_event (src_point.get_location (), src_point.get_fndecl (), src_stack_depth, diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index d7e7e7cab04..42be8094997 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -238,9 +238,10 @@ public: FINAL OVERRIDE { emission_path->add_event - (new custom_event (UNKNOWN_LOCATION, NULL_TREE, 0, - "later on," - " when the signal is delivered to the process")); + (new precanned_custom_event + (UNKNOWN_LOCATION, NULL_TREE, 0, + "later on," + " when the signal is delivered to the process")); } };