xref: /llvm-project/clang/test/OpenMP/target_parallel_for_firstprivate_messages.cpp (revision e04483ee35ba28c089cbbcec97a96b67ce0a035e)
1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s
4 
5 extern int omp_default_mem_alloc;
6 void foo() {
7 }
8 
9 bool foobool(int argc) {
10   return argc;
11 }
12 
13 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14 extern S1 a;
15 class S2 {
16   mutable int a;
17 
18 public:
19   S2() : a(0) {}
20   S2(const S2 &s2) : a(s2.a) {}
21   static float S2s;
22   static const float S2sc;
23 };
24 const float S2::S2sc = 0;
25 const S2 b;
26 const S2 ba[5];
27 class S3 {
28   int a;
29   S3 &operator=(const S3 &s3);
30 
31 public:
32   S3() : a(0) {}
33   S3(const S3 &s3) : a(s3.a) {}
34 };
35 const S3 c;
36 const S3 ca[5];
37 extern const int f;
38 class S4 {
39   int a;
40   S4();
41   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
42 
43 public:
44   S4(int v) : a(v) {}
45 };
46 class S5 {
47   int a;
48   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
49 
50 public:
51   S5() : a(0) {}
52   S5(int v) : a(v) {}
53 };
54 class S6 {
55   int a;
56   S6() : a(0) {}
57 
58 public:
59   S6(const S6 &s6) : a(s6.a) {}
60   S6(int v) : a(v) {}
61 };
62 
63 S3 h;
64 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
65 
66 template <class I, class C>
67 int foomain(int argc, char **argv) {
68   I e(4);
69   C g(5);
70   int i;
71   int &j = i;
72 #pragma omp target parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73   for (int k = 0; k < argc; ++k)
74     ++k;
75 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
76   for (int k = 0; k < argc; ++k)
77     ++k;
78 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}}
79   for (int k = 0; k < argc; ++k)
80     ++k;
81 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
82   for (int k = 0; k < argc; ++k)
83     ++k;
84 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
85   for (int k = 0; k < argc; ++k)
86     ++k;
87 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
88   for (int k = 0; k < argc; ++k)
89     ++k;
90 #pragma omp target parallel for firstprivate(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
91   for (int k = 0; k < argc; ++k)
92     ++k;
93 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
94   for (int k = 0; k < argc; ++k)
95     ++k;
96 #pragma omp target parallel for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
97   for (int k = 0; k < argc; ++k)
98     ++k;
99 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
100   for (int k = 0; k < argc; ++k)
101     ++k;
102 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
103   for (int k = 0; k < argc; ++k)
104     ++k;
105 #pragma omp target parallel for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
106   for (int k = 0; k < argc; ++k)
107     ++k;
108 #pragma omp parallel
109   {
110     int v = 0;
111     int i;
112 #pragma omp target parallel for firstprivate(i)
113     for (int k = 0; k < argc; ++k) {
114       i = k;
115       v += i;
116     }
117   }
118 #pragma omp parallel shared(i)
119 #pragma omp parallel private(i)
120 #pragma omp target parallel for firstprivate(j)
121   for (int k = 0; k < argc; ++k)
122     ++k;
123 #pragma omp target parallel for firstprivate(i)
124   for (int k = 0; k < argc; ++k)
125     ++k;
126 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
127   for (i = 0; i < argc; ++i)
128     foo();
129 #pragma omp parallel private(i)
130 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
131   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
132     foo();
133 #pragma omp parallel reduction(+ : i)
134 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
135   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
136     foo();
137   return 0;
138 }
139 
140 namespace A {
141 double x;
142 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
143 }
144 namespace B {
145 using A::x;
146 }
147 
148 int main(int argc, char **argv) {
149   const int d = 5;
150   const int da[5] = {0};
151   S4 e(4);
152   S5 g(5);
153   S3 m;
154   S6 n(2);
155   int i;
156   int &j = i;
157 #pragma omp target parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
158   for (i = 0; i < argc; ++i)
159     foo();
160 #pragma omp target parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
161   for (i = 0; i < argc; ++i)
162     foo();
163 #pragma omp target parallel for firstprivate() // expected-error {{expected expression}}
164   for (i = 0; i < argc; ++i)
165     foo();
166 #pragma omp target parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
167   for (i = 0; i < argc; ++i)
168     foo();
169 #pragma omp target parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
170   for (i = 0; i < argc; ++i)
171     foo();
172 #pragma omp target parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
173   for (i = 0; i < argc; ++i)
174     foo();
175 #pragma omp target parallel for firstprivate(argc)
176   for (i = 0; i < argc; ++i)
177     foo();
178 #pragma omp target parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
179   for (i = 0; i < argc; ++i)
180     foo();
181 #pragma omp target parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
182   for (i = 0; i < argc; ++i)
183     foo();
184 #pragma omp target parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
185   for (i = 0; i < argc; ++i)
186     foo();
187 #pragma omp target parallel for firstprivate(2 * 2) // expected-error {{expected variable name}}
188   for (i = 0; i < argc; ++i)
189     foo();
190 #pragma omp target parallel for firstprivate(ba) // OK
191   for (i = 0; i < argc; ++i)
192     foo();
193 #pragma omp target parallel for firstprivate(ca) // OK
194   for (i = 0; i < argc; ++i)
195     foo();
196 #pragma omp target parallel for firstprivate(da) // OK
197   for (i = 0; i < argc; ++i)
198     foo();
199   int xa;
200 #pragma omp target parallel for firstprivate(xa) // OK
201   for (i = 0; i < argc; ++i)
202     foo();
203 #pragma omp target parallel for firstprivate(S2::S2s) // OK
204   for (i = 0; i < argc; ++i)
205     foo();
206 #pragma omp target parallel for firstprivate(S2::S2sc) // OK
207   for (i = 0; i < argc; ++i)
208     foo();
209 #pragma omp target parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp target parallel for'}}
210   for (i = 0; i < argc; ++i)
211     foo();
212 #pragma omp target parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
213   for (i = 0; i < argc; ++i)
214     foo();
215 #pragma omp target parallel for firstprivate(m) // OK
216   for (i = 0; i < argc; ++i)
217     foo();
218 #pragma omp target parallel for firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
219   for (i = 0; i < argc; ++i)
220     foo();
221 #pragma omp target parallel for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
222   for (i = 0; i < argc; ++i)
223     foo();
224 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
225   for (i = 0; i < argc; ++i)    // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
226     foo();
227 #pragma omp parallel shared(xa)
228 #pragma omp target parallel for firstprivate(xa) // OK: may be firstprivate
229   for (i = 0; i < argc; ++i)
230     foo();
231 #pragma omp target parallel for firstprivate(j)
232   for (i = 0; i < argc; ++i)
233     foo();
234 #pragma omp target parallel for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
235   for (i = 0; i < argc; ++i)
236     foo();
237 #pragma omp target parallel for lastprivate(n) firstprivate(n) // OK
238   for (i = 0; i < argc; ++i)
239     foo();
240 #pragma omp parallel
241   {
242     int v = 0;
243     int i;
244 #pragma omp target parallel for firstprivate(i)
245     for (int k = 0; k < argc; ++k) {
246       i = k;
247       v += i;
248     }
249   }
250 #pragma omp parallel private(i)
251 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
252   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
253     foo();
254 #pragma omp parallel reduction(+ : i)
255 #pragma omp target parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
256   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
257     foo();
258   static int si;
259 #pragma omp target parallel for firstprivate(si) // OK
260   for (i = 0; i < argc; ++i)
261     si = i + 1;
262 
263   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
264 }
265