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 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 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 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 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 simd linear(z:B:ib)
40 for (int i = 0; i < 10; ++i) ;
41 #pragma omp simd linear(B:B::bfoo())
42 for (int i = 0; i < 10; ++i) ;
43 #pragma omp simd linear(X::x : ::z)
44 for (int i = 0; i < 10; ++i) ;
45 #pragma omp simd linear(B,::z, X::x)
46 for (int i = 0; i < 10; ++i) ;
47 #pragma omp simd linear(::z)
48 for (int i = 0; i < 10; ++i) ;
49 // expected-error@+1 {{expected variable name}}
50 #pragma omp simd linear(B::bfoo())
51 for (int i = 0; i < 10; ++i) ;
52 #pragma omp simd linear(B::ib,B:C1+C2)
53 for (int i = 0; i < 10; ++i) ;
54 }
55
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 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 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 simd linear // expected-error {{expected '(' after 'linear'}}
117 for (int k = 0; k < argc; ++k) ++k;
118 #pragma omp 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 simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
121 for (int k = 0; k < argc; ++k) ++k;
122 #pragma omp simd linear (uval( // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
123 for (int k = 0; k < argc; ++k) ++k;
124 #pragma omp simd linear (ref() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
125 for (int k = 0; k < argc; ++k) ++k;
126 #pragma omp simd linear (foo() // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
127 for (int k = 0; k < argc; ++k) ++k;
128 #pragma omp simd linear () // expected-error {{expected expression}}
129 for (int k = 0; k < argc; ++k) ++k;
130 #pragma omp simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
131 for (int k = 0; k < argc; ++k) ++k;
132 #pragma omp simd linear (val argc // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
133 for (int k = 0; k < argc; ++k) ++k;
134 #pragma omp simd linear (val(argc, // expected-error {{expected expression}} expected-error 2 {{expected ')'}} expected-note 2 {{to match this '('}}
135 for (int k = 0; k < argc; ++k) ++k;
136 #pragma omp simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
137 for (int k = 0; k < argc; ++k) ++k;
138 #pragma omp 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 '('}}
139 for (int k = 0; k < argc; ++k) ++k;
140 #pragma omp simd linear (S1) // expected-error {{'S1' does not refer to a value}}
141 for (int k = 0; k < argc; ++k) ++k;
142 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
143 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
144 #pragma omp simd linear (val(a, b):B::ib)
145 for (int k = 0; k < argc; ++k) ++k;
146 #pragma omp simd linear (argv[1]) // expected-error {{expected variable name}}
147 for (int k = 0; k < argc; ++k) ++k;
148 #pragma omp 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'}}
149 for (int k = 0; k < argc; ++k) ++k;
150 #pragma omp simd linear(h, z) // expected-error {{threadprivate or thread local variable cannot be linear}}
151 for (int k = 0; k < argc; ++k) ++k;
152 #pragma omp simd linear(uval(i)) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
153 for (int k = 0; k < argc; ++k) ++k;
154 #pragma omp parallel
155 {
156 int v = 0;
157 int i;
158 #pragma omp simd linear(v:i)
159 for (int k = 0; k < argc; ++k) { i = k; v += i; }
160 }
161 #pragma omp simd linear(ref(j))
162 for (int k = 0; k < argc; ++k) ++k;
163 #pragma omp simd linear(uval(j))
164 for (int k = 0; k < argc; ++k) ++k;
165 int v = 0;
166 #pragma omp simd linear(v:j)
167 for (int k = 0; k < argc; ++k) { ++k; v += j; }
168 #pragma omp simd linear(i)
169 for (int k = 0; k < argc; ++k) ++k;
170 return 0;
171 }
172
173 namespace A {
174 double x;
175 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
176 }
177 namespace C {
178 using A::x;
179 }
180
linear_modifiers(int argc)181 void linear_modifiers(int argc) {
182 int &f = argc;
183 #pragma omp simd linear(f)
184 for (int k = 0; k < argc; ++k) ++k;
185 #pragma omp simd linear(val(f))
186 for (int k = 0; k < argc; ++k) ++k;
187 #pragma omp simd linear(uval(f))
188 for (int k = 0; k < argc; ++k) ++k;
189 #pragma omp simd linear(ref(f))
190 for (int k = 0; k < argc; ++k) ++k;
191 #pragma omp simd linear(foo(f)) // expected-error {{expected one of 'ref', val' or 'uval' modifiers}}
192 for (int k = 0; k < argc; ++k) ++k;
193 }
194
195 int f;
main(int argc,char ** argv)196 int main(int argc, char **argv) {
197 double darr[100];
198 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
199 test_template<-4>(darr, 4);
200 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
201 test_warn<0>();
202
203 S4 e(4); // expected-note {{'e' defined here}}
204 S5 g(5); // expected-note {{'g' defined here}}
205 int i, z;
206 int &j = i;
207 #pragma omp simd linear(f) linear(f) // expected-error {{linear variable cannot be linear}} expected-note {{defined as linear}}
208 for (int k = 0; k < argc; ++k) ++k;
209 #pragma omp simd linear // expected-error {{expected '(' after 'linear'}}
210 for (int k = 0; k < argc; ++k) ++k;
211 #pragma omp simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
212 for (int k = 0; k < argc; ++k) ++k;
213 #pragma omp simd linear () // expected-error {{expected expression}}
214 for (int k = 0; k < argc; ++k) ++k;
215 #pragma omp simd linear (val // expected-error {{use of undeclared identifier 'val'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
216 for (int k = 0; k < argc; ++k) ++k;
217 #pragma omp simd linear (ref()) // expected-error {{expected expression}}
218 for (int k = 0; k < argc; ++k) ++k;
219 #pragma omp simd linear (foo()) // expected-error {{expected expression}}
220 for (int k = 0; k < argc; ++k) ++k;
221 #pragma omp simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
222 for (int k = 0; k < argc; ++k) ++k;
223 #pragma omp simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
224 for (int k = 0; k < argc; ++k) ++k;
225 #pragma omp simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
226 for (int k = 0; k < argc; ++k) ++k;
227 #pragma omp simd linear (argc)
228 for (int k = 0; k < argc; ++k) ++k;
229 #pragma omp simd linear (S1) // expected-error {{'S1' does not refer to a value}}
230 for (int k = 0; k < argc; ++k) ++k;
231 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
232 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
233 #pragma omp simd linear(a, b, z)
234 for (int k = 0; k < argc; ++k) ++k;
235 #pragma omp simd linear (argv[1]) // expected-error {{expected variable name}}
236 for (int k = 0; k < argc; ++k) ++k;
237 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
238 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
239 #pragma omp simd linear(val(e, g))
240 for (int k = 0; k < argc; ++k) ++k;
241 #pragma omp simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
242 for (int k = 0; k < argc; ++k) ++k;
243 #pragma omp parallel
244 {
245 int i;
246 #pragma omp simd linear(val(i))
247 for (int k = 0; k < argc; ++k) ++k;
248 #pragma omp simd linear(uval(i) : 4) // expected-error {{variable of non-reference type 'int' can be used only with 'val' modifier, but used with 'uval'}}
249 for (int k = 0; k < argc; ++k) { ++k; i += 4; }
250 }
251 #pragma omp simd linear(ref(j))
252 for (int k = 0; k < argc; ++k) ++k;
253 #pragma omp simd linear(i)
254 for (int k = 0; k < argc; ++k) ++k;
255
256 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
257 return 0;
258 }
259
260