From patchwork Mon Oct 24 20:53:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 59369 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75AAB3858294 for ; Mon, 24 Oct 2022 20:53:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75AAB3858294 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666644832; bh=7dgTFXAwPyE1AIDIaLKv6flRX3QGaztVPUAe9FYYK/4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EYfsdkexO/XP9wCGDpOawOFVp+koU7XG018hluNAxYjL6OWimNuGVuuGVHBO4zNUy I82qG4uRmlSmDZFx8J5G/3/4ESxg5bpVj6RL/SzguP+i/SwV6hQx8qw6RGU3Oi6huh AVIh7UfLxRRiZDz2jGfCRsVNHLG5RSy4Fy+1MDSk= 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 D0DE9385801E for ; Mon, 24 Oct 2022 20:53:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0DE9385801E 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-150-cEElVN-aMcqrE1HfyUV0Jg-1; Mon, 24 Oct 2022 16:53:21 -0400 X-MC-Unique: cEElVN-aMcqrE1HfyUV0Jg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4AEEC185A792 for ; Mon, 24 Oct 2022 20:53:21 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73E0E2024CCA; Mon, 24 Oct 2022 20:53:14 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] analyzer: simplify sm_state_map lookup Date: Mon, 24 Oct 2022 16:53:12 -0400 Message-Id: <20221024205312.1760173-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 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_H2, 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.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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r13-3467-g53881c47e4b357. gcc/analyzer/ChangeLog: * engine.cc (impl_region_model_context::get_malloc_map): Replace with... (impl_region_model_context::get_state_map_by_name): ...this. (impl_region_model_context::get_fd_map): Delete. (impl_region_model_context::get_taint_map): Delete. * exploded-graph.h (impl_region_model_context::get_fd_map): Delete. (impl_region_model_context::get_malloc_map): Delete. (impl_region_model_context::get_taint_map): Delete. (impl_region_model_context::get_state_map_by_name): New. * region-model.h (region_model_context::get_state_map_by_name): New vfunc. (region_model_context::get_fd_map): Convert from vfunc to function. (region_model_context::get_malloc_map): Likewise. (region_model_context::get_taint_map): Likewise. (noop_region_model_context::get_state_map_by_name): New. (noop_region_model_context::get_fd_map): Delete. (noop_region_model_context::get_malloc_map): Delete. (noop_region_model_context::get_taint_map): Delete. (region_model_context_decorator::get_state_map_by_name): New. (region_model_context_decorator::get_fd_map): Delete. (region_model_context_decorator::get_malloc_map): Delete. (region_model_context_decorator::get_taint_map): Delete. Signed-off-by: David Malcolm --- gcc/analyzer/engine.cc | 47 ++++---------------- gcc/analyzer/exploded-graph.h | 13 ++---- gcc/analyzer/region-model.h | 80 +++++++++++++++-------------------- 3 files changed, 48 insertions(+), 92 deletions(-) diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index a664a99eb78..52978dd0d37 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -214,50 +214,21 @@ impl_region_model_context::terminate_path () } bool -impl_region_model_context::get_malloc_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) -{ - unsigned malloc_sm_idx; - if (!m_ext_state.get_sm_idx_by_name ("malloc", &malloc_sm_idx)) - return false; - - *out_smap = m_new_state->m_checker_states[malloc_sm_idx]; - *out_sm = &m_ext_state.get_sm (malloc_sm_idx); - *out_sm_idx = malloc_sm_idx; - return true; -} - -bool -impl_region_model_context::get_fd_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) -{ - unsigned fd_sm_idx; - if (!m_ext_state.get_sm_idx_by_name ("file-descriptor", &fd_sm_idx)) - return false; - - *out_smap = m_new_state->m_checker_states[fd_sm_idx]; - *out_sm = &m_ext_state.get_sm (fd_sm_idx); - *out_sm_idx = fd_sm_idx; - return true; -} - -bool -impl_region_model_context::get_taint_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) +impl_region_model_context::get_state_map_by_name (const char *name, + sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) { if (!m_new_state) return false; - unsigned taint_sm_idx; - if (!m_ext_state.get_sm_idx_by_name ("taint", &taint_sm_idx)) + unsigned sm_idx; + if (!m_ext_state.get_sm_idx_by_name (name, &sm_idx)) return false; - *out_smap = m_new_state->m_checker_states[taint_sm_idx]; - *out_sm = &m_ext_state.get_sm (taint_sm_idx); - *out_sm_idx = taint_sm_idx; + *out_smap = m_new_state->m_checker_states[sm_idx]; + *out_sm = &m_ext_state.get_sm (sm_idx); + *out_sm_idx = sm_idx; return true; } diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index ad278e277dc..5996252f1fb 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -96,15 +96,10 @@ class impl_region_model_context : public region_model_context { return &m_ext_state; } - bool get_fd_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) final override; - bool get_malloc_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) final override; - bool get_taint_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) final override; + bool get_state_map_by_name (const char *name, + sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) override; const gimple *get_stmt () const override { return m_stmt; } diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index d849e0d774b..19e8043daa4 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -737,19 +737,33 @@ class region_model_context virtual const extrinsic_state *get_ext_state () const = 0; - /* Hook for clients to access the "fd" state machine in + /* Hook for clients to access the a specific state machine in any underlying program_state. */ - virtual bool get_fd_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) = 0; - /* Likewise for the "malloc" state machine. */ - virtual bool get_malloc_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) = 0; - /* Likewise for the "taint" state machine. */ - virtual bool get_taint_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) = 0; + virtual bool get_state_map_by_name (const char *name, + sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) = 0; + + /* Precanned ways for clients to access specific state machines. */ + bool get_fd_map (sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) + { + return get_state_map_by_name ("file-descriptor", out_smap, out_sm, + out_sm_idx); + } + bool get_malloc_map (sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) + { + return get_state_map_by_name ("malloc", out_smap, out_sm, out_sm_idx); + } + bool get_taint_map (sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) + { + return get_state_map_by_name ("taint", out_smap, out_sm, out_sm_idx); + } /* Get the current statement, if any. */ virtual const gimple *get_stmt () const = 0; @@ -796,21 +810,10 @@ public: const extrinsic_state *get_ext_state () const override { return NULL; } - bool get_fd_map (sm_state_map **, - const state_machine **, - unsigned *) override - { - return false; - } - bool get_malloc_map (sm_state_map **, - const state_machine **, - unsigned *) override - { - return false; - } - bool get_taint_map (sm_state_map **, - const state_machine **, - unsigned *) override + bool get_state_map_by_name (const char *, + sm_state_map **, + const state_machine **, + unsigned *) override { return false; } @@ -929,25 +932,12 @@ class region_model_context_decorator : public region_model_context return m_inner->get_ext_state (); } - bool get_fd_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) override - { - return m_inner->get_fd_map (out_smap, out_sm, out_sm_idx); - } - - bool get_malloc_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) override - { - return m_inner->get_malloc_map (out_smap, out_sm, out_sm_idx); - } - - bool get_taint_map (sm_state_map **out_smap, - const state_machine **out_sm, - unsigned *out_sm_idx) override + bool get_state_map_by_name (const char *name, + sm_state_map **out_smap, + const state_machine **out_sm, + unsigned *out_sm_idx) override { - return m_inner->get_taint_map (out_smap, out_sm, out_sm_idx); + return m_inner->get_state_map_by_name (name, out_smap, out_sm, out_sm_idx); } const gimple *get_stmt () const override