]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/37861 (Bogus array bounds warning)
authorMartin Jambor <mjambor@suse.cz>
Sat, 28 Feb 2009 18:33:27 +0000 (19:33 +0100)
committerMartin Jambor <jamborm@gcc.gnu.org>
Sat, 28 Feb 2009 18:33:27 +0000 (19:33 +0100)
2009-02-28  Martin Jambor  <mjambor@suse.cz>

Backport from mainline:
2008-12-02  Martin Jambor  <mjambor@suse.cz>

PR middle-end/37861
* tree-ssa-forwprop.c
(forward_propagate_addr_into_variable_array_index): Check that the
offset is not computed from a MULT_EXPR if element size is one.

From-SVN: r144491

gcc/ChangeLog
gcc/tree-ssa-forwprop.c

index 9fb63146febe42a257ad6ed10a030b7bc4b67667..04bfd8f95d3a561c71ed56f462bdb5cd28cd2940 100644 (file)
@@ -1,3 +1,13 @@
+2009-02-28  Martin Jambor  <mjambor@suse.cz>
+
+       Backport from mainline:
+       2008-12-02  Martin Jambor  <mjambor@suse.cz>
+       
+       PR middle-end/37861
+       * tree-ssa-forwprop.c 
+       (forward_propagate_addr_into_variable_array_index): Check that the
+       offset is not computed from a MULT_EXPR if element size is one.
+
 2009-02-28  Uros Bizjak  <ubizjak@gmail.com>
 
        Backport from mainline:
index c0e0cf800d3e4828610376f7ca5958f51fe29ff1..56536748ec556ea717efab25d08ee6db6a8beede 100644 (file)
@@ -487,28 +487,36 @@ static bool
 forward_propagate_addr_into_variable_array_index (tree offset,
                                                  tree def_rhs, tree use_stmt)
 {
-  tree index;
+  tree index, offset_def;
 
-  /* Try to find an expression for a proper index.  This is either
-     a multiplication expression by the element size or just the
-     ssa name we came along in case the element size is one.  */
+  /* Get the offset's defining statement.  */
+  offset_def = SSA_NAME_DEF_STMT (offset);
+
+  /* Try to find an expression for a proper index.  This is either a
+     multiplication expression by the element size or just the ssa name we came
+     along in case the element size is one. In that case, however, we do not
+     allow multiplications because they can be computing index to a higher
+     level dimension (PR 37861). */
   if (integer_onep (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (def_rhs)))))
-    index = offset;
-  else
     {
-      /* Get the offset's defining statement.  */
-      offset = SSA_NAME_DEF_STMT (offset);
+      if (TREE_CODE (offset_def) == GIMPLE_MODIFY_STMT
+         && TREE_CODE (GIMPLE_STMT_OPERAND (offset_def, 1)) == MULT_EXPR)
+       return false;
 
+      index = offset;
+    }
+  else
+    {
       /* The statement which defines OFFSET before type conversion
          must be a simple GIMPLE_MODIFY_STMT.  */
-      if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT)
+      if (TREE_CODE (offset_def) != GIMPLE_MODIFY_STMT)
        return false;
 
       /* The RHS of the statement which defines OFFSET must be a
         multiplication of an object by the size of the array elements. 
         This implicitly verifies that the size of the array elements
         is constant.  */
-     offset = GIMPLE_STMT_OPERAND (offset, 1);
+     offset = GIMPLE_STMT_OPERAND (offset_def, 1);
       if (TREE_CODE (offset) != MULT_EXPR
          || TREE_CODE (TREE_OPERAND (offset, 1)) != INTEGER_CST
          || !simple_cst_equal (TREE_OPERAND (offset, 1),