| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-fdec-static -frecursive" } |
| 3 |
|
| 4 |
! Contributed by Mark Eggleston <[email protected]> |
| 5 |
! |
| 6 |
! Check automatic variables can be used in equivalence statements. |
| 7 |
! Any other variables that do not explicitly have the automatic |
| 8 |
! attribute will be given the automatic attribute. |
| 9 |
! |
| 10 |
! Check that variables are on the stack by incorporating the |
| 11 |
! equivalence in a recursive function. |
| 12 |
! |
| 13 |
program test |
| 14 |
integer :: f |
| 15 |
|
| 16 |
f = factorial(5) |
| 17 |
if (f.ne.120) stop 2 |
| 18 |
|
| 19 |
contains |
| 20 |
function factorial(n) result(f) |
| 21 |
integer :: f |
| 22 |
integer, intent(in) :: n |
| 23 |
integer, automatic :: a |
| 24 |
integer :: b |
| 25 |
equivalence (a,b) |
| 26 |
|
| 27 |
if (loc(a).ne.loc(b)) stop 1 |
| 28 |
b = n |
| 29 |
if (a.eq.1) then |
| 30 |
f = 1 |
| 31 |
else |
| 32 |
f = a * factorial(b-1) |
| 33 |
end if |
| 34 |
end function |
| 35 |
end program test |