Skip statements with no BB in ranger.
authorAldy Hernandez <aldyh@redhat.com>
Fri, 3 Sep 2021 08:42:37 +0000 (10:42 +0200)
committerAldy Hernandez <aldyh@redhat.com>
Fri, 3 Sep 2021 13:30:56 +0000 (15:30 +0200)
The function postfold_gcond_edges() registers relations coming out of a
GIMPLE_COND.  With upcoming changes, we may be called with statements
not in the IL (for example, dummy statements created by the
forward threader).  This patch avoids breakage by exiting if the
statement does not have a defining basic block.  There is a similar
change to the path solver.

Tested on x86-64 Linux.

gcc/ChangeLog:

* gimple-range-fold.cc (fold_using_range::postfold_gcond_edges):
Skip statements with no defining BB.
* gimple-range-path.cc (path_range_query::range_defined_in_block):
Do not get confused by statements with no defining BB.

gcc/gimple-range-fold.cc
gcc/gimple-range-path.cc

index 8be6d47..7cf8830 100644 (file)
@@ -1360,6 +1360,10 @@ fold_using_range::postfold_gcond_edges (gcond *s, irange& lhs_range,
   range_operator *handler;
   basic_block bb = gimple_bb (s);
 
+  // We may get asked to fold an artificial statement not in the CFG.
+  if (!bb)
+    return;
+
   edge e0 = EDGE_SUCC (bb, 0);
   if (!single_pred_p (e0->dest))
     e0 = NULL;
index a8226a6..77b823e 100644 (file)
@@ -221,14 +221,19 @@ path_range_query::range_defined_in_block (irange &r, tree name, basic_block bb)
   else if (!fold_range (r, def_stmt, this))
     r.set_varying (TREE_TYPE (name));
 
-  if (DEBUG_SOLVER)
+  if (DEBUG_SOLVER && (bb || !r.varying_p ()))
     {
-      fprintf (dump_file, "range_defined_in_block (BB%d) for ", bb->index);
+      fprintf (dump_file, "range_defined_in_block (BB%d) for ", bb ? bb->index : -1);
       print_generic_expr (dump_file, name, TDF_SLIM);
       fprintf (dump_file, " is ");
       r.dump (dump_file);
       fprintf (dump_file, "\n");
     }
+
+  // We may have an artificial statement not in the IL.
+  if (!bb && r.varying_p ())
+    return false;
+
   return true;
 }