This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR33330, alias pruning bug with fortran
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 7 Sep 2007 14:04:05 +0200 (CEST)
- Subject: [PATCH] Fix PR33330, alias pruning bug with fortran
This fixes PR33330, a bug where we incorrectly pruned aliases for
char[1:1] & my_char_ref;
char D.874;
char my_char;
<bb 2>:
# my_char_4 = VDEF <my_char_3(D)>
my_char = 121;
my_char_ref_1 = (char[1:1] &) &my_char;
# VUSE <NMT.30_5(D)>
D.874_2 = (*my_char_ref_1)[1]{lb: 1 sz: 1};
which is created from a fortran testcase which involves inlining.
I believe that we have to allow accessing of my_char via an array
reference with zero index. That is,
int a;
((int[1])&a)[0];
does not invoke undefined behavior as it is the same as *&a.
(Whether we should have cleaned up the reference by forward-propagating
(char[1:1] &) &my_char into (*my_char_ref_1)[1]{lb: 1 sz: 1} is
another thing, but certainly the IL is valid). Creating a C testcase
is difficult because the C frontend lowers the array accesses.
Bootstrapped and tested on i686-pc-linux-gnu, applied to mainline.
Richard.
2007-09-07 Richard Guenther <rguenther@suse.de>
PR middle-end/33330
* tree-ssa-operands.c (access_can_touch_variable): An access
of the form (*p)[0] can touch a variable of same size.
Index: tree-ssa-operands.c
===================================================================
--- tree-ssa-operands.c (revision 128235)
+++ tree-ssa-operands.c (working copy)
@@ -1292,6 +1292,15 @@ access_can_touch_variable (tree ref, tre
}
To implement this, we just punt on accesses through union
pointers entirely.
+
+ Another case we have to allow is accessing a variable
+ through an array access at offset zero. This happens from
+ code generated by the fortran frontend like
+
+ char[1:1] & my_char_ref;
+ char my_char;
+ my_char_ref_1 = (char[1:1] &) &my_char;
+ D.874_2 = (*my_char_ref_1)[1]{lb: 1 sz: 1};
*/
else if (ref
&& flag_strict_aliasing
@@ -1300,6 +1309,14 @@ access_can_touch_variable (tree ref, tre
&& base
&& (TREE_CODE (base) != INDIRECT_REF
|| TREE_CODE (TREE_TYPE (base)) != UNION_TYPE)
+ && (TREE_CODE (base) != INDIRECT_REF
+ || TREE_CODE (ref) != ARRAY_REF
+ || offset != 0
+ || (DECL_SIZE (alias)
+ && TREE_CODE (DECL_SIZE (alias)) == INTEGER_CST
+ && size != -1
+ && (unsigned HOST_WIDE_INT)size
+ != TREE_INT_CST_LOW (DECL_SIZE (alias))))
&& !AGGREGATE_TYPE_P (TREE_TYPE (alias))
&& TREE_CODE (TREE_TYPE (alias)) != COMPLEX_TYPE
&& !var_ann (alias)->is_heapvar