This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR36091
- From: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 5 Apr 2009 22:10:03 +0200
- Subject: [Patch, fortran] PR36091
The symbol generated by trans-stmt.c(forall_make_variable_temp) uses
lbound = 0 for all dimensions. This does not matter, except for
bounds checking. The fix is to use the array_spec and convert the
bounds, instead of using the array descriptor. Rather than adding a
test, forall_13.f90, where the problem was identified, has been
modified to use the -fbounds-check option.
Bootstrapped and regtested on FC9/x86_64 - OK for trunk?
Paul
2009-04-05 Paul Thomas <pault@gcc.gnu.org>
PR fortran/36091
* trans-array.c (gfc_conv_array_ref): If the symbol has the
temporary attribute use the array_spec for the bounds.
* gfortran.h : Add the temporary field to the structure
'symbol_attribute'.
* trans-stmt.c (forall_make_variable_temp): Set the symbol's
temporary attribute.
2009-04-05 Paul Thomas <pault@gcc.gnu.org
PR fortran/36091
* gfortran.dg/forall_13.f90: Add -fbounds-check option.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c (revision 145540)
+++ gcc/fortran/trans-array.c (working copy)
@@ -2450,6 +2450,7 @@
tree tmp;
tree stride;
gfc_se indexse;
+ gfc_se tmpse;
/* Handle scalarized references separately. */
if (ar->type != AR_ELEMENT)
@@ -2480,6 +2481,15 @@
/* Lower bound. */
tmp = gfc_conv_array_lbound (se->expr, n);
+ if (sym->attr.temporary)
+ {
+ gfc_init_se (&tmpse, se);
+ gfc_conv_expr_type (&tmpse, ar->as->lower[n],
+ gfc_array_index_type);
+ gfc_add_block_to_block (&se->pre, &tmpse.pre);
+ tmp = tmpse.expr;
+ }
+
cond = fold_build2 (LT_EXPR, boolean_type_node,
indexse.expr, tmp);
asprintf (&msg, "%s for array '%s', "
@@ -2497,6 +2507,15 @@
|| (ar->as->type != AS_ASSUMED_SIZE && !ar->as->cp_was_assumed))
{
tmp = gfc_conv_array_ubound (se->expr, n);
+ if (sym->attr.temporary)
+ {
+ gfc_init_se (&tmpse, se);
+ gfc_conv_expr_type (&tmpse, ar->as->upper[n],
+ gfc_array_index_type);
+ gfc_add_block_to_block (&se->pre, &tmpse.pre);
+ tmp = tmpse.expr;
+ }
+
cond = fold_build2 (GT_EXPR, boolean_type_node,
indexse.expr, tmp);
asprintf (&msg, "%s for array '%s', "
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (revision 145540)
+++ gcc/fortran/gfortran.h (working copy)
@@ -621,7 +621,7 @@
{
/* Variable attributes. */
unsigned allocatable:1, dimension:1, external:1, intrinsic:1,
- optional:1, pointer:1, target:1, value:1, volatile_:1,
+ optional:1, pointer:1, target:1, value:1, volatile_:1, temporary:1,
dummy:1, result:1, assign:1, threadprivate:1, not_always_present:1,
implied_index:1, subref_array_pointer:1, proc_pointer:1;
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c (revision 145540)
+++ gcc/fortran/trans-stmt.c (working copy)
@@ -1754,6 +1754,7 @@
new_sym = gfc_new_symbol (old_sym->name, NULL);
new_sym->ts = old_sym->ts;
new_sym->attr.referenced = 1;
+ new_sym->attr.temporary = 1;
new_sym->attr.dimension = old_sym->attr.dimension;
new_sym->attr.flavor = old_sym->attr.flavor;
Index: gcc/testsuite/gfortran.dg/forall_13.f90
===================================================================
--- gcc/testsuite/gfortran.dg/forall_13.f90 (revision 145540)
+++ gcc/testsuite/gfortran.dg/forall_13.f90 (working copy)
@@ -5,6 +5,9 @@
! Contributed by Dick Hendrickson on comp.lang.fortran,
! " Most elegant syntax for inverting a permutation?" 20071006
!
+! Test the fix for PR36091 as well...
+! { dg-options "-fbounds-check" }
+!
integer :: p(4) = (/2,4,1,3/)
forall (i = 1:4) p(p(i)) = i ! This was the original
if (any (p .ne. (/3,1,4,2/))) call abort ()