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