This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, middle-end] Fix PR 37861 - Bogus array bounds warning
- From: Martin Jambor <mjambor at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Richard Guenther <rguenther at suse dot de>
- Date: Wed, 5 Nov 2008 10:48:45 +0100
- Subject: [PATCH, middle-end] Fix PR 37861 - Bogus array bounds warning
Hi,
the following patch gets rid of the bogus warning.
The problem is, that fwprop currently generates array_refs of the form
&(*formatstr_3(D))[cumulative_offset] for multidimensional arrays and
the cumulative offset can then naturally be bigger than the respective
dimension of the array.
This happens because, when multidimensional arrays are passed as a
formal parameter, they are gimplified into a pointer, thus
formatstr[10][100] becomes char[100] * formatstr. We do not want to
be doing the transformation on such variables and the patch inhibits
them.
I have bootstrapped and regression tested it on x86_64-suse-linux
(revision 141561). I hope this won't cause any performance problems.
OK for trunk?
Martin
2008-11-05 Martin Jambor <mjambor@suse.cz>
PR middle-end/37861
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Don't turn
pointer arithmetics into array_ref if the array is accessed
through an indirect_ref.
Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c (revision 141546)
+++ gcc/tree-ssa-forwprop.c (working copy)
@@ -812,6 +812,7 @@ forward_propagate_addr_expr_1 (tree name
array_ref = TREE_OPERAND (def_rhs, 0);
if (TREE_CODE (array_ref) != ARRAY_REF
|| TREE_CODE (TREE_TYPE (TREE_OPERAND (array_ref, 0))) != ARRAY_TYPE
+ || TREE_CODE (TREE_OPERAND (array_ref, 0)) == INDIRECT_REF
|| !integer_zerop (TREE_OPERAND (array_ref, 1)))
return false;