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