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