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