| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-std=gnu" } |
| 3 |
! PR fortran/29391 |
| 4 |
! This file is here to check that LBOUND and UBOUND return correct values |
| 5 |
! |
| 6 |
! Contributed by Francois-Xavier Coudert ([email protected]) |
| 7 |
implicit none |
| 8 |
integer, allocatable :: i(:,:), j(:), u(:,:,:,:) |
| 9 |
|
| 10 |
allocate (i(-1:1,-1:1)) |
| 11 |
i = 0 |
| 12 |
allocate (j(-1:2)) |
| 13 |
j = 0 |
| 14 |
allocate (u(7,4,2,9)) |
| 15 |
|
| 16 |
call foo(u,4) |
| 17 |
call jackal(-1,-8) |
| 18 |
call jackal(-1,8) |
| 19 |
|
| 20 |
if (any(lbound(i(-1:1,-1:1)) /= 1)) STOP 1 |
| 21 |
if (lbound(i(-1:1,-1:1), 1) /= 1) STOP 2 |
| 22 |
if (lbound(i(-1:1,-1:1), 2) /= 1) STOP 3 |
| 23 |
|
| 24 |
if (any(ubound(i(-1:1,-1:1)) /= 3)) STOP 4 |
| 25 |
if (ubound(i(-1:1,-1:1), 1) /= 3) STOP 5 |
| 26 |
if (ubound(i(-1:1,-1:1), 2) /= 3) STOP 6 |
| 27 |
|
| 28 |
if (any(lbound(i(:,:)) /= 1)) STOP 7 |
| 29 |
if (lbound(i(:,:), 1) /= 1) STOP 8 |
| 30 |
if (lbound(i(:,:), 2) /= 1) STOP 9 |
| 31 |
|
| 32 |
if (any(ubound(i(:,:)) /= 3)) STOP 10 |
| 33 |
if (ubound(i(:,:), 1) /= 3) STOP 11 |
| 34 |
if (ubound(i(:,:), 2) /= 3) STOP 12 |
| 35 |
|
| 36 |
if (any(lbound(i(0:,-1:)) /= 1)) STOP 13 |
| 37 |
if (lbound(i(0:,-1:), 1) /= 1) STOP 14 |
| 38 |
if (lbound(i(0:,-1:), 2) /= 1) STOP 15 |
| 39 |
|
| 40 |
if (any(ubound(i(0:,-1:)) /= [2,3])) STOP 16 |
| 41 |
if (ubound(i(0:,-1:), 1) /= 2) STOP 17 |
| 42 |
if (ubound(i(0:,-1:), 2) /= 3) STOP 18 |
| 43 |
|
| 44 |
if (any(lbound(i(:0,:0)) /= 1)) STOP 19 |
| 45 |
if (lbound(i(:0,:0), 1) /= 1) STOP 20 |
| 46 |
if (lbound(i(:0,:0), 2) /= 1) STOP 21 |
| 47 |
|
| 48 |
if (any(ubound(i(:0,:0)) /= 2)) STOP 22 |
| 49 |
if (ubound(i(:0,:0), 1) /= 2) STOP 23 |
| 50 |
if (ubound(i(:0,:0), 2) /= 2) STOP 24 |
| 51 |
|
| 52 |
if (any(lbound(transpose(i)) /= 1)) STOP 25 |
| 53 |
if (lbound(transpose(i), 1) /= 1) STOP 26 |
| 54 |
if (lbound(transpose(i), 2) /= 1) STOP 27 |
| 55 |
|
| 56 |
if (any(ubound(transpose(i)) /= 3)) STOP 28 |
| 57 |
if (ubound(transpose(i), 1) /= 3) STOP 29 |
| 58 |
if (ubound(transpose(i), 2) /= 3) STOP 30 |
| 59 |
|
| 60 |
if (any(lbound(reshape(i,[2,2])) /= 1)) STOP 31 |
| 61 |
if (lbound(reshape(i,[2,2]), 1) /= 1) STOP 32 |
| 62 |
if (lbound(reshape(i,[2,2]), 2) /= 1) STOP 33 |
| 63 |
|
| 64 |
if (any(ubound(reshape(i,[2,2])) /= 2)) STOP 34 |
| 65 |
if (ubound(reshape(i,[2,2]), 1) /= 2) STOP 35 |
| 66 |
if (ubound(reshape(i,[2,2]), 2) /= 2) STOP 36 |
| 67 |
|
| 68 |
if (any(lbound(cshift(i,-1)) /= 1)) STOP 37 |
| 69 |
if (lbound(cshift(i,-1), 1) /= 1) STOP 38 |
| 70 |
if (lbound(cshift(i,-1), 2) /= 1) STOP 39 |
| 71 |
|
| 72 |
if (any(ubound(cshift(i,-1)) /= 3)) STOP 40 |
| 73 |
if (ubound(cshift(i,-1), 1) /= 3) STOP 41 |
| 74 |
if (ubound(cshift(i,-1), 2) /= 3) STOP 42 |
| 75 |
|
| 76 |
if (any(lbound(eoshift(i,-1)) /= 1)) STOP 43 |
| 77 |
if (lbound(eoshift(i,-1), 1) /= 1) STOP 44 |
| 78 |
if (lbound(eoshift(i,-1), 2) /= 1) STOP 45 |
| 79 |
|
| 80 |
if (any(ubound(eoshift(i,-1)) /= 3)) STOP 46 |
| 81 |
if (ubound(eoshift(i,-1), 1) /= 3) STOP 47 |
| 82 |
if (ubound(eoshift(i,-1), 2) /= 3) STOP 48 |
| 83 |
|
| 84 |
if (any(lbound(spread(i,1,2)) /= 1)) STOP 49 |
| 85 |
if (lbound(spread(i,1,2), 1) /= 1) STOP 50 |
| 86 |
if (lbound(spread(i,1,2), 2) /= 1) STOP 51 |
| 87 |
|
| 88 |
if (any(ubound(spread(i,1,2)) /= [2,3,3])) STOP 52 |
| 89 |
if (ubound(spread(i,1,2), 1) /= 2) STOP 53 |
| 90 |
if (ubound(spread(i,1,2), 2) /= 3) STOP 54 |
| 91 |
if (ubound(spread(i,1,2), 3) /= 3) STOP 55 |
| 92 |
|
| 93 |
if (any(lbound(maxloc(i)) /= 1)) STOP 56 |
| 94 |
if (lbound(maxloc(i), 1) /= 1) STOP 57 |
| 95 |
|
| 96 |
if (any(ubound(maxloc(i)) /= 2)) STOP 58 |
| 97 |
if (ubound(maxloc(i), 1) /= 2) STOP 59 |
| 98 |
|
| 99 |
if (any(lbound(minloc(i)) /= 1)) STOP 60 |
| 100 |
if (lbound(minloc(i), 1) /= 1) STOP 61 |
| 101 |
|
| 102 |
if (any(ubound(minloc(i)) /= 2)) STOP 62 |
| 103 |
if (ubound(minloc(i), 1) /= 2) STOP 63 |
| 104 |
|
| 105 |
if (any(lbound(maxval(i,2)) /= 1)) STOP 64 |
| 106 |
if (lbound(maxval(i,2), 1) /= 1) STOP 65 |
| 107 |
|
| 108 |
if (any(ubound(maxval(i,2)) /= 3)) STOP 66 |
| 109 |
if (ubound(maxval(i,2), 1) /= 3) STOP 67 |
| 110 |
|
| 111 |
if (any(lbound(minval(i,2)) /= 1)) STOP 68 |
| 112 |
if (lbound(minval(i,2), 1) /= 1) STOP 69 |
| 113 |
|
| 114 |
if (any(ubound(minval(i,2)) /= 3)) STOP 70 |
| 115 |
if (ubound(minval(i,2), 1) /= 3) STOP 71 |
| 116 |
|
| 117 |
if (any(lbound(any(i==1,2)) /= 1)) STOP 72 |
| 118 |
if (lbound(any(i==1,2), 1) /= 1) STOP 73 |
| 119 |
|
| 120 |
if (any(ubound(any(i==1,2)) /= 3)) STOP 74 |
| 121 |
if (ubound(any(i==1,2), 1) /= 3) STOP 75 |
| 122 |
|
| 123 |
if (any(lbound(count(i==1,2)) /= 1)) STOP 76 |
| 124 |
if (lbound(count(i==1,2), 1) /= 1) STOP 77 |
| 125 |
|
| 126 |
if (any(ubound(count(i==1,2)) /= 3)) STOP 78 |
| 127 |
if (ubound(count(i==1,2), 1) /= 3) STOP 79 |
| 128 |
|
| 129 |
if (any(lbound(merge(i,i,.true.)) /= 1)) STOP 80 |
| 130 |
if (lbound(merge(i,i,.true.), 1) /= 1) STOP 81 |
| 131 |
if (lbound(merge(i,i,.true.), 2) /= 1) STOP 82 |
| 132 |
|
| 133 |
if (any(ubound(merge(i,i,.true.)) /= 3)) STOP 83 |
| 134 |
if (ubound(merge(i,i,.true.), 1) /= 3) STOP 84 |
| 135 |
if (ubound(merge(i,i,.true.), 2) /= 3) STOP 85 |
| 136 |
|
| 137 |
if (any(lbound(lbound(i)) /= 1)) STOP 86 |
| 138 |
if (lbound(lbound(i), 1) /= 1) STOP 87 |
| 139 |
|
| 140 |
if (any(ubound(lbound(i)) /= 2)) STOP 88 |
| 141 |
if (ubound(lbound(i), 1) /= 2) STOP 89 |
| 142 |
|
| 143 |
if (any(lbound(ubound(i)) /= 1)) STOP 90 |
| 144 |
if (lbound(ubound(i), 1) /= 1) STOP 91 |
| 145 |
|
| 146 |
if (any(ubound(ubound(i)) /= 2)) STOP 92 |
| 147 |
if (ubound(ubound(i), 1) /= 2) STOP 93 |
| 148 |
|
| 149 |
if (any(lbound(shape(i)) /= 1)) STOP 94 |
| 150 |
if (lbound(shape(i), 1) /= 1) STOP 95 |
| 151 |
|
| 152 |
if (any(ubound(shape(i)) /= 2)) STOP 96 |
| 153 |
if (ubound(shape(i), 1) /= 2) STOP 97 |
| 154 |
|
| 155 |
if (any(lbound(product(i,2)) /= 1)) STOP 98 |
| 156 |
if (any(ubound(product(i,2)) /= 3)) STOP 99 |
| 157 |
if (any(lbound(sum(i,2)) /= 1)) STOP 100 |
| 158 |
if (any(ubound(sum(i,2)) /= 3)) STOP 101 |
| 159 |
if (any(lbound(matmul(i,i)) /= 1)) STOP 102 |
| 160 |
if (any(ubound(matmul(i,i)) /= 3)) STOP 103 |
| 161 |
if (any(lbound(pack(i,.true.)) /= 1)) STOP 104 |
| 162 |
if (any(ubound(pack(i,.true.)) /= 9)) STOP 105 |
| 163 |
if (any(lbound(unpack(j,[.true.],[2])) /= 1)) STOP 106 |
| 164 |
if (any(ubound(unpack(j,[.true.],[2])) /= 1)) STOP 107 |
| 165 |
|
| 166 |
call sub1(i,3) |
| 167 |
call sub1(reshape([7,9,4,6,7,9],[3,2]),3) |
| 168 |
call sub2 |
| 169 |
|
| 170 |
contains |
| 171 |
|
| 172 |
subroutine sub1(a,n) |
| 173 |
integer :: n, a(2:n+1,4:*) |
| 174 |
|
| 175 |
if (any([lbound(a,1), lbound(a,2)] /= [2, 4])) STOP 108 |
| 176 |
if (any(lbound(a) /= [2, 4])) STOP 109 |
| 177 |
end subroutine sub1 |
| 178 |
|
| 179 |
subroutine sub2 |
| 180 |
integer :: x(3:2, 1:2) |
| 181 |
|
| 182 |
if (size(x) /= 0) STOP 110 |
| 183 |
if (lbound (x, 1) /= 1 .or. lbound(x, 2) /= 1) STOP 111 |
| 184 |
if (any (lbound (x) /= [1, 1])) STOP 112 |
| 185 |
if (ubound (x, 1) /= 0 .or. ubound(x, 2) /= 2) STOP 113 |
| 186 |
if (any (ubound (x) /= [0, 2])) STOP 114 |
| 187 |
end subroutine sub2 |
| 188 |
|
| 189 |
subroutine sub3 |
| 190 |
integer :: x(4:5, 1:2) |
| 191 |
|
| 192 |
if (size(x) /= 0) STOP 115 |
| 193 |
if (lbound (x, 1) /= 4 .or. lbound(x, 2) /= 1) STOP 116 |
| 194 |
if (any (lbound (x) /= [4, 1])) STOP 117 |
| 195 |
if (ubound (x, 1) /= 4 .or. ubound(x, 2) /= 2) STOP 118 |
| 196 |
if (any (ubound (x) /= [4, 2])) STOP 119 |
| 197 |
end subroutine sub3 |
| 198 |
|
| 199 |
subroutine foo (x,n) |
| 200 |
integer :: x(7,n,2,*), n |
| 201 |
|
| 202 |
if (ubound(x,1) /= 7 .or. ubound(x,2) /= 4 .or. ubound(x,3) /= 2) STOP 120 |
| 203 |
end subroutine foo |
| 204 |
|
| 205 |
subroutine jackal (b, c) |
| 206 |
integer :: b, c |
| 207 |
integer :: soda(b:c, 3:4) |
| 208 |
|
| 209 |
if (b > c) then |
| 210 |
if (size(soda) /= 0) STOP 121 |
| 211 |
if (lbound (soda, 1) /= 1 .or. ubound (soda, 1) /= 0) STOP 122 |
| 212 |
else |
| 213 |
if (size(soda) /= 2*(c-b+1)) STOP 123 |
| 214 |
if (lbound (soda, 1) /= b .or. ubound (soda, 1) /= c) STOP 124 |
| 215 |
end if |
| 216 |
|
| 217 |
if (lbound (soda, 2) /= 3 .or. ubound (soda, 2) /= 4) STOP 125 |
| 218 |
if (any (lbound (soda) /= [lbound(soda,1), lbound(soda,2)])) STOP 126 |
| 219 |
if (any (ubound (soda) /= [ubound(soda,1), ubound(soda,2)])) STOP 127 |
| 220 |
|
| 221 |
end subroutine jackal |
| 222 |
|
| 223 |
end |