Clang Project

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