This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH middle-end/30511] Fix fortran bootstrap problem


Hi, 

finally I found out why my previous testing did not catch the bootstrap 
problems and fixed that. 

The patch below adds a workaround for the C frontend converting 

   &a->b[i-'a']

into

   &a->b[0] + (i*sizeof(void*)-'a'*sizeof(void*))

which is later optimized into

   &a->b[i] - 'a'*sizeof(void*)

and thereby triggering the warning. The fix is to suppress the warning when 
the address of the array ref is immediatly and only used in a binary 
expression. I will look if fixing the C frontend for this case is possible.

Patch below is bootstrapped on i686 and x86_64-suse-linux, regtest is in 
prograss. Ok if it passes?


2007-01-20  Dirk Mueller  <dmueller@suse.de>

        PR middle-end/30511
        * tree-vrp.c (check_array_bounds): do not warn
        about ADDR_EXPR's of ARRAY_REF's which are immediately
        used in binary expressions.

--- tree-vrp.c	(revision 120953)
+++ tree-vrp.c	(working copy)
@@ -3564,7 +3564,8 @@ static tree
 check_array_bounds (tree *tp, int *walk_subtree, void *data)
 {
   tree t = *tp;
-  location_t *location = EXPR_LOCUS ((tree) data);
+  tree stmt = (tree)data;
+  location_t *location = EXPR_LOCUS (stmt);
 
   *walk_subtree = TRUE;
 
@@ -3572,18 +3573,34 @@ check_array_bounds (tree *tp, int *walk_
     check_array_ref (t, location, false /*ignore_off_by_one*/);
   else if (TREE_CODE (t) == ADDR_EXPR)
     {
+       use_operand_p op;
+       tree use_stmt;
        t = TREE_OPERAND (t, 0);
 
        /* Don't warn on statements like
-          ssa_name = 500 + &array[-200] which are sometimes
-          produced by various optimizing passes.  */
-       if (TREE_CODE ((tree)data) == GIMPLE_MODIFY_STMT
-           && BINARY_CLASS_P (GIMPLE_STMT_OPERAND ((tree)data, 1)))
-         {
-           *walk_subtree = FALSE;
-           return NULL_TREE;
-         }
-       while (handled_component_p (t))
+
+          ssa_name = 500 + &array[-200]
+
+          or
+
+          ssa_name = &array[-200]
+          other_name = ssa_name + 300;
+
+          which are sometimes
+          produced by other optimizing passes.  */
+
+       if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT
+           && BINARY_CLASS_P (GIMPLE_STMT_OPERAND (stmt, 1)))
+         *walk_subtree = FALSE;
+
+       if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT
+           && TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 0)) == SSA_NAME
+           && single_imm_use (GIMPLE_STMT_OPERAND (stmt, 0), &op, &use_stmt)
+           && TREE_CODE (use_stmt) == GIMPLE_MODIFY_STMT
+           && BINARY_CLASS_P (GIMPLE_STMT_OPERAND (use_stmt, 1)))
+         *walk_subtree = FALSE;
+
+       while (*walk_subtree && handled_component_p (t))
          {
            if (TREE_CODE (t) == ARRAY_REF)
              check_array_ref (t, location, true /*ignore_off_by_one*/);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]