1! { dg-do run }
2!
3implicit none
4integer, allocatable :: A[:], B[:,:]
5integer :: n1, n2, n3
6
7if (allocated (a)) STOP 1
8if (allocated (b)) STOP 2
9
10allocate(a[*])
11a = 5 + this_image ()
12if (a[this_image ()] /= 5 + this_image ()) STOP 1
13
14a[this_image ()] = 8 - 2*this_image ()
15if (a[this_image ()] /= 8 - 2*this_image ()) STOP 2
16
17if (lcobound(a, dim=1) /= 1 .or. ucobound(a,dim=1) /= num_images()) &
18  STOP 3
19deallocate(a)
20
21allocate(a[4:*])
22a[this_image ()] = 8 - 2*this_image ()
23
24if (lcobound(a, dim=1) /= 4 .or. ucobound(a,dim=1) /= 3 + num_images()) &
25  STOP 4
26
27n1 = -1
28n2 = 5
29n3 = 3
30allocate (B[n1:n2, n3:*])
31if (any (lcobound(b) /= [-1, 3]) .or. lcobound(B, dim=2) /= n3) &
32  STOP 5
33call sub(A, B)
34
35if (allocated (a)) STOP 6
36if (.not.allocated (b)) STOP 7
37
38call two(.true.)
39call two(.false.)
40
41! automatically deallocate "B"
42contains
43  subroutine sub(x, y)
44    integer, allocatable :: x[:], y[:,:]
45
46    if (any (lcobound(y) /= [-1, 3]) .or. lcobound(y, dim=2) /= n3) &
47      STOP 8
48    if (lcobound(x, dim=1) /= 4 .or. ucobound(x,dim=1) /= 3 + num_images()) &
49      STOP 9
50    if (x[this_image ()] /= 8 - 2*this_image ()) STOP 3
51    deallocate(x)
52  end subroutine sub
53
54  subroutine two(init)
55    logical, intent(in) :: init
56    integer, allocatable, SAVE :: a[:]
57
58    if (init) then
59      if (allocated(a)) STOP 10
60      allocate(a[*])
61      a = 45
62   else
63      if (.not. allocated(a)) STOP 11
64      if (a /= 45) STOP 12
65      deallocate(a)
66    end if
67  end subroutine two
68end
69