This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] PR 50554 - redefinition of index variable with inquire(iolength=...)
- From: Thomas Koenig <tkoenig at netcologne dot de>
- 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: Thu, 27 Jun 2013 20:52:27 +0200
- Subject: [patch, fortran] PR 50554 - redefinition of index variable with inquire(iolength=...)
Hello world,
the attached patch raises an error if an index variable is redefined
with inquire(iolength=...).
OK for trunk?
Thomas
2013-06-27 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/50554
* frontend-passes.c (doloop_code): Check do loop variables for
EXEC_IOLENGTH.
(do_function): Whitespace fix.
(gfc_code_walker): Handle EXEC_IOLENGTH.
2013-06-27 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/50554
* gfortran.dg/do_check_9.f90: New test.
! { dg-do compile }
! PR 50554 - error for index variable redefined by inquire (iolength=...)
program main
implicit none
integer :: i
do i=1,10 ! { dg-error "beginning at" }
inquire (iolength=i) 'aa' ! { dg-error "cannot be redefined" }
end do
end program main
Index: frontend-passes.c
===================================================================
--- frontend-passes.c (Revision 200132)
+++ frontend-passes.c (Arbeitskopie)
@@ -1615,6 +1615,7 @@ doloop_code (gfc_code **c, int *walk_subtrees ATTR
int i;
gfc_formal_arglist *f;
gfc_actual_arglist *a;
+ gfc_symbol *do_sym;
co = *c;
@@ -1654,8 +1655,6 @@ doloop_code (gfc_code **c, int *walk_subtrees ATTR
{
for (i=0; i<doloop_level; i++)
{
- gfc_symbol *do_sym;
-
if (doloop_list[i] == NULL)
break;
@@ -1683,6 +1682,27 @@ doloop_code (gfc_code **c, int *walk_subtrees ATTR
}
break;
+ case EXEC_IOLENGTH:
+
+ for (i=0; i<doloop_level; i++)
+ {
+ gfc_expr *iolength;
+
+ if (doloop_list[i] == NULL)
+ break;
+
+ do_sym = doloop_list[i]->ext.iterator->var->symtree->n.sym;
+
+ iolength = co->ext.inquire->iolength;
+ if (iolength != NULL && iolength->symtree->n.sym == do_sym)
+ gfc_error_now ("Variable '%s' at %L cannot be redefined "
+ "inside loop beginning at %L", do_sym->name,
+ &iolength->where, &doloop_list[i]->loc);
+
+ }
+
+ break;
+
default:
break;
}
@@ -1724,7 +1744,6 @@ do_function (gfc_expr **e, int *walk_subtrees ATTR
for (i=0; i<doloop_level; i++)
{
gfc_symbol *do_sym;
-
if (doloop_list[i] == NULL)
break;
@@ -2057,6 +2076,10 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t code
WALK_SUBEXPR (co->ext.inquire->round);
break;
+ case EXEC_IOLENGTH:
+ WALK_SUBEXPR (co->ext.inquire->iolength);
+ break;
+
case EXEC_WAIT:
WALK_SUBEXPR (co->ext.wait->unit);
WALK_SUBEXPR (co->ext.wait->iostat);