blob: 49ee3fed3e94b04a8c50af7d688c7ec69bf6dbed [file] [log] [blame]
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +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 Bertolli9e8c6c12016-01-19 16:53:55 +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(); // expected-note {{implicitly declared private here}}
25
26public:
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000027 S4(int v) : a(v) {
28#pragma omp target private(a) private(this->a)
29 for (int k = 0; k < v; ++k)
30 ++this->a;
31 }
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +000032};
33class S5 {
34 int a;
35 S5() : a(0) {} // expected-note {{implicitly declared private here}}
36
37public:
38 S5(int v) : a(v) {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000039 S5 &operator=(S5 &s) {
40#pragma omp target private(a) private(this->a) private(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}}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +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 private(a) private(this->a)
55 for (int k = 0; k < v; ++k)
56 ++this->a;
57 }
58 S6 &operator=(S6 &s) {
59#pragma omp target private(a) private(this->a) private(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 private(a) private(this->a) private(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 private(a) private(this->a) private(s.a) private(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 }
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +000083};
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 private // expected-error {{expected '(' after 'private'}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +000095{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +000096#pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +000097{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +000098#pragma omp target private() // expected-error {{expected expression}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +000099{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000100#pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000101{}
Alexey Bataevc5970622016-04-01 08:43:42 +0000102#pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000103{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000104#pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000105{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000106#pragma omp target private(argc)
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000107{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000108#pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000109{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000110#pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000111{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000112#pragma omp target private(argv[1]) // expected-error {{expected variable name}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000113{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000114#pragma omp target private(e, g)
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000115{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000116#pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000117{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000118#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;
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000123 }
124#pragma omp parallel shared(i)
125#pragma omp parallel private(i)
126#pragma omp target private(j)
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000127{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000128#pragma omp target private(i)
129 {}
130 return 0;
131}
132
133void bar(S4 a[2]) {
134#pragma omp parallel
135#pragma omp target private(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);
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000150 S6<float> s6(0.0) , s6_0(1.0);
151 S7<S6<float> > s7(0.0) , s7_0(1.0);
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000152 int i;
153 int &j = i;
154#pragma omp target private // expected-error {{expected '(' after 'private'}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000155{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000156#pragma omp target private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000157{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000158#pragma omp target private() // expected-error {{expected expression}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000159{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000160#pragma omp target private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000161{}
Alexey Bataevc5970622016-04-01 08:43:42 +0000162#pragma omp target private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000163{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000164#pragma omp target private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000165{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000166#pragma omp target private(argc)
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000167{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000168#pragma omp target private(S1) // expected-error {{'S1' does not refer to a value}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000169{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000170#pragma omp target private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000171{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000172#pragma omp target private(argv[1]) // expected-error {{expected variable name}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000173{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000174#pragma omp target private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000175{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000176#pragma omp target private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000177{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000178#pragma omp target private(B::x) // expected-error {{threadprivate or thread local variable cannot be private}}
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000179{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000180#pragma omp target shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp target'}}
181#pragma omp parallel
182 {
183 int i;
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000184 }
185#pragma omp parallel shared(i)
186#pragma omp parallel private(i)
187#pragma omp target private(j)
Arpith Chacko Jacob3d58f262016-02-02 04:00:47 +0000188{}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000189#pragma omp target private(i)
190 {}
191 static int si;
192#pragma omp target private(si) // OK
193 {}
Carlo Bertollib74bfc82016-03-18 21:43:32 +0000194#pragma omp target map(i) private(i) // expected-error {{private variable cannot be in a map clause in '#pragma omp target' directive}}
195 {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +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}}
Carlo Bertolli9e8c6c12016-01-19 16:53:55 +0000199}
200