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: 60499 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E91BB3896C3B for ; Sat, 12 Nov 2022 23:46:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E91BB3896C3B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668296803; 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=Jxu2ochaxkVTp08tIKcp/0BjiIBVcHre+mXuUaS+yEGH1VBhmY3KbeycR1Wd3shB7 1MZ0CYh42/O6fanZNkJy7aT+yrZqGsdan1aqN38RIcS/Unz0q58U7U4sp04JNi6NTW ekTGgRjGj8HSfauvo653ygeIiwj5e4pgOUgWQlQc= 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-Google-Smtp-Source: AA0mqf79MUzGr1mYA1oG/OaCNwMZLVEpjdbonBHS6A/j8pFq6NFn21WNwBNfBfSVtqVhjqrPHuuYdg== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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