From patchwork Mon Jun 12 15:32:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1793973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=) Authentication-Results: legolas.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=fL3ZF8cN; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QfwjZ0jGBz20QH for ; Tue, 13 Jun 2023 01:34:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED9E43888C4E for ; Mon, 12 Jun 2023 15:34:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED9E43888C4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686584095; bh=F3ATWGyffw4IRA5oSYxTLPiS1RHKB9suGtYGpzVHQ/o=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fL3ZF8cNSKekyWZW2356kOe75Hndnp3P/rE19qqQc4+1MJvPjnjQCZp8WsfPI8tPJ An8QRFNUc1QqzCZ1VN+26y6UygVSylb586Rqq3OjcGNXKLXb83cjSXIab/YGqg3tdU NQezsInPmppQiKCYsBcrmpim0a3O8oh58MCkZVH4= 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 31EFD3858020 for ; Mon, 12 Jun 2023 15:32:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31EFD3858020 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-66iFGxoaM6-poibUyuzkDw-1; Mon, 12 Jun 2023 11:32:43 -0400 X-MC-Unique: 66iFGxoaM6-poibUyuzkDw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f9a7a41baeso45001791cf.1 for ; Mon, 12 Jun 2023 08:32:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686583962; x=1689175962; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q0umecH9tKHgRkeEvRIEznQIrI/LlYxiRc4wxX63K7k=; b=Yo3YPZ3L4Tk7DRwTuiHLlOCgpEMq+wdjWp2XsKd7vHNGYIU6QqLIMbRxCPl5XPTTXL 6T/FwFu3/WQUBLxccn6FJM5JZzG6dKzRiYdVNP6c1zjIlLeInkqhfAaDTT6BlDHmE0bV fo1zPcbz7gRpDb+DSyS0rr2qd+fgBEj0U6T9UNxWaFEjJf+TJ5ELI7g0i0IsP21UDlFh ItmMpWxSJBGxhPHf6V0aQyTdASjNOu0bYK1OT3eWs2hWxNZOoapKWPThunkGoEEBUySQ tQSsCUV0+f6zO/xnm5TOJ0P/pDmmi0eyIREulk8SdtH+NKvVQYb6MW3/tWZcpdzOmXAi YXeA== X-Gm-Message-State: AC+VfDz7uFqlnvYnPCI7ngxHQIIo49XZ8u2F68WevhDOlPmQMzw6v4cV +QO1itNmIFe3pZH5f+vN4H4rzXtIwJTie4mceKrLBqHvcsKBWQQjMEHwqWU2nk1uKJWulgcYzYE Gte62OctmLkIRW+pEGCE3A5Zmr9PIwYMhAKOHZzQX6531PmyGwE1v5fIDtu9TVXRz4xmZcj6yzV I8Eg== X-Received: by 2002:ac8:7fc8:0:b0:3f3:845f:122c with SMTP id b8-20020ac87fc8000000b003f3845f122cmr11007393qtk.34.1686583962559; Mon, 12 Jun 2023 08:32:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ51ruHhXALpNFLnck75XrvEFfVYmInFfaukVbT0W9S2kLpiVcit0FRziWLIa5ZR4Fg6WOmbwg== X-Received: by 2002:ac8:7fc8:0:b0:3f3:845f:122c with SMTP id b8-20020ac87fc8000000b003f3845f122cmr11007363qtk.34.1686583962143; Mon, 12 Jun 2023 08:32:42 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::ca58? ([2607:fea8:51df:4200::ca58]) by smtp.gmail.com with ESMTPSA id fy26-20020a05622a5a1a00b003f86bc1753bsm3475201qtb.80.2023.06.12.08.32.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jun 2023 08:32:41 -0700 (PDT) Message-ID: <419f4280-d0c5-7fbe-2dae-4c198b69186e@redhat.com> Date: Mon, 12 Jun 2023 11:32:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED 8/17] - Split pointer based range operators to range-op-ptr.cc X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch moves all the pointer specific code into a new file range-op-ptr.cc Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From cb511d2209fa3a05801983a6965656734c1592c6 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sat, 10 Jun 2023 16:17:51 -0400 Subject: [PATCH 08/17] Split pointer ibased range operators to range-op-ptr.cc MOve the pointer table and all pointer specific operators into a new file for pointers. * Makefile.in (OBJS): Add range-op-ptr.o. * range-op-mixed.h (update_known_bitmask): Move prototype here. (minus_op1_op2_relation_effect): Move prototype here. (wi_includes_zero_p): Move function to here. (wi_zero_p): Ditto. * range-op.cc (update_known_bitmask): Remove static. (wi_includes_zero_p): Move to header. (wi_zero_p): Move to header. (minus_op1_op2_relation_effect): Remove static. (operator_pointer_diff): Move class and routines to range-op-ptr.cc. (pointer_plus_operator): Ditto. (pointer_min_max_operator): Ditto. (pointer_and_operator): Ditto. (pointer_or_operator): Ditto. (pointer_table): Ditto. (range_op_table::initialize_pointer_ops): Ditto. * range-op-ptr.cc: New. --- gcc/Makefile.in | 1 + gcc/range-op-mixed.h | 25 ++++ gcc/range-op-ptr.cc | 286 +++++++++++++++++++++++++++++++++++++++++++ gcc/range-op.cc | 258 +------------------------------------- 4 files changed, 314 insertions(+), 256 deletions(-) create mode 100644 gcc/range-op-ptr.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 0c02f312985..4be82e83b9e 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1588,6 +1588,7 @@ OBJS = \ range.o \ range-op.o \ range-op-float.o \ + range-op-ptr.o \ read-md.o \ read-rtl.o \ read-rtl-function.o \ diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index cd137acd0e6..b188f5a516e 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -22,6 +22,31 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_RANGE_OP_MIXED_H #define GCC_RANGE_OP_MIXED_H +void update_known_bitmask (irange &, tree_code, const irange &, const irange &); +bool minus_op1_op2_relation_effect (irange &lhs_range, tree type, + const irange &, const irange &, + relation_kind rel); + + +// Return TRUE if 0 is within [WMIN, WMAX]. + +inline bool +wi_includes_zero_p (tree type, const wide_int &wmin, const wide_int &wmax) +{ + signop sign = TYPE_SIGN (type); + return wi::le_p (wmin, 0, sign) && wi::ge_p (wmax, 0, sign); +} + +// Return TRUE if [WMIN, WMAX] is the singleton 0. + +inline bool +wi_zero_p (tree type, const wide_int &wmin, const wide_int &wmax) +{ + unsigned prec = TYPE_PRECISION (type); + return wmin == wmax && wi::eq_p (wmin, wi::zero (prec)); +} + + enum bool_range_state { BRS_FALSE, BRS_TRUE, BRS_EMPTY, BRS_FULL }; bool_range_state get_bool_state (vrange &r, const vrange &lhs, tree val_type); diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc new file mode 100644 index 00000000000..55c37cc8c86 --- /dev/null +++ b/gcc/range-op-ptr.cc @@ -0,0 +1,286 @@ +/* Code for range operators. + Copyright (C) 2017-2023 Free Software Foundation, Inc. + Contributed by Andrew MacLeod + and Aldy Hernandez . + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "insn-codes.h" +#include "rtl.h" +#include "tree.h" +#include "gimple.h" +#include "cfghooks.h" +#include "tree-pass.h" +#include "ssa.h" +#include "optabs-tree.h" +#include "gimple-pretty-print.h" +#include "diagnostic-core.h" +#include "flags.h" +#include "fold-const.h" +#include "stor-layout.h" +#include "calls.h" +#include "cfganal.h" +#include "gimple-iterator.h" +#include "gimple-fold.h" +#include "tree-eh.h" +#include "gimple-walk.h" +#include "tree-cfg.h" +#include "wide-int.h" +#include "value-relation.h" +#include "range-op.h" +#include "tree-ssa-ccp.h" +#include "range-op-mixed.h" + +class pointer_plus_operator : public range_operator +{ + using range_operator::op2_range; +public: + virtual void wi_fold (irange &r, tree type, + const wide_int &lh_lb, + const wide_int &lh_ub, + const wide_int &rh_lb, + const wide_int &rh_ub) const; + virtual bool op2_range (irange &r, tree type, + const irange &lhs, + const irange &op1, + relation_trio = TRIO_VARYING) const; + void update_bitmask (irange &r, const irange &lh, const irange &rh) const + { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); } +} op_pointer_plus; + +void +pointer_plus_operator::wi_fold (irange &r, tree type, + const wide_int &lh_lb, + const wide_int &lh_ub, + const wide_int &rh_lb, + const wide_int &rh_ub) const +{ + // Check for [0,0] + const, and simply return the const. + if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub) + { + r.set (type, rh_lb, rh_lb); + return; + } + + // For pointer types, we are really only interested in asserting + // whether the expression evaluates to non-NULL. + // + // With -fno-delete-null-pointer-checks we need to be more + // conservative. As some object might reside at address 0, + // then some offset could be added to it and the same offset + // subtracted again and the result would be NULL. + // E.g. + // static int a[12]; where &a[0] is NULL and + // ptr = &a[6]; + // ptr -= 6; + // ptr will be NULL here, even when there is POINTER_PLUS_EXPR + // where the first range doesn't include zero and the second one + // doesn't either. As the second operand is sizetype (unsigned), + // consider all ranges where the MSB could be set as possible + // subtractions where the result might be NULL. + if ((!wi_includes_zero_p (type, lh_lb, lh_ub) + || !wi_includes_zero_p (type, rh_lb, rh_ub)) + && !TYPE_OVERFLOW_WRAPS (type) + && (flag_delete_null_pointer_checks + || !wi::sign_mask (rh_ub))) + r = range_nonzero (type); + else if (lh_lb == lh_ub && lh_lb == 0 + && rh_lb == rh_ub && rh_lb == 0) + r = range_zero (type); + else + r.set_varying (type); +} + +bool +pointer_plus_operator::op2_range (irange &r, tree type, + const irange &lhs ATTRIBUTE_UNUSED, + const irange &op1 ATTRIBUTE_UNUSED, + relation_trio trio) const +{ + relation_kind rel = trio.lhs_op1 (); + r.set_varying (type); + + // If the LHS and OP1 are equal, the op2 must be zero. + if (rel == VREL_EQ) + r.set_zero (type); + // If the LHS and OP1 are not equal, the offset must be non-zero. + else if (rel == VREL_NE) + r.set_nonzero (type); + else + return false; + return true; +} + +class pointer_min_max_operator : public range_operator +{ +public: + virtual void wi_fold (irange & r, tree type, + const wide_int &lh_lb, const wide_int &lh_ub, + const wide_int &rh_lb, const wide_int &rh_ub) const; +} op_ptr_min_max; + +void +pointer_min_max_operator::wi_fold (irange &r, tree type, + const wide_int &lh_lb, + const wide_int &lh_ub, + const wide_int &rh_lb, + const wide_int &rh_ub) const +{ + // For MIN/MAX expressions with pointers, we only care about + // nullness. If both are non null, then the result is nonnull. + // If both are null, then the result is null. Otherwise they + // are varying. + if (!wi_includes_zero_p (type, lh_lb, lh_ub) + && !wi_includes_zero_p (type, rh_lb, rh_ub)) + r = range_nonzero (type); + else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) + r = range_zero (type); + else + r.set_varying (type); +} + + +class pointer_and_operator : public range_operator +{ +public: + virtual void wi_fold (irange &r, tree type, + const wide_int &lh_lb, const wide_int &lh_ub, + const wide_int &rh_lb, const wide_int &rh_ub) const; +} op_pointer_and; + +void +pointer_and_operator::wi_fold (irange &r, tree type, + const wide_int &lh_lb, + const wide_int &lh_ub, + const wide_int &rh_lb ATTRIBUTE_UNUSED, + const wide_int &rh_ub ATTRIBUTE_UNUSED) const +{ + // For pointer types, we are really only interested in asserting + // whether the expression evaluates to non-NULL. + if (wi_zero_p (type, lh_lb, lh_ub) || wi_zero_p (type, lh_lb, lh_ub)) + r = range_zero (type); + else + r.set_varying (type); +} + + +class pointer_or_operator : public range_operator +{ + using range_operator::op1_range; + using range_operator::op2_range; +public: + virtual bool op1_range (irange &r, tree type, + const irange &lhs, + const irange &op2, + relation_trio rel = TRIO_VARYING) const; + virtual bool op2_range (irange &r, tree type, + const irange &lhs, + const irange &op1, + relation_trio rel = TRIO_VARYING) const; + virtual void wi_fold (irange &r, tree type, + const wide_int &lh_lb, const wide_int &lh_ub, + const wide_int &rh_lb, const wide_int &rh_ub) const; +} op_pointer_or; + +bool +pointer_or_operator::op1_range (irange &r, tree type, + const irange &lhs, + const irange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + if (lhs.undefined_p ()) + return false; + if (lhs.zero_p ()) + { + r.set_zero (type); + return true; + } + r.set_varying (type); + return true; +} + +bool +pointer_or_operator::op2_range (irange &r, tree type, + const irange &lhs, + const irange &op1, + relation_trio) const +{ + return pointer_or_operator::op1_range (r, type, lhs, op1); +} + +void +pointer_or_operator::wi_fold (irange &r, tree type, + const wide_int &lh_lb, + const wide_int &lh_ub, + const wide_int &rh_lb, + const wide_int &rh_ub) const +{ + // For pointer types, we are really only interested in asserting + // whether the expression evaluates to non-NULL. + if (!wi_includes_zero_p (type, lh_lb, lh_ub) + && !wi_includes_zero_p (type, rh_lb, rh_ub)) + r = range_nonzero (type); + else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) + r = range_zero (type); + else + r.set_varying (type); +} + +class operator_pointer_diff : public range_operator +{ + virtual bool op1_op2_relation_effect (irange &lhs_range, + tree type, + const irange &op1_range, + const irange &op2_range, + relation_kind rel) const; + void update_bitmask (irange &r, const irange &lh, const irange &rh) const + { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); } +} op_pointer_diff; + +bool +operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type, + const irange &op1_range, + const irange &op2_range, + relation_kind rel) const +{ + return minus_op1_op2_relation_effect (lhs_range, type, op1_range, op2_range, + rel); +} + +// When PRANGE is implemented, these are all the opcodes which are currently +// expecting routines with PRANGE signatures. + +pointer_table::pointer_table () +{ + set (BIT_AND_EXPR, op_pointer_and); + set (BIT_IOR_EXPR, op_pointer_or); + set (MIN_EXPR, op_ptr_min_max); + set (MAX_EXPR, op_ptr_min_max); +} + +// Initialize any pointer operators to the primary table + +void +range_op_table::initialize_pointer_ops () +{ + set (POINTER_PLUS_EXPR, op_pointer_plus); + set (POINTER_DIFF_EXPR, op_pointer_diff); +} diff --git a/gcc/range-op.cc b/gcc/range-op.cc index e83f627a722..e0cd1b10790 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -381,7 +381,7 @@ irange_to_masked_value (const irange &r, widest_int &value, widest_int &mask) // Update the known bitmasks in R when applying the operation CODE to // LH and RH. -static void +void update_known_bitmask (irange &r, tree_code code, const irange &lh, const irange &rh) { @@ -444,24 +444,6 @@ get_shift_range (irange &r, tree type, const irange &op) return true; } -// Return TRUE if 0 is within [WMIN, WMAX]. - -static inline bool -wi_includes_zero_p (tree type, const wide_int &wmin, const wide_int &wmax) -{ - signop sign = TYPE_SIGN (type); - return wi::le_p (wmin, 0, sign) && wi::ge_p (wmax, 0, sign); -} - -// Return TRUE if [WMIN, WMAX] is the singleton 0. - -static inline bool -wi_zero_p (tree type, const wide_int &wmin, const wide_int &wmax) -{ - unsigned prec = TYPE_PRECISION (type); - return wmin == wmax && wi::eq_p (wmin, wi::zero (prec)); -} - // Default wide_int fold operation returns [MIN, MAX]. void @@ -1844,7 +1826,7 @@ operator_minus::lhs_op1_relation (const irange &, const irange &op1, // LHS of the expression. If so, apply it to LHS_RANGE. This is a helper // function for both MINUS_EXPR and POINTER_DIFF_EXPR. -static bool +bool minus_op1_op2_relation_effect (irange &lhs_range, tree type, const irange &op1_range ATTRIBUTE_UNUSED, const irange &op2_range ATTRIBUTE_UNUSED, @@ -1951,29 +1933,6 @@ operator_minus::op2_range (irange &r, tree type, return fold_range (r, type, op1, lhs); } - -class operator_pointer_diff : public range_operator -{ - virtual bool op1_op2_relation_effect (irange &lhs_range, - tree type, - const irange &op1_range, - const irange &op2_range, - relation_kind rel) const; - void update_bitmask (irange &r, const irange &lh, const irange &rh) const - { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); } -} op_pointer_diff; - -bool -operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type, - const irange &op1_range, - const irange &op2_range, - relation_kind rel) const -{ - return minus_op1_op2_relation_effect (lhs_range, type, op1_range, op2_range, - rel); -} - - void operator_min::update_bitmask (irange &r, const irange &lh, const irange &rh) const @@ -4319,202 +4278,6 @@ operator_addr_expr::op1_range (irange &r, tree type, { return operator_addr_expr::fold_range (r, type, lhs, op2); } - - -class pointer_plus_operator : public range_operator -{ - using range_operator::op2_range; -public: - virtual void wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb, - const wide_int &rh_ub) const; - virtual bool op2_range (irange &r, tree type, - const irange &lhs, - const irange &op1, - relation_trio = TRIO_VARYING) const; - void update_bitmask (irange &r, const irange &lh, const irange &rh) const - { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); } -} op_pointer_plus; - -void -pointer_plus_operator::wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb, - const wide_int &rh_ub) const -{ - // Check for [0,0] + const, and simply return the const. - if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub) - { - r.set (type, rh_lb, rh_lb); - return; - } - - // For pointer types, we are really only interested in asserting - // whether the expression evaluates to non-NULL. - // - // With -fno-delete-null-pointer-checks we need to be more - // conservative. As some object might reside at address 0, - // then some offset could be added to it and the same offset - // subtracted again and the result would be NULL. - // E.g. - // static int a[12]; where &a[0] is NULL and - // ptr = &a[6]; - // ptr -= 6; - // ptr will be NULL here, even when there is POINTER_PLUS_EXPR - // where the first range doesn't include zero and the second one - // doesn't either. As the second operand is sizetype (unsigned), - // consider all ranges where the MSB could be set as possible - // subtractions where the result might be NULL. - if ((!wi_includes_zero_p (type, lh_lb, lh_ub) - || !wi_includes_zero_p (type, rh_lb, rh_ub)) - && !TYPE_OVERFLOW_WRAPS (type) - && (flag_delete_null_pointer_checks - || !wi::sign_mask (rh_ub))) - r = range_nonzero (type); - else if (lh_lb == lh_ub && lh_lb == 0 - && rh_lb == rh_ub && rh_lb == 0) - r = range_zero (type); - else - r.set_varying (type); -} - -bool -pointer_plus_operator::op2_range (irange &r, tree type, - const irange &lhs ATTRIBUTE_UNUSED, - const irange &op1 ATTRIBUTE_UNUSED, - relation_trio trio) const -{ - relation_kind rel = trio.lhs_op1 (); - r.set_varying (type); - - // If the LHS and OP1 are equal, the op2 must be zero. - if (rel == VREL_EQ) - r.set_zero (type); - // If the LHS and OP1 are not equal, the offset must be non-zero. - else if (rel == VREL_NE) - r.set_nonzero (type); - else - return false; - return true; -} - -class pointer_min_max_operator : public range_operator -{ -public: - virtual void wi_fold (irange & r, tree type, - const wide_int &lh_lb, const wide_int &lh_ub, - const wide_int &rh_lb, const wide_int &rh_ub) const; -} op_ptr_min_max; - -void -pointer_min_max_operator::wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb, - const wide_int &rh_ub) const -{ - // For MIN/MAX expressions with pointers, we only care about - // nullness. If both are non null, then the result is nonnull. - // If both are null, then the result is null. Otherwise they - // are varying. - if (!wi_includes_zero_p (type, lh_lb, lh_ub) - && !wi_includes_zero_p (type, rh_lb, rh_ub)) - r = range_nonzero (type); - else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) - r = range_zero (type); - else - r.set_varying (type); -} - - -class pointer_and_operator : public range_operator -{ -public: - virtual void wi_fold (irange &r, tree type, - const wide_int &lh_lb, const wide_int &lh_ub, - const wide_int &rh_lb, const wide_int &rh_ub) const; -} op_pointer_and; - -void -pointer_and_operator::wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb ATTRIBUTE_UNUSED, - const wide_int &rh_ub ATTRIBUTE_UNUSED) const -{ - // For pointer types, we are really only interested in asserting - // whether the expression evaluates to non-NULL. - if (wi_zero_p (type, lh_lb, lh_ub) || wi_zero_p (type, lh_lb, lh_ub)) - r = range_zero (type); - else - r.set_varying (type); -} - - -class pointer_or_operator : public range_operator -{ - using range_operator::op1_range; - using range_operator::op2_range; -public: - virtual bool op1_range (irange &r, tree type, - const irange &lhs, - const irange &op2, - relation_trio rel = TRIO_VARYING) const; - virtual bool op2_range (irange &r, tree type, - const irange &lhs, - const irange &op1, - relation_trio rel = TRIO_VARYING) const; - virtual void wi_fold (irange &r, tree type, - const wide_int &lh_lb, const wide_int &lh_ub, - const wide_int &rh_lb, const wide_int &rh_ub) const; -} op_pointer_or; - -bool -pointer_or_operator::op1_range (irange &r, tree type, - const irange &lhs, - const irange &op2 ATTRIBUTE_UNUSED, - relation_trio) const -{ - if (lhs.undefined_p ()) - return false; - if (lhs.zero_p ()) - { - r.set_zero (type); - return true; - } - r.set_varying (type); - return true; -} - -bool -pointer_or_operator::op2_range (irange &r, tree type, - const irange &lhs, - const irange &op1, - relation_trio) const -{ - return pointer_or_operator::op1_range (r, type, lhs, op1); -} - -void -pointer_or_operator::wi_fold (irange &r, tree type, - const wide_int &lh_lb, - const wide_int &lh_ub, - const wide_int &rh_lb, - const wide_int &rh_ub) const -{ - // For pointer types, we are really only interested in asserting - // whether the expression evaluates to non-NULL. - if (!wi_includes_zero_p (type, lh_lb, lh_ub) - && !wi_includes_zero_p (type, rh_lb, rh_ub)) - r = range_nonzero (type); - else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) - r = range_zero (type); - else - r.set_varying (type); -} // Initialize any integral operators to the primary table @@ -4537,23 +4300,6 @@ range_op_table::initialize_integral_ops () set (ABSU_EXPR, op_absu); } -pointer_table::pointer_table () -{ - set (BIT_AND_EXPR, op_pointer_and); - set (BIT_IOR_EXPR, op_pointer_or); - set (MIN_EXPR, op_ptr_min_max); - set (MAX_EXPR, op_ptr_min_max); -} - -// Initialize any pointer operators to the primary table - -void -range_op_table::initialize_pointer_ops () -{ - set (POINTER_PLUS_EXPR, op_pointer_plus); - set (POINTER_DIFF_EXPR, op_pointer_diff); -} - #if CHECKING_P #include "selftest.h" -- 2.40.1