]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't calculate new values when using the private context callback.
authorAndrew MacLeod <amacleod@redhat.com>
Mon, 8 Nov 2021 14:32:42 +0000 (09:32 -0500)
committerAndrew MacLeod <amacleod@redhat.com>
Mon, 8 Nov 2021 17:48:57 +0000 (12:48 -0500)
When using rangers private callback mechanism to provide context
to fold_stmt calls, we are only suppose to be using the cache in read
only mode, never calculate new values.

gcc/
PR tree-optimization/103122
* gimple-range.cc (gimple_ranger::range_of_expr): Request the cache
entry with "calulate new values" set to false.

gcc/testsuite/
* g++.dg/pr103122.C: New.

gcc/gimple-range.cc
gcc/testsuite/g++.dg/pr103122.C [new file with mode: 0644]

index e1177b1c5e8f448bbeae2c5167719bcb995efcc0..87dba6e81d89c7f15745d83de485e6413367b6b9 100644 (file)
@@ -88,8 +88,8 @@ gimple_ranger::range_of_expr (irange &r, tree expr, gimple *stmt)
       if (!m_cache.get_global_range (r, expr))
         r = gimple_range_global (expr);
       // Pick up implied context information from the on-entry cache
-      // if current_bb is set.
-      if (current_bb && m_cache.block_range (tmp, current_bb, expr))
+      // if current_bb is set.  Do not attempt any new calculations.
+      if (current_bb && m_cache.block_range (tmp, current_bb, expr, false))
        {
          r.intersect (tmp);
          char str[80];
diff --git a/gcc/testsuite/g++.dg/pr103122.C b/gcc/testsuite/g++.dg/pr103122.C
new file mode 100644 (file)
index 0000000..3465ead
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+unsigned a;
+int b;
+short c;
+void d(long) {
+  for (bool e = (bool)c - 1; e < (bool)b - 1; e += 0)
+    ;
+  if (a) {
+    for (char f = 0; f < 7; f = 7)
+      for (int g = 0; g < c; g += 10)
+        ;
+    d(-!c);
+  }
+}