• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -verify -fopenmp %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;
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 {{firstprivate variable must be shared}}
113     foo();
114     v += i;
115   }
116 #pragma omp parallel shared(i)
117 #pragma omp parallel private(i)
118 #pragma omp single firstprivate(j)
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 
135 namespace A {
136 double x;
137 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
138 }
139 namespace B {
140 using A::x;
141 }
142 
main(int argc,char ** argv)143 int main(int argc, char **argv) {
144   const int d = 5;
145   const int da[5] = {0};
146   S4 e(4);
147   S5 g(5);
148   S3 m;
149   S6 n(2);
150   int i;
151   int &j = i;
152 #pragma omp parallel
153 #pragma omp single firstprivate // expected-error {{expected '(' after 'firstprivate'}}
154   foo();
155 #pragma omp parallel
156 #pragma omp single firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
157   foo();
158 #pragma omp parallel
159 #pragma omp single firstprivate() // expected-error {{expected expression}}
160   foo();
161 #pragma omp parallel
162 #pragma omp single firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
163   foo();
164 #pragma omp parallel
165 #pragma omp single firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
166   foo();
167 #pragma omp parallel
168 #pragma omp single firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
169   foo();
170 #pragma omp parallel
171 #pragma omp single firstprivate(argc)
172   foo();
173 #pragma omp parallel
174 #pragma omp single firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
175   foo();
176 #pragma omp parallel
177 #pragma omp single firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
178   foo();
179 #pragma omp parallel
180 #pragma omp single firstprivate(argv[1]) // expected-error {{expected variable name}}
181   foo();
182 #pragma omp parallel
183 #pragma omp single firstprivate(2 * 2) // expected-error {{expected variable name}}
184   foo();
185 #pragma omp parallel
186 #pragma omp single firstprivate(ba) // OK
187   foo();
188 #pragma omp parallel
189 #pragma omp single firstprivate(ca) // OK
190   foo();
191 #pragma omp parallel
192 #pragma omp single firstprivate(da) // OK
193   foo();
194   int xa;
195 #pragma omp parallel
196 #pragma omp single firstprivate(xa) // OK
197   foo();
198 #pragma omp parallel
199 #pragma omp single firstprivate(S2::S2s) // OK
200   foo();
201 #pragma omp parallel
202 #pragma omp single firstprivate(S2::S2sc) // OK
203   foo();
204 #pragma omp parallel
205 #pragma omp single safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp single'}}
206   foo();
207 #pragma omp parallel
208 #pragma omp single firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
209   foo();
210 #pragma omp parallel
211 #pragma omp single firstprivate(m) // OK
212   foo();
213 #pragma omp parallel
214 #pragma omp single firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
215   foo();
216 #pragma omp parallel
217 #pragma omp single private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
218   foo();
219 #pragma omp parallel shared(xa)
220 #pragma omp single firstprivate(xa) // OK: may be firstprivate
221   foo();
222 #pragma omp parallel
223 #pragma omp single firstprivate(j)
224   foo();
225 #pragma omp parallel
226 #pragma omp single firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
227   foo();
228 #pragma omp parallel
229 #pragma omp single firstprivate(n) // OK
230   foo();
231 #pragma omp parallel
232   {
233     int v = 0;
234     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?}}
235 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
236     foo();
237     v += i;
238   }
239 #pragma omp parallel private(i)    // expected-note {{defined as private}}
240 #pragma omp single firstprivate(i) // expected-error {{firstprivate variable must be shared}}
241   foo();
242 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
243 #pragma omp single firstprivate(i)    // expected-error {{firstprivate variable must be shared}}
244   foo();
245   static int t;
246 #pragma omp single firstprivate(t)    // OK
247   foo();
248 
249   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
250 }
251