blob: 16223db71ad573dcb3a659e760ad34c390c84d97 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexander Musman1bb328c2014-06-04 13:06:39 +00002
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
Alexey Bataev7ff55242014-06-19 09:13:45 +000014
Alexander Musman1bb328c2014-06-04 13:06:39 +000015public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000016 S2() : a(0) {}
17 S2(S2 &s2) : a(s2.a) {}
Alexey Bataev38e89532015-04-16 04:54:05 +000018 const S2 &operator=(const S2 &) const;
Alexey Bataev7ff55242014-06-19 09:13:45 +000019 static float S2s; // expected-note {{static data member is predetermined as shared}}
Alexander Musman1bb328c2014-06-04 13:06:39 +000020 static const float S2sc;
21};
Alexey Bataev7ff55242014-06-19 09:13:45 +000022const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
Alexander Musman1bb328c2014-06-04 13:06:39 +000023const S2 b;
24const S2 ba[5];
Alexey Bataev38e89532015-04-16 04:54:05 +000025class S3 {
Alexander Musman1bb328c2014-06-04 13:06:39 +000026 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000027 S3 &operator=(const S3 &s3); // expected-note {{implicitly declared private here}}
Alexey Bataev7ff55242014-06-19 09:13:45 +000028
Alexander Musman1bb328c2014-06-04 13:06:39 +000029public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000030 S3() : a(0) {}
31 S3(S3 &s3) : a(s3.a) {}
Alexander Musman1bb328c2014-06-04 13:06:39 +000032};
Alexey Bataev7ff55242014-06-19 09:13:45 +000033const S3 c; // expected-note {{global variable is predetermined as shared}}
34const S3 ca[5]; // expected-note {{global variable is predetermined as shared}}
35extern const int f; // expected-note {{global variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +000036class S4 {
Alexander Musman1bb328c2014-06-04 13:06:39 +000037 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000038 S4(); // expected-note {{implicitly declared private here}}
Alexander Musman1bb328c2014-06-04 13:06:39 +000039 S4(const S4 &s4);
Alexey Bataev7ff55242014-06-19 09:13:45 +000040
Alexander Musman1bb328c2014-06-04 13:06:39 +000041public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000042 S4(int v) : a(v) {}
Alexander Musman1bb328c2014-06-04 13:06:39 +000043};
Alexey Bataev38e89532015-04-16 04:54:05 +000044class S5 {
Alexander Musman1bb328c2014-06-04 13:06:39 +000045 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000046 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataev7ff55242014-06-19 09:13:45 +000047
Alexander Musman1bb328c2014-06-04 13:06:39 +000048public:
Alexey Bataev7ff55242014-06-19 09:13:45 +000049 S5(const S5 &s5) : a(s5.a) {}
50 S5(int v) : a(v) {}
Alexander Musman1bb328c2014-06-04 13:06:39 +000051};
52
53S3 h;
54#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
55
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +000056namespace A {
57double x;
58#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
59}
60namespace B {
61using A::x;
62}
63
Alexey Bataev7ff55242014-06-19 09:13:45 +000064template <class I, class C>
65int foomain(I argc, C **argv) {
Alexander Musman1bb328c2014-06-04 13:06:39 +000066 I e(4);
67 I g(5);
68 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000069 int &j = i;
Alexey Bataev7ff55242014-06-19 09:13:45 +000070#pragma omp simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
71 for (int k = 0; k < argc; ++k)
72 ++k;
73#pragma omp simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
74 for (int k = 0; k < argc; ++k)
75 ++k;
76#pragma omp simd lastprivate() // expected-error {{expected expression}}
77 for (int k = 0; k < argc; ++k)
78 ++k;
79#pragma omp simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
80 for (int k = 0; k < argc; ++k)
81 ++k;
Alexey Bataevc5970622016-04-01 08:43:42 +000082#pragma omp simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev7ff55242014-06-19 09:13:45 +000083 for (int k = 0; k < argc; ++k)
84 ++k;
85#pragma omp simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
86 for (int k = 0; k < argc; ++k)
87 ++k;
88#pragma omp simd lastprivate(argc)
89 for (int k = 0; k < argc; ++k)
90 ++k;
91#pragma omp simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
92 for (int k = 0; k < argc; ++k)
93 ++k;
94#pragma omp simd lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
95 for (int k = 0; k < argc; ++k)
96 ++k;
97#pragma omp simd lastprivate(argv[1]) // expected-error {{expected variable name}}
98 for (int k = 0; k < argc; ++k)
99 ++k;
100#pragma omp simd lastprivate(e, g)
101 for (int k = 0; k < argc; ++k)
102 ++k;
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000103#pragma omp simd lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000104 for (int k = 0; k < argc; ++k)
105 ++k;
106#pragma omp simd firstprivate(i) // expected-error {{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp simd'}}
107 for (int k = 0; k < argc; ++k)
108 ++k;
109#pragma omp parallel
Alexander Musman1bb328c2014-06-04 13:06:39 +0000110 {
111 int v = 0;
112 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000113#pragma omp simd lastprivate(i)
114 for (int k = 0; k < argc; ++k) {
115 i = k;
116 v += i;
117 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000118 }
Alexey Bataev7ff55242014-06-19 09:13:45 +0000119#pragma omp parallel shared(i)
120#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000121#pragma omp simd lastprivate(j)
Alexey Bataev7ff55242014-06-19 09:13:45 +0000122 for (int k = 0; k < argc; ++k)
123 ++k;
124#pragma omp simd lastprivate(i)
125 for (int k = 0; k < argc; ++k)
126 ++k;
Alexander Musman1bb328c2014-06-04 13:06:39 +0000127 return 0;
128}
129
130int main(int argc, char **argv) {
Alexey Bataev7ff55242014-06-19 09:13:45 +0000131 const int d = 5; // expected-note {{constant variable is predetermined as shared}}
132 const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000133 S4 e(4);
134 S5 g(5);
135 S3 m;
Alexander Musman1bb328c2014-06-04 13:06:39 +0000136 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000137 int &j = i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000138#pragma omp simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
139 for (i = 0; i < argc; ++i)
140 foo();
141#pragma omp simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
142 for (i = 0; i < argc; ++i)
143 foo();
144#pragma omp simd lastprivate() // expected-error {{expected expression}}
145 for (i = 0; i < argc; ++i)
146 foo();
147#pragma omp simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
148 for (i = 0; i < argc; ++i)
149 foo();
Alexey Bataevc5970622016-04-01 08:43:42 +0000150#pragma omp simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000151 for (i = 0; i < argc; ++i)
152 foo();
153#pragma omp simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
154 for (i = 0; i < argc; ++i)
155 foo();
156#pragma omp simd lastprivate(argc)
157 for (i = 0; i < argc; ++i)
158 foo();
159#pragma omp simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
160 for (i = 0; i < argc; ++i)
161 foo();
162#pragma omp simd lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be lastprivate}}
163 for (i = 0; i < argc; ++i)
164 foo();
165#pragma omp simd lastprivate(argv[1]) // expected-error {{expected variable name}}
166 for (i = 0; i < argc; ++i)
167 foo();
168#pragma omp simd lastprivate(2 * 2) // expected-error {{expected variable name}}
169 for (i = 0; i < argc; ++i)
170 foo();
171#pragma omp simd lastprivate(ba)
172 for (i = 0; i < argc; ++i)
173 foo();
174#pragma omp simd lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
175 for (i = 0; i < argc; ++i)
176 foo();
177#pragma omp simd lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
178 for (i = 0; i < argc; ++i)
179 foo();
Alexander Musman1bb328c2014-06-04 13:06:39 +0000180 int xa;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000181#pragma omp simd lastprivate(xa) // OK
182 for (i = 0; i < argc; ++i)
183 foo();
184#pragma omp simd lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
185 for (i = 0; i < argc; ++i)
186 foo();
187#pragma omp simd lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
188 for (i = 0; i < argc; ++i)
189 foo();
190#pragma omp simd firstprivate(g) // expected-error {{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp simd'}}
191 for (i = 0; i < argc; ++i)
192 foo();
Alexey Bataev38e89532015-04-16 04:54:05 +0000193#pragma omp simd lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000194 for (i = 0; i < argc; ++i)
195 foo();
Alexey Bataev38e89532015-04-16 04:54:05 +0000196#pragma omp simd lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000197 for (i = 0; i < argc; ++i)
198 foo();
199#pragma omp simd lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
200 for (i = 0; i < argc; ++i)
201 foo();
202#pragma omp simd private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
203 for (i = 0; i < argc; ++i)
204 foo();
Alexey Bataev4acb8592014-07-07 13:01:15 +0000205#pragma omp simd lastprivate(i) // expected-note {{defined as lastprivate}}
206 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp simd' directive may not be lastprivate, predetermined as linear}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000207 foo();
208#pragma omp parallel private(xa)
209#pragma omp simd lastprivate(xa) // OK: may be lastprivate
210 for (i = 0; i < argc; ++i)
211 foo();
212#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000213#pragma omp simd lastprivate(j)
Alexey Bataev7ff55242014-06-19 09:13:45 +0000214 for (i = 0; i < argc; ++i)
215 foo();
Kelvin Li4eea8c62015-09-15 18:56:58 +0000216 static int t;
217#pragma omp simd lastprivate(t) // OK
218 for (i = 0; i < argc; ++i)
219 foo();
Alexey Bataev74caaf22016-02-20 04:09:36 +0000220 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000221}