]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/66113 (Variable n cannot appear in the expression with nested blocks)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 16 May 2015 12:33:01 +0000 (12:33 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 16 May 2015 12:33:01 +0000 (12:33 +0000)
2015-05-16  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/66113
* expr.c (is_parent_of_current_ns):  New function.
(check_restricted):  Use it.

2015-05-16  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/66113
* gfortran.dg/block_14.f90:  New test.

From-SVN: r223238

gcc/fortran/ChangeLog
gcc/fortran/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/block_14.f90 [new file with mode: 0644]

index 7cff4760cac3426280f967818f37e105bbe6188d..002a147ce62f94130fa8fb4edf8bcf4460d2e87c 100644 (file)
@@ -1,3 +1,9 @@
+2015-05-16  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/66113
+       * expr.c (is_parent_of_current_ns):  New function.
+       (check_restricted):  Use it.
+
 2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        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  <mikael@gcc.gnu.org
+2015-05-16  Mikael Morin  <mikael@gcc.gnu.org>
            Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/65792
index c34be9079b9026c42e77ac5738b4734d94149080..aa79243fa04b261e85f1bf3ac320429ed15f744d 100644 (file)
@@ -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)))
index 7260828346d5d7ec2ccafd7b963376e69cff94f2..b3aa87ca73c9145eb40dd0aaf0e8cebef977a311 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-16  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/66113
+       * gfortran.dg/block_14.f90:  New test.
+
 2015-05-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        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 (file)
index 0000000..50e6568
--- /dev/null
@@ -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