]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: PR93263 -fno-automatic and RECURSIVE
authorMark Eggleston <markeggleston@gcc.gnu.org>
Fri, 17 Jan 2020 09:44:23 +0000 (09:44 +0000)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Fri, 17 Jan 2020 09:44:49 +0000 (09:44 +0000)
The use of -fno-automatic should not affect the save attribute of a
recursive procedure. The first test case checks unsaved variables
and the second checks saved variables.

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr93263_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr93263_2.f90 [new file with mode: 0644]

index b7f3146d90340e092b27406bc58312b8684b84d8..ea6d1b8b4d6abffb756d646f7152e165ea3871ed 100644 (file)
@@ -1,3 +1,14 @@
+2020-01-17  Mark Eggleston  <mark.eggleston@codethink.com>
+
+        Backport from mainline
+       Mark Eggleston  <mark.eggleston@codethink.com>
+
+       PR fortran/93236
+       * resolve.c (resolve_types): Declare boolean recursive and set with the
+       value of the recursive attribute of namespace proc_name symbol
+       structure if it exists.  Call gfc_save_all if both flag_automatic and
+       recursive are false or ns->save_all is true.
+
 2020-01-10  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from mainline
index b38075766537e170b6ed1ad535fcc22e98420f05..a4ad26efffc5ef4ba6613b42081dc136f0811bc2 100644 (file)
@@ -16769,6 +16769,7 @@ resolve_types (gfc_namespace *ns)
   gfc_data *d;
   gfc_equiv *eq;
   gfc_namespace* old_ns = gfc_current_ns;
+  bool recursive = ns->proc_name && ns->proc_name->attr.recursive;
 
   if (ns->types_resolved)
     return;
@@ -16822,7 +16823,7 @@ resolve_types (gfc_namespace *ns)
 
   gfc_traverse_ns (ns, resolve_values);
 
-  if (ns->save_all || !flag_automatic)
+  if (ns->save_all || (!flag_automatic && !recursive))
     gfc_save_all (ns);
 
   iter_stack = NULL;
index 4acbb6c88bced0a3ad41b1457ffc772482bbf65b..6203349acb6f6fc7b8ed8a2eb3b5dd5dd52d379a 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-17  Mark Eggleston  <mark.eggleston@codethink.com>
+
+       Backport from mainline
+       Mark Eggleston  <mark.eggleston@codethink.com>
+       Tobias Burnus  <burnus@gcc.gnu.org>
+
+       * gfortran.dg/pr93263_1.f90: New test.
+       * gfortran.dg/pr93263_2.f90: New test.
+
 2020-01-15  Joseph Myers  <joseph@codesourcery.com>
 
        Backport from mainline:
diff --git a/gcc/testsuite/gfortran.dg/pr93263_1.f90 b/gcc/testsuite/gfortran.dg/pr93263_1.f90
new file mode 100644 (file)
index 0000000..f96b358
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-fno-automatic -fdump-tree-original" }
+!
+! Test contributed by Mark Eggleston  <mark.eggleston@codethink.com>
+
+program main
+  implicit none
+  call check(2)
+end 
+
+recursive subroutine check(n)
+  implicit none
+  integer n, a
+  a = 10
+  print*,"n=",n
+  if (n==1) then
+    a=a-1
+    print*,"assigning a=",a
+  else
+    a=a-2
+    print*,"assigning a=",a
+    call check(n-1)
+  endif
+  print*,"a=",a
+end 
+
+! { dg-final { scan-tree-dump-not "static integer\\(kind=4\\) a" "original" } }
+! { dg-final { scan-tree-dump-not "integer\\(kind=4\\) a" "original" } }
+
diff --git a/gcc/testsuite/gfortran.dg/pr93263_2.f90 b/gcc/testsuite/gfortran.dg/pr93263_2.f90
new file mode 100644 (file)
index 0000000..fd353c6
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do run }
+!
+! Test contributed by Tobias Burnus  <burnus@gcc.gnu.org>
+
+  integer :: cnt
+  cnt = 0
+  call sub()
+  if (cnt /= 5) stop 1
+contains
+  recursive subroutine sub()
+    save
+    logical :: first = .true.
+    integer :: i
+    cnt = cnt + 1
+    if (first) then
+      first = .false.
+      i = 1
+    end if
+    print *, "Hello", i
+    i = i + 1
+    if (i <= 5) call sub()
+  end subroutine
+end
+