From patchwork Sat Nov 12 23:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Reutner-Fischer X-Patchwork-Id: 19269 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1471417wru; Sat, 12 Nov 2022 15:47:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6y3Aq6YqK5RB4ZHdo1XWRSQsHD1bV6W6O+fS/pH3vJjAeA4whidPwcEz2pHDyVeffApa7v X-Received: by 2002:aa7:c54a:0:b0:459:9e3:c0b0 with SMTP id s10-20020aa7c54a000000b0045909e3c0b0mr6422839edr.279.1668296870734; Sat, 12 Nov 2022 15:47:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296870; cv=none; d=google.com; s=arc-20160816; b=DErxw5NR5PQNK3bjPnwmHPhT6wDRwG/HKsBkyodAsi5mcRJzWyIs1Ut7P7buZ+ZWil orNeQoI1xKSRcOmSUKbI/mfJklfObWuKrpwyHH1+6p0arqqa3saIxYgCsS2ScQg6ttpR ZDlITEQhquUk8QQ569CJh9dHI1moINPWRSl2T4c68Dn7TTGfuS3veu+YN45vs6zvq9aF S9IUL6IEVEhDknHFB2WF2o41Rddfp1R0bkKVWhoXQH+jl3Mh5G8N7uHHeHNzA2FnjPdg w3gvuGy8/7tsfEW9F60FTfxe4pepcBhbTHB40VkHKqPtFaHatZUg/5TpCk7txMfEUbdc Jtdw== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=wqSBdXjnlhYeXIswHDcAMivSKxJSKASfKa11+vQbA2A=; b=UOzZctCaek6lh0hnutrC5a5nfF+bii65yDGrIgjieFIzJ/H5LhtsZDnPQYbJDLszZe cNq4LMs9ffwcmz3l8rPVW/r2IrkLAKSF7COaMj4z0LfeqA9ft1LK2TszPatICt/QgW6t kmBTDHwiearEGY+f9OWcQfPABNPlmsD+SKcqL8fNkG5jomnQTfuGI3vZ0Ljxv47Okbb4 6dbrVtgugqfuyailEdVmhJJVa3GnQgOYOzSDQ4P7YzRohxc04L7sx2EDP3Of8Q9rgiTX 6O42M8iqM9lSyhLJVOgqQOOeyDPgeSmgeQ+0M1HcKiCjyXmgPoxT6yjYCn18Qr5q+jnt hImg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BI1W+gM8; 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 hb38-20020a170907162600b007a92b00c075si3975908ejc.891.2022.11.12.15.47.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 15:47:50 -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=BI1W+gM8; 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 44A9F389EC54 for ; Sat, 12 Nov 2022 23:46:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 44A9F389EC54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668296818; bh=wqSBdXjnlhYeXIswHDcAMivSKxJSKASfKa11+vQbA2A=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=BI1W+gM8C2vwbbkipq4YLjjRc73/dP0VVo5NvolV4+sG8sarFXNWZ9cZlftmjaVMf qR9R0uyNkOBd/pC3x5U+8kR8/bzIcfEBlt1c035JU4h06L8i6W/R6HwiEJ/oSEKzpG D9AmkZRo3HX9wEwfb19HoGqHyaTInJ/JaFAX32F8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 59D393885C1F; Sat, 12 Nov 2022 23:45:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59D393885C1F Received: by mail-wm1-x32b.google.com with SMTP id v7so5016999wmn.0; Sat, 12 Nov 2022 15:45:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wqSBdXjnlhYeXIswHDcAMivSKxJSKASfKa11+vQbA2A=; b=FkzOQYRBZI4u1lNQuumdAZavebL5/FUHl2Pe6GDFbCALp+nGbp711rJezHXwfFwgxo oT1h6sazkL5yIR3KQMQDwGwtevdElUs2thtOJuwvTP5JGh71LzCpd92mFfmZlDSX/3k3 W6yWUGFj4eejFowzKQg/HPkSSZeU3A1yDjT4WSKYHOhhkTyPj8xtrfUO7mu8P9PhhEiK ymercg6ufB8ikTQDxTf5nwFY2so6eQqA3S/J4Rr8QscNnmrtH8Dxp0/20P/xE361cP58 JI2PafdQQPkr1t7/wdyncXGUxc5bU+rAH+pirnoliiAhGg/6ocEFcTqJBS/DDvHUKRVZ QbpA== X-Gm-Message-State: ANoB5pmQAsDZfeiXRISVAy2LHEOi/Qe9vMTIeg2E7SHkUGpZqu/UgukB yWQVaZ9TMGBl0mGsC7XZe3I9SCSALfQ= X-Received: by 2002:a05:600c:d2:b0:3cf:68bb:f5b8 with SMTP id u18-20020a05600c00d200b003cf68bbf5b8mr4702153wmm.67.1668296748155; Sat, 12 Nov 2022 15:45:48 -0800 (PST) Received: from nbbrfq ([2001:871:227:81c4:d7ff:3a0e:48da:5fe3]) by smtp.gmail.com with ESMTPSA id s21-20020a1cf215000000b003a6a3595edasm7772332wmc.27.2022.11.12.15.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Nov 2022 15:45:45 -0800 (PST) X-Google-Original-From: Bernhard Reutner-Fischer Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1ou0C1-000Oq0-0D; Sun, 13 Nov 2022 00:45:45 +0100 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer , fortran@gcc.gnu.org, Andrew MacLeod , Aldy Hernandez Subject: [PATCH 4/5] value-range: Add as_string diagnostics helper Date: Sun, 13 Nov 2022 00:45:42 +0100 Message-Id: <20221112234543.95441-5-aldot@gcc.gnu.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221112234543.95441-1-aldot@gcc.gnu.org> References: <20221112234543.95441-1-aldot@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: Bernhard Reutner-Fischer via Gcc-patches From: Bernhard Reutner-Fischer Reply-To: Bernhard Reutner-Fischer 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?1749336059584793732?= X-GMAIL-MSGID: =?utf-8?q?1749336059584793732?= gcc/ChangeLog: * value-range.cc (get_bound_with_infinite_markers): New static helper. (irange::as_string): New definition. * value-range.h: New declaration. --- Provide means to print a value range to a newly allocated buffer. The caller is responsible to free() the allocated memory. Bootstrapped and regtested on x86_86-unknown-linux with no regressions. Ok for trunk? Cc: Andrew MacLeod Cc: Aldy Hernandez --- gcc/value-range.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/value-range.h | 3 +++ 2 files changed, 59 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a855aaf626c..51cd9a38d90 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -3099,6 +3099,62 @@ debug (const value_range &vr) fprintf (stderr, "\n"); } +/* Helper for irange::as_string(). Print a bound to an allocated buffer. */ +static char * +get_bound_with_infinite_markers (tree bound) +{ + tree type = TREE_TYPE (bound); + wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + + if (INTEGRAL_TYPE_P (type) + && !TYPE_UNSIGNED (type) + && TREE_CODE (bound) == INTEGER_CST + && wi::to_wide (bound) == type_min + && TYPE_PRECISION (type) != 1) + return xstrdup ("-INF"); + else if (TREE_CODE (bound) == INTEGER_CST + && wi::to_wide (bound) == type_max + && TYPE_PRECISION (type) != 1) + return xstrdup ("+INF"); + else + return print_generic_expr_to_str (bound); +} + + +/* Return an irange as string. Return NULL on failure, an allocated + string on success. */ +char * +irange::as_string () +{ + char *ret = NULL; + if (undefined_p() || varying_p () || m_num_ranges == 0) + return ret; + + for (unsigned i = 0; i < m_num_ranges; ++i) + { + tree lb = m_base[i * 2]; + tree ub = m_base[i * 2 + 1]; + /* Construct [lower_bound,upper_bound]. */ + char *lbs = get_bound_with_infinite_markers (lb); + char *ubs = get_bound_with_infinite_markers (ub); + /* Paranoia mode */ + if (!lbs) + lbs = xstrdup (""); + if (!ubs) + ubs = xstrdup (""); + + if (ret) + ret = reconcat (ret, ret, "[", lbs, ",", ubs, "]", NULL); + else + ret = concat ("[", lbs, ",", ubs, "]", NULL); + + free (lbs); + free (ubs); + } + return ret; +} + /* Create two value-ranges in *VR0 and *VR1 from the anti-range *AR so that *VR0 U *VR1 == *AR. Returns true if that is possible, false otherwise. If *AR can be represented with a single range diff --git a/gcc/value-range.h b/gcc/value-range.h index c87734dd8cd..76242e4bf45 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -160,6 +160,9 @@ public: wide_int get_nonzero_bits () const; void set_nonzero_bits (const wide_int_ref &bits); + // For diagnostics. + char *as_string (); + // Deprecated legacy public methods. tree min () const; // DEPRECATED tree max () const; // DEPRECATED