aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/gfortran.dg')
-rw-r--r--gcc/testsuite/gfortran.dg/save_5.f9052
1 files changed, 52 insertions, 0 deletions
diff --git a/gcc/testsuite/gfortran.dg/save_5.f90 b/gcc/testsuite/gfortran.dg/save_5.f90
new file mode 100644
index 0000000..20d3b7a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/save_5.f90
@@ -0,0 +1,52 @@
+! { dg-do run }
+! { dg-options "-fno-automatic" }
+!
+! PR fortran/55733
+!
+! Check that -fno-automatic makes the local variable SAVEd
+!
+
+! Scalar allocatable
+subroutine foo(i)
+ integer :: i
+ integer, allocatable :: j
+ if (i == 1) j = 42
+ if (.not. allocated (j)) call abort ()
+ if (j /= 42) call abort ()
+end
+
+! Deferred-length string scalar
+subroutine bar()
+ logical, save :: first = .true.
+ character(len=:), allocatable :: str
+ if (first) then
+ first = .false.
+ if (allocated (str)) call abort ()
+ str = "ABCDEF"
+ end if
+ if (.not. allocated (str)) call abort ()
+ if (len (str) /= 6) call abort ()
+ if (str(1:6) /= "ABCDEF") call abort ()
+end subroutine bar
+
+! Deferred-length string array
+subroutine bar_array()
+ logical, save :: first = .true.
+ character(len=:), allocatable :: str
+ if (first) then
+ first = .false.
+ if (allocated (str)) call abort ()
+ str = "ABCDEF"
+ end if
+ if (.not. allocated (str)) call abort ()
+ if (len (str) /= 6) call abort ()
+ if (str(1:6) /= "ABCDEF") call abort ()
+end subroutine bar_array
+
+call foo(1)
+call foo(2)
+call bar()
+call bar_array()
+call bar()
+call bar_array()
+end