| 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 parallel |
| 73 | #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}} |
| 74 | { |
| 75 | foo(); |
| 76 | } |
| 77 | #pragma omp parallel |
| 78 | #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 79 | { |
| 80 | foo(); |
| 81 | } |
| 82 | #pragma omp parallel |
| 83 | #pragma omp sections firstprivate() // expected-error {{expected expression}} |
| 84 | { |
| 85 | foo(); |
| 86 | } |
| 87 | #pragma omp parallel |
| 88 | #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 89 | { |
| 90 | foo(); |
| 91 | } |
| 92 | #pragma omp parallel |
| 93 | #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 94 | { |
| 95 | foo(); |
| 96 | } |
| 97 | #pragma omp parallel |
| 98 | #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 99 | { |
| 100 | foo(); |
| 101 | } |
| 102 | #pragma omp parallel |
| 103 | #pragma omp sections 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 '('}} |
| 104 | { |
| 105 | foo(); |
| 106 | } |
| 107 | #pragma omp parallel |
| 108 | #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 109 | { |
| 110 | foo(); |
| 111 | } |
| 112 | #pragma omp parallel |
| 113 | #pragma omp sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} |
| 114 | { |
| 115 | foo(); |
| 116 | } |
| 117 | #pragma omp parallel |
| 118 | #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}} |
| 119 | { |
| 120 | foo(); |
| 121 | } |
| 122 | #pragma omp parallel |
| 123 | #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} |
| 124 | { |
| 125 | foo(); |
| 126 | } |
| 127 | #pragma omp parallel |
| 128 | #pragma omp sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} |
| 129 | { |
| 130 | foo(); |
| 131 | } |
| 132 | #pragma omp parallel |
| 133 | #pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}} |
| 134 | { |
| 135 | foo(); |
| 136 | } |
| 137 | #pragma omp parallel |
| 138 | { |
| 139 | int v = 0; |
| 140 | int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}} |
| 141 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 142 | { |
| 143 | foo(); |
| 144 | } |
| 145 | v += i; |
| 146 | } |
| 147 | #pragma omp parallel shared(i) |
| 148 | #pragma omp parallel private(i) |
| 149 | #pragma omp sections firstprivate(j) |
| 150 | { |
| 151 | foo(); |
| 152 | } |
| 153 | #pragma omp parallel |
| 154 | #pragma omp sections firstprivate(i) |
| 155 | { |
| 156 | foo(); |
| 157 | } |
| 158 | #pragma omp parallel |
| 159 | #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} |
| 160 | { |
| 161 | foo(); |
| 162 | } |
| 163 | #pragma omp parallel private(i) // expected-note {{defined as private}} |
| 164 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 165 | { |
| 166 | foo(); |
| 167 | } |
| 168 | #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} |
| 169 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 170 | { |
| 171 | foo(); |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | namespace A { |
| 177 | double x; |
| 178 | #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} |
| 179 | } |
| 180 | namespace B { |
| 181 | using A::x; |
| 182 | } |
| 183 | |
| 184 | int main(int argc, char **argv) { |
| 185 | const int d = 5; |
| 186 | const int da[5] = {0}; |
| 187 | S4 e(4); |
| 188 | S5 g(5); |
| 189 | S3 m; |
| 190 | S6 n(2); |
| 191 | int i; |
| 192 | int &j = i; |
| 193 | #pragma omp parallel |
| 194 | #pragma omp sections firstprivate // expected-error {{expected '(' after 'firstprivate'}} |
| 195 | { |
| 196 | foo(); |
| 197 | } |
| 198 | #pragma omp parallel |
| 199 | #pragma omp sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 200 | { |
| 201 | foo(); |
| 202 | } |
| 203 | #pragma omp parallel |
| 204 | #pragma omp sections firstprivate() // expected-error {{expected expression}} |
| 205 | { |
| 206 | foo(); |
| 207 | } |
| 208 | #pragma omp parallel |
| 209 | #pragma omp sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 210 | { |
| 211 | foo(); |
| 212 | } |
| 213 | #pragma omp parallel |
| 214 | #pragma omp sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 215 | { |
| 216 | foo(); |
| 217 | } |
| 218 | #pragma omp parallel |
| 219 | #pragma omp sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 220 | { |
| 221 | foo(); |
| 222 | } |
| 223 | #pragma omp parallel |
| 224 | #pragma omp sections firstprivate(argc) |
| 225 | { |
| 226 | foo(); |
| 227 | } |
| 228 | #pragma omp parallel |
| 229 | #pragma omp sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 230 | { |
| 231 | foo(); |
| 232 | } |
| 233 | #pragma omp parallel |
| 234 | #pragma omp sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} |
| 235 | { |
| 236 | foo(); |
| 237 | } |
| 238 | #pragma omp parallel |
| 239 | #pragma omp sections firstprivate(argv[1]) // expected-error {{expected variable name}} |
| 240 | { |
| 241 | foo(); |
| 242 | } |
| 243 | #pragma omp parallel |
| 244 | #pragma omp sections firstprivate(2 * 2) // expected-error {{expected variable name}} |
| 245 | { |
| 246 | foo(); |
| 247 | } |
| 248 | #pragma omp parallel |
| 249 | #pragma omp sections firstprivate(ba) // OK |
| 250 | { |
| 251 | foo(); |
| 252 | } |
| 253 | #pragma omp parallel |
| 254 | #pragma omp sections firstprivate(ca) // OK |
| 255 | { |
| 256 | foo(); |
| 257 | } |
| 258 | #pragma omp parallel |
| 259 | #pragma omp sections firstprivate(da) // OK |
| 260 | { |
| 261 | foo(); |
| 262 | } |
| 263 | int xa; |
| 264 | #pragma omp parallel |
| 265 | #pragma omp sections firstprivate(xa) // OK |
| 266 | { |
| 267 | foo(); |
| 268 | } |
| 269 | #pragma omp parallel |
| 270 | #pragma omp sections firstprivate(S2::S2s) // OK |
| 271 | { |
| 272 | foo(); |
| 273 | } |
| 274 | #pragma omp parallel |
| 275 | #pragma omp sections firstprivate(S2::S2sc) // OK |
| 276 | { |
| 277 | foo(); |
| 278 | } |
| 279 | #pragma omp parallel |
| 280 | #pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}} |
| 281 | { |
| 282 | foo(); |
| 283 | } |
| 284 | #pragma omp parallel |
| 285 | #pragma omp sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} |
| 286 | { |
| 287 | foo(); |
| 288 | } |
| 289 | #pragma omp parallel |
| 290 | #pragma omp sections firstprivate(m) // OK |
| 291 | { |
| 292 | foo(); |
| 293 | } |
| 294 | #pragma omp parallel |
| 295 | #pragma omp sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} |
| 296 | { |
| 297 | foo(); |
| 298 | } |
| 299 | #pragma omp parallel |
| 300 | #pragma omp sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} |
| 301 | { |
| 302 | foo(); |
| 303 | } |
| 304 | #pragma omp parallel shared(xa) |
| 305 | #pragma omp sections firstprivate(xa) // OK: may be firstprivate |
| 306 | { |
| 307 | foo(); |
| 308 | } |
| 309 | #pragma omp parallel |
| 310 | #pragma omp sections firstprivate(j) |
| 311 | { |
| 312 | foo(); |
| 313 | } |
| 314 | #pragma omp parallel |
| 315 | #pragma omp sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} |
| 316 | { |
| 317 | foo(); |
| 318 | } |
| 319 | #pragma omp parallel |
| 320 | #pragma omp sections lastprivate(n) firstprivate(n) // OK |
| 321 | { |
| 322 | foo(); |
| 323 | } |
| 324 | #pragma omp parallel |
| 325 | { |
| 326 | int v = 0; |
| 327 | int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}} |
| 328 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 329 | { |
| 330 | foo(); |
| 331 | } |
| 332 | v += i; |
| 333 | } |
| 334 | #pragma omp parallel private(i) // expected-note {{defined as private}} |
| 335 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 336 | { |
| 337 | foo(); |
| 338 | } |
| 339 | #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}} |
| 340 | #pragma omp sections firstprivate(i) // expected-error {{firstprivate variable must be shared}} |
| 341 | { |
| 342 | foo(); |
| 343 | } |
| 344 | static int r; |
| 345 | #pragma omp sections firstprivate(r) // OK |
| 346 | { |
| 347 | foo(); |
| 348 | } |
| 349 | |
| 350 | return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} |
| 351 | } |
| 352 | |