public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3610] Fix bug in frange::contains_p() for signed zeros.
@ 2022-11-02 13:37 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2022-11-02 13:37 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:58511b3fc035f7fe77c3403f7b99de3a795a7964

commit r13-3610-g58511b3fc035f7fe77c3403f7b99de3a795a7964
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Nov 2 12:39:45 2022 +0100

    Fix bug in frange::contains_p() for signed zeros.
    
    The contains_p() code wasn't returning true for non-singleton ranges
    containing signed zeros.  With this patch we now handle:
    
            -0.0 exists in [-3, +5.0]
            +0.0 exists in [-3, +5.0]
    
    gcc/ChangeLog:
    
            * value-range.cc (frange::contains_p): Fix signed zero handling.
            (range_tests_signed_zeros): New test.

Diff:
---
 gcc/value-range.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/value-range.cc b/gcc/value-range.cc
index 3743ec714b3..a855aaf626c 100644
--- a/gcc/value-range.cc
+++ b/gcc/value-range.cc
@@ -661,7 +661,7 @@ frange::contains_p (tree cst) const
     {
       // Make sure the signs are equal for signed zeros.
       if (HONOR_SIGNED_ZEROS (m_type) && real_iszero (rv))
-	return m_min.sign == m_max.sign && m_min.sign == rv->sign;
+	return rv->sign == m_min.sign || rv->sign == m_max.sign;
       return true;
     }
   return false;
@@ -3859,6 +3859,14 @@ range_tests_signed_zeros ()
   ASSERT_TRUE (r0.contains_p (neg_zero));
   ASSERT_FALSE (r0.contains_p (zero));
 
+  r0 = frange (neg_zero, zero);
+  ASSERT_TRUE (r0.contains_p (neg_zero));
+  ASSERT_TRUE (r0.contains_p (zero));
+
+  r0 = frange_float ("-3", "5");
+  ASSERT_TRUE (r0.contains_p (neg_zero));
+  ASSERT_TRUE (r0.contains_p (zero));
+
   // The intersection of zeros that differ in sign is a NAN (or
   // undefined if not honoring NANs).
   r0 = frange (neg_zero, neg_zero);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-02 13:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 13:37 [gcc r13-3610] Fix bug in frange::contains_p() for signed zeros Aldy Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).