1! { dg-do run }
2! { dg-require-effective-target tls_runtime }
3
4  use omp_lib
5  integer, allocatable, save :: a, b(:), c(:,:)
6  integer :: p
7!$omp threadprivate (a, b, c)
8  if (allocated (a) .or. allocated (b) .or. allocated (c)) STOP 1
9
10  call omp_set_dynamic (.false.)
11  call omp_set_num_threads (4)
12
13!$omp parallel num_threads (4)
14  if (allocated (a) .or. allocated (b) .or. allocated (c)) STOP 2
15!$omp end parallel
16
17  allocate (a, b(6:9), c(3, 8:9))
18  a = 4
19  b = 5
20  c = 6
21  if (.not.allocated (a)) STOP 3
22  if (.not.allocated (b) .or. size (b) /= 4) STOP 4
23  if (lbound (b, 1) /= 6 .or. ubound (b, 1) /= 9) STOP 5
24  if (.not.allocated (c) .or. size (c) /= 6) STOP 6
25  if (size (c, 1) /= 3 .or. size (c, 2) /= 2) STOP 7
26  if (lbound (c, 1) /= 1 .or. ubound (c, 1) /= 3) STOP 8
27  if (lbound (c, 2) /= 8 .or. ubound (c, 2) /= 9) STOP 9
28
29!$omp parallel num_threads (4) copyin (a, b, c) private (p)
30  p = omp_get_thread_num ()
31  if (.not.allocated (a)) STOP 10
32  if (.not.allocated (b) .or. size (b) /= 4) STOP 11
33  if (lbound (b, 1) /= 6 .or. ubound (b, 1) /= 9) STOP 12
34  if (.not.allocated (c) .or. size (c) /= 6) STOP 13
35  if (size (c, 1) /= 3 .or. size (c, 2) /= 2) STOP 14
36  if (lbound (c, 1) /= 1 .or. ubound (c, 1) /= 3) STOP 15
37  if (lbound (c, 2) /= 8 .or. ubound (c, 2) /= 9) STOP 16
38  if (a /= 4 .or. any (b /= 5) .or. any (c /= 6)) STOP 17
39  deallocate (a, b, c)
40  if (allocated (a) .or. allocated (b) .or. allocated (c)) STOP 18
41  allocate (a, b(p:9), c(3, p:7))
42  a = p
43  b = p
44  c = p
45  if (.not.allocated (a)) STOP 19
46  if (.not.allocated (b) .or. size (b) /= (10 - p)) STOP 20
47  if (lbound (b, 1) /= p .or. ubound (b, 1) /= 9) STOP 21
48  if (.not.allocated (c) .or. size (c) /= (3 * (8 - p))) STOP 22
49  if (size (c, 1) /= 3 .or. size (c, 2) /= (8 - p)) STOP 23
50  if (lbound (c, 1) /= 1 .or. ubound (c, 1) /= 3) STOP 24
51  if (lbound (c, 2) /= p .or. ubound (c, 2) /= 7) STOP 25
52  if (a /= p .or. any (b /= p) .or. any (c /= p)) STOP 26
53!$omp end parallel
54
55!$omp parallel num_threads (4) copyin (a, b, c)
56  if (.not.allocated (a)) STOP 27
57  if (.not.allocated (b) .or. size (b) /= 10) STOP 28
58  if (lbound (b, 1) /= 0 .or. ubound (b, 1) /= 9) STOP 29
59  if (.not.allocated (c) .or. size (c) /= 24) STOP 30
60  if (size (c, 1) /= 3 .or. size (c, 2) /= 8) STOP 31
61  if (lbound (c, 1) /= 1 .or. ubound (c, 1) /= 3) STOP 32
62  if (lbound (c, 2) /= 0 .or. ubound (c, 2) /= 7) STOP 33
63  if (a /= 0 .or. any (b /= 0) .or. any (c /= 0)) STOP 34
64!$omp end parallel
65
66  deallocate (a, b, c)
67  if (allocated (a) .or. allocated (b) .or. allocated (c)) STOP 35
68
69!$omp parallel num_threads (4) copyin (a, b, c)
70  if (allocated (a) .or. allocated (b) .or. allocated (c)) STOP 36
71!$omp end parallel
72end
73