1 // RUN: %clang_cc1 -verify -fopenmp %s 2 3 void foo() { 4 } 5 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: 16 S2() : a(0) {} 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: 29 S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}} 30 S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}} 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: 41 S4(int v) : a(v) {} 42 }; 43 class S5 { 44 int a; 45 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}} 46 47 public: 48 S5() : a(0) {} 49 S5(int v) : a(v) {} 50 }; 51 class S6 { 52 int a; 53 S6() : a(0) {} 54 55 public: 56 S6(const S6 &s6) : a(s6.a) {} 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> 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 for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 71 for (int k = 0; k < argc; ++k) 72 ++k; 73 #pragma omp parallel 74 #pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 75 for (int k = 0; k < argc; ++k) 76 ++k; 77 #pragma omp parallel 78 #pragma omp for firstprivate() // expected-error {{expected expression}} 79 for (int k = 0; k < argc; ++k) 80 ++k; 81 #pragma omp parallel 82 #pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 83 for (int k = 0; k < argc; ++k) 84 ++k; 85 #pragma omp parallel 86 #pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 87 for (int k = 0; k < argc; ++k) 88 ++k; 89 #pragma omp parallel 90 #pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 91 for (int k = 0; k < argc; ++k) 92 ++k; 93 #pragma omp parallel 94 #pragma omp for firstprivate(argc) 95 for (int k = 0; k < argc; ++k) 96 ++k; 97 #pragma omp parallel 98 #pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 99 for (int k = 0; k < argc; ++k) 100 ++k; 101 #pragma omp parallel 102 #pragma omp for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} 103 for (int k = 0; k < argc; ++k) 104 ++k; 105 #pragma omp parallel 106 #pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}} 107 for (int k = 0; k < argc; ++k) 108 ++k; 109 #pragma omp parallel 110 #pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 111 for (int k = 0; k < argc; ++k) 112 ++k; 113 #pragma omp parallel 114 #pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 115 for (int k = 0; k < argc; ++k) 116 ++k; 117 #pragma omp parallel 118 #pragma omp for linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp for'}} 119 for (int k = 0; k < argc; ++k) 120 ++k; 121 #pragma omp parallel 122 { 123 int v = 0; 124 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}} 125 #pragma omp for firstprivate(i) // expected-error {{private variable cannot be firstprivate}} 126 for (int k = 0; k < argc; ++k) { 127 i = k; 128 v += i; 129 } 130 } 131 #pragma omp parallel shared(i) 132 #pragma omp parallel private(i) 133 #pragma omp for firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} 134 for (int k = 0; k < argc; ++k) 135 ++k; 136 #pragma omp parallel 137 #pragma omp for firstprivate(i) 138 for (int k = 0; k < argc; ++k) 139 ++k; 140 #pragma omp parallel 141 #pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 142 for (i = 0; i < argc; ++i) 143 foo(); 144 #pragma omp parallel private(i) // expected-note {{defined as private}} 145 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 146 for (i = 0; i < argc; ++i) 147 foo(); 148 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 149 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 150 for (i = 0; i < argc; ++i) 151 foo(); 152 return 0; 153 } 154 155 void bar(S4 a[2]) { 156 #pragma omp parallel 157 #pragma omp for firstprivate(a) 158 for (int i = 0; i < 2; ++i) 159 foo(); 160 } 161 162 namespace A { 163 double x; 164 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} 165 } 166 namespace B { 167 using A::x; 168 } 169 170 int main(int argc, char **argv) { 171 const int d = 5; 172 const int da[5] = {0}; 173 S4 e(4); 174 S5 g(5); 175 S3 m; 176 S6 n(2); 177 int i; 178 int &j = i; // expected-note {{'j' defined here}} 179 #pragma omp parallel 180 #pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}} 181 for (i = 0; i < argc; ++i) 182 foo(); 183 #pragma omp parallel 184 #pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 185 for (i = 0; i < argc; ++i) 186 foo(); 187 #pragma omp parallel 188 #pragma omp for firstprivate() // expected-error {{expected expression}} 189 for (i = 0; i < argc; ++i) 190 foo(); 191 #pragma omp parallel 192 #pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} 193 for (i = 0; i < argc; ++i) 194 foo(); 195 #pragma omp parallel 196 #pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} 197 for (i = 0; i < argc; ++i) 198 foo(); 199 #pragma omp parallel 200 #pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} 201 for (i = 0; i < argc; ++i) 202 foo(); 203 #pragma omp parallel 204 #pragma omp for firstprivate(argc) 205 for (i = 0; i < argc; ++i) 206 foo(); 207 #pragma omp parallel 208 #pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}} 209 for (i = 0; i < argc; ++i) 210 foo(); 211 #pragma omp parallel 212 #pragma omp for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{no matching constructor for initialization of 'S3'}} 213 for (i = 0; i < argc; ++i) 214 foo(); 215 #pragma omp parallel 216 #pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}} 217 for (i = 0; i < argc; ++i) 218 foo(); 219 #pragma omp parallel 220 #pragma omp for firstprivate(2 * 2) // expected-error {{expected variable name}} 221 for (i = 0; i < argc; ++i) 222 foo(); 223 #pragma omp parallel 224 #pragma omp for firstprivate(ba) // OK 225 for (i = 0; i < argc; ++i) 226 foo(); 227 #pragma omp parallel 228 #pragma omp for firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}} 229 for (i = 0; i < argc; ++i) 230 foo(); 231 #pragma omp parallel 232 #pragma omp for firstprivate(da) // OK 233 for (i = 0; i < argc; ++i) 234 foo(); 235 int xa; 236 #pragma omp parallel 237 #pragma omp for firstprivate(xa) // OK 238 for (i = 0; i < argc; ++i) 239 foo(); 240 #pragma omp parallel 241 #pragma omp for firstprivate(S2::S2s) // OK 242 for (i = 0; i < argc; ++i) 243 foo(); 244 #pragma omp parallel 245 #pragma omp for firstprivate(S2::S2sc) // OK 246 for (i = 0; i < argc; ++i) 247 foo(); 248 #pragma omp parallel 249 #pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}} 250 for (i = 0; i < argc; ++i) 251 foo(); 252 #pragma omp parallel 253 #pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} 254 for (i = 0; i < argc; ++i) 255 foo(); 256 #pragma omp parallel 257 #pragma omp for firstprivate(m) // OK 258 for (i = 0; i < argc; ++i) 259 foo(); 260 #pragma omp parallel 261 #pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 262 for (i = 0; i < argc; ++i) 263 foo(); 264 #pragma omp parallel 265 #pragma omp for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} 266 for (i = 0; i < argc; ++i) 267 foo(); 268 #pragma omp parallel 269 #pragma omp for firstprivate(i) // expected-note {{defined as firstprivate}} 270 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}} 271 foo(); 272 #pragma omp parallel shared(xa) 273 #pragma omp for firstprivate(xa) // OK: may be firstprivate 274 for (i = 0; i < argc; ++i) 275 foo(); 276 #pragma omp parallel 277 #pragma omp for firstprivate(j) // expected-error {{arguments of OpenMP clause 'firstprivate' cannot be of reference type}} 278 for (i = 0; i < argc; ++i) 279 foo(); 280 #pragma omp parallel 281 #pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} 282 for (i = 0; i < argc; ++i) 283 foo(); 284 #pragma omp parallel 285 #pragma omp for lastprivate(n) firstprivate(n) // OK 286 for (i = 0; i < argc; ++i) 287 foo(); 288 #pragma omp parallel 289 { 290 int v = 0; 291 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}} 292 #pragma omp for firstprivate(i) // expected-error {{private variable cannot be firstprivate}} 293 for (int k = 0; k < argc; ++k) { 294 i = k; 295 v += i; 296 } 297 } 298 #pragma omp parallel private(i) // expected-note {{defined as private}} 299 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 300 for (i = 0; i < argc; ++i) 301 foo(); 302 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} 303 #pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}} 304 for (i = 0; i < argc; ++i) 305 foo(); 306 #pragma omp parallel 307 #pragma omp for firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} 308 for (i = 0; i < argc; ++i) 309 foo(); 310 311 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} 312 } 313 314