From 1aae3f05473e1e6bbfb80a9adfbc8cff4a61e310 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Sat, 16 May 2015 12:33:01 +0000 Subject: [PATCH] re PR fortran/66113 (Variable n cannot appear in the expression with nested blocks) 2015-05-16 Thomas Koenig PR fortran/66113 * expr.c (is_parent_of_current_ns): New function. (check_restricted): Use it. 2015-05-16 Thomas Koenig PR fortran/66113 * gfortran.dg/block_14.f90: New test. From-SVN: r223238 --- gcc/fortran/ChangeLog | 8 +++++++- gcc/fortran/expr.c | 16 +++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/block_14.f90 | 21 +++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/block_14.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 7cff4760cac..002a147ce62 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2015-05-16 Thomas Koenig + + PR fortran/66113 + * expr.c (is_parent_of_current_ns): New function. + (check_restricted): Use it. + 2015-05-16 Manuel López-Ibáñez PR fortran/44054 @@ -28,7 +34,7 @@ (gfc_diagnostics_init): Initialize caret_chars array. (gfc_diagnostics_finish): Reset caret_chars array to default. -2015-05-16 Mikael Morin Paul Thomas PR fortran/65792 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index c34be9079b9..aa79243fa04 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2841,6 +2841,18 @@ check_references (gfc_ref* ref, bool (*checker) (gfc_expr*)) return check_references (ref->next, checker); } +/* Return true if ns is a parent of the current ns. */ + +static bool +is_parent_of_current_ns (gfc_namespace *ns) +{ + gfc_namespace *p; + for (p = gfc_current_ns->parent; p; p = p->parent) + if (ns == p) + return true; + + return false; +} /* Verify that an expression is a restricted expression. Like its cousin check_init_expr(), an error message is generated if we @@ -2929,9 +2941,7 @@ check_restricted (gfc_expr *e) || sym->attr.dummy || sym->attr.implied_index || sym->attr.flavor == FL_PARAMETER - || (sym->ns && sym->ns == gfc_current_ns->parent) - || (sym->ns && gfc_current_ns->parent - && sym->ns == gfc_current_ns->parent->parent) + || is_parent_of_current_ns (sym->ns) || (sym->ns->proc_name != NULL && sym->ns->proc_name->attr.flavor == FL_MODULE) || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7260828346d..b3aa87ca73c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-05-16 Thomas Koenig + + PR fortran/66113 + * gfortran.dg/block_14.f90: New test. + 2015-05-16 Manuel López-Ibáñez PR fortran/44054 diff --git a/gcc/testsuite/gfortran.dg/block_14.f90 b/gcc/testsuite/gfortran.dg/block_14.f90 new file mode 100644 index 00000000000..50e65687e49 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/block_14.f90 @@ -0,0 +1,21 @@ +! { dg-do run } +! PR 66113 - this used to ICE with deeply nested BLOCKS. +program main + integer :: n + real :: s + n = 3 + block + block + block + block + block + real, dimension(n) :: a + a = 3. + s = sum(a) + end block + end block + end block + end block + end block + if (s /= 9) call abort +end program main -- 2.30.2