Commit 59e36b72 by Paul Thomas

re PR fortran/36091 (false positive in bounds checking with forall)

2009-04-06  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-06  Paul Thomas  <pault@gcc.gnu.org

        PR fortran/36091
        * gfortran.dg/forall_13.f90: Add -fbounds-check option.

From-SVN: r145581
parent ecef6119
2009-04-06 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 Daniel Franke <franke.daniel@gmail.com> 2009-04-05 Daniel Franke <franke.daniel@gmail.com>
PR fortran/29458 PR fortran/29458
......
...@@ -621,7 +621,7 @@ typedef struct ...@@ -621,7 +621,7 @@ typedef struct
{ {
/* Variable attributes. */ /* Variable attributes. */
unsigned allocatable:1, dimension:1, external:1, intrinsic:1, 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, dummy:1, result:1, assign:1, threadprivate:1, not_always_present:1,
implied_index:1, subref_array_pointer:1, proc_pointer:1; implied_index:1, subref_array_pointer:1, proc_pointer:1;
......
...@@ -2452,6 +2452,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym, ...@@ -2452,6 +2452,7 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
tree tmp; tree tmp;
tree stride; tree stride;
gfc_se indexse; gfc_se indexse;
gfc_se tmpse;
/* Handle scalarized references separately. */ /* Handle scalarized references separately. */
if (ar->type != AR_ELEMENT) if (ar->type != AR_ELEMENT)
...@@ -2482,6 +2483,15 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym, ...@@ -2482,6 +2483,15 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
/* Lower bound. */ /* Lower bound. */
tmp = gfc_conv_array_lbound (se->expr, n); 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, cond = fold_build2 (LT_EXPR, boolean_type_node,
indexse.expr, tmp); indexse.expr, tmp);
asprintf (&msg, "%s for array '%s', " asprintf (&msg, "%s for array '%s', "
...@@ -2499,6 +2509,15 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym, ...@@ -2499,6 +2509,15 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_symbol * sym,
|| (ar->as->type != AS_ASSUMED_SIZE && !ar->as->cp_was_assumed)) || (ar->as->type != AS_ASSUMED_SIZE && !ar->as->cp_was_assumed))
{ {
tmp = gfc_conv_array_ubound (se->expr, n); 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, cond = fold_build2 (GT_EXPR, boolean_type_node,
indexse.expr, tmp); indexse.expr, tmp);
asprintf (&msg, "%s for array '%s', " asprintf (&msg, "%s for array '%s', "
......
...@@ -1754,6 +1754,7 @@ forall_make_variable_temp (gfc_code *c, stmtblock_t *pre, stmtblock_t *post) ...@@ -1754,6 +1754,7 @@ forall_make_variable_temp (gfc_code *c, stmtblock_t *pre, stmtblock_t *post)
new_sym = gfc_new_symbol (old_sym->name, NULL); new_sym = gfc_new_symbol (old_sym->name, NULL);
new_sym->ts = old_sym->ts; new_sym->ts = old_sym->ts;
new_sym->attr.referenced = 1; new_sym->attr.referenced = 1;
new_sym->attr.temporary = 1;
new_sym->attr.dimension = old_sym->attr.dimension; new_sym->attr.dimension = old_sym->attr.dimension;
new_sym->attr.flavor = old_sym->attr.flavor; new_sym->attr.flavor = old_sym->attr.flavor;
......
2009-04-06 Paul Thomas <pault@gcc.gnu.org
PR fortran/36091
* gfortran.dg/forall_13.f90: Add -fbounds-check option.
2009-04-06 Hans-Peter Nilsson <hp@axis.com> 2009-04-06 Hans-Peter Nilsson <hp@axis.com>
* gfortran.dg/namelist_51.f90, gfortran.dg/utf8_2.f03, * gfortran.dg/namelist_51.f90, gfortran.dg/utf8_2.f03,
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
! Contributed by Dick Hendrickson on comp.lang.fortran, ! Contributed by Dick Hendrickson on comp.lang.fortran,
! " Most elegant syntax for inverting a permutation?" 20071006 ! " 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/) integer :: p(4) = (/2,4,1,3/)
forall (i = 1:4) p(p(i)) = i ! This was the original forall (i = 1:4) p(p(i)) = i ! This was the original
if (any (p .ne. (/3,1,4,2/))) call abort () if (any (p .ne. (/3,1,4,2/))) call abort ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment