From patchwork Wed Feb 2 23:35:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1587819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=bCikwT8q; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jpysf2Hvyz9sFn for ; Thu, 3 Feb 2022 10:38:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1ED8385800D for ; Wed, 2 Feb 2022 23:38:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1ED8385800D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643845091; bh=eEz20extFJPp+2tLvLXOrHF8T8wNGARLmgiKiQIt+NI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bCikwT8qvtDYmck995xGkjcFurxmTWWyEw4gnXyjyRsazqJlirlj3oM7lnttlbYzn yLVKMKt9QOejfrw/1krG/mlZWL8+4SmYN9qZdNe19ul6nZ/ixrK6SkczoJASYmaqYW mFql3KMfv++joOuyaejEKPgrYGi74Q7OPrO/94DE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id D1BD2385840B for ; Wed, 2 Feb 2022 23:35:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D1BD2385840B Received: by mail-il1-x130.google.com with SMTP id s1so712488ilj.7 for ; Wed, 02 Feb 2022 15:35:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eEz20extFJPp+2tLvLXOrHF8T8wNGARLmgiKiQIt+NI=; b=J0MWd5Hdjlf148fB0Suah/aSM+hzXPJZ6ENqHuEZt8LRTt24ltEv76QqL71JJ2Dvbr 1X7CAS5Fw+Wu4DDGfJXh0KZaCyHbx/X/HOq8oa0xg08TZFih7Kk1WNRAvmTN2a2speVA PEA5KuTOJMR/TnJ8UFjbtczxOjJNMOyA1yQkwr9aVKGwNvbJREA4Gv6FIohdLcumKM7B 7H4if+3EygZZ6qgzR8s+u64RflXKRJCpVTTz1wC0FQ57vYx8CuCnlGr90PDjX9XjEIql ONLUS++Sdy1RE1e8URvVDnNUOm6An8CIYeH/X1mLObn3o+KZzfFDO+zTfWJzo0bQvwS/ /7ZA== X-Gm-Message-State: AOAM533xXvbexc7hAKbeVAb0Qj2ev/Cgvri1kXmdLSi+oMYN87zfSDRS 3oOvO09JVAJiCCUE7TXPI7iqup0M3H0eMg== X-Google-Smtp-Source: ABdhPJx4laR660fewnZ1YJt6DBwspW1BAGKYQdFJhM5wUmTdi8zbHem3HTiv6ivqGDAt3Z/45v+2IQ== X-Received: by 2002:a05:6e02:15c2:: with SMTP id q2mr12883026ilu.226.1643844938170; Wed, 02 Feb 2022 15:35:38 -0800 (PST) Received: from bigbox.redhat.com (97-118-100-142.hlrn.qwest.net. [97.118.100.142]) by smtp.googlemail.com with ESMTPSA id l1sm7481267iln.29.2022.02.02.15.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 15:35:37 -0800 (PST) X-Google-Original-From: Martin Sebor To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] Enable pointer_query caching for -Warray-bounds. Date: Wed, 2 Feb 2022 16:35:29 -0700 Message-Id: <20220202233530.2568647-3-msebor@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220202233530.2568647-1-msebor@redhat.com> References: <20220202233530.2568647-1-msebor@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Martin Sebor via Gcc-patches From: Martin Sebor Reply-To: Martin Sebor Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The second patch in the series adds a pointer_query instance to the array bounds checker object and uses it for each invocation to check a function. gcc/ChangeLog: * gimple-array-bounds.cc (array_bounds_checker::array_bounds_checker): Define ctor. (array_bounds_checker::get_value_range): Use new member. (array_bounds_checker::check_mem_ref): Same. * gimple-array-bounds.h (array_bounds_checker::array_bounds_checker): Outline ctor. (array_bounds_checker::m_ptr_query): New member. --- gcc/gimple-array-bounds.cc | 13 ++++++++++--- gcc/gimple-array-bounds.h | 10 ++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc index 80c70b49607..7ec8b08c8d2 100644 --- a/gcc/gimple-array-bounds.cc +++ b/gcc/gimple-array-bounds.cc @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "tree.h" #include "gimple.h" #include "ssa.h" +#include "pointer-query.h" #include "gimple-array-bounds.h" #include "gimple-iterator.h" #include "gimple-walk.h" @@ -37,7 +38,13 @@ along with GCC; see the file COPYING3. If not see #include "domwalk.h" #include "tree-cfg.h" #include "attribs.h" -#include "pointer-query.h" + +array_bounds_checker::array_bounds_checker (struct function *func, + range_query *qry) + : fun (func), m_ptr_qry (qry) +{ + /* No-op. */ +} // This purposely returns a value_range, not a value_range_equiv, to // break the dependency on equivalences for this pass. @@ -45,7 +52,7 @@ along with GCC; see the file COPYING3. If not see const value_range * array_bounds_checker::get_value_range (const_tree op, gimple *stmt) { - return ranges->get_value_range (op, stmt); + return m_ptr_qry.rvals->get_value_range (op, stmt); } /* Try to determine the DECL that REF refers to. Return the DECL or @@ -401,7 +408,7 @@ array_bounds_checker::check_mem_ref (location_t location, tree ref, axssize = wi::to_offset (access_size); access_ref aref; - if (!compute_objsize (ref, m_stmt, 0, &aref, ranges)) + if (!m_ptr_qry.get_ref (ref, m_stmt, &aref, 0)) return false; if (aref.offset_in_range (axssize)) diff --git a/gcc/gimple-array-bounds.h b/gcc/gimple-array-bounds.h index d42146b87c8..eb399271da7 100644 --- a/gcc/gimple-array-bounds.h +++ b/gcc/gimple-array-bounds.h @@ -20,13 +20,14 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_GIMPLE_ARRAY_BOUNDS_H #define GCC_GIMPLE_ARRAY_BOUNDS_H +#include "pointer-query.h" + class array_bounds_checker { friend class check_array_bounds_dom_walker; public: - array_bounds_checker (struct function *fun, range_query *v) - : fun (fun), ranges (v) { } + array_bounds_checker (struct function *, range_query *); void check (); private: @@ -38,8 +39,9 @@ private: /* Current function. */ struct function *fun; - /* Ranger instance. */ - range_query *ranges; + /* A pointer_query object to store information about pointers and + their targets in. */ + pointer_query m_ptr_qry; /* Current statement. */ gimple *m_stmt; };