| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Check that the evaluation of MINLOC's BACK argument is made only once |
| 4 |
! before the scalarisation loops. |
| 5 |
|
| 6 |
program p |
| 7 |
implicit none |
| 8 |
integer, parameter :: data10(*) = (/ 2, 5, 2, 3, 3, 5, 3, 6, 0, 1 /) |
| 9 |
logical, parameter :: mask10(*) = (/ .false., .true., .false., & |
| 10 |
.false., .true., .true., & |
| 11 |
.true. , .true., .false., & |
| 12 |
.false. /) |
| 13 |
integer :: calls_count = 0 |
| 14 |
call check_int_const_shape |
| 15 |
call check_int_const_shape_scalar_mask |
| 16 |
call check_int_const_shape_array_mask |
| 17 |
call check_int_const_shape_optional_mask_present |
| 18 |
call check_int_const_shape_optional_mask_absent |
| 19 |
call check_int_const_shape_empty |
| 20 |
call check_int_alloc |
| 21 |
call check_int_alloc_scalar_mask |
| 22 |
call check_int_alloc_array_mask |
| 23 |
call check_int_alloc_empty |
| 24 |
call check_real_const_shape |
| 25 |
call check_real_const_shape_scalar_mask |
| 26 |
call check_real_const_shape_array_mask |
| 27 |
call check_real_const_shape_optional_mask_present |
| 28 |
call check_real_const_shape_optional_mask_absent |
| 29 |
call check_real_const_shape_empty |
| 30 |
call check_real_alloc |
| 31 |
call check_real_alloc_scalar_mask |
| 32 |
call check_real_alloc_array_mask |
| 33 |
call check_real_alloc_empty |
| 34 |
contains |
| 35 |
function get_scalar_false() |
| 36 |
logical :: get_scalar_false |
| 37 |
calls_count = calls_count + 1 |
| 38 |
get_scalar_false = .false. |
| 39 |
end function |
| 40 |
subroutine check_int_const_shape() |
| 41 |
integer :: a(10) |
| 42 |
logical :: m(10) |
| 43 |
integer :: r |
| 44 |
a = data10 |
| 45 |
calls_count = 0 |
| 46 |
r = minloc(a, dim = 1, back = get_scalar_false()) |
| 47 |
if (calls_count /= 1) stop 11 |
| 48 |
end subroutine |
| 49 |
subroutine check_int_const_shape_scalar_mask() |
| 50 |
integer :: a(10) |
| 51 |
integer :: r |
| 52 |
a = data10 |
| 53 |
calls_count = 0 |
| 54 |
! We only check the case of a .true. mask. |
| 55 |
! If the mask is .false., the back argument is not necessary to deduce |
| 56 |
! the value returned by minloc, so the compiler is free to elide it, |
| 57 |
! and the value of calls_count is undefined in that case. |
| 58 |
r = minloc(a, dim = 1, mask = .true., back = get_scalar_false()) |
| 59 |
if (calls_count /= 1) stop 18 |
| 60 |
end subroutine |
| 61 |
subroutine check_int_const_shape_array_mask() |
| 62 |
integer :: a(10) |
| 63 |
logical :: m(10) |
| 64 |
integer :: r |
| 65 |
a = data10 |
| 66 |
m = mask10 |
| 67 |
calls_count = 0 |
| 68 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 69 |
if (calls_count /= 1) stop 32 |
| 70 |
end subroutine |
| 71 |
subroutine call_minloc_int(r, a, m, b) |
| 72 |
integer :: a(:) |
| 73 |
logical, optional :: m(:) |
| 74 |
logical, optional :: b |
| 75 |
integer :: r |
| 76 |
r = minloc(a, dim = 1, mask = m, back = b) |
| 77 |
end subroutine |
| 78 |
subroutine check_int_const_shape_optional_mask_present() |
| 79 |
integer :: a(10) |
| 80 |
logical :: m(10) |
| 81 |
integer :: r |
| 82 |
a = data10 |
| 83 |
m = mask10 |
| 84 |
calls_count = 0 |
| 85 |
call call_minloc_int(r, a, m, get_scalar_false()) |
| 86 |
if (calls_count /= 1) stop 39 |
| 87 |
end subroutine |
| 88 |
subroutine check_int_const_shape_optional_mask_absent() |
| 89 |
integer :: a(10) |
| 90 |
integer :: r |
| 91 |
a = data10 |
| 92 |
calls_count = 0 |
| 93 |
call call_minloc_int(r, a, b = get_scalar_false()) |
| 94 |
if (calls_count /= 1) stop 46 |
| 95 |
end subroutine |
| 96 |
subroutine check_int_const_shape_empty() |
| 97 |
integer :: a(0) |
| 98 |
logical :: m(0) |
| 99 |
integer :: r |
| 100 |
a = (/ integer:: /) |
| 101 |
m = (/ logical:: /) |
| 102 |
calls_count = 0 |
| 103 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 104 |
if (calls_count /= 1) stop 53 |
| 105 |
end subroutine |
| 106 |
subroutine check_int_alloc() |
| 107 |
integer, allocatable :: a(:) |
| 108 |
integer :: r |
| 109 |
allocate(a(10)) |
| 110 |
a(:) = data10 |
| 111 |
calls_count = 0 |
| 112 |
r = minloc(a, dim = 1, back = get_scalar_false()) |
| 113 |
if (calls_count /= 1) stop 60 |
| 114 |
end subroutine |
| 115 |
subroutine check_int_alloc_scalar_mask() |
| 116 |
integer, allocatable :: a(:) |
| 117 |
integer :: r |
| 118 |
allocate(a(10)) |
| 119 |
a(:) = data10 |
| 120 |
calls_count = 0 |
| 121 |
! We only check the case of a .true. mask. |
| 122 |
! If the mask is .false., the back argument is not necessary to deduce |
| 123 |
! the value returned by minloc, so the compiler is free to elide it, |
| 124 |
! and the value of calls_count is undefined in that case. |
| 125 |
r = minloc(a, dim = 1, mask = .true., back = get_scalar_false()) |
| 126 |
if (calls_count /= 1) stop 67 |
| 127 |
end subroutine |
| 128 |
subroutine check_int_alloc_array_mask() |
| 129 |
integer, allocatable :: a(:) |
| 130 |
logical, allocatable :: m(:) |
| 131 |
integer :: r |
| 132 |
allocate(a(10), m(10)) |
| 133 |
a(:) = data10 |
| 134 |
m(:) = mask10 |
| 135 |
calls_count = 0 |
| 136 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 137 |
if (calls_count /= 1) stop 81 |
| 138 |
end subroutine |
| 139 |
subroutine check_int_alloc_empty() |
| 140 |
integer, allocatable :: a(:) |
| 141 |
logical, allocatable :: m(:) |
| 142 |
integer :: r |
| 143 |
allocate(a(0), m(0)) |
| 144 |
calls_count = 0 |
| 145 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 146 |
if (calls_count /= 1) stop 88 |
| 147 |
end subroutine |
| 148 |
subroutine check_real_const_shape() |
| 149 |
real :: a(10) |
| 150 |
integer :: r |
| 151 |
a = (/ real:: data10 /) |
| 152 |
calls_count = 0 |
| 153 |
r = minloc(a, dim = 1, back = get_scalar_false()) |
| 154 |
if (calls_count /= 1) stop 95 |
| 155 |
end subroutine |
| 156 |
subroutine check_real_const_shape_scalar_mask() |
| 157 |
real :: a(10) |
| 158 |
integer :: r |
| 159 |
a = (/ real:: data10 /) |
| 160 |
calls_count = 0 |
| 161 |
! We only check the case of a .true. mask. |
| 162 |
! If the mask is .false., the back argument is not necessary to deduce |
| 163 |
! the value returned by minloc, so the compiler is free to elide it, |
| 164 |
! and the value of calls_count is undefined in that case. |
| 165 |
r = minloc(a, dim = 1, mask = .true., back = get_scalar_false()) |
| 166 |
if (calls_count /= 1) stop 102 |
| 167 |
end subroutine |
| 168 |
subroutine check_real_const_shape_array_mask() |
| 169 |
real :: a(10) |
| 170 |
logical :: m(10) |
| 171 |
integer :: r |
| 172 |
a = (/ real:: data10 /) |
| 173 |
m = mask10 |
| 174 |
calls_count = 0 |
| 175 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 176 |
if (calls_count /= 1) stop 116 |
| 177 |
end subroutine |
| 178 |
subroutine call_minloc_real(r, a, m, b) |
| 179 |
real :: a(:) |
| 180 |
logical, optional :: m(:) |
| 181 |
logical, optional :: b |
| 182 |
integer :: r |
| 183 |
r = minloc(a, dim = 1, mask = m, back = b) |
| 184 |
end subroutine |
| 185 |
subroutine check_real_const_shape_optional_mask_present() |
| 186 |
real :: a(10) |
| 187 |
logical :: m(10) |
| 188 |
integer :: r |
| 189 |
a = (/ real:: data10 /) |
| 190 |
m = mask10 |
| 191 |
calls_count = 0 |
| 192 |
call call_minloc_real(r, a, m, b = get_scalar_false()) |
| 193 |
if (calls_count /= 1) stop 123 |
| 194 |
end subroutine |
| 195 |
subroutine check_real_const_shape_optional_mask_absent() |
| 196 |
real :: a(10) |
| 197 |
integer :: r |
| 198 |
a = (/ real:: data10 /) |
| 199 |
calls_count = 0 |
| 200 |
call call_minloc_real(r, a, b = get_scalar_false()) |
| 201 |
if (calls_count /= 1) stop 130 |
| 202 |
end subroutine |
| 203 |
subroutine check_real_const_shape_empty() |
| 204 |
real :: a(0) |
| 205 |
logical :: m(0) |
| 206 |
integer :: r |
| 207 |
a = (/ real:: /) |
| 208 |
m = (/ logical:: /) |
| 209 |
calls_count = 0 |
| 210 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 211 |
if (calls_count /= 1) stop 137 |
| 212 |
end subroutine |
| 213 |
subroutine check_real_alloc() |
| 214 |
real, allocatable :: a(:) |
| 215 |
integer :: r |
| 216 |
allocate(a(10)) |
| 217 |
a(:) = (/ real:: data10 /) |
| 218 |
calls_count = 0 |
| 219 |
r = minloc(a, dim = 1, back = get_scalar_false()) |
| 220 |
if (calls_count /= 1) stop 144 |
| 221 |
end subroutine |
| 222 |
subroutine check_real_alloc_scalar_mask() |
| 223 |
real, allocatable :: a(:) |
| 224 |
integer :: r |
| 225 |
allocate(a(10)) |
| 226 |
a(:) = (/ real:: data10 /) |
| 227 |
calls_count = 0 |
| 228 |
! We only check the case of a .true. mask. |
| 229 |
! If the mask is .false., the back argument is not necessary to deduce |
| 230 |
! the value returned by minloc, so the compiler is free to elide it, |
| 231 |
! and the value of calls_count is undefined in that case. |
| 232 |
r = minloc(a, dim = 1, mask = .true., back = get_scalar_false()) |
| 233 |
if (calls_count /= 1) stop 151 |
| 234 |
end subroutine |
| 235 |
subroutine check_real_alloc_array_mask() |
| 236 |
real, allocatable :: a(:) |
| 237 |
logical, allocatable :: m(:) |
| 238 |
integer :: r |
| 239 |
allocate(a(10), m(10)) |
| 240 |
a(:) = (/ real:: data10 /) |
| 241 |
m(:) = mask10 |
| 242 |
calls_count = 0 |
| 243 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 244 |
if (calls_count /= 1) stop 165 |
| 245 |
end subroutine |
| 246 |
subroutine check_real_alloc_empty() |
| 247 |
real, allocatable :: a(:) |
| 248 |
logical, allocatable :: m(:) |
| 249 |
integer :: r |
| 250 |
allocate(a(0), m(0)) |
| 251 |
a(:) = (/ real:: /) |
| 252 |
m(:) = (/ logical :: /) |
| 253 |
calls_count = 0 |
| 254 |
r = minloc(a, dim = 1, mask = m, back = get_scalar_false()) |
| 255 |
if (calls_count /= 1) stop 172 |
| 256 |
end subroutine |
| 257 |
end program p |