From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id ED4053889E06; Sat, 12 Nov 2022 23:56:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED4053889E06 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1030.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso7600737pjc.5; Sat, 12 Nov 2022 15:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=om12tJFsDSXHdFpokNCFit/Pu5laskogKxg1fmyfG5k=; b=N1toWpY40jeIqLm4qyOclfe8K3bi2edHsDC+rU9ZVUM6OUiTHN/n8FhtWqXx1RfAAy 2x/TA6YmSs7ait2QjYSw34utcvDgUvfM66cYnRgjJEyOgB6va99dZ5nNh+OHtpgK7/xf 4NcTuSvIq0GMSOc5kYtWGvMXZ0hPOr3/blmiBbTArlc+LsJIPxiZCo/M9gjqJ1ue3XfM eeZEG8HWLqlsgOD42vOGUV1OXqIkOG2eawa1xzoQmUeUzxMKPJDWEwsMUzW5XyR8RArn VVdSbJA5epnJYYj7hXDYsTalm6f5NpaXjCcJGqfWVKug4p8L8yQ3XPLbC/HTi4IuRx+H VZ9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=om12tJFsDSXHdFpokNCFit/Pu5laskogKxg1fmyfG5k=; b=3G8Fh1bJpyaW8hdLTZ8VokOSMWtpOWHOh3wT722WcowlTm3er6G73RG/1gMb5GhMtl Qu9nGpSgdz0yDW5NQ1+HuPccRUP1T8ofMOAn8Dk0Sy86PdozSckgQiNfQ+qXZVgdVXl6 uc/aQJlje64y5zqWW7pDiDlmzTrmxoQyoh6dE+lgn+/Cdn0XWJXonMn2vl57pl/tn3xf 2/o7GICWctptJuDP+uHs050tdIdTZmB8+7dn3gM/axho+Jm2KYUPvZw+4E1hJ8KW0LgQ 05JpSK7Ee4Db1wgTCGFAec9zD44lGGjuVNbcmlvfQcgjQcfEearIjOn6hFVjlD4Xbfn4 uDqA== X-Gm-Message-State: ANoB5pn/KUuhoNa/BA4ZItcEJCV8zVHL7oPzyMwq7Gu0tcfQfmDK90WK Urn9ard1UNrXkDoW1lNhtb53j1+cJLyfeC9qmRs= X-Google-Smtp-Source: AA0mqf7iwCMrL61I1f7GMSSxnc667fRpkk03E4N2btw9jGZwOfinn+zvoNOJgIlPZ6wCpwaTixMS3aUDCbE+TovKiJs= X-Received: by 2002:a17:902:b103:b0:187:3c62:5837 with SMTP id q3-20020a170902b10300b001873c625837mr8068463plr.123.1668297371801; Sat, 12 Nov 2022 15:56:11 -0800 (PST) MIME-Version: 1.0 References: <20221112234543.95441-1-aldot@gcc.gnu.org> <20221112234543.95441-5-aldot@gcc.gnu.org> In-Reply-To: <20221112234543.95441-5-aldot@gcc.gnu.org> From: Andrew Pinski Date: Sat, 12 Nov 2022 15:55:59 -0800 Message-ID: Subject: Re: [PATCH 4/5] value-range: Add as_string diagnostics helper To: Bernhard Reutner-Fischer Cc: gcc-patches@gcc.gnu.org, Bernhard Reutner-Fischer , fortran@gcc.gnu.org, Andrew MacLeod , Aldy Hernandez Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.5 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 List-Id: On Sat, Nov 12, 2022 at 3:47 PM Bernhard Reutner-Fischer via Gcc-patches wrote: > > 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 * Can we start using std::string instead of char* here? > +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); No reason to do xstrdup any more either. > +} > + > + > +/* Return an irange as string. Return NULL on failure, an allocated > + string on success. */ > +char * Likewise. Thanks, Andrew Pinski > +irange::as_string () > +{ > + char *ret = NULL; This becomes std::string ret; > + 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 > -- > 2.38.1 >