aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2007-04-15 15:28:06 +0000
committerPaul Thomas <pault@gcc.gnu.org>2007-04-15 15:28:06 +0000
commit9a3db5a366f36a48e6879ed17b9c5dbf87442808 (patch)
tree998d5a983b982f9cb8acff35d3022b8d994d5cd2
parente3e093eceff3da3fa4aa20745d2e3fb2d3b6e519 (diff)
downloadgcc-9a3db5a366f36a48e6879ed17b9c5dbf87442808.zip
gcc-9a3db5a366f36a48e6879ed17b9c5dbf87442808.tar.gz
gcc-9a3db5a366f36a48e6879ed17b9c5dbf87442808.tar.bz2
re PR fortran/31204 (wrong host association of implied loop variable)
2007-04-15 Paul Thomas <pault@gcc.gnu.org> PR fortran/31204 * primary.c (check_for_implicit_index): New function to check that a host associated variable is not an undeclared implied do loop index. (gfc_match_rvalue, match_variable): Use it and reset the implied_index attribute. * gfortran.h : Add the implied_index field to symbol_attribute. * match.c (gfc_match_iterator): Mark the iterator variable with the new attribute. * decl.c (build_sym): Reset the new attribute. 2007-04-15 Paul Thomas <pault@gcc.gnu.org> PR fortran/31204 * gfortran.dg/array_constructor_16.f90: New test. From-SVN: r123849
-rw-r--r--gcc/fortran/ChangeLog13
-rw-r--r--gcc/fortran/decl.c2
-rw-r--r--gcc/fortran/match.c2
-rw-r--r--gcc/fortran/primary.c38
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/array_constructor_16.f9034
6 files changed, 94 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 3d8b03c..b6a3b29 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,16 @@
+2007-04-15 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/31204
+ * primary.c (check_for_implicit_index): New function to check
+ that a host associated variable is not an undeclared implied
+ do loop index.
+ (gfc_match_rvalue, match_variable): Use it and reset the
+ implied_index attribute.
+ * gfortran.h : Add the implied_index field to symbol_attribute.
+ * match.c (gfc_match_iterator): Mark the iterator variable
+ with the new attribute.
+ * decl.c (build_sym): Reset the new attribute.
+
2007-04-15 Kazu Hirata <kazu@codesourcery.com>
* gfc-internals.texi: Fix typos.
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 9b54bca..7665bc8 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -769,6 +769,8 @@ build_sym (const char *name, gfc_charlen *cl,
if (gfc_copy_attr (&sym->attr, &attr, var_locus) == FAILURE)
return FAILURE;
+ sym->attr.implied_index = 0;
+
return SUCCESS;
}
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 2483ea3..c2c239d 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -536,6 +536,8 @@ gfc_match_iterator (gfc_iterator *iter, int init_flag)
goto cleanup;
}
+ var->symtree->n.sym->attr.implied_index = 1;
+
m = init_flag ? gfc_match_init_expr (&e1) : gfc_match_expr (&e1);
if (m == MATCH_NO)
goto syntax;
diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index 9e27edc..41c7507 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -1989,6 +1989,28 @@ cleanup:
}
+/* If the symbol is an implicit do loop index and implicitly typed,
+ it should not be host associated. Provide a symtree from the
+ current namespace. */
+static match
+check_for_implicit_index (gfc_symtree **st, gfc_symbol **sym)
+{
+ if ((*sym)->attr.flavor == FL_VARIABLE
+ && (*sym)->ns != gfc_current_ns
+ && (*sym)->attr.implied_index
+ && (*sym)->attr.implicit_type
+ && !(*sym)->attr.use_assoc)
+ {
+ int i;
+ i = gfc_get_sym_tree ((*sym)->name, NULL, st);
+ if (i)
+ return MATCH_ERROR;
+ *sym = (*st)->n.sym;
+ }
+ return MATCH_YES;
+}
+
+
/* Matches a variable name followed by anything that might follow it--
array reference, argument list of a function, etc. */
@@ -2024,7 +2046,14 @@ gfc_match_rvalue (gfc_expr **result)
e = NULL;
where = gfc_current_locus;
+ /* If this is an implicit do loop index and implicitly typed,
+ it should not be host associated. */
+ m = check_for_implicit_index (&symtree, &sym);
+ if (m != MATCH_YES)
+ return m;
+
gfc_set_sym_referenced (sym);
+ sym->attr.implied_index = 0;
if (sym->attr.function && sym->result == sym)
{
@@ -2394,6 +2423,15 @@ match_variable (gfc_expr **result, int equiv_flag, int host_flag)
where = gfc_current_locus;
sym = st->n.sym;
+
+ /* If this is an implicit do loop index and implicitly typed,
+ it should not be host associated. */
+ m = check_for_implicit_index (&st, &sym);
+ if (m != MATCH_YES)
+ return m;
+
+ sym->attr.implied_index = 0;
+
gfc_set_sym_referenced (sym);
switch (sym->attr.flavor)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8d566cb..efd83ef 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-15 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/31204
+ * gfortran.dg/array_constructor_16.f90: New test.
+
2007-04-15 Kazu Hirata <kazu@codesourcery.com>
* gcc.dg/pr19340.c, gcc.dg/tree-ssa/loop-1.c,
diff --git a/gcc/testsuite/gfortran.dg/array_constructor_16.f90 b/gcc/testsuite/gfortran.dg/array_constructor_16.f90
new file mode 100644
index 0000000..7c2e8d1
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/array_constructor_16.f90
@@ -0,0 +1,34 @@
+! { dg-do run }
+! Tests the fix for PR31204, in which 'i' below would be incorrectly
+! host associated by the contained subroutines. The checks for 'ii'
+! and 'iii' have been added, since they can be host associated because
+! of the explicit declarations in the main program.
+!
+! Contributed by Joost VandeVondele <jv244@cam.ac.uk>
+!
+ integer ii
+ INTEGER, PARAMETER :: jmin(1:10) = (/ (i, i = 1, 10) /)
+ INTEGER, PARAMETER :: kmin(1:10) = (/ (ii, ii = 1, 10) /)
+ INTEGER, PARAMETER :: lmin(1:10) = (/ (iii, iii = 1, 10) /)
+ integer iii
+ CALL two
+
+CONTAINS
+
+ SUBROUTINE one
+ i = 99
+ ii = 99
+ iii = 999
+ END SUBROUTINE
+
+ SUBROUTINE two
+ i = 0
+ ii = 0
+ iii = 0
+ CALL one
+ IF (i .NE. 0) CALL ABORT ()
+ IF (ii .NE. 99) CALL ABORT ()
+ IF (iii .NE. 999) CALL ABORT ()
+ END SUBROUTINE
+END
+