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: 10276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp647403wru; Mon, 24 Oct 2022 13:54:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5KM0osAt89Y2Q1Wa486+bfwryvBV9ihU119+fW9Vkp6ParqbwbDdfS8cwAE0VGHLGZqaCW X-Received: by 2002:a05:6402:46:b0:45c:bd68:6ab0 with SMTP id f6-20020a056402004600b0045cbd686ab0mr32709217edu.16.1666644847475; Mon, 24 Oct 2022 13:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666644847; cv=none; d=google.com; s=arc-20160816; b=H8Y6rURs9ASTy9xFp1x7LAFbLwDttE3H7L5lecaI7bVfFQN7ZogUSW+8U/4JySlatQ P9gJTBqPacdPbFUD4SPXR3tTEX9w/cGOUCy2DTtRz6hvfUAt5HF4SJ/KmLLDAprUmqc6 h6WrMh0r7XcYT5Hzw4OxPstmUKdldkY3UOqS7EuLC9NDJ8EAywdIGZYJatfNqhpJpPbo uBP56aVSQ1EZi5bq4Tn8GTcxGesrxvRD7sYvIk6y142z9ClcwYL3+TWZ08ZF//dXfl5T WWgRPoDRUY/SoaL90wEkG+OBnPF/+BvvWPcwmIiCmj6FymqC5rt9MTITxjmqrNzHe+JF 2RJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7dgTFXAwPyE1AIDIaLKv6flRX3QGaztVPUAe9FYYK/4=; b=qCdQOkUgO8rCV+ls1PXlZCNXBg/n2Uk2BTWI8J/N1Gu0XRFcYie0q/srpm17qLEk93 D77nUb0eAvfYLnB3Zf3cvaAI7wFxV0Kc24vzBQufgxo7B8WJea7RAlsQpm2nxK/JJSLz XVArI+XrX6EhXk1/J4/qSJg6wIgYDpdJFzKt6ddSrAPgmaVKYom0nKRC2ikHq8PvrdD0 AWvsNkd/jSDE8WnNWtHApilk60rwt+3omAQz4xWURf1V0k8EfLwZgjH30Y234tfvRJDs S1w/VtROQU6eL/PJduhAQKA2VRsXMRURMeSo6t3SoRng15f63g4GT6fMjnTdBRKCkHC3 uuUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="kj0UT/bC"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jg17-20020a170907971100b0078d8cc2006csi828063ejc.697.2022.10.24.13.54.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 13:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="kj0UT/bC"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 717273858439 for ; Mon, 24 Oct 2022 20:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 717273858439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666644846; bh=7dgTFXAwPyE1AIDIaLKv6flRX3QGaztVPUAe9FYYK/4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kj0UT/bCP40fiaV9NJ3Wv5o4jbD4dqvykoLVQHHhGHkC9GFCa7o8/dM1q2PWTX7XE /a0LUM1e5fEhW2GpvTKP/lN31uSyorilDtfsL1/cZr6JUbpK/WayYZfaeMDLs4KGSR F9RB7FZw06RtLWrxbsDBRUPOINmulakuiWWLX7oY= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747603787315489914?= X-GMAIL-MSGID: =?utf-8?q?1747603787315489914?= 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