From patchwork Thu Sep 29 22:35:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1684643 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=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: 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=Caj/zKZ0; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Mdp9940Dwz1yqc for ; Fri, 30 Sep 2022 08:35:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1905B38515FC for ; Thu, 29 Sep 2022 22:35:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1905B38515FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664490935; bh=o0zb2iUDlZd6TIfMUhNf7GQBvrX+ZuMSNN6q2ZO+oVo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Caj/zKZ0LuSiEF1oPFukwFg+Bq3sd1iBwJDa35e0CHE/2MbZ48xwGERyYmAkFRSC3 Oywquyv9lwteLEtTBmGdNrWXPRDSHgOsL6QMvEHOHsERAHvO1GQ/5Aar/9GbyTOVDr D4qNpGRLArWfeDGOcCeqBsFcC25Su9r4quzRepOs= 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 99A313851167 for ; Thu, 29 Sep 2022 22:35:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99A313851167 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-600-P8_u3HTRMH2fJCzaxR_K8Q-1; Thu, 29 Sep 2022 18:35:12 -0400 X-MC-Unique: P8_u3HTRMH2fJCzaxR_K8Q-1 Received: by mail-qv1-f70.google.com with SMTP id em2-20020ad44f82000000b004af5338777cso1875809qvb.4 for ; Thu, 29 Sep 2022 15:35:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=jaY3e/Tfqo8NlMtUVih//wnRiRZ1abJBF0f02NOIo4k=; b=KMNI8coh9QUb27IJzpPRM85IqC6yjqXVzcSKkCPQLSExqrX9kc/JRI42CPPTdHSC9m j3QxUl5RJ7o1RJq8GzQ2pTtvJq3SQhSwprtszUTxwO4kSSPYqKaafxe5WAfJlST+Irvh XLP2D6gtmowHIGhHGC1uGcGaLH3uE789PU9ILkmUeSf94dRAjI5avAA9MvW+xMmoxEqE BPCFFvdP+IBXMOwYQ8/nSioPR9PKk0bZ2D47FqQNE2OWlKaqL3YyjoGoO8WZ/Gg/1a/S 3avsPu61RJACb+rsvZhb33Hxj+F5ugqH9eqlPhZmMWDWxKZJdJ8v/FwS3px3zia4heYI OVvQ== X-Gm-Message-State: ACrzQf2wpGrzDnx4YJZNayCvudCCodfELN1I6/ok0OP2MIrxicK91Mtw Xsg4wIttPZVZJoGKPCrHrqfGzoOYgpD5Idn1rhdPqnAGZmYJj3/8T8y2FJICt/6l2qxLvwR8k6J piWprHm+1EJtlVF9laN5DzkUmDiN7I8adJ/NHz6z94jwXVDK/F6r1883Sjx4rPZGSiUqtzA== X-Received: by 2002:a05:622a:1482:b0:35b:afa9:d8a3 with SMTP id t2-20020a05622a148200b0035bafa9d8a3mr4512657qtx.621.1664490911975; Thu, 29 Sep 2022 15:35:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZwrdoIKhGTzKTMZF8Ww49xOCDXp63ivFZsSLuoSlYPiatbSjuWvEoCvDNpG+E4xVHy+YTKw== X-Received: by 2002:a05:622a:1482:b0:35b:afa9:d8a3 with SMTP id t2-20020a05622a148200b0035bafa9d8a3mr4512643qtx.621.1664490911684; Thu, 29 Sep 2022 15:35:11 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id l5-20020ac80785000000b0035cf31005e2sm302571qth.73.2022.09.29.15.35.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Sep 2022 15:35:10 -0700 (PDT) Message-ID: <16763009-abeb-5785-80fc-40cd755fef0c@redhat.com> Date: Thu, 29 Sep 2022 18:35:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: gcc-patches Subject: [PATCH] Audit op1_range and op2_range for undefined LHS. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.5 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, 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: 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" If the LHS is undefined, GORI should not proceed further.  There are a few places where this happens, and a few potential traps. Most haven't been an issue up until now, but forthcoming changes tend to cause them to trigger more often. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From beb135aaabac4771a405b8d41ad37285ee6f872e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 27 Sep 2022 19:12:06 -0400 Subject: [PATCH 2/6] Audit op1_range and op2_range for undefined LHS. If the LHS is undefined, GORI should cease looking. There are numerous places where this happens, and a few potential traps. * range-op.cc (operator_minus::op2_range): Check for undefined. (operator_mult::op1_range): Ditto. (operator_exact_divide::op1_range): Ditto. (operator_lshift::op1_range): Ditto. (operator_rshift::op1_range): Ditto. (operator_cast::op1_range): Ditto. (operator_bitwise_and::op1_range): Ditto. (operator_bitwise_or::op1_range): Ditto. (operator_trunc_mod::op1_range): Ditto. (operator_trunc_mod::op2_range): Ditto. (operator_bitwise_not::op1_range): Ditto. (pointer_or_operator::op1_range): Ditto. (range_op_handler::op1_range): Ditto. (range_op_handler::op2_range): Ditto. --- gcc/range-op.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 072ebd32109..9bb04c361d0 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1481,6 +1481,8 @@ operator_minus::op2_range (irange &r, tree type, const irange &op1, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; return fold_range (r, type, op1, lhs); } @@ -1650,6 +1652,8 @@ operator_mult::op1_range (irange &r, tree type, relation_kind rel ATTRIBUTE_UNUSED) const { tree offset; + if (lhs.undefined_p ()) + return false; // We can't solve 0 = OP1 * N by dividing by N with a wrapping type. // For example: For 0 = OP1 * 2, OP1 could be 0, or MAXINT, whereas @@ -1902,6 +1906,8 @@ operator_exact_divide::op1_range (irange &r, tree type, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; tree offset; // [2, 4] = op1 / [3,3] since its exact divide, no need to worry about // remainders in the endpoints, so op1 = [2,4] * [3,3] = [6,12]. @@ -2111,6 +2117,8 @@ operator_lshift::op1_range (irange &r, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; tree shift_amount; if (!lhs.contains_p (build_zero_cst (type))) @@ -2183,6 +2191,8 @@ operator_rshift::op1_range (irange &r, relation_kind rel ATTRIBUTE_UNUSED) const { tree shift; + if (lhs.undefined_p ()) + return false; if (op2.singleton_p (&shift)) { // Ignore nonsensical shifts. @@ -2401,6 +2411,8 @@ operator_cast::op1_range (irange &r, tree type, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; tree lhs_type = lhs.type (); gcc_checking_assert (types_compatible_p (op2.type(), type)); @@ -2936,6 +2948,8 @@ operator_bitwise_and::op1_range (irange &r, tree type, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; if (types_compatible_p (type, boolean_type_node)) return op_logical_and.op1_range (r, type, lhs, op2); @@ -3112,6 +3126,8 @@ operator_bitwise_or::op1_range (irange &r, tree type, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; // If this is really a logical wi_fold, call that. if (types_compatible_p (type, boolean_type_node)) return op_logical_or.op1_range (r, type, lhs, op2); @@ -3361,6 +3377,8 @@ operator_trunc_mod::op1_range (irange &r, tree type, const irange &, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; // PR 91029. signop sign = TYPE_SIGN (type); unsigned prec = TYPE_PRECISION (type); @@ -3385,6 +3403,8 @@ operator_trunc_mod::op2_range (irange &r, tree type, const irange &, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; // PR 91029. signop sign = TYPE_SIGN (type); unsigned prec = TYPE_PRECISION (type); @@ -3513,6 +3533,8 @@ operator_bitwise_not::op1_range (irange &r, tree type, const irange &op2, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; if (types_compatible_p (type, boolean_type_node)) return op_logical_not.op1_range (r, type, lhs, op2); @@ -3999,6 +4021,8 @@ pointer_or_operator::op1_range (irange &r, tree type, const irange &op2 ATTRIBUTE_UNUSED, relation_kind rel ATTRIBUTE_UNUSED) const { + if (lhs.undefined_p ()) + return false; if (lhs.zero_p ()) { tree zero = build_zero_cst (type); @@ -4230,6 +4254,9 @@ range_op_handler::op1_range (vrange &r, tree type, relation_kind rel) const { gcc_checking_assert (m_valid); + + if (lhs.undefined_p ()) + return false; if (m_int) return m_int->op1_range (as_a (r), type, as_a (lhs), @@ -4251,6 +4278,8 @@ range_op_handler::op2_range (vrange &r, tree type, relation_kind rel) const { gcc_checking_assert (m_valid); + if (lhs.undefined_p ()) + return false; if (m_int) return m_int->op2_range (as_a (r), type, as_a (lhs), -- 2.37.3