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