1*6bd8dc91SMike Rice // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fopenmp \
2*6bd8dc91SMike Rice // RUN:  -fopenmp-version=51 -Wuninitialized %s
3*6bd8dc91SMike Rice 
foo()4*6bd8dc91SMike Rice void foo()
5*6bd8dc91SMike Rice {
6*6bd8dc91SMike Rice   int i,j,k;
7*6bd8dc91SMike Rice   int z;
8*6bd8dc91SMike Rice 
9*6bd8dc91SMike Rice   // expected-error@+2 {{statement after '#pragma omp target teams loop' must be a for loop}}
10*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
11*6bd8dc91SMike Rice   i = 0;
12*6bd8dc91SMike Rice 
13*6bd8dc91SMike Rice   // OpenMP 5.1 [2.22 Nesting of regions]
14*6bd8dc91SMike Rice   //
15*6bd8dc91SMike Rice   // A barrier region may not be closely nested inside a worksharing, loop,
16*6bd8dc91SMike Rice   // task, taskloop, critical, ordered, atomic, or masked region.
17*6bd8dc91SMike Rice 
18*6bd8dc91SMike Rice   // expected-error@+3 {{region cannot be closely nested inside 'target teams loop' region}}
19*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
20*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
21*6bd8dc91SMike Rice     #pragma omp barrier
22*6bd8dc91SMike Rice   }
23*6bd8dc91SMike Rice 
24*6bd8dc91SMike Rice   // A masked region may not be closely nested inside a worksharing, loop,
25*6bd8dc91SMike Rice   // atomic, task, or taskloop region.
26*6bd8dc91SMike Rice 
27*6bd8dc91SMike Rice   // expected-error@+3 {{region cannot be closely nested inside 'target teams loop' region}}
28*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
29*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
30*6bd8dc91SMike Rice     #pragma omp masked filter(2)
31*6bd8dc91SMike Rice     { }
32*6bd8dc91SMike Rice   }
33*6bd8dc91SMike Rice 
34*6bd8dc91SMike Rice   // An ordered region that corresponds to an ordered construct without any
35*6bd8dc91SMike Rice   // clause or with the threads or depend clause may not be closely nested
36*6bd8dc91SMike Rice   // inside a critical, ordered, loop, atomic, task, or taskloop region.
37*6bd8dc91SMike Rice 
38*6bd8dc91SMike Rice   // expected-error@+3 {{region cannot be closely nested inside 'target teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
39*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
40*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
41*6bd8dc91SMike Rice     #pragma omp ordered
42*6bd8dc91SMike Rice     { }
43*6bd8dc91SMike Rice   }
44*6bd8dc91SMike Rice 
45*6bd8dc91SMike Rice   // expected-error@+3 {{region cannot be closely nested inside 'target teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
46*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
47*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
48*6bd8dc91SMike Rice     #pragma omp ordered threads
49*6bd8dc91SMike Rice     { }
50*6bd8dc91SMike Rice   }
51*6bd8dc91SMike Rice 
52*6bd8dc91SMike Rice   // expected-error@+3 {{region cannot be closely nested inside 'target teams loop' region; perhaps you forget to enclose 'omp ordered' directive into a for or a parallel for region with 'ordered' clause?}}
53*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread)
54*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
55*6bd8dc91SMike Rice     #pragma omp ordered depend(source)
56*6bd8dc91SMike Rice   }
57*6bd8dc91SMike Rice 
58*6bd8dc91SMike Rice   // bind clause
59*6bd8dc91SMike Rice 
60*6bd8dc91SMike Rice   // expected-error@+1 {{directive '#pragma omp target teams loop' cannot contain more than one 'bind' clause}}
61*6bd8dc91SMike Rice   #pragma omp target teams loop bind(thread) bind(thread)
62*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
63*6bd8dc91SMike Rice   }
64*6bd8dc91SMike Rice 
65*6bd8dc91SMike Rice   // expected-error@+1 {{expected 'teams', 'parallel' or 'thread' in OpenMP clause 'bind'}}
66*6bd8dc91SMike Rice   #pragma omp target teams loop bind(other)
67*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
68*6bd8dc91SMike Rice   }
69*6bd8dc91SMike Rice 
70*6bd8dc91SMike Rice   // collapse clause
71*6bd8dc91SMike Rice 
72*6bd8dc91SMike Rice   // expected-error@+4 {{expected 2 for loops after '#pragma omp target teams loop', but found only 1}}
73*6bd8dc91SMike Rice   // expected-note@+1 {{as specified in 'collapse' clause}}
74*6bd8dc91SMike Rice   #pragma omp target teams loop collapse(2) bind(thread)
75*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
76*6bd8dc91SMike Rice     z = i+11;
77*6bd8dc91SMike Rice 
78*6bd8dc91SMike Rice   // expected-error@+1 {{directive '#pragma omp target teams loop' cannot contain more than one 'collapse' clause}}
79*6bd8dc91SMike Rice   #pragma omp target teams loop collapse(2) collapse(2) bind(thread)
80*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
81*6bd8dc91SMike Rice     for (j=0; j<1000; ++j)
82*6bd8dc91SMike Rice       z = i+j+11;
83*6bd8dc91SMike Rice 
84*6bd8dc91SMike Rice   // order clause
85*6bd8dc91SMike Rice 
86*6bd8dc91SMike Rice   // expected-error@+1 {{expected 'concurrent' in OpenMP clause 'order'}}
87*6bd8dc91SMike Rice   #pragma omp target teams loop order(foo) bind(thread)
88*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
89*6bd8dc91SMike Rice     z = i+11;
90*6bd8dc91SMike Rice 
91*6bd8dc91SMike Rice   // private clause
92*6bd8dc91SMike Rice 
93*6bd8dc91SMike Rice   // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
94*6bd8dc91SMike Rice   #pragma omp target teams loop private(undef_var) bind(thread)
95*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
96*6bd8dc91SMike Rice     z = i+11;
97*6bd8dc91SMike Rice 
98*6bd8dc91SMike Rice   // lastprivate
99*6bd8dc91SMike Rice 
100*6bd8dc91SMike Rice   // A list item may not appear in a lastprivate clause unless it is the loop
101*6bd8dc91SMike Rice   // iteration variable of a loop that is associated with the construct.
102*6bd8dc91SMike Rice 
103*6bd8dc91SMike Rice   // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target teams loop' directives}}
104*6bd8dc91SMike Rice   #pragma omp target teams loop lastprivate(z) bind(thread)
105*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
106*6bd8dc91SMike Rice     z = i+11;
107*6bd8dc91SMike Rice   }
108*6bd8dc91SMike Rice 
109*6bd8dc91SMike Rice   // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target teams loop' directives}}
110*6bd8dc91SMike Rice   #pragma omp target teams loop lastprivate(k) collapse(2) bind(thread)
111*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
112*6bd8dc91SMike Rice     for (j=0; j<1000; ++j)
113*6bd8dc91SMike Rice       for (k=0; k<1000; ++k)
114*6bd8dc91SMike Rice         z = i+j+k+11;
115*6bd8dc91SMike Rice 
116*6bd8dc91SMike Rice   // reduction
117*6bd8dc91SMike Rice 
118*6bd8dc91SMike Rice   // expected-error@+1 {{use of undeclared identifier 'undef_var'}}
119*6bd8dc91SMike Rice   #pragma omp target teams loop reduction(+:undef_var) bind(thread)
120*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
121*6bd8dc91SMike Rice     z = i+11;
122*6bd8dc91SMike Rice 
123*6bd8dc91SMike Rice   // nowait
124*6bd8dc91SMike Rice 
125*6bd8dc91SMike Rice   // expected-error@+1 {{directive '#pragma omp target teams loop' cannot contain more than one 'nowait' clause}}
126*6bd8dc91SMike Rice   #pragma omp target teams loop nowait nowait
127*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
128*6bd8dc91SMike Rice     z = i+11;
129*6bd8dc91SMike Rice 
130*6bd8dc91SMike Rice }
131*6bd8dc91SMike Rice 
132*6bd8dc91SMike Rice template <typename T, int C>
templ_test(T t)133*6bd8dc91SMike Rice void templ_test(T t) {
134*6bd8dc91SMike Rice   T i,z;
135*6bd8dc91SMike Rice 
136*6bd8dc91SMike Rice   // expected-error@+4 {{expected 2 for loops after '#pragma omp target teams loop', but found only 1}}
137*6bd8dc91SMike Rice   // expected-note@+1 {{as specified in 'collapse' clause}}
138*6bd8dc91SMike Rice   #pragma omp target teams loop collapse(C) bind(thread)
139*6bd8dc91SMike Rice   for (i=0; i<1000; ++i)
140*6bd8dc91SMike Rice     z = i+11;
141*6bd8dc91SMike Rice 
142*6bd8dc91SMike Rice   // expected-error@+1 {{only loop iteration variables are allowed in 'lastprivate' clause in 'omp target teams loop' directives}}
143*6bd8dc91SMike Rice   #pragma omp target teams loop lastprivate(z) bind(thread)
144*6bd8dc91SMike Rice   for (i=0; i<1000; ++i) {
145*6bd8dc91SMike Rice     z = i+11;
146*6bd8dc91SMike Rice   }
147*6bd8dc91SMike Rice }
148*6bd8dc91SMike Rice 
bar()149*6bd8dc91SMike Rice void bar()
150*6bd8dc91SMike Rice {
151*6bd8dc91SMike Rice   templ_test<int, 2>(16); // expected-note {{in instantiation of function template specialization 'templ_test<int, 2>' requested here}}
152*6bd8dc91SMike Rice }
153