2017-02-20 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / dec_static_2.f90
blob392f3427c148fcc4d2cbc5f38d3783dd5842b7aa
1 ! { dg-do run }
2 ! { dg-options "-fdec-static -fno-automatic -finit-local-zero" }
4 ! Test STATIC and AUTOMATIC with -fno-automatic and recursive subroutines.
6 subroutine assert(s, i1, i2)
7 implicit none
8 integer, intent(in) :: i1, i2
9 character(*), intent(in) :: s
10 if (i1 .ne. i2) then
11 print *, s, ": expected ", i2, " but was ", i1
12 call abort
13 endif
14 endsubroutine
16 function f (x)
17 implicit none
18 integer f
19 integer, intent(in) :: x
20 integer, static :: a ! should be SAVEd
21 a = a + x ! should increment by x every time
22 f = a
23 return
24 endfunction
26 recursive subroutine g (x)
27 implicit none
28 integer, intent(in) :: x
29 integer, automatic :: a ! should be automatic (in recursive)
30 a = a + x ! should be set to x every time
31 call assert ("g%a", a, x)
32 endsubroutine
34 subroutine h (x)
35 implicit none
36 integer, intent(in) :: x
37 integer, automatic :: a ! should be automatic (outside recursive)
38 a = a + x ! should be set to x every time
39 call assert ("h%a", a, x)
40 endsubroutine
42 implicit none
43 integer :: f
45 ! Should return static value of c; accumulates x
46 call assert ("f()", f(3), 3)
47 call assert ("f()", f(4), 7)
48 call assert ("f()", f(2), 9)
50 call g(3)
51 call g(4)
52 call g(2)
54 call h(3)
55 call h(4)
56 call h(2)
58 end