blob: 6dbad671de7c6510174927eadc8896e0aaa93143 [file] [log] [blame]
Carlo Bertollic0e8e692016-02-11 20:12:28 +00001// RUN: %clang_cc1 -verify -fopenmp %s
2
3struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
4extern S1 a;
5class S2 {
6 mutable int a;
7
8public:
9 S2() : a(0) {}
10};
11const S2 b;
12const S2 ba[5];
13class S3 {
14 int a;
15
16public:
17 S3() : a(0) {}
18};
19const S3 ca[5];
20class S4 {
21 int a;
22 S4();
23
24public:
25 S4(int v) : a(v) {
26#pragma omp target firstprivate(a) firstprivate(this->a)
27 for (int k = 0; k < v; ++k)
28 ++this->a;
29 }
30};
31class S5 {
32 int a;
33 S5() : a(0) {}
34
35public:
36 S5(int v) : a(v) {}
37 S5 &operator=(S5 &s) {
38#pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}}
39 for (int k = 0; k < s.a; ++k)
40 ++s.a;
41 return *this;
42 }
43};
44
45template <typename T>
46class S6 {
47public:
48 T a;
49
50 S6() : a(0) {}
51 S6(T v) : a(v) {
52#pragma omp target firstprivate(a) firstprivate(this->a)
53 for (int k = 0; k < v; ++k)
54 ++this->a;
55 }
56 S6 &operator=(S6 &s) {
57#pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) // expected-error {{expected variable name or data member of current class}}
58 for (int k = 0; k < s.a; ++k)
59 ++s.a;
60 return *this;
61 }
62};
63
64template <typename T>
65class S7 : public T {
66 T a;
67 S7() : a(0) {}
68
69public:
70 S7(T v) : a(v) {
71#pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(T::a)
72 for (int k = 0; k < a.a; ++k)
73 ++this->a.a;
74 }
75 S7 &operator=(S7 &s) {
76#pragma omp target firstprivate(a) firstprivate(this->a) firstprivate(s.a) firstprivate(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
77 for (int k = 0; k < s.a.a; ++k)
78 ++s.a.a;
79 return *this;
80 }
81};
82
83S3 h;
84#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
85
86template <class I, class C>
87int foomain(I argc, C **argv) {
88 I e(4);
89 I g(5);
90 int i;
91 int &j = i;
92#pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}}
93{}
94#pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
95{}
96#pragma omp target firstprivate() // expected-error {{expected expression}}
97{}
98#pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
99{}
Alexey Bataevc5970622016-04-01 08:43:42 +0000100#pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Carlo Bertollic0e8e692016-02-11 20:12:28 +0000101{}
102#pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
103{}
104#pragma omp target firstprivate(argc)
105{}
106#pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
107{}
108#pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
109{}
110#pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
111{}
112#pragma omp target firstprivate(e, g)
113{}
114#pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
115{}
116#pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
117#pragma omp parallel
118 {
119 int v = 0;
120 int i;
121 }
122#pragma omp parallel shared(i)
123#pragma omp parallel firstprivate(i)
124#pragma omp target firstprivate(j)
125{}
126#pragma omp target firstprivate(i)
127 {}
128 return 0;
129}
130
131void bar(S4 a[2]) {
132#pragma omp parallel
133#pragma omp target firstprivate(a)
134 {}
135}
136
137namespace A {
138double x;
139#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
140}
141namespace B {
142using A::x;
143}
144
145int main(int argc, char **argv) {
146 S4 e(4);
147 S5 g(5);
148 S6<float> s6(0.0) , s6_0(1.0);
149 S7<S6<float> > s7(0.0) , s7_0(1.0);
150 int i;
151 int &j = i;
152#pragma omp target firstprivate // expected-error {{expected '(' after 'firstprivate'}}
153{}
154#pragma omp target firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
155{}
156#pragma omp target firstprivate() // expected-error {{expected expression}}
157{}
158#pragma omp target firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
159{}
Alexey Bataevc5970622016-04-01 08:43:42 +0000160#pragma omp target firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Carlo Bertollic0e8e692016-02-11 20:12:28 +0000161{}
162#pragma omp target firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
163{}
164#pragma omp target firstprivate(argc)
165{}
166#pragma omp target firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
167{}
168#pragma omp target firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
169{}
170#pragma omp target firstprivate(argv[1]) // expected-error {{expected variable name}}
171{}
172#pragma omp target firstprivate(e, g)
173{}
174#pragma omp target firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
175{}
176#pragma omp target firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
177{}
178#pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
179#pragma omp parallel
180 {
181 int i;
182 }
183#pragma omp parallel shared(i)
184#pragma omp parallel firstprivate(i)
185#pragma omp target firstprivate(j)
186{}
187#pragma omp target firstprivate(i)
188 {}
189 static int si;
190#pragma omp target firstprivate(si) // OK
191 {}
Carlo Bertollib74bfc82016-03-18 21:43:32 +0000192#pragma omp target map(i) firstprivate(i) // expected-error {{firstprivate variable cannot be in a map clause in '#pragma omp target' directive}}
193 {}
Carlo Bertollic0e8e692016-02-11 20:12:28 +0000194 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
195 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
196 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
197}
198