1! { dg-do run }
2!
3! PR fortran/94690
4! PR middle-end/66199
5
6module m
7  implicit none
8  integer u(1024), v(1024), w(1024)
9  !$omp declare target (u, v, w)
10
11contains
12
13integer function f2 (a, b, c)
14  integer :: a, b, c, d, e
15  !$omp target map(from: d, e)
16  !$omp teams default(none) firstprivate (a, b, c) shared(d, e, u, v, w)
17  !$omp distribute lastprivate(d, e)
18  do d = a, b-1
19    u(d) = v(d) + w(d)
20    e = c + d * 5
21  end do
22  !$omp end teams
23  !$omp end target
24  f2 = d + e
25end
26
27integer function f3 (a1, b1, a2, b2)
28  integer :: a1, b1, a2, b2, d1, d2
29  !$omp target map(from: d1, d2)
30  !$omp teams default(none) shared(a1, b1, a2, b2, d1, d2, u, v, w)
31  !$omp distribute firstprivate (a1, b1, a2, b2) lastprivate(d1, d2) collapse(2)
32  do d1 = a1, b1-1
33    do d2 = a2, b2-1
34      u(d1 * 32 + d2) = v(d1 * 32 + d2) + w(d1 * 32 + d2)
35    end do
36  end do
37  !$omp end teams
38  !$omp end target
39  f3 = d1 + d2
40end
41end module
42
43use m
44  if (f2 (0, 1024, 17) /= 1024 + (17 + 5 * 1023)) stop 1
45  if (f3 (0, 32, 0, 32) /= 64) stop 2
46end
47