This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix aliasing problem with fortran
- From: Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: fortran at gcc dot gnu dot org
- Date: Mon, 16 May 2005 21:32:16 +0200
- Subject: [patch] Fix aliasing problem with fortran
Hello,
gfc_get_array_type_bounds constructs an arraytype, and each time it does
so, it builds a new range type. The range types produced here are not
shared, and in turn the array type built here is different each time
and gets a different aliasing class. However, the code produced by the
frontend sometimes after inlining contains
int tmp[0:];
int (*b)[0:];
b = &tmp;
where the types of tmp and *b are different, but fields of tmp are accessed
both through tmp and through *b. Such accesses are then (at RTL level)
supposed not to alias, thus causing a misscompilation in scheduling.
I don't have a testcase for clean branch, one of the testcases in the
testsuite fails for me in this way with some patches I am working on
applied.
Bootstrapped & regtested on i686.
Zdenek
* trans-types.c (gfc_array_range_type): New variable.
(gfc_init_types): Initialize gfc_array_range_type.
(gfc_get_array_type_bounds): Use gfc_array_range_type.
Index: fortran/trans-types.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-types.c,v
retrieving revision 1.43
diff -c -3 -p -r1.43 trans-types.c
*** fortran/trans-types.c 12 May 2005 18:19:37 -0000 1.43
--- fortran/trans-types.c 16 May 2005 14:04:20 -0000
*************** Software Foundation, 59 Temple Place - S
*** 50,55 ****
--- 50,56 ----
static tree gfc_get_derived_type (gfc_symbol * derived);
tree gfc_array_index_type;
+ tree gfc_array_range_type;
tree pvoid_type_node;
tree ppvoid_type_node;
tree pchar_type_node;
*************** gfc_init_types (void)
*** 528,533 ****
--- 529,538 ----
pchar_type_node = build_pointer_type (gfc_character1_type_node);
gfc_array_index_type = gfc_get_int_type (gfc_index_integer_kind);
+ gfc_array_range_type
+ = build_range_type (gfc_array_index_type,
+ build_int_cst (gfc_array_index_type, 0),
+ NULL_TREE);
/* The maximum array element size that can be handled is determined
by the number of bits available to store this field in the array
*************** gfc_get_array_type_bounds (tree etype, i
*** 1182,1190 ****
/* We define data as an unknown size array. Much better than doing
pointer arithmetic. */
arraytype =
! build_array_type (etype,
! build_range_type (gfc_array_index_type,
! gfc_index_zero_node, NULL_TREE));
arraytype = build_pointer_type (arraytype);
GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type) = arraytype;
--- 1187,1193 ----
/* We define data as an unknown size array. Much better than doing
pointer arithmetic. */
arraytype =
! build_array_type (etype, gfc_array_range_type);
arraytype = build_pointer_type (arraytype);
GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type) = arraytype;