! { dg-do run }
module target6
contains
subroutine foo (p, v, w, n)
double precision, pointer :: p(:), v(:), w(:)
double precision :: q(n)
integer :: i, n
!$omp target data if (n > 256) map (to: v(1:n), w(:n)) map (from: p(1:n), q)
!$omp target if (n > 256)
!$omp parallel do simd
do i = 1, n
p(i) = v(i) * w(i)
q(i) = p(i)
end do
!$omp end target
!$omp target update if (n > 256) from (p)
if (p(i) /= i * iand (i, 63)) STOP 1
v(i) = v(i) + 1
!$omp target update if (n > 256) to (v(1:n))
!$omp end target data
if (q(i) /= (v(i) - 1) * w(i)) STOP 2
if (p(i) /= q(i) + w(i)) STOP 3
end subroutine
end module target6
use target6, only : foo
integer :: n, i
n = 10000
allocate (p(n), v(n), w(n))
v(i) = i
w(i) = iand (i, 63)
call foo (p, v, w, n)
if (p(i) /= (i + 1) * iand (i, 63)) STOP 4
deallocate (p, v, w)
end