Alexey Bataev | a914888 | 2019-07-08 15:45:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2 | |
Alexey Bataev | a914888 | 2019-07-08 15:45:24 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized |
Alexey Bataev | a8a9153a | 2017-12-29 18:07:07 +0000 | [diff] [blame] | 4 | |
Alexey Bataev | 471171c | 2019-03-28 19:15:36 +0000 | [diff] [blame] | 5 | typedef void **omp_allocator_handle_t; |
| 6 | extern const omp_allocator_handle_t omp_default_mem_alloc; |
| 7 | extern const omp_allocator_handle_t omp_large_cap_mem_alloc; |
| 8 | extern const omp_allocator_handle_t omp_const_mem_alloc; |
| 9 | extern const omp_allocator_handle_t omp_high_bw_mem_alloc; |
| 10 | extern const omp_allocator_handle_t omp_low_lat_mem_alloc; |
| 11 | extern const omp_allocator_handle_t omp_cgroup_mem_alloc; |
| 12 | extern const omp_allocator_handle_t omp_pteam_mem_alloc; |
| 13 | extern const omp_allocator_handle_t omp_thread_mem_alloc; |
| 14 | |
Alexey Bataev | 195ae903 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 15 | void xxx(int argc) { |
| 16 | int i, step; // expected-note {{initialize the variable 'step' to silence this warning}} |
| 17 | #pragma omp target teams distribute simd linear(i : step) // expected-warning {{variable 'step' is uninitialized when used here}} |
| 18 | for (i = 0; i < 10; ++i) |
| 19 | ; |
| 20 | } |
| 21 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 22 | namespace X { |
| 23 | int x; |
| 24 | }; |
| 25 | |
| 26 | struct B { |
| 27 | static int ib; // expected-note {{'B::ib' declared here}} |
| 28 | static int bfoo() { return 8; } |
| 29 | }; |
| 30 | |
| 31 | int bfoo() { return 4; } |
| 32 | |
| 33 | int z; |
| 34 | const int C1 = 1; |
| 35 | const int C2 = 2; |
| 36 | void test_linear_colons() |
| 37 | { |
| 38 | int B = 0; |
| 39 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 40 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 41 | #pragma omp target teams distribute simd linear(B:bfoo()) |
| 42 | for (int i = 0; i < 10; ++i) ; |
| 43 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 44 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 45 | #pragma omp target teams distribute simd linear(B::ib:B:bfoo()) // 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@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 49 | #pragma omp target teams distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}} |
| 50 | for (int i = 0; i < 10; ++i) ; |
| 51 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 52 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 53 | #pragma omp target teams distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}} |
| 54 | for (int i = 0; i < 10; ++i) ; |
| 55 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 56 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 57 | #pragma omp target teams distribute simd linear(B:B::bfoo()) |
| 58 | for (int i = 0; i < 10; ++i) ; |
| 59 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 60 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 61 | #pragma omp target teams distribute simd linear(X::x : ::z) |
| 62 | for (int i = 0; i < 10; ++i) ; |
| 63 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 64 | // expected-error@+1 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 65 | #pragma omp target teams distribute simd linear(B,::z, X::x) |
| 66 | for (int i = 0; i < 10; ++i) ; |
| 67 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 68 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 69 | #pragma omp target teams distribute simd linear(::z) |
| 70 | for (int i = 0; i < 10; ++i) ; |
| 71 | |
| 72 | #pragma omp target teams distribute simd linear(B::bfoo()) // expected-error {{expected variable name}} |
| 73 | for (int i = 0; i < 10; ++i) ; |
| 74 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 75 | // expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 76 | #pragma omp target teams distribute simd linear(B::ib,B:C1+C2) |
| 77 | for (int i = 0; i < 10; ++i) ; |
| 78 | } |
| 79 | |
| 80 | template<int L, class T, class N> T test_template(T* arr, N num) { |
| 81 | N i; |
| 82 | T sum = (T)0; |
| 83 | T ind2 = - num * L; // expected-note {{'ind2' defined here}} |
| 84 | |
| 85 | #pragma omp target teams distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}} |
| 86 | for (i = 0; i < num; ++i) { |
| 87 | T cur = arr[(int)ind2]; |
| 88 | ind2 += L; |
| 89 | sum += cur; |
| 90 | } |
| 91 | return T(); |
| 92 | } |
| 93 | |
| 94 | template<int LEN> int test_warn() { |
| 95 | int ind2 = 0; |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 96 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 97 | #pragma omp target teams distribute simd linear(ind2:LEN) // expected-warning {{zero linear step (ind2 should probably be const)}} |
| 98 | for (int i = 0; i < 100; i++) { |
| 99 | ind2 += LEN; |
| 100 | } |
| 101 | return ind2; |
| 102 | } |
| 103 | |
| 104 | struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}} |
| 105 | extern S1 a; |
| 106 | class S2 { |
| 107 | mutable int a; |
| 108 | public: |
| 109 | S2():a(0) { } |
| 110 | }; |
| 111 | const S2 b; // expected-note 2 {{'b' defined here}} |
| 112 | const S2 ba[5]; |
| 113 | class S3 { |
| 114 | int a; |
| 115 | public: |
| 116 | S3():a(0) { } |
| 117 | }; |
| 118 | const S3 ca[5]; |
| 119 | class S4 { |
| 120 | int a; |
| 121 | S4(); |
| 122 | public: |
| 123 | S4(int v):a(v) { } |
| 124 | }; |
| 125 | class S5 { |
| 126 | int a; |
| 127 | S5():a(0) {} |
| 128 | public: |
| 129 | S5(int v):a(v) { } |
| 130 | }; |
| 131 | |
| 132 | S3 h; |
| 133 | #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}} |
| 134 | |
| 135 | template<class I, class C> int foomain(I argc, C **argv) { |
| 136 | I e(4); |
| 137 | I g(5); |
| 138 | int i; |
| 139 | int &j = i; |
| 140 | |
| 141 | #pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}} |
| 142 | for (int k = 0; k < argc; ++k) ++k; |
| 143 | |
| 144 | #pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 145 | for (int k = 0; k < argc; ++k) ++k; |
| 146 | |
| 147 | #pragma omp target teams distribute simd linear () // expected-error {{expected expression}} |
| 148 | for (int k = 0; k < argc; ++k) ++k; |
| 149 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 150 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 151 | #pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 152 | for (int k = 0; k < argc; ++k) ++k; |
| 153 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 154 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 155 | #pragma omp target teams distribute simd linear (argc, // 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 teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 159 | for (int k = 0; k < argc; ++k) ++k; |
| 160 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 161 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 162 | #pragma omp target teams distribute simd linear (argc : 5) |
| 163 | for (int k = 0; k < argc; ++k) ++k; |
| 164 | |
| 165 | #pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}} |
| 166 | for (int k = 0; k < argc; ++k) ++k; |
| 167 | |
Joel E. Denny | bae586f | 2019-01-04 22:12:13 +0000 | [diff] [blame] | 168 | #pragma omp target teams 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 | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 169 | for (int k = 0; k < argc; ++k) ++k; |
| 170 | |
| 171 | #pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}} |
| 172 | for (int k = 0; k < argc; ++k) ++k; |
| 173 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 174 | // expected-error@+1 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 175 | #pragma omp target teams distribute simd linear(e, g) |
| 176 | for (int k = 0; k < argc; ++k) ++k; |
| 177 | |
| 178 | #pragma omp target teams distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}} |
| 179 | for (int k = 0; k < argc; ++k) ++k; |
| 180 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 181 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 182 | #pragma omp target teams distribute simd linear(i) |
| 183 | for (int k = 0; k < argc; ++k) ++k; |
| 184 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | namespace A { |
| 189 | double x; |
| 190 | #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}} |
| 191 | } |
| 192 | namespace C { |
| 193 | using A::x; |
| 194 | } |
| 195 | |
| 196 | int main(int argc, char **argv) { |
| 197 | double darr[100]; |
| 198 | // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}} |
| 199 | test_template<-4>(darr, 4); |
| 200 | // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}} |
| 201 | test_warn<0>(); |
| 202 | |
| 203 | S4 e(4); // expected-note {{'e' defined here}} |
| 204 | S5 g(5); // expected-note {{'g' defined here}} |
| 205 | int i; |
| 206 | int &j = i; |
| 207 | |
| 208 | #pragma omp target teams distribute simd linear // expected-error {{expected '(' after 'linear'}} |
| 209 | for (int k = 0; k < argc; ++k) ++k; |
| 210 | |
| 211 | #pragma omp target teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 212 | for (int k = 0; k < argc; ++k) ++k; |
| 213 | |
| 214 | #pragma omp target teams distribute simd linear () // expected-error {{expected expression}} |
| 215 | for (int k = 0; k < argc; ++k) ++k; |
| 216 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 217 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 218 | #pragma omp target teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 219 | for (int k = 0; k < argc; ++k) ++k; |
| 220 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 221 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 222 | #pragma omp target teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}} |
| 223 | for (int k = 0; k < argc; ++k) ++k; |
| 224 | |
| 225 | #pragma omp target teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}} |
| 226 | for (int k = 0; k < argc; ++k) ++k; |
| 227 | |
Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 228 | // expected-error@+1 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}} |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 229 | #pragma omp target teams 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 | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 230 | for (int k = 0; k < argc; ++k) ++k; |
| 231 | |
| 232 | #pragma omp target teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}} |
| 233 | for (int k = 0; k < argc; ++k) ++k; |
| 234 | |
| 235 | |
Joel E. Denny | bae586f | 2019-01-04 22:12:13 +0000 | [diff] [blame] | 236 | #pragma omp target teams 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'}} |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 237 | for (int k = 0; k < argc; ++k) ++k; |
| 238 | |
| 239 | #pragma omp target teams distribute simd linear (argv[1]) // expected-error {{expected variable name}} |
| 240 | for (int k = 0; k < argc; ++k) ++k; |
| 241 | |
| 242 | #pragma omp target teams 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'}} |
| 243 | for (int k = 0; k < argc; ++k) ++k; |
| 244 | |
| 245 | #pragma omp target teams distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}} |
| 246 | for (int k = 0; k < argc; ++k) ++k; |
| 247 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 248 | foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}} |
| 249 | return 0; |
| 250 | } |
| 251 | |