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