1 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 2 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s 3 4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50 5 // RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51 6 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52 7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK 8 9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 10 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50 11 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 12 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51 13 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 14 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52 15 16 // RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s 17 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 18 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s 19 // expected-no-diagnostics 20 21 #ifndef HEADER 22 #define HEADER 23 24 #if _OPENMP == 201811 25 void bar(); 26 #pragma omp declare target to(bar) device_type(any) 27 // OMP50: #pragma omp declare target{{$}} 28 // OMP50: void bar(); 29 // OMP50: #pragma omp end declare target{{$}} 30 void baz(); 31 #pragma omp declare target to(baz) device_type(nohost) 32 // OMP50: #pragma omp declare target device_type(nohost){{$}} 33 // OMP50: void baz(); 34 // OMP50: #pragma omp end declare target{{$}} 35 void bazz(); 36 #pragma omp declare target to(bazz) device_type(host) 37 // OMP50: #pragma omp declare target device_type(host){{$}} 38 // OMP50: void bazz(); 39 // OMP50: #pragma omp end declare target{{$}} 40 #endif // _OPENMP 41 42 #if _OPENMP == 202011 43 extern "C" { 44 void boo_c() {} 45 #pragma omp declare target to(boo_c) indirect 46 // OMP51: #pragma omp declare target indirect 47 // OMP51: void boo_c() { 48 // OMP51: } 49 // OMP51: #pragma omp end declare target 50 #pragma omp declare target indirect 51 void yoo(){} 52 #pragma omp end declare target 53 // OMP51: #pragma omp declare target indirect 54 // OMP51: void yoo() { 55 // OMP51: } 56 // OMP51: #pragma omp end declare target 57 } 58 extern "C++" { 59 void boo_cpp() {} 60 #pragma omp declare target to(boo_cpp) indirect 61 // OMP51: #pragma omp declare target indirect 62 // OMP51: void boo_cpp() { 63 // OMP51: } 64 // OMP51: #pragma omp end declare target 65 66 constexpr bool f() {return false;} 67 #pragma omp begin declare target indirect(f()) 68 void zoo() {} 69 void xoo(); 70 #pragma omp end declare target 71 #pragma omp declare target to(zoo) indirect(false) 72 // OMP51: #pragma omp declare target indirect(f()) 73 // OMP51: #pragma omp declare target indirect(false) 74 // OMP51: void zoo() { 75 // OMP51: } 76 // OMP51: #pragma omp end declare target 77 // OMP51: #pragma omp declare target indirect(f()) 78 // OMP51: void xoo(); 79 // OMP51: #pragma omp end declare target 80 81 } 82 #endif // _OPENMP 83 84 #if _OPENMP == 202111 85 extern "C" { 86 void boo_c() {} 87 #pragma omp declare target enter(boo_c) indirect 88 // OMP52: #pragma omp declare target indirect 89 // OMP52: void boo_c() { 90 // OMP52: } 91 // OMP52: #pragma omp end declare target 92 #pragma omp declare target indirect 93 void yoo(){} 94 #pragma omp end declare target 95 // OMP52: #pragma omp declare target indirect 96 // OMP52: void yoo() { 97 // OMP52: } 98 // OMP52: #pragma omp end declare target 99 } 100 extern "C++" { 101 void boo_cpp() {} 102 #pragma omp declare target enter(boo_cpp) indirect 103 // OMP52: #pragma omp declare target indirect 104 // OMP52: void boo_cpp() { 105 // OMP52: } 106 // OMP52: #pragma omp end declare target 107 108 constexpr bool f() {return false;} 109 #pragma omp begin declare target indirect(f()) 110 void zoo() {} 111 void xoo(); 112 #pragma omp end declare target 113 #pragma omp declare target enter(zoo) indirect(false) 114 // OMP52: #pragma omp declare target indirect(f()) 115 // OMP52: #pragma omp declare target indirect(false) 116 // OMP52: void zoo() { 117 // OMP52: } 118 // OMP52: #pragma omp end declare target 119 // OMP52: #pragma omp declare target indirect(f()) 120 // OMP52: void xoo(); 121 // OMP52: #pragma omp end declare target 122 123 } 124 #endif // _OPENMP 125 126 int out_decl_target = 0; 127 #pragma omp declare target (out_decl_target) 128 129 // CHECK: #pragma omp declare target{{$}} 130 // CHECK: int out_decl_target = 0; 131 // CHECK: #pragma omp end declare target{{$}} 132 // CHECK: #pragma omp declare target{{$}} 133 // CHECK: void lambda() 134 // CHECK: #pragma omp end declare target{{$}} 135 136 #pragma omp declare target 137 void lambda () { 138 #ifdef __cpp_lambdas 139 (void)[&] { ++out_decl_target; }; 140 #else 141 #pragma clang __debug captured 142 (void)out_decl_target; 143 #endif 144 }; 145 #pragma omp end declare target 146 147 #pragma omp declare target 148 // CHECK: #pragma omp declare target{{$}} 149 void foo() {} 150 // CHECK-NEXT: void foo() 151 #pragma omp end declare target 152 // CHECK: #pragma omp end declare target{{$}} 153 154 extern "C" { 155 #pragma omp declare target 156 // CHECK: #pragma omp declare target 157 void foo_c() {} 158 // CHECK-NEXT: void foo_c() 159 #pragma omp end declare target 160 // CHECK: #pragma omp end declare target 161 } 162 163 extern "C++" { 164 #pragma omp declare target 165 // CHECK: #pragma omp declare target 166 void foo_cpp() {} 167 // CHECK-NEXT: void foo_cpp() 168 #pragma omp end declare target 169 // CHECK: #pragma omp end declare target 170 } 171 172 #pragma omp declare target 173 template <class T> 174 struct C { 175 // CHECK: template <class T> struct C { 176 // CHECK: #pragma omp declare target 177 // CHECK-NEXT: static T ts; 178 // CHECK-NEXT: #pragma omp end declare target 179 180 // CHECK: template<> struct C<int> 181 T t; 182 // CHECK-NEXT: int t; 183 static T ts; 184 // CHECK-NEXT: #pragma omp declare target 185 // CHECK-NEXT: static int ts; 186 // CHECK: #pragma omp end declare target 187 188 C(T t) : t(t) { 189 } 190 // CHECK: #pragma omp declare target 191 // CHECK-NEXT: C(int t) : t(t) { 192 // CHECK-NEXT: } 193 // CHECK: #pragma omp end declare target 194 195 T foo() { 196 return t; 197 } 198 // CHECK: #pragma omp declare target 199 // CHECK-NEXT: int foo() { 200 // CHECK-NEXT: return this->t; 201 // CHECK-NEXT: } 202 // CHECK: #pragma omp end declare target 203 }; 204 205 template<class T> 206 T C<T>::ts = 1; 207 // CHECK: #pragma omp declare target 208 // CHECK: T ts = 1; 209 // CHECK: #pragma omp end declare target 210 211 // CHECK: #pragma omp declare target 212 // CHECK: int test1() 213 int test1() { 214 C<int> c(1); 215 return c.foo() + c.ts; 216 } 217 #pragma omp end declare target 218 // CHECK: #pragma omp end declare target 219 220 int a1; 221 void f1() { 222 } 223 #pragma omp declare target (a1, f1) 224 // CHECK: #pragma omp declare target{{$}} 225 // CHECK: int a1; 226 // CHECK: #pragma omp end declare target{{$}} 227 // CHECK: #pragma omp declare target{{$}} 228 // CHECK: void f1() 229 // CHECK: #pragma omp end declare target{{$}} 230 231 int b1, b2, b3; 232 void f2() { 233 } 234 #if _OPENMP >= 202111 235 #pragma omp declare target enter(b1) enter(b2), enter(b3, f2) 236 #else 237 #pragma omp declare target to(b1) to(b2), to(b3, f2) 238 #endif // _OPENMP == 202111 239 // CHECK: #pragma omp declare target{{$}} 240 // CHECK: int b1; 241 // CHECK: #pragma omp end declare target{{$}} 242 // CHECK: #pragma omp declare target{{$}} 243 // CHECK: int b2; 244 // CHECK: #pragma omp end declare target{{$}} 245 // CHECK: #pragma omp declare target{{$}} 246 // CHECK: int b3; 247 // CHECK: #pragma omp end declare target{{$}} 248 // CHECK: #pragma omp declare target{{$}} 249 // CHECK: void f2() 250 // CHECK: #pragma omp end declare target{{$}} 251 252 int c1, c2, c3; 253 #pragma omp declare target link(c1) link(c2), link(c3) 254 // CHECK: #pragma omp declare target link{{$}} 255 // CHECK: int c1; 256 // CHECK: #pragma omp end declare target{{$}} 257 // CHECK: #pragma omp declare target link{{$}} 258 // CHECK: int c2; 259 // CHECK: #pragma omp end declare target{{$}} 260 // CHECK: #pragma omp declare target link{{$}} 261 // CHECK: int c3; 262 // CHECK: #pragma omp end declare target{{$}} 263 264 struct SSSt { 265 #pragma omp declare target 266 static int a; 267 int b; 268 #pragma omp end declare target 269 }; 270 271 // CHECK: struct SSSt { 272 // CHECK: #pragma omp declare target 273 // CHECK: static int a; 274 // CHECK: #pragma omp end declare target 275 // CHECK: int b; 276 277 template <class T> 278 struct SSSTt { 279 #pragma omp declare target 280 static T a; 281 int b; 282 #pragma omp end declare target 283 }; 284 285 // CHECK: template <class T> struct SSSTt { 286 // CHECK: #pragma omp declare target 287 // CHECK: static T a; 288 // CHECK: #pragma omp end declare target 289 // CHECK: int b; 290 291 #pragma omp declare target 292 template <typename T> 293 T baz() { return T(); } 294 #pragma omp end declare target 295 296 template <> 297 int baz() { return 1; } 298 299 // CHECK: #pragma omp declare target 300 // CHECK: template <typename T> T baz() { 301 // CHECK: return T(); 302 // CHECK: } 303 // CHECK: #pragma omp end declare target 304 // CHECK: #pragma omp declare target 305 // CHECK: template<> float baz<float>() { 306 // CHECK: return float(); 307 // CHECK: } 308 // CHECK: template<> int baz<int>() { 309 // CHECK: return 1; 310 // CHECK: } 311 // CHECK: #pragma omp end declare target 312 313 #pragma omp declare target 314 #include "declare_target_include.h" 315 void xyz(); 316 #pragma omp end declare target 317 318 // CHECK: #pragma omp declare target 319 // CHECK: void zyx(); 320 // CHECK: #pragma omp end declare target 321 // CHECK: #pragma omp declare target 322 // CHECK: void xyz(); 323 // CHECK: #pragma omp end declare target 324 325 #pragma omp declare target 326 #pragma omp declare target 327 void abc(); 328 #pragma omp end declare target 329 void cba(); 330 #pragma omp end declare target 331 332 // CHECK: #pragma omp declare target 333 // CHECK: void abc(); 334 // CHECK: #pragma omp end declare target 335 // CHECK: #pragma omp declare target 336 // CHECK: void cba(); 337 // CHECK: #pragma omp end declare target 338 339 #pragma omp declare target 340 int abc1() { return 1; } 341 #if _OPENMP >= 202111 342 #pragma omp declare target enter(abc1) device_type(nohost) 343 #else 344 #pragma omp declare target to(abc1) device_type(nohost) 345 #endif // _OPENMP == 202111 346 #pragma omp end declare target 347 348 // CHECK-NEXT: #pragma omp declare target 349 // CHECK-NEXT: #pragma omp declare target device_type(nohost) 350 // CHECK-NEXT: int abc1() { 351 // CHECK-NEXT: return 1; 352 // CHECK-NEXT: } 353 // CHECK-NEXT: #pragma omp end declare target 354 355 #pragma omp declare target 356 int inner_link; 357 #pragma omp declare target link(inner_link) 358 #pragma omp end declare target 359 360 // CHECK-NEXT: #pragma omp declare target 361 // CHECK-NEXT: #pragma omp declare target link 362 // CHECK-NEXT: int inner_link; 363 // CHECK-NEXT: #pragma omp end declare target 364 365 void foo2() { return ;} 366 // CHECK: #pragma omp declare target 367 // CHECK-NEXT: void foo2() { 368 // CHECK-NEXT: return; 369 // CHECK-NEXT: } 370 371 int x; 372 // CHECK: #pragma omp declare target link 373 // CHECK-NEXT: int x; 374 // CHECK-NEXT: #pragma omp end declare target 375 376 int main (int argc, char **argv) { 377 foo(); 378 foo_c(); 379 foo_cpp(); 380 test1(); 381 baz<float>(); 382 baz<int>(); 383 384 #if _OPENMP >= 202111 385 #pragma omp declare target enter(foo2) 386 #else 387 #pragma omp declare target to (foo2) 388 #endif 389 390 #pragma omp declare target link(x) 391 return (0); 392 } 393 394 // CHECK: #pragma omp declare target 395 // CHECK-NEXT: int ts = 1; 396 // CHECK-NEXT: #pragma omp end declare target 397 398 // Do not expect anything here since the region is empty. 399 #pragma omp declare target 400 #pragma omp end declare target 401 402 #endif 403