1 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s
4 
5 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
6 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
8 
9 // RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s
12 // expected-no-diagnostics
13 
14 #ifndef HEADER
15 #define HEADER
16 
17 #if _OPENMP == 201811
18 void bar();
19 #pragma omp declare target to(bar) device_type(any)
20 // OMP50: #pragma omp declare target{{$}}
21 // OMP50: void bar();
22 // OMP50: #pragma omp end declare target{{$}}
23 void baz();
24 #pragma omp declare target to(baz) device_type(nohost)
25 // OMP50: #pragma omp declare target device_type(nohost){{$}}
26 // OMP50: void baz();
27 // OMP50: #pragma omp end declare target{{$}}
28 void bazz();
29 #pragma omp declare target to(bazz) device_type(host)
30 // OMP50: #pragma omp declare target device_type(host){{$}}
31 // OMP50: void bazz();
32 // OMP50: #pragma omp end declare target{{$}}
33 #endif // _OPENMP
34 
35 int out_decl_target = 0;
36 #pragma omp declare target (out_decl_target)
37 
38 // CHECK: #pragma omp declare target{{$}}
39 // CHECK: int out_decl_target = 0;
40 // CHECK: #pragma omp end declare target{{$}}
41 // CHECK: #pragma omp declare target{{$}}
42 // CHECK: void lambda()
43 // CHECK: #pragma omp end declare target{{$}}
44 
45 #pragma omp declare target
lambda()46 void lambda () {
47 #ifdef __cpp_lambdas
48   (void)[&] { ++out_decl_target; };
49 #else
50   #pragma clang __debug captured
51   (void)out_decl_target;
52 #endif
53 };
54 #pragma omp end declare target
55 
56 #pragma omp declare target
57 // CHECK: #pragma omp declare target{{$}}
foo()58 void foo() {}
59 // CHECK-NEXT: void foo()
60 #pragma omp end declare target
61 // CHECK: #pragma omp end declare target{{$}}
62 
63 extern "C" {
64 #pragma omp declare target
65 // CHECK: #pragma omp declare target
foo_c()66 void foo_c() {}
67 // CHECK-NEXT: void foo_c()
68 #pragma omp end declare target
69 // CHECK: #pragma omp end declare target
70 }
71 
72 extern "C++" {
73 #pragma omp declare target
74 // CHECK: #pragma omp declare target
foo_cpp()75 void foo_cpp() {}
76 // CHECK-NEXT: void foo_cpp()
77 #pragma omp end declare target
78 // CHECK: #pragma omp end declare target
79 }
80 
81 #pragma omp declare target
82 template <class T>
83 struct C {
84 // CHECK: template <class T> struct C {
85 // CHECK: #pragma omp declare target
86 // CHECK-NEXT: static T ts;
87 // CHECK-NEXT: #pragma omp end declare target
88 
89 // CHECK: template<> struct C<int>
90   T t;
91 // CHECK-NEXT: int t;
92   static T ts;
93 // CHECK-NEXT: #pragma omp declare target
94 // CHECK-NEXT: static int ts;
95 // CHECK: #pragma omp end declare target
96 
CC97   C(T t) : t(t) {
98   }
99 // CHECK: #pragma omp declare target
100 // CHECK-NEXT: C(int t) : t(t) {
101 // CHECK-NEXT: }
102 // CHECK: #pragma omp end declare target
103 
fooC104   T foo() {
105     return t;
106   }
107 // CHECK: #pragma omp declare target
108 // CHECK-NEXT: int foo() {
109 // CHECK-NEXT: return this->t;
110 // CHECK-NEXT: }
111 // CHECK: #pragma omp end declare target
112 };
113 
114 template<class T>
115 T C<T>::ts = 1;
116 // CHECK: #pragma omp declare target
117 // CHECK: T ts = 1;
118 // CHECK: #pragma omp end declare target
119 
120 // CHECK: #pragma omp declare target
121 // CHECK: int test1()
test1()122 int test1() {
123   C<int> c(1);
124   return c.foo() + c.ts;
125 }
126 #pragma omp end declare target
127 // CHECK: #pragma omp end declare target
128 
129 int a1;
f1()130 void f1() {
131 }
132 #pragma omp declare target (a1, f1)
133 // CHECK: #pragma omp declare target{{$}}
134 // CHECK: int a1;
135 // CHECK: #pragma omp end declare target{{$}}
136 // CHECK: #pragma omp declare target{{$}}
137 // CHECK: void f1()
138 // CHECK: #pragma omp end declare target{{$}}
139 
140 int b1, b2, b3;
f2()141 void f2() {
142 }
143 #pragma omp declare target to(b1) to(b2), to(b3, f2)
144 // CHECK: #pragma omp declare target{{$}}
145 // CHECK: int b1;
146 // CHECK: #pragma omp end declare target{{$}}
147 // CHECK: #pragma omp declare target{{$}}
148 // CHECK: int b2;
149 // CHECK: #pragma omp end declare target{{$}}
150 // CHECK: #pragma omp declare target{{$}}
151 // CHECK: int b3;
152 // CHECK: #pragma omp end declare target{{$}}
153 // CHECK: #pragma omp declare target{{$}}
154 // CHECK: void f2()
155 // CHECK: #pragma omp end declare target{{$}}
156 
157 int c1, c2, c3;
158 #pragma omp declare target link(c1) link(c2), link(c3)
159 // CHECK: #pragma omp declare target link{{$}}
160 // CHECK: int c1;
161 // CHECK: #pragma omp end declare target{{$}}
162 // CHECK: #pragma omp declare target link{{$}}
163 // CHECK: int c2;
164 // CHECK: #pragma omp end declare target{{$}}
165 // CHECK: #pragma omp declare target link{{$}}
166 // CHECK: int c3;
167 // CHECK: #pragma omp end declare target{{$}}
168 
169 struct SSSt {
170 #pragma omp declare target
171   static int a;
172   int b;
173 #pragma omp end declare target
174 };
175 
176 // CHECK: struct SSSt {
177 // CHECK: #pragma omp declare target
178 // CHECK: static int a;
179 // CHECK: #pragma omp end declare target
180 // CHECK: int b;
181 
182 template <class T>
183 struct SSSTt {
184 #pragma omp declare target
185   static T a;
186   int b;
187 #pragma omp end declare target
188 };
189 
190 // CHECK: template <class T> struct SSSTt {
191 // CHECK: #pragma omp declare target
192 // CHECK: static T a;
193 // CHECK: #pragma omp end declare target
194 // CHECK: int b;
195 
196 #pragma omp declare target
197 template <typename T>
baz()198 T baz() { return T(); }
199 #pragma omp end declare target
200 
201 template <>
baz()202 int baz() { return 1; }
203 
204 // CHECK: #pragma omp declare target
205 // CHECK: template <typename T> T baz() {
206 // CHECK:     return T();
207 // CHECK: }
208 // CHECK: #pragma omp end declare target
209 // CHECK: #pragma omp declare target
210 // CHECK: template<> float baz<float>() {
211 // CHECK:     return float();
212 // CHECK: }
213 // CHECK: template<> int baz<int>() {
214 // CHECK:     return 1;
215 // CHECK: }
216 // CHECK: #pragma omp end declare target
217 
218 #pragma omp declare target
219   #include "declare_target_include.h"
220   void xyz();
221 #pragma omp end declare target
222 
223 // CHECK: #pragma omp declare target
224 // CHECK: void zyx();
225 // CHECK: #pragma omp end declare target
226 // CHECK: #pragma omp declare target
227 // CHECK: void xyz();
228 // CHECK: #pragma omp end declare target
229 
230 #pragma omp declare target
231   #pragma omp declare target
232     void abc();
233   #pragma omp end declare target
234   void cba();
235 #pragma omp end declare target
236 
237 // CHECK: #pragma omp declare target
238 // CHECK: void abc();
239 // CHECK: #pragma omp end declare target
240 // CHECK: #pragma omp declare target
241 // CHECK: void cba();
242 // CHECK: #pragma omp end declare target
243 
244 #pragma omp declare target
abc1()245 int abc1() { return 1; }
246 #pragma omp declare target to(abc1) device_type(nohost)
247 #pragma omp end declare target
248 
249 // CHECK-NEXT: #pragma omp declare target
250 // CHECK-NEXT: #pragma omp declare target device_type(nohost)
251 // CHECK-NEXT: int abc1() {
252 // CHECK-NEXT: return 1;
253 // CHECK-NEXT: }
254 // CHECK-NEXT: #pragma omp end declare target
255 
256 #pragma omp declare target
257 int inner_link;
258 #pragma omp declare target link(inner_link)
259 #pragma omp end declare target
260 
261 // CHECK-NEXT: #pragma omp declare target
262 // CHECK-NEXT: #pragma omp declare target link
263 // CHECK-NEXT: int inner_link;
264 // CHECK-NEXT: #pragma omp end declare target
265 
main(int argc,char ** argv)266 int main (int argc, char **argv) {
267   foo();
268   foo_c();
269   foo_cpp();
270   test1();
271   baz<float>();
272   baz<int>();
273   return (0);
274 }
275 
276 // CHECK: #pragma omp declare target
277 // CHECK-NEXT: int ts = 1;
278 // CHECK-NEXT: #pragma omp end declare target
279 
280 // Do not expect anything here since the region is empty.
281 #pragma omp declare target
282 #pragma omp end declare target
283 
284 #endif
285