From patchwork Fri Jan 31 01:19:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1231746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518607-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=qmbEJWls; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eOvoQZdB; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487zsZ1XWhz9sPJ for ; Fri, 31 Jan 2020 12:19:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=AuDG+VhN59R9G5Y5xEFNxwDHivpHwz6HwqaYZRy7JT8gJdxcA6FLN VuuvDjRjkw5JKLjRh83zd9DtB+n5VhS1jMkSZGrp4wva28YZFbwz0X6mDEnQD0iN LXm37n/VI0g/Fr7YAfdouULP05Wx5jaSh/+/81msBpbTH99/PdCdsE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=MnnpQBX60hvVwEm9xyXjRQLOoA8=; b=qmbEJWls5/iWmOUrSCgNfjHaq9sL ESl7nD7Hj+pDDvwBZmOjnI3FLwO8Owv6vHjQvw05dqzlEB+WCFCq5eBvSEDqA5bn UrycEZjSjFgiQOdLmvp96+2OrUNI45LhRJ8Akl/IZ8CN9XV75b8X6Y+rLnMGVpwd PKA/YZGPvpyxzQU= Received: (qmail 57284 invoked by alias); 31 Jan 2020 01:19:30 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57184 invoked by uid 89); 31 Jan 2020 01:19:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1681 X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 Jan 2020 01:19:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580433566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rxYhpo9BhDsmscbfipa4a3It9bQMVB1p7c5bJ3TsJ8g=; b=eOvoQZdBeSS58ldgueUm3Ey6WBSEfaUIdKHY2IMOGNRraJ8zzdcvJH/UApbEFijjqI9h/X oU26+M3KgYttQTMFAYqynwNX7Ky/TZ4ZU3ebzDHqoY4t0I6xZG8/K8ZHUgpLzp1fufCHD/ /8GxGZg3avseuUaaEu786E16DOiRbrg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-260-dtLYy4e5M_Kg-GMvG0AW-Q-1; Thu, 30 Jan 2020 20:19:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CEFD4800D41 for ; Fri, 31 Jan 2020 01:19:21 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41E4D7794C; Fri, 31 Jan 2020 01:19:21 +0000 (UTC) From: David Malcolm To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, David Malcolm Subject: [PATCH 1/2] analyzer: further fixes for comparisons between uncomparable types (PR 93450) Date: Thu, 30 Jan 2020 20:19:17 -0500 Message-Id: <20200131011918.26107-2-dmalcolm@redhat.com> In-Reply-To: <20200131011918.26107-1-dmalcolm@redhat.com> References: <20200130143616.GM17695@tucnak> <20200131011918.26107-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes gcc/analyzer/ChangeLog: PR analyzer/93450 * constraint-manager.cc (constraint_manager::get_or_add_equiv_class): Only compare constants if their types are compatible. * region-model.cc (constant_svalue::eval_condition): Replace check for identical types with call to types_compatible_p. --- gcc/analyzer/constraint-manager.cc | 4 +++- gcc/analyzer/region-model.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc index 777bd1b13c9..f3e31ee0830 100644 --- a/gcc/analyzer/constraint-manager.cc +++ b/gcc/analyzer/constraint-manager.cc @@ -958,7 +958,9 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid) other_id.m_idx++) { const equiv_class &other_ec = other_id.get_obj (*this); - if (other_ec.m_constant) + if (other_ec.m_constant + && types_compatible_p (TREE_TYPE (new_ec->m_constant), + TREE_TYPE (other_ec.m_constant))) { /* If we have two ECs, both with constants, the constants must be non-equal (or they would be in the same EC). diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index a15088a2e3c..b546114bfd5 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -667,7 +667,7 @@ constant_svalue::eval_condition (constant_svalue *lhs, gcc_assert (CONSTANT_CLASS_P (rhs_const)); /* Check for comparable types. */ - if (TREE_TYPE (lhs_const) == TREE_TYPE (rhs_const)) + if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const))) { tree comparison = fold_build2 (op, boolean_type_node, lhs_const, rhs_const); From patchwork Fri Jan 31 01:19:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1231747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518608-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=REw5u1ok; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FeE2Pwsl; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 487zsm5YMSz9sPJ for ; Fri, 31 Jan 2020 12:19:56 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=hytENU0yalnzv6Oal1uZzNxrX62GqSNzMHhr/LEZ+PyjHIBagUGkF ZoBpT03yYyjeaojpkxGxZtyNArA/lk2W8bBUwlSS2/R2tXnqFpr+Q8e0LT07Z6jg T5I8/G7da959wDbSfj4+Bo8rqac9ya1d7dPmOb0Qt5c+EqiAkGdpbU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=default; bh=kUzE0XHq2y7wWwVye4p+k+r8N1M=; b=REw5u1okkRaBU6lXuTXwP6/Jl7dN mzrAH6iceCURWJvq6VCb6rQcFrHwFrHcLuHhn4eYtVMSqE5UTIvFGipOt7XumWzc 2Cd9SVsNhiXybvHKx82tQ8sJ25lZo6Xne5+zp5Gy/ITsMsxoOSF+wNB+kjf7+5Ru rie6NHsstvetaIo= Received: (qmail 57374 invoked by alias); 31 Jan 2020 01:19:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 57278 invoked by uid 89); 31 Jan 2020 01:19:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 Jan 2020 01:19:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580433567; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dUYFYbJlKdPVlgZlCCioXqb7y7i/qk8OVWCJov1aopw=; b=FeE2Pwsl+f+iGBWRaavuod1zAQ9wvsFoChgQFjj+yJu8BsIvKxWvfU/HelVQdn1x7dSn/M 4jfyeQq151Pa0qvfHtwv7kMmsf4PnJTgqcZ7mjcBA6gVX/20DQZg2FSHlZ03SrtmCM8gL+ b6y5DDDNygMhnLDVkDYWiv/DllhS9Qk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-200-YfWnh2YnNfmobqpQDu8FOw-1; Thu, 30 Jan 2020 20:19:23 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B61A182B8E7 for ; Fri, 31 Jan 2020 01:19:22 +0000 (UTC) Received: from t470.redhat.com (ovpn-117-41.phx2.redhat.com [10.3.117.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 040A07793E; Fri, 31 Jan 2020 01:19:21 +0000 (UTC) From: David Malcolm To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, David Malcolm Subject: [PATCH 2/2] analyzer: avoid use of fold_build2 Date: Thu, 30 Jan 2020 20:19:18 -0500 Message-Id: <20200131011918.26107-3-dmalcolm@redhat.com> In-Reply-To: <20200131011918.26107-1-dmalcolm@redhat.com> References: <20200130143616.GM17695@tucnak> <20200131011918.26107-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes Various places in the analyzer use fold_build2, test the result, then discard it. It's more efficient to use fold_binary, which avoids building and GC-ing a redundant tree for the cases where folding fails. gcc/analyzer/ChangeLog: * constraint-manager.cc (range::constrained_to_single_element): Replace fold_build2 with fold_binary. Remove unnecessary newline. (constraint_manager::get_or_add_equiv_class): Replace fold_build2 with fold_binary in two places, and remove out-of-date comment. (constraint_manager::eval_condition): Replace fold_build2 with fold_binary. * region-model.cc (constant_svalue::eval_condition): Likewise. (region_model::on_assignment): Likewise. --- gcc/analyzer/constraint-manager.cc | 15 ++++++--------- gcc/analyzer/region-model.cc | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc index f3e31ee0830..4d138188856 100644 --- a/gcc/analyzer/constraint-manager.cc +++ b/gcc/analyzer/constraint-manager.cc @@ -145,10 +145,9 @@ range::constrained_to_single_element (tree *out) m_upper_bound.ensure_closed (true); // Are they equal? - tree comparison - = fold_build2 (EQ_EXPR, boolean_type_node, - m_lower_bound.m_constant, - m_upper_bound.m_constant); + tree comparison = fold_binary (EQ_EXPR, boolean_type_node, + m_lower_bound.m_constant, + m_upper_bound.m_constant); if (comparison == boolean_true_node) { *out = m_lower_bound.m_constant; @@ -930,7 +929,7 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid) FOR_EACH_VEC_ELT (m_equiv_classes, i, ec) if (ec->m_constant) { - tree eq = fold_build2 (EQ_EXPR, boolean_type_node, + tree eq = fold_binary (EQ_EXPR, boolean_type_node, cst, ec->m_constant); if (eq == boolean_true_node) { @@ -967,10 +966,8 @@ constraint_manager::get_or_add_equiv_class (svalue_id sid) Determine the direction of the inequality, and record that fact. */ tree lt - = fold_build2 (LT_EXPR, boolean_type_node, + = fold_binary (LT_EXPR, boolean_type_node, new_ec->m_constant, other_ec.m_constant); - //gcc_assert (lt == boolean_true_node || lt == boolean_false_node); - // not true for int vs float comparisons if (lt == boolean_true_node) add_constraint_internal (new_id, CONSTRAINT_LT, other_id); else if (lt == boolean_false_node) @@ -1016,7 +1013,7 @@ constraint_manager::eval_condition (equiv_class_id lhs_ec, if (lhs_const && rhs_const) { tree comparison - = fold_build2 (op, boolean_type_node, lhs_const, rhs_const); + = fold_binary (op, boolean_type_node, lhs_const, rhs_const); if (comparison == boolean_true_node) return tristate (tristate::TS_TRUE); if (comparison == boolean_false_node) diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index b546114bfd5..95d002f9c28 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -670,7 +670,7 @@ constant_svalue::eval_condition (constant_svalue *lhs, if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const))) { tree comparison - = fold_build2 (op, boolean_type_node, lhs_const, rhs_const); + = fold_binary (op, boolean_type_node, lhs_const, rhs_const); if (comparison == boolean_true_node) return tristate (tristate::TS_TRUE); if (comparison == boolean_false_node) @@ -4070,9 +4070,9 @@ region_model::on_assignment (const gassign *assign, region_model_context *ctxt) if (tree rhs1_cst = maybe_get_constant (rhs1_sid)) if (tree rhs2_cst = maybe_get_constant (rhs2_sid)) { - tree result = fold_build2 (op, TREE_TYPE (lhs), + tree result = fold_binary (op, TREE_TYPE (lhs), rhs1_cst, rhs2_cst); - if (CONSTANT_CLASS_P (result)) + if (result && CONSTANT_CLASS_P (result)) { svalue_id result_sid = get_or_create_constant_svalue (result);