[PATCH][mem-ref2] Fix some warning regressions

Richard Guenther rguenther@suse.de
Wed Jun 16 22:18:00 GMT 2010


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

Richard.

2010-06-16  Richard Guenther  <rguenther@suse.de>

	* tree-ssa.c (warn_uninitialized_var): Handle MEM_REF.

Index: gcc/tree-ssa.c
===================================================================
--- gcc/tree-ssa.c	(revision 160824)
+++ gcc/tree-ssa.c	(working copy)
@@ -1650,8 +1650,9 @@ warn_uninitialized_var (tree *tp, int *w
   /* We do not care about LHS.  */
   if (wi->is_lhs)
     {
-      /* Except for operands of INDIRECT_REF.  */
-      if (!INDIRECT_REF_P (t))
+      /* Except for operands of dereferences.  */
+      if (!INDIRECT_REF_P (t)
+	  && TREE_CODE (t) != MEM_REF)
 	return NULL_TREE;
       t = TREE_OPERAND (t, 0);
     }

2010-06-16  Richard Guenther  <rguenther@suse.de>

	* tree-vrp.c (check_array_ref): Handle MEM_REF.
	(search_for_addr_array): Likewise.
	(check_array_bounds): Likewise.

Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 160824)
--- gcc/tree-vrp.c	(working copy)
*************** check_array_ref (location_t location, tr
*** 5071,5079 ****
    /* Accesses to trailing arrays via pointers may access storage
       beyond the types array bounds.  */
    base = get_base_address (ref);
!   if (base
!       && (INDIRECT_REF_P (base)
! 	  || TREE_CODE (base) == MEM_REF))
      {
        tree cref, next = NULL_TREE;
  
--- 5071,5077 ----
    /* Accesses to trailing arrays via pointers may access storage
       beyond the types array bounds.  */
    base = get_base_address (ref);
!   if (base && TREE_CODE (base) == MEM_REF)
      {
        tree cref, next = NULL_TREE;
  
*************** search_for_addr_array (tree t, location_
*** 5172,5177 ****
--- 5170,5220 ----
        t = TREE_OPERAND (t, 0);
      }
    while (handled_component_p (t));
+ 
+   if (TREE_CODE (t) == MEM_REF
+       && TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR
+       && !TREE_NO_WARNING (t))
+     {
+       tree tem = TREE_OPERAND (TREE_OPERAND (t, 0), 0);
+       tree low_bound, up_bound, el_sz;
+       double_int idx;
+       if (TREE_CODE (TREE_TYPE (tem)) != ARRAY_TYPE
+ 	  || TREE_CODE (TREE_TYPE (TREE_TYPE (tem))) == ARRAY_TYPE
+ 	  || !TYPE_DOMAIN (TREE_TYPE (tem)))
+ 	return;
+ 
+       low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (tem)));
+       up_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (tem)));
+       el_sz = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (tem)));
+       if (!low_bound
+ 	  || TREE_CODE (low_bound) != INTEGER_CST
+ 	  || !up_bound
+ 	  || TREE_CODE (up_bound) != INTEGER_CST
+ 	  || !el_sz
+ 	  || TREE_CODE (el_sz) != INTEGER_CST)
+ 	return;
+ 
+       idx = mem_ref_offset (t);
+       idx = double_int_sdiv (idx, tree_to_double_int (el_sz), TRUNC_DIV_EXPR);
+       if (double_int_scmp (idx, double_int_zero) < 0)
+ 	{
+ 	  warning_at (location, OPT_Warray_bounds,
+ 		      "array subscript is below array bounds");
+ 	  TREE_NO_WARNING (t) = 1;
+ 	}
+       else if (double_int_scmp (idx,
+ 				double_int_add
+ 				  (double_int_add
+ 				    (tree_to_double_int (up_bound),
+ 				     double_int_neg
+ 				       (tree_to_double_int (low_bound))),
+ 				    double_int_one)) > 0)
+ 	{
+ 	  warning_at (location, OPT_Warray_bounds,
+ 		      "array subscript is above array bounds");
+ 	  TREE_NO_WARNING (t) = 1;
+ 	}
+     }
  }
  
  /* walk_tree() callback that checks if *TP is
*************** check_array_bounds (tree *tp, int *walk_
*** 5200,5206 ****
    if (TREE_CODE (t) == ARRAY_REF)
      check_array_ref (location, t, false /*ignore_off_by_one*/);
  
!   if (TREE_CODE (t) == INDIRECT_REF
        || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0)))
      search_for_addr_array (TREE_OPERAND (t, 0), location);
  
--- 5243,5249 ----
    if (TREE_CODE (t) == ARRAY_REF)
      check_array_ref (location, t, false /*ignore_off_by_one*/);
  
!   if (TREE_CODE (t) == MEM_REF
        || (TREE_CODE (t) == RETURN_EXPR && TREE_OPERAND (t, 0)))
      search_for_addr_array (TREE_OPERAND (t, 0), location);
  



More information about the Gcc-patches mailing list