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