Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp %s |
| 2 | |
| 3 | namespace X { |
| 4 | int x; |
| 5 | }; |
| 6 | |
| 7 | struct B { |
| 8 | static int ib; // expected-note {{'B::ib' declared here}} |
| 9 | static int bfoo() { return 8; } |
| 10 | }; |
| 11 | |
| 12 | int bfoo() { return 4; } |
| 13 | |
| 14 | int z; |
| 15 | const int C1 = 1; |
| 16 | const int C2 = 2; |
| 17 | void test_linear_colons() |
| 18 | { |
| 19 | int B = 0; |
| 20 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 21 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 22 | #pragma omp target |
| 23 | #pragma omp teams |
| 24 | #pragma omp distribute simd linear(B:bfoo()) |
| 25 | for (int i = 0; i < 10; ++i) ; |
| 26 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 27 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 28 | #pragma omp target |
| 29 | #pragma omp teams |
| 30 | #pragma omp distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}} |
| 31 | for (int i = 0; i < 10; ++i) ; |
| 32 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 33 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 34 | #pragma omp target |
| 35 | #pragma omp teams |
| 36 | #pragma omp distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}} |
| 37 | for (int i = 0; i < 10; ++i) ; |
| 38 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 39 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 40 | #pragma omp target |
| 41 | #pragma omp teams |
| 42 | #pragma omp distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}} |
| 43 | for (int i = 0; i < 10; ++i) ; |
| 44 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 45 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 46 | #pragma omp target |
| 47 | #pragma omp teams |
| 48 | #pragma omp distribute simd linear(B:B::bfoo()) |
| 49 | for (int i = 0; i < 10; ++i) ; |
| 50 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 51 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 52 | #pragma omp target |
| 53 | #pragma omp teams |
| 54 | #pragma omp distribute simd linear(X::x : ::z) |
| 55 | for (int i = 0; i < 10; ++i) ; |
| 56 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 57 | // expected-error@+3 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 58 | #pragma omp target |
| 59 | #pragma omp teams |
| 60 | #pragma omp distribute simd linear(B,::z, X::x) |
| 61 | for (int i = 0; i < 10; ++i) ; |
| 62 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 63 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 64 | #pragma omp target |
| 65 | #pragma omp teams |
| 66 | #pragma omp distribute simd linear(::z) |
| 67 | for (int i = 0; i < 10; ++i) ; |
| 68 | |
| 69 | #pragma omp target |
| 70 | #pragma omp teams |
| 71 | #pragma omp distribute simd linear(B::bfoo()) // expected-error {{expected variable name}} |
| 72 | for (int i = 0; i < 10; ++i) ; |
| 73 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 74 | // expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 75 | #pragma omp target |
| 76 | #pragma omp teams |
| 77 | #pragma omp distribute simd linear(B::ib,B:C1+C2) |
| 78 | for (int i = 0; i < 10; ++i) ; |
| 79 | } |
| 80 | |
| 81 | template<int L, class T, class N> T test_template(T* arr, N num) { |
| 82 | N i; |
| 83 | T sum = (T)0; |
| 84 | T ind2 = - num * L; // expected-note {{'ind2' defined here}} |
| 85 | |
| 86 | #pragma omp target |
| 87 | #pragma omp teams |
| 88 | #pragma omp distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}} |
| 89 | for (i = 0; i < num; ++i) { |
| 90 | T cur = arr[(int)ind2]; |
| 91 | ind2 += L; |
| 92 | sum += cur; |
| 93 | } |
| 94 | return T(); |
| 95 | } |
| 96 | |
| 97 | template<int LEN> int test_warn() { |
| 98 | int ind2 = 0; |
| 99 | #pragma omp target |
| 100 | #pragma omp teams |
| 101 | #pragma omp parallel for simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}} |
| 102 | for (int i = 0; i < 100; i++) { |
| 103 | ind2 += LEN; |
| 104 | } |
| 105 | return ind2; |
| 106 | } |
| 107 | |
| 108 | struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} |
| 109 | extern S1 a; |
| 110 | class S2 { |
| 111 | mutable int a; |
| 112 | public: |
| 113 | S2():a(0) { } |
| 114 | }; |
| 115 | const S2 b; // expected-note 2 {{'b' defined here}} |
| 116 | const S2 ba[5]; |
| 117 | class S3 { |
| 118 | int a; |
| 119 | public: |
| 120 | S3():a(0) { } |
| 121 | }; |
| 122 | const S3 ca[5]; |
| 123 | class S4 { |
| 124 | int a; |
| 125 | S4(); |
| 126 | public: |
| 127 | S4(int v):a(v) { } |
| 128 | }; |
| 129 | class S5 { |
| 130 | int a; |
| 131 | S5():a(0) {} |
| 132 | public: |
| 133 | S5(int v):a(v) { } |
| 134 | }; |
| 135 | |
| 136 | S3 h; |
| 137 | #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} |
| 138 | |
| 139 | template<class I, class C> int foomain(I argc, C **argv) { |
| 140 | I e(4); |
| 141 | I g(5); |
| 142 | int i; |
| 143 | int &j = i; |
| 144 | |
| 145 | #pragma omp target |
| 146 | #pragma omp teams |
| 147 | #pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}} |
| 148 | for (int k = 0; k < argc; ++k) ++k; |
| 149 | |
| 150 | #pragma omp target |
| 151 | #pragma omp teams |
| 152 | #pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 153 | for (int k = 0; k < argc; ++k) ++k; |
| 154 | |
| 155 | #pragma omp target |
| 156 | #pragma omp teams |
| 157 | #pragma omp distribute simd linear () // expected-error {{expected expression}} |
| 158 | for (int k = 0; k < argc; ++k) ++k; |
| 159 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 160 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 161 | #pragma omp target |
| 162 | #pragma omp teams |
| 163 | #pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 164 | for (int k = 0; k < argc; ++k) ++k; |
| 165 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 166 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 167 | #pragma omp target |
| 168 | #pragma omp teams |
| 169 | #pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 170 | for (int k = 0; k < argc; ++k) ++k; |
| 171 | |
| 172 | #pragma omp target |
| 173 | #pragma omp teams |
| 174 | #pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 175 | for (int k = 0; k < argc; ++k) ++k; |
| 176 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 177 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 178 | #pragma omp target |
| 179 | #pragma omp teams |
| 180 | #pragma omp distribute simd linear (argc : 5) |
| 181 | for (int k = 0; k < argc; ++k) ++k; |
| 182 | |
| 183 | #pragma omp target |
| 184 | #pragma omp teams |
| 185 | #pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}} |
| 186 | for (int k = 0; k < argc; ++k) ++k; |
| 187 | |
| 188 | #pragma omp target |
| 189 | #pragma omp teams |
| 190 | #pragma omp distribute simd linear (a, b:B::ib) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{const-qualified variable cannot be linear}} |
| 191 | for (int k = 0; k < argc; ++k) ++k; |
| 192 | |
| 193 | #pragma omp target |
| 194 | #pragma omp teams |
| 195 | #pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}} |
| 196 | for (int k = 0; k < argc; ++k) ++k; |
| 197 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 198 | // expected-error@+3 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 199 | #pragma omp target |
| 200 | #pragma omp teams |
| 201 | #pragma omp distribute simd linear(e, g) |
| 202 | for (int k = 0; k < argc; ++k) ++k; |
| 203 | |
| 204 | #pragma omp target |
| 205 | #pragma omp teams |
| 206 | #pragma omp distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}} |
| 207 | for (int k = 0; k < argc; ++k) ++k; |
| 208 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 209 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 210 | #pragma omp target |
| 211 | #pragma omp teams |
| 212 | #pragma omp distribute simd linear(i) |
| 213 | for (int k = 0; k < argc; ++k) ++k; |
| 214 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | namespace A { |
| 219 | double x; |
| 220 | #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} |
| 221 | } |
| 222 | namespace C { |
| 223 | using A::x; |
| 224 | } |
| 225 | |
| 226 | int main(int argc, char **argv) { |
| 227 | double darr[100]; |
| 228 | // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}} |
| 229 | test_template<-4>(darr, 4); |
| 230 | // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}} |
| 231 | test_warn<0>(); |
| 232 | |
| 233 | S4 e(4); // expected-note {{'e' defined here}} |
| 234 | S5 g(5); // expected-note {{'g' defined here}} |
| 235 | int i; |
| 236 | int &j = i; |
| 237 | |
| 238 | #pragma omp target |
| 239 | #pragma omp teams |
| 240 | #pragma omp distribute simd linear // expected-error {{expected '(' after 'linear'}} |
| 241 | for (int k = 0; k < argc; ++k) ++k; |
| 242 | |
| 243 | #pragma omp target |
| 244 | #pragma omp teams |
| 245 | #pragma omp distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 246 | for (int k = 0; k < argc; ++k) ++k; |
| 247 | |
| 248 | #pragma omp target |
| 249 | #pragma omp teams |
| 250 | #pragma omp distribute simd linear () // expected-error {{expected expression}} |
| 251 | for (int k = 0; k < argc; ++k) ++k; |
| 252 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 253 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 254 | #pragma omp target |
| 255 | #pragma omp teams |
| 256 | #pragma omp distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 257 | for (int k = 0; k < argc; ++k) ++k; |
| 258 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 259 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 260 | #pragma omp target |
| 261 | #pragma omp teams |
| 262 | #pragma omp distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 263 | for (int k = 0; k < argc; ++k) ++k; |
| 264 | |
| 265 | #pragma omp target |
| 266 | #pragma omp teams |
| 267 | #pragma omp distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 268 | for (int k = 0; k < argc; ++k) ++k; |
| 269 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 270 | // expected-error@+3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 271 | #pragma omp target |
| 272 | #pragma omp teams |
| 273 | #pragma omp distribute simd linear (argc) |
| 274 | for (int k = 0; k < argc; ++k) ++k; |
| 275 | |
| 276 | #pragma omp target |
| 277 | #pragma omp teams |
| 278 | #pragma omp distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}} |
| 279 | for (int k = 0; k < argc; ++k) ++k; |
| 280 | |
| 281 | |
| 282 | #pragma omp target |
| 283 | #pragma omp teams |
| 284 | #pragma omp distribute simd linear (a, b) // expected-error {{linear variable with incomplete type 'S1'}} expected-error {{const-qualified variable cannot be linear}} |
| 285 | for (int k = 0; k < argc; ++k) ++k; |
| 286 | |
| 287 | #pragma omp target |
| 288 | #pragma omp teams |
| 289 | #pragma omp distribute simd linear (argv[1]) // expected-error {{expected variable name}} |
| 290 | for (int k = 0; k < argc; ++k) ++k; |
| 291 | |
| 292 | #pragma omp target |
| 293 | #pragma omp teams |
| 294 | #pragma omp distribute simd linear(e, g) // expected-error {{argument of a linear clause should be of integral or pointer type, not 'S4'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S5'}} |
| 295 | for (int k = 0; k < argc; ++k) ++k; |
| 296 | |
| 297 | #pragma omp target |
| 298 | #pragma omp teams |
| 299 | #pragma omp distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}} |
| 300 | for (int k = 0; k < argc; ++k) ++k; |
| 301 | |
| 302 | #pragma omp parallel |
| 303 | { |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 304 | int k; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 305 | #pragma omp target |
| 306 | #pragma omp teams |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 307 | #pragma omp distribute simd linear(k) |
| 308 | for (k = 0; k < argc; ++k) ++k; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 309 | |
| 310 | #pragma omp target |
| 311 | #pragma omp teams |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame^] | 312 | #pragma omp distribute simd linear(k : 4) |
| 313 | for (k = 0; k < argc; k+=4) { } |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 316 | foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}} |
| 317 | return 0; |
| 318 | } |
| 319 | |