From patchwork Mon Feb 27 13:58:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 61963 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2431783wrd; Mon, 27 Feb 2023 05:58:58 -0800 (PST) X-Google-Smtp-Source: AK7set8niMa4v87hxwfyEHgKN1C2hvf+iUZUnw4hN6v1fjzcJyzEMIZR/pCg8gs+lgjsP8Sgz6zf X-Received: by 2002:a17:907:76ea:b0:88c:6345:d0e7 with SMTP id kg10-20020a17090776ea00b0088c6345d0e7mr31941584ejc.36.1677506338760; Mon, 27 Feb 2023 05:58:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677506338; cv=none; d=google.com; s=arc-20160816; b=tncdTSfndCJyW6oL7cthVwNNoZjz6LpmV9y1oyKXnWY0BnVYhyjnIDmHVI19G16QF/ F6Hd6AOsxxMX5QgPQEZCl73IrDLsXVc6ogNo7AAh0bJQEvbh6FewSRGu1cjyWsQCx7dB B/2m4w0vRZuTlWbr90nYzMSfXQqRhVbJWcxkDj28kmt84swUlkAwSwwBMYxeKwh43O65 tD1R5tlqr7I9+//Ve72uPFMa9PbBICOTOWeSuEow1UmNowAm7iXT1XVhdx1FQUb+uMzD qjaDbEKUZnB+f13smvL0ZsP9EsFU1SPk3q8/e3h6LBgrYj2zmjtk1b1ARGYJ6+iW3aW+ d0FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=TBmLK7XzfUDYfl/uxUKwTC9KvpZPOvASwUI41qcnz34=; b=VAa4ZpFuw27768wIIvO4nfpO33YqbA2M54J9MACuQJeiJHcz1YyUKU3Trr20c9i75T Hs1s6BYNZJLxNemj7CgqkF5vRlgXSuLqbDNNMiKT8ZMTk1nyDR7kjYEGv9gHgbqW5++y 64F6Jru1tyInHO2DQF3SUVhUF5XAxDFMaCFQNB3WRczJTafL9Q071QXQDIK/sg0BrMvh PNv//vSUJpPrfjsYeDmYgN0roHNLPanpdQNQ62E/Efz+ZW+rRVsmxXvt3uF19DgmjwhO ixKQQXE+Gw9xfGJe6rF1g+283Tp+0CyRFekHr6V0n/f5Qvy+0f/9knnc/cg9YkMQlrCp A24w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XWBc3lFV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gt33-20020a1709072da100b008e6a0cfc574si10553266ejc.795.2023.02.27.05.58.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 05:58:58 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XWBc3lFV; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 90EDF385842C for ; Mon, 27 Feb 2023 13:58:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 90EDF385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677506337; bh=TBmLK7XzfUDYfl/uxUKwTC9KvpZPOvASwUI41qcnz34=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XWBc3lFVxXUtfyMKfoLWtCQhAdNwXqa4psN8Ikl4MfNWI7AhfOKj75lVhGKj1ghmO HoFue8wbtehP3Vw6c2YZQOCyPqwofWU2PCO4/9u5+gyN3Ifg0pXuvngNZ3FIDy4SuK Jg+pCeSuAGPBQWntoWyJ1CWDGJjISnZweoWzOSZs= 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 [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id D4E903858D32 for ; Mon, 27 Feb 2023 13:58:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D4E903858D32 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0766F1FD63; Mon, 27 Feb 2023 13:58:11 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C9AD22C141; Mon, 27 Feb 2023 13:58:10 +0000 (UTC) Date: Mon, 27 Feb 2023 13:58:10 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: aldyh@redhat.com Subject: [PATCH] Fixup possible VR_ANTI_RANGE value_range issues User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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" Message-Id: <20230227135857.90EDF385842C@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758992886627157239?= X-GMAIL-MSGID: =?utf-8?q?1758992886627157239?= After fixing PR107561 the following avoids looking at VR_ANTI_RANGE ranges where it doesn't seem obvious the code does the correct thing here (lower_bound and upper_bound do not work as expected). Bootstrapped and tested on x86_64-unknown-linux-gnu. OK? Thanks, Richard. * gimple-ssa-sprintf.cc (get_int_range): Avoid VR_ANTI_RANGE by using range_int_cst_p. (format_integer): Likewise. (handle_printf_call): Guard against VR_ANTI_RANGE. * graphite-sese-to-poly.cc (add_param_constraints): Likewise. * tree-ssa-strlen.cc (set_strlen_range): Likewise. --- gcc/gimple-ssa-sprintf.cc | 6 +++--- gcc/graphite-sese-to-poly.cc | 2 +- gcc/tree-ssa-strlen.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc index 18975708d2c..61974072f62 100644 --- a/gcc/gimple-ssa-sprintf.cc +++ b/gcc/gimple-ssa-sprintf.cc @@ -1082,7 +1082,7 @@ get_int_range (tree arg, gimple *stmt, value_range vr; query->range_of_expr (vr, arg, stmt); - if (!vr.undefined_p () && !vr.varying_p ()) + if (range_int_cst_p (&vr)) { HOST_WIDE_INT type_min = (TYPE_UNSIGNED (argtype) @@ -1391,7 +1391,7 @@ format_integer (const directive &dir, tree arg, pointer_query &ptr_qry) value_range vr; ptr_qry.rvals->range_of_expr (vr, arg, dir.info->callstmt); - if (!vr.varying_p () && !vr.undefined_p ()) + if (range_int_cst_p (&vr)) { argmin = wide_int_to_tree (TREE_TYPE (arg), vr.lower_bound ()); argmax = wide_int_to_tree (TREE_TYPE (arg), vr.upper_bound ()); @@ -4623,7 +4623,7 @@ handle_printf_call (gimple_stmt_iterator *gsi, pointer_query &ptr_qry) value_range vr; ptr_qry.rvals->range_of_expr (vr, size, info.callstmt); - if (!vr.undefined_p ()) + if (!vr.undefined_p () && vr.kind () != VR_ANTI_RANGE) { tree type = TREE_TYPE (size); tree tmin = wide_int_to_tree (type, vr.lower_bound ()); diff --git a/gcc/graphite-sese-to-poly.cc b/gcc/graphite-sese-to-poly.cc index fbe7667380a..b89262640ac 100644 --- a/gcc/graphite-sese-to-poly.cc +++ b/gcc/graphite-sese-to-poly.cc @@ -426,7 +426,7 @@ add_param_constraints (scop_p scop, graphite_dim_t p, tree parameter) if (INTEGRAL_TYPE_P (type) && get_range_query (cfun)->range_of_expr (r, parameter) - && !r.undefined_p ()) + && range_int_cst_p (&r)) { min = r.lower_bound (); max = r.upper_bound (); diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index 7508c1768a5..e1230522564 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -1936,7 +1936,7 @@ set_strlen_range (tree lhs, wide_int min, wide_int max, { value_range r; get_range_query (cfun)->range_of_expr (r, bound); - if (!r.undefined_p ()) + if (range_int_cst_p (&r)) { /* For a bound in a known range, adjust the range determined above as necessary. For a bound in some anti-range or