]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gfortran.dg/auto_in_equiv_3.f90
Allow automatics in equivalences
[thirdparty/gcc.git] / gcc / testsuite / gfortran.dg / auto_in_equiv_3.f90
1 ! { dg-run }
2 ! { dg-options "-fdec-static -fno-automatic" }
3
4 ! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
5
6 ! Storage is NOT on the static unless explicitly specified using the
7 ! DEC extension "automatic". The address of the first local variable
8 ! is used to determine that storage for the automatic local variable
9 ! is different to that of a local variable with no attributes. The
10 ! contents of the local variable in suba should be overwritten by the
11 ! call to subb.
12 !
13 program test
14 integer :: dummy
15 integer, parameter :: address = kind(loc(dummy))
16 integer(address) :: ad1
17 integer(address) :: ad2
18 integer(address) :: ad3
19 logical :: ok
20
21 call suba(0, ad1)
22 call subb(0, ad2)
23 call suba(1, ad1)
24 call subc(0, ad3)
25 ok = (ad1.eq.ad3).and.(ad1.ne.ad2)
26 if (.not.ok) stop 4
27
28 contains
29 subroutine suba(option, addr)
30 integer, intent(in) :: option
31 integer(address), intent(out) :: addr
32 integer, automatic :: a
33 integer :: b
34 equivalence (a, b)
35 addr = loc(a)
36 if (option.eq.0) then
37 ! initialise a and c
38 a = 9
39 if (a.ne.b) stop 1
40 if (loc(a).ne.loc(b)) stop 2
41 else
42 ! a should've been overwritten
43 if (a.eq.9) stop 3
44 end if
45 end subroutine suba
46
47 subroutine subb(dummy, addr)
48 integer, intent(in) :: dummy
49 integer(address), intent(out) :: addr
50 integer :: x
51 addr = loc(x)
52 x = 77
53 end subroutine subb
54
55 subroutine subc(dummy, addr)
56 integer, intent(in) :: dummy
57 integer(address), intent(out) :: addr
58 integer, automatic :: y
59 addr = loc(y)
60 y = 77
61 end subroutine subc
62
63 end program test