PR ipa/83051
[official-gcc.git] / gcc / testsuite / gfortran.dg / dec_static_1.f90
blob7f319ec0a5ca2080ebda2b27fd888d8891a5efa6
1 ! { dg-do run }
2 ! { dg-options "-fdec-static -finit-local-zero" }
4 ! Test AUTOMATIC and STATIC attributes.
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 assert
16 function f (x, y)
17 implicit none
18 integer f
19 integer, intent(in) :: x, y
20 integer :: a ! only a can actually be saved
21 integer, automatic :: c ! should actually be automatic
22 save
24 ! a should be incremented by x every time and saved
25 a = a + x
26 f = a
28 ! c should be zeroed every time, therefore equal y
29 c = c + y
30 call assert ("f%c", c, y)
31 return
32 endfunction
34 implicit none
35 integer :: f
37 ! Should return static value of a; accumulates x
38 call assert ("f()", f(1,3), 1)
39 call assert ("f()", f(1,4), 2)
40 call assert ("f()", f(1,2), 3)
42 end