Alexey Bataev | db39021 | 2015-05-20 04:24:19 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp %s |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 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) {} |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 17 | S2(const S2 &s2) : a(s2.a) {} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 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) {} |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 30 | S3(const S3 &s3) : a(s3.a) {} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 31 | }; |
| 32 | const S3 c; |
| 33 | const S3 ca[5]; |
| 34 | extern const int f; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 35 | class S4 { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 36 | int a; |
| 37 | S4(); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 38 | S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 39 | |
| 40 | public: |
| 41 | S4(int v) : a(v) {} |
| 42 | }; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 43 | class S5 { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 44 | int a; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 45 | S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 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) { |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 65 | I e(4); |
| 66 | C g(5); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 67 | int i; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 68 | int &j = i; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 69 | #pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}} |
| 70 | { |
| 71 | foo(); |
| 72 | } |
| 73 | #pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 74 | { |
| 75 | foo(); |
| 76 | } |
| 77 | #pragma omp parallel sections firstprivate() // expected-error {{expected expression}} |
| 78 | { |
| 79 | foo(); |
| 80 | } |
| 81 | #pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 82 | { |
| 83 | foo(); |
| 84 | } |
| 85 | #pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 86 | { |
| 87 | foo(); |
| 88 | } |
| 89 | #pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 90 | { |
| 91 | foo(); |
| 92 | } |
| 93 | #pragma omp parallel sections firstprivate(argc) |
| 94 | { |
| 95 | foo(); |
| 96 | } |
| 97 | #pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 98 | { |
| 99 | foo(); |
| 100 | } |
| 101 | #pragma omp parallel sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} |
| 102 | { |
| 103 | foo(); |
| 104 | } |
| 105 | #pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}} |
| 106 | { |
| 107 | foo(); |
| 108 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 109 | #pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 110 | { |
| 111 | foo(); |
| 112 | } |
| 113 | #pragma omp parallel sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}} |
| 114 | { |
| 115 | foo(); |
| 116 | } |
| 117 | #pragma omp parallel sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}} |
| 118 | { |
| 119 | foo(); |
| 120 | } |
| 121 | #pragma omp parallel |
| 122 | { |
| 123 | int v = 0; |
| 124 | int i; |
| 125 | #pragma omp parallel sections firstprivate(i) |
| 126 | { |
| 127 | foo(); |
| 128 | } |
| 129 | v += i; |
| 130 | } |
| 131 | #pragma omp parallel shared(i) |
| 132 | #pragma omp parallel private(i) |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 133 | #pragma omp parallel sections firstprivate(j) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 134 | { |
| 135 | foo(); |
| 136 | } |
| 137 | #pragma omp parallel sections firstprivate(i) |
| 138 | { |
| 139 | foo(); |
| 140 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 141 | #pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 142 | { |
| 143 | foo(); |
| 144 | } |
| 145 | #pragma omp parallel private(i) |
| 146 | #pragma omp parallel sections firstprivate(i) |
| 147 | { |
| 148 | foo(); |
| 149 | } |
| 150 | #pragma omp parallel reduction(+ : i) |
| 151 | #pragma omp parallel sections firstprivate(i) |
| 152 | { |
| 153 | foo(); |
| 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 158 | namespace A { |
| 159 | double x; |
| 160 | #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} |
| 161 | } |
| 162 | namespace B { |
| 163 | using A::x; |
| 164 | } |
| 165 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 166 | int main(int argc, char **argv) { |
| 167 | const int d = 5; |
| 168 | const int da[5] = {0}; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 169 | S4 e(4); |
| 170 | S5 g(5); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 171 | S3 m; |
| 172 | S6 n(2); |
| 173 | int i; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 174 | int &j = i; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 175 | #pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}} |
| 176 | { |
| 177 | foo(); |
| 178 | } |
| 179 | #pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 180 | { |
| 181 | foo(); |
| 182 | } |
| 183 | #pragma omp parallel sections firstprivate() // expected-error {{expected expression}} |
| 184 | { |
| 185 | foo(); |
| 186 | } |
| 187 | #pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 188 | { |
| 189 | foo(); |
| 190 | } |
| 191 | #pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 192 | { |
| 193 | foo(); |
| 194 | } |
| 195 | #pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 196 | { |
| 197 | foo(); |
| 198 | } |
| 199 | #pragma omp parallel sections firstprivate(argc) |
| 200 | { |
| 201 | foo(); |
| 202 | } |
| 203 | #pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}} |
| 204 | { |
| 205 | foo(); |
| 206 | } |
| 207 | #pragma omp parallel sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} |
| 208 | { |
| 209 | foo(); |
| 210 | } |
| 211 | #pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}} |
| 212 | { |
| 213 | foo(); |
| 214 | } |
| 215 | #pragma omp parallel sections firstprivate(2 * 2) // expected-error {{expected variable name}} |
| 216 | { |
| 217 | foo(); |
| 218 | } |
| 219 | #pragma omp parallel sections firstprivate(ba) // OK |
| 220 | { |
| 221 | foo(); |
| 222 | } |
| 223 | #pragma omp parallel sections firstprivate(ca) // OK |
| 224 | { |
| 225 | foo(); |
| 226 | } |
| 227 | #pragma omp parallel sections firstprivate(da) // OK |
| 228 | { |
| 229 | foo(); |
| 230 | } |
| 231 | int xa; |
| 232 | #pragma omp parallel sections firstprivate(xa) // OK |
| 233 | { |
| 234 | foo(); |
| 235 | } |
| 236 | #pragma omp parallel sections firstprivate(S2::S2s) // OK |
| 237 | { |
| 238 | foo(); |
| 239 | } |
| 240 | #pragma omp parallel sections firstprivate(S2::S2sc) // OK |
| 241 | { |
| 242 | foo(); |
| 243 | } |
| 244 | #pragma omp parallel sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel sections'}} |
| 245 | { |
| 246 | foo(); |
| 247 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 248 | #pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 249 | { |
| 250 | foo(); |
| 251 | } |
| 252 | #pragma omp parallel sections firstprivate(m) // OK |
| 253 | { |
| 254 | foo(); |
| 255 | } |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 256 | #pragma omp parallel sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 257 | { |
| 258 | foo(); |
| 259 | } |
| 260 | #pragma omp parallel sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}} |
| 261 | { |
| 262 | foo(); |
| 263 | } |
| 264 | #pragma omp parallel shared(xa) |
| 265 | #pragma omp parallel sections firstprivate(xa) // OK: may be firstprivate |
| 266 | { |
| 267 | foo(); |
| 268 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 269 | #pragma omp parallel sections firstprivate(j) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 270 | { |
| 271 | foo(); |
| 272 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 273 | #pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}} |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 274 | { |
| 275 | foo(); |
| 276 | } |
| 277 | #pragma omp parallel sections lastprivate(n) firstprivate(n) // OK |
| 278 | { |
| 279 | foo(); |
| 280 | } |
| 281 | #pragma omp parallel |
| 282 | { |
| 283 | int v = 0; |
| 284 | int i; |
| 285 | #pragma omp parallel sections firstprivate(i) |
| 286 | { |
| 287 | foo(); |
| 288 | } |
| 289 | v += i; |
| 290 | } |
| 291 | #pragma omp parallel private(i) |
| 292 | #pragma omp parallel sections firstprivate(i) |
| 293 | { |
| 294 | foo(); |
| 295 | } |
| 296 | #pragma omp parallel reduction(+ : i) |
| 297 | #pragma omp parallel sections firstprivate(i) |
| 298 | { |
| 299 | foo(); |
| 300 | } |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 301 | static int r; |
| 302 | #pragma omp parallel sections firstprivate(r) // OK |
| 303 | { |
| 304 | foo(); |
| 305 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 306 | |
| 307 | return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}} |
| 308 | } |