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