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