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