283 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 7extern int omp_default_mem_alloc;8void xxx(int argc) {9 int i, sz; // expected-note {{initialize the variable 'sz' to silence this warning}}10#pragma omp target11#pragma omp teams distribute simd linear(i : sz) // expected-warning {{variable 'sz' is uninitialized when used here}}12 for (i = 0; i < 10; ++i)13 ;14}15 16namespace X {17 int x;18};19 20struct B {21 static int ib; // expected-note {{'B::ib' declared here}}22 static int bfoo() { return 8; }23};24 25int bfoo() { return 4; }26 27int z;28const int C1 = 1;29const int C2 = 2;30void test_linear_colons()31{32 int B = 0;33 34// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}35#pragma omp target36#pragma omp teams distribute simd linear(B:bfoo())37 for (int i = 0; i < 10; ++i) ;38 39// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}40#pragma omp target41#pragma omp teams distribute simd linear(B::ib:B:bfoo()) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'}}42 for (int i = 0; i < 10; ++i) ;43 44// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}45#pragma omp target46#pragma omp teams distribute simd linear(B:ib) // expected-error {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}47 for (int i = 0; i < 10; ++i) ;48 49// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}50#pragma omp target51#pragma omp teams distribute simd linear(z:B:ib) // expected-error {{unexpected ':' in nested name specifier; did you mean '::'?}}52 for (int i = 0; i < 10; ++i) ;53 54// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}55#pragma omp target56#pragma omp teams distribute simd linear(B:B::bfoo())57 for (int i = 0; i < 10; ++i) ;58 59// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}60#pragma omp target61#pragma omp teams distribute simd linear(X::x : ::z)62 for (int i = 0; i < 10; ++i) ;63 64// expected-error@+2 3 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}65#pragma omp target66#pragma omp teams distribute simd linear(B,::z, X::x)67 for (int i = 0; i < 10; ++i) ;68 69// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}70#pragma omp target71#pragma omp teams distribute simd linear(::z)72 for (int i = 0; i < 10; ++i) ;73 74#pragma omp target75#pragma omp teams distribute simd linear(B::bfoo()) // expected-error {{expected variable name}}76 for (int i = 0; i < 10; ++i) ;77 78// expected-error@+2 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}79#pragma omp target80#pragma omp teams distribute simd linear(B::ib,B:C1+C2)81 for (int i = 0; i < 10; ++i) ;82}83 84template<int L, class T, class N> T test_template(T* arr, N num) {85 N i;86 T sum = (T)0;87 T ind2 = - num * L; // expected-note {{'ind2' defined here}}88 89#pragma omp target90#pragma omp teams distribute simd linear(ind2:L) // expected-error {{argument of a linear clause should be of integral or pointer type}}91 for (i = 0; i < num; ++i) {92 T cur = arr[(int)ind2];93 ind2 += L;94 sum += cur;95 }96 return T();97}98 99template<int LEN> int test_warn() {100 int ind2 = 0;101// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}102 #pragma omp target103 #pragma omp teams distribute simd linear(ind2:LEN) // expected-warning {{zero linear step ('ind2' should probably be const)}}104 for (int i = 0; i < 100; i++) {105 ind2 += LEN;106 }107 return ind2;108}109 110struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}111extern S1 a;112class S2 {113 mutable int a;114public:115 S2():a(0) { }116};117const S2 b; // expected-note 2 {{'b' defined here}}118const S2 ba[5];119class S3 {120 int a;121public:122 S3():a(0) { }123};124const S3 ca[5];125class S4 {126 int a;127 S4();128public:129 S4(int v):a(v) { }130};131class S5 {132 int a;133 S5():a(0) {}134public:135 S5(int v):a(v) { }136};137 138S3 h;139#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}140 141template<class I, class C> int foomain(I argc, C **argv) {142 I e(4);143 I g(5);144 int i;145 int &j = i;146 147#pragma omp target148#pragma omp teams distribute simd linear // expected-error {{expected '(' after 'linear'}}149 for (int k = 0; k < argc; ++k) ++k;150 151#pragma omp target152#pragma omp teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}153 for (int k = 0; k < argc; ++k) ++k;154 155#pragma omp target156#pragma omp teams distribute simd linear () // expected-error {{expected expression}}157 for (int k = 0; k < argc; ++k) ++k;158 159// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}160#pragma omp target161#pragma omp teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}162 for (int k = 0; k < argc; ++k) ++k;163 164// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}165#pragma omp target166#pragma omp teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}167 for (int k = 0; k < argc; ++k) ++k;168 169#pragma omp target170#pragma omp teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}171 for (int k = 0; k < argc; ++k) ++k;172 173// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}174#pragma omp target175#pragma omp teams distribute 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 '('}}176 for (int k = 0; k < argc; ++k) ++k;177 178#pragma omp target179#pragma omp teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}180 for (int k = 0; k < argc; ++k) ++k;181 182#pragma omp target183#pragma omp 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'}}184 for (int k = 0; k < argc; ++k) ++k;185 186#pragma omp target187#pragma omp teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}188 for (int k = 0; k < argc; ++k) ++k;189 190// expected-error@+2 2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}191#pragma omp target192#pragma omp teams distribute simd linear(e, g)193 for (int k = 0; k < argc; ++k) ++k;194 195#pragma omp target196#pragma omp teams distribute simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}197 for (int k = 0; k < argc; ++k) ++k;198 199// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}200#pragma omp target201#pragma omp teams distribute simd linear(i)202 for (int k = 0; k < argc; ++k) ++k;203 204 return 0;205}206 207namespace A {208double x;209#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}210}211namespace C {212using A::x;213}214 215int main(int argc, char **argv) {216 double darr[100];217 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}218 test_template<-4>(darr, 4);219 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}220 test_warn<0>();221 222 S4 e(4); // expected-note {{'e' defined here}}223 S5 g(5); // expected-note {{'g' defined here}}224 int i;225 int &j = i;226 227#pragma omp target228#pragma omp teams distribute simd linear // expected-error {{expected '(' after 'linear'}}229 for (int k = 0; k < argc; ++k) ++k;230 231#pragma omp target232#pragma omp teams distribute simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}233 for (int k = 0; k < argc; ++k) ++k;234 235#pragma omp target236#pragma omp teams distribute simd linear () // expected-error {{expected expression}}237 for (int k = 0; k < argc; ++k) ++k;238 239// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}240#pragma omp target241#pragma omp teams distribute simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}242 for (int k = 0; k < argc; ++k) ++k;243 244// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}245#pragma omp target246#pragma omp teams distribute simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}247 for (int k = 0; k < argc; ++k) ++k;248 249#pragma omp target250#pragma omp teams distribute simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}251 for (int k = 0; k < argc; ++k) ++k;252 253// expected-error@+2 {{only loop iteration variables are allowed in 'linear' clause in distribute directives}}254#pragma omp target255#pragma omp teams distribute simd linear (argc)256 for (int k = 0; k < argc; ++k) ++k;257 258#pragma omp target259#pragma omp teams distribute simd linear (S1) // expected-error {{'S1' does not refer to a value}}260 for (int k = 0; k < argc; ++k) ++k;261 262 263#pragma omp target264#pragma omp teams distribute simd linear (a, b) // expected-error {{incomplete type 'S1' where a complete type is required}} expected-error {{linear variable with incomplete type 'S1'}} expected-error {{argument of a linear clause should be of integral or pointer type, not 'S2'}}265 for (int k = 0; k < argc; ++k) ++k;266 267#pragma omp target268#pragma omp teams distribute simd linear (argv[1]) // expected-error {{expected variable name}}269 for (int k = 0; k < argc; ++k) ++k;270 271#pragma omp target272#pragma omp 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'}}273 for (int k = 0; k < argc; ++k) ++k;274 275#pragma omp target276#pragma omp teams distribute simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}277 for (int k = 0; k < argc; ++k) ++k;278 279 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}280 return 0;281}282 283