The following fixes PR61482, avoiding to call set_value_range
with [-INF(OVF), +INF(OVF)].

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c      (revision 211698)
+++ gcc/tree-vrp.c      (working copy)
@@ -3892,15 +3892,6 @@ adjust_range_with_scev (value_range_t *v
        max = init;
       else
        min = init;
-
-      /* If we would create an invalid range, then just assume we
-        know absolutely nothing.  This may be over-conservative,
-        but it's clearly safe, and should happen only in unreachable
-         parts of code, or for invalid programs.  */
-      if (compare_values (min, max) == 1)
-       return;
-
-      set_value_range (vr, VR_RANGE, min, max, vr->equiv);
     }
   else if (vr->type == VR_RANGE)
     {
@@ -3933,16 +3924,20 @@ adjust_range_with_scev (value_range_t *v
              || compare_values (tmax, max) == -1)
            max = tmax;
        }
+    }
+  else
+    return;
 
-      /* If we just created an invalid range with the minimum
-        greater than the maximum, we fail conservatively.
-        This should happen only in unreachable
-        parts of code, or for invalid programs.  */
-      if (compare_values (min, max) == 1)
-       return;
+  /* If we just created an invalid range with the minimum
+     greater than the maximum, we fail conservatively.
+     This should happen only in unreachable
+     parts of code, or for invalid programs.  */
+  if (compare_values (min, max) == 1
+      || (is_negative_overflow_infinity (min)
+         && is_positive_overflow_infinity (max)))
+    return;
 
-      set_value_range (vr, VR_RANGE, min, max, vr->equiv);
-    }
+  set_value_range (vr, VR_RANGE, min, max, vr->equiv);
 }
 
 
Index: gcc/testsuite/g++.dg/torture/pr61482.C
===================================================================
--- gcc/testsuite/g++.dg/torture/pr61482.C      (revision 0)
+++ gcc/testsuite/g++.dg/torture/pr61482.C      (working copy)
@@ -0,0 +1,29 @@
+// { dg-do compile }
+
+class A
+{
+public:
+    int m_fn1 ();
+};
+class B
+{
+  void m_fn2 (const int &p1);
+  A mThebesLayerDataStack;
+};
+int b, c;
+void B::m_fn2 (const int &p1)
+{
+  if (c && b)
+    {
+      int i;
+      i = mThebesLayerDataStack.m_fn1 ();
+      for (; i >= 0;)
+       {
+         ++i;
+         break;
+       }
+      --i;
+      for (; i >= 0; --i)
+       mThebesLayerDataStack.m_fn1 ();
+    }
+}

Reply via email to