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