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