[PATCH] Fix PR42577

Richard Guenther rguenther@suse.de
Sat Jan 2 19:12:00 GMT 2010


This fixes array bound warnings from VRP that are issued from code
that is proven to be unreachable by VRP.  The existing code to do
this is both ineffective and too complicated.

I didn't manage to create a small testcase from the testcase
in PR42577 (I also didn't check if this fixes other PRs).

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-01-02  Richard Guenther  <rguenther@suse.de>

	PR middle-end/42577
	* tree-vrp.c (check_all_array_refs): Skip non-excutable blocks.
	(simplify_switch_using_ranges): Mark to be removed edges
	as non-executable.

Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 155568)
--- gcc/tree-vrp.c	(working copy)
*************** check_all_array_refs (void)
*** 5122,5157 ****
  
    FOR_EACH_BB (bb)
      {
!       /* Skip bb's that are clearly unreachable.  */
!       if (single_pred_p (bb))
!       {
! 	int i;
! 	bool reachable = true;
! 	edge e2;
! 	edge e = EDGE_PRED (bb, 0);
! 	basic_block pred_bb = e->src;
! 	gimple ls = NULL;
! 
! 	for (i = 0; VEC_iterate (edge, to_remove_edges, i, e2); ++i)
! 	  if (e == e2)
! 	    {
! 	      reachable = false;
! 	      break;
! 	    }
! 
! 	if (!reachable)
! 	  continue;
! 
! 	if (!gsi_end_p (gsi_last_bb (pred_bb)))
! 	  ls = gsi_stmt (gsi_last_bb (pred_bb));
  
- 	if (ls && gimple_code (ls) == GIMPLE_COND
- 	    && ((gimple_cond_false_p (ls)
- 		 && (EDGE_PRED (bb, 0)->flags & EDGE_TRUE_VALUE))
- 		|| (gimple_cond_true_p (ls)
- 		    && (EDGE_PRED (bb, 0)->flags & EDGE_FALSE_VALUE))))
- 	  continue;
-       }
        for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
  	{
  	  gimple stmt = gsi_stmt (si);
--- 5122,5137 ----
  
    FOR_EACH_BB (bb)
      {
!       edge_iterator ei;
!       edge e;
!       bool executable = false;
! 
!       /* Skip blocks that were found to be unreachable.  */
!       FOR_EACH_EDGE (e, ei, bb->preds)
! 	executable |= !!(e->flags & EDGE_EXECUTABLE);
!       if (!executable)
! 	continue;
  
        for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
  	{
  	  gimple stmt = gsi_stmt (si);
*************** simplify_switch_using_ranges (gimple stm
*** 6926,6931 ****
--- 6906,6912 ----
  	  fprintf (dump_file, "removing unreachable case label\n");
  	}
        VEC_safe_push (edge, heap, to_remove_edges, e);
+       e->flags &= ~EDGE_EXECUTABLE;
      }
  
    /* And queue an update for the stmt.  */
*************** vrp_finalize (void)
*** 7255,7261 ****
    substitute_and_fold (single_val_range, vrp_fold_stmt);
  
    if (warn_array_bounds)
!       check_all_array_refs ();
  
    /* We must identify jump threading opportunities before we release
       the datastructures built by VRP.  */
--- 7236,7242 ----
    substitute_and_fold (single_val_range, vrp_fold_stmt);
  
    if (warn_array_bounds)
!     check_all_array_refs ();
  
    /* We must identify jump threading opportunities before we release
       the datastructures built by VRP.  */



More information about the Gcc-patches mailing list