Debian Codegraph @

gcc/testsuite/gfortran.dg/dec_static_2.f90

raw
1 ! { dg-do run }
2 ! { dg-options "-fdec-static -fno-automatic -finit-local-zero" }
3 !
4 ! Test STATIC and AUTOMATIC with -fno-automatic and recursive subroutines.
5 !
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 STOP 1
13 endif
14 endsubroutine
15
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
25
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
33
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
41
42 implicit none
43 integer :: f
44
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)
49
50 call g(3)
51 call g(4)
52 call g(2)
53
54 call h(3)
55 call h(4)
56 call h(2)
57
58 end