diff mbox series

[committed] do not create non-canonical ranges in value_range_base::invert

Message ID cde8d21e-041f-5590-53bf-220ffbe14e99@redhat.com
State New
Headers show
Series [committed] do not create non-canonical ranges in value_range_base::invert | expand

Commit Message

Aldy Hernandez Nov. 4, 2019, 9:40 p.m. UTC
value_range_base::invert is twiddling the range kind in place.  You 
can't do that, because you may create non-canonical ranges.  Fixed by 
using the canonicalizing constructor.

Committed as obvious.
diff mbox series

Patch

commit 7a1b10ff2446e3e7800a19e8970bfe57f894cda9
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Nov 4 21:15:47 2019 +0100

    Use the value_range_base constructors in value_range_base::invert to
    make sure we build canonically correct ranges.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c585360b537..6bdd5ffddbd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@ 
+2019-11-04  Aldy Hernandez  <aldyh@redhat.com>
+
+	* tree-vrp.c (value_range_base::invert): Use constructors to build
+	range.
+
 2019-11-04  Aldy Hernandez  <aldyh@redhat.com>
 
 	* tree-vrp.c (range_int_cst_singleton_p): Remove.
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index 070db903147..085308e519f 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -6286,10 +6286,12 @@  value_range_base::contains_p (tree cst) const
 void
 value_range_base::invert ()
 {
+  /* We can't just invert VR_RANGE and VR_ANTI_RANGE because we may
+     create non-canonical ranges.  Use the constructors instead.  */
   if (m_kind == VR_RANGE)
-    m_kind = VR_ANTI_RANGE;
+    *this = value_range_base (VR_ANTI_RANGE, m_min, m_max);
   else if (m_kind == VR_ANTI_RANGE)
-    m_kind = VR_RANGE;
+    *this = value_range_base (VR_RANGE, m_min, m_max);
   else
     gcc_unreachable ();
 }