blob: 33871813b889fa80a7067bf4471a2fd0a39f5e5d [file] [log] [blame]
Alexander Musman1bb328c2014-06-04 13:06:39 +00001// RUN: %clang_cc1 -verify -fopenmp=libiomp5 %s
2
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 Bataev7ff55242014-06-19 09:13:45 +000056template <class I, class C>
57int foomain(I argc, C **argv) {
Alexander Musman1bb328c2014-06-04 13:06:39 +000058 I e(4);
59 I g(5);
60 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +000061 int &j = i; // expected-note {{'j' defined here}}
62#pragma omp simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
63 for (int k = 0; k < argc; ++k)
64 ++k;
65#pragma omp simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
66 for (int k = 0; k < argc; ++k)
67 ++k;
68#pragma omp simd lastprivate() // expected-error {{expected expression}}
69 for (int k = 0; k < argc; ++k)
70 ++k;
71#pragma omp simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
72 for (int k = 0; k < argc; ++k)
73 ++k;
74#pragma omp simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
75 for (int k = 0; k < argc; ++k)
76 ++k;
77#pragma omp simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
78 for (int k = 0; k < argc; ++k)
79 ++k;
80#pragma omp simd lastprivate(argc)
81 for (int k = 0; k < argc; ++k)
82 ++k;
83#pragma omp simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
84 for (int k = 0; k < argc; ++k)
85 ++k;
86#pragma omp simd lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
87 for (int k = 0; k < argc; ++k)
88 ++k;
89#pragma omp simd lastprivate(argv[1]) // expected-error {{expected variable name}}
90 for (int k = 0; k < argc; ++k)
91 ++k;
92#pragma omp simd lastprivate(e, g)
93 for (int k = 0; k < argc; ++k)
94 ++k;
95#pragma omp simd lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
96 for (int k = 0; k < argc; ++k)
97 ++k;
98#pragma omp simd firstprivate(i) // expected-error {{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp simd'}}
99 for (int k = 0; k < argc; ++k)
100 ++k;
101#pragma omp parallel
Alexander Musman1bb328c2014-06-04 13:06:39 +0000102 {
103 int v = 0;
104 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000105#pragma omp simd lastprivate(i)
106 for (int k = 0; k < argc; ++k) {
107 i = k;
108 v += i;
109 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000110 }
Alexey Bataev7ff55242014-06-19 09:13:45 +0000111#pragma omp parallel shared(i)
112#pragma omp parallel private(i)
113#pragma omp simd lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
114 for (int k = 0; k < argc; ++k)
115 ++k;
116#pragma omp simd lastprivate(i)
117 for (int k = 0; k < argc; ++k)
118 ++k;
Alexander Musman1bb328c2014-06-04 13:06:39 +0000119 return 0;
120}
121
122int main(int argc, char **argv) {
Alexey Bataev7ff55242014-06-19 09:13:45 +0000123 const int d = 5; // expected-note {{constant variable is predetermined as shared}}
124 const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000125 S4 e(4);
126 S5 g(5);
127 S3 m;
Alexander Musman1bb328c2014-06-04 13:06:39 +0000128 int i;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000129 int &j = i; // expected-note {{'j' defined here}}
130#pragma omp simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
131 for (i = 0; i < argc; ++i)
132 foo();
133#pragma omp simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
134 for (i = 0; i < argc; ++i)
135 foo();
136#pragma omp simd lastprivate() // expected-error {{expected expression}}
137 for (i = 0; i < argc; ++i)
138 foo();
139#pragma omp simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
140 for (i = 0; i < argc; ++i)
141 foo();
142#pragma omp simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
143 for (i = 0; i < argc; ++i)
144 foo();
145#pragma omp simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
146 for (i = 0; i < argc; ++i)
147 foo();
148#pragma omp simd lastprivate(argc)
149 for (i = 0; i < argc; ++i)
150 foo();
151#pragma omp simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
152 for (i = 0; i < argc; ++i)
153 foo();
154#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}}
155 for (i = 0; i < argc; ++i)
156 foo();
157#pragma omp simd lastprivate(argv[1]) // expected-error {{expected variable name}}
158 for (i = 0; i < argc; ++i)
159 foo();
160#pragma omp simd lastprivate(2 * 2) // expected-error {{expected variable name}}
161 for (i = 0; i < argc; ++i)
162 foo();
163#pragma omp simd lastprivate(ba)
164 for (i = 0; i < argc; ++i)
165 foo();
166#pragma omp simd lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
167 for (i = 0; i < argc; ++i)
168 foo();
169#pragma omp simd lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
170 for (i = 0; i < argc; ++i)
171 foo();
Alexander Musman1bb328c2014-06-04 13:06:39 +0000172 int xa;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000173#pragma omp simd lastprivate(xa) // OK
174 for (i = 0; i < argc; ++i)
175 foo();
176#pragma omp simd lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
177 for (i = 0; i < argc; ++i)
178 foo();
179#pragma omp simd lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
180 for (i = 0; i < argc; ++i)
181 foo();
182#pragma omp simd firstprivate(g) // expected-error {{unexpected OpenMP clause 'firstprivate' in directive '#pragma omp simd'}}
183 for (i = 0; i < argc; ++i)
184 foo();
Alexey Bataev38e89532015-04-16 04:54:05 +0000185#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 +0000186 for (i = 0; i < argc; ++i)
187 foo();
Alexey Bataev38e89532015-04-16 04:54:05 +0000188#pragma omp simd lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000189 for (i = 0; i < argc; ++i)
190 foo();
191#pragma omp simd lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
192 for (i = 0; i < argc; ++i)
193 foo();
194#pragma omp simd private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
195 for (i = 0; i < argc; ++i)
196 foo();
Alexey Bataev4acb8592014-07-07 13:01:15 +0000197#pragma omp simd lastprivate(i) // expected-note {{defined as lastprivate}}
198 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 +0000199 foo();
200#pragma omp parallel private(xa)
201#pragma omp simd lastprivate(xa) // OK: may be lastprivate
202 for (i = 0; i < argc; ++i)
203 foo();
204#pragma omp parallel
205#pragma omp simd lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
206 for (i = 0; i < argc; ++i)
207 foo();
Alexander Musman1bb328c2014-06-04 13:06:39 +0000208 return 0;
209}