From patchwork Thu Jan 26 12:49:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 48609 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp252460wrn; Thu, 26 Jan 2023 04:49:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXsD10ADUu11whKQvoDCnLFH8Yzy90mz+un5ietf/1HOdLffkVRwuP0MacWFlPHeti+wdFMZ X-Received: by 2002:a05:6402:1008:b0:47a:e008:8662 with SMTP id c8-20020a056402100800b0047ae0088662mr35151514edu.34.1674737388885; Thu, 26 Jan 2023 04:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674737388; cv=none; d=google.com; s=arc-20160816; b=BJOZG5yJ4Utel/6+usIewmQOJPdPCv+vtTvDiyis6ux7yEFOfc1gQlE6tmzmdUPZIe 5qw0codYDlMrnSXTqDSPNbNAOQZuoIcjmSOjGAICmvGvWksblyRQ/SVaFErPEsX8ILNT 9Wc/DqNAJcTRBQDDfvJFqUB3gK9I3nVd65lqasz3aZpioxM1ruaqV0pPE60+1599wp12 ix5/nlVN0EysDuK72P84o9cqtRer3qxia8c/Zr/6Oc+aKWMu00ri2QM56v68kVG49TCk pfT7FKaru1kxPLhHk4VMojyOQzo/UAVkJo24BuBbkwtJ9JONWSyXOMo3tHO6+gT1cTg7 XLZA== 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:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5+fo4JygnbbzuF5QHlBgHYIY/GDH5MfdWkNZGrEpbXY=; b=iEcwyfW+KDzPwRk+cH/mJxI6OWev5yw8SLkfSYN5VlwLsb7u3CAkVjKgLVjTsjWXYL Ms2YxhrkrfFaHqHRoQoHOuToOF8zJXl9A+6l+fnt8nQ8VC1b9/Vd655YdBV7E4tK+EXS sxUkeGO8c1MtQqkvCnkBZXW4yMcH3o4NT1GwMXNC7xrroI2BzxyLuO7ezqCGHvwMqOc6 oMOCSJ8fBC42MugsGKt2LgZiLEYCYRKxsiEc/JH9p26/yPumHGeiZSljGqsxsWiSssFX BIIxg9NigMju2hW9tp8vi9jS9tT9a1cSunxVwAaNWMbhZQvLFQu7cLFOfoSPV/yAfhx7 DsYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="f/uFPay2"; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b21-20020a0564021f1500b0048d6ace589esi1805652edb.128.2023.01.26.04.49.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 04:49:48 -0800 (PST) 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="f/uFPay2"; 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 DEA2F3858C74 for ; Thu, 26 Jan 2023 12:49:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEA2F3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674737387; bh=5+fo4JygnbbzuF5QHlBgHYIY/GDH5MfdWkNZGrEpbXY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=f/uFPay2iqsEkQCT7Nj9oBrR3m3MxztyDZFNIIrl1S1hcJR5AONKR6+bhTEvOEECo GIg9xt4wJXwdDkGXc3bHj7kGmFvR1m/QXeycW/QG+lvzSIJop8vqNZt+YddMPGmRU1 7cmLiehNv7P2jHdL9Fk43QS4W/T98lZNBO4K+5Bc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 59BAD3858D38 for ; Thu, 26 Jan 2023 12:49:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59BAD3858D38 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 92C1C1FF40 for ; Thu, 26 Jan 2023 12:49:04 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 81D8013A09 for ; Thu, 26 Jan 2023 12:49:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dxzIHsB20mNYTAAAMHmgww (envelope-from ) for ; Thu, 26 Jan 2023 12:49:04 +0000 Date: Thu, 26 Jan 2023 13:49:04 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108547 - robustify uninit predicate analysis MIME-Version: 1.0 Message-Id: <20230126124904.81D8013A09@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener 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?1756089432351393061?= X-GMAIL-MSGID: =?utf-8?q?1756089432351393061?= Predicate analysis, when looking through casts doesn't bother to convert boundary constants to the type of the bounded variables. The following robustifies value_sat_pred_p to use widest_ints to deal with this, like other code in predicate analysis. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108547 * gimple-predicate-analysis.cc (value_sat_pred_p): Use widest_int. * gcc.dg/uninit-pr108547.c: New testcase. --- gcc/gimple-predicate-analysis.cc | 6 +++--- gcc/testsuite/gcc.dg/uninit-pr108547.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/uninit-pr108547.c diff --git a/gcc/gimple-predicate-analysis.cc b/gcc/gimple-predicate-analysis.cc index a7719ff493f..094e8c7aff3 100644 --- a/gcc/gimple-predicate-analysis.cc +++ b/gcc/gimple-predicate-analysis.cc @@ -728,11 +728,11 @@ value_sat_pred_p (tree val, tree boundary, tree_code cmpc, if (cmpc != BIT_AND_EXPR) return is_value_included_in (val, boundary, cmpc); - wide_int andw = wi::to_wide (val) & wi::to_wide (boundary); + widest_int andw = wi::to_widest (val) & wi::to_widest (boundary); if (exact_p) - return andw == wi::to_wide (val); + return andw == wi::to_widest (val); - return andw.to_uhwi (); + return wi::ne_p (andw, 0); } /* Return true if the domain of single predicate expression PRED1 diff --git a/gcc/testsuite/gcc.dg/uninit-pr108547.c b/gcc/testsuite/gcc.dg/uninit-pr108547.c new file mode 100644 index 00000000000..d8f6c9ff87a --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr108547.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wuninitialized" } */ + +int func_7_uc_10li_19 (int); +int li_4, li_5, us_8; +unsigned char func_7_ptr_13, func_7_uc_14; +void func_7_ptr_18() { + if (li_5) { + for (;;) + ; + short s_15; + for (; func_7_uc_14;) { + us_8 = 7; + for (; us_8; us_8 += 1) + lblD2AF1FAB: + if (us_8) + li_4 = 1; + func_7_uc_14 += (__INTPTR_TYPE__)func_7_ptr_18; + if (func_7_ptr_13 & 1 && (func_7_uc_14 &= func_7_ptr_13)) + s_15 %= func_7_uc_10li_19(s_15); /* { dg-warning "uninitialized" } */ + } + } + goto lblD2AF1FAB; +}