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