| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-fdec-static -finit-local-zero" } |
| 3 |
! |
| 4 |
! Test AUTOMATIC and STATIC attributes. |
| 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 assert |
| 15 |
|
| 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 |
| 23 |
|
| 24 |
! a should be incremented by x every time and saved |
| 25 |
a = a + x |
| 26 |
f = a |
| 27 |
|
| 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 |
| 33 |
|
| 34 |
implicit none |
| 35 |
integer :: f |
| 36 |
|
| 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) |
| 41 |
|
| 42 |
end |