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