brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.2 KiB · 68f73d5 Raw
403 lines · cpp
1// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s2// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s3 4// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP505// RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP516// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP527// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=60 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK8 9// RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s10// 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=OMP5011// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s12// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP5113// RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s14// 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=OMP5215 16// RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s17// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s18// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -I %S/Inputs -verify %s -ast-print | FileCheck %s19// expected-no-diagnostics20 21#ifndef HEADER22#define HEADER23 24#if _OPENMP == 20181125void 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{{$}}30void 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{{$}}35void 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 // _OPENMP41 42#if _OPENMP == 20201143extern "C" {44void boo_c() {}45#pragma omp declare target to(boo_c) indirect46// OMP51: #pragma omp declare target indirect47// OMP51: void boo_c() {48// OMP51: }49// OMP51: #pragma omp end declare target50#pragma omp declare target indirect51void yoo(){}52#pragma omp end declare target53// OMP51: #pragma omp declare target indirect54// OMP51: void yoo() {55// OMP51: }56// OMP51: #pragma omp end declare target57}58extern "C++" {59void boo_cpp() {}60#pragma omp declare target to(boo_cpp) indirect61// OMP51: #pragma omp declare target indirect62// OMP51: void boo_cpp() {63// OMP51: }64// OMP51: #pragma omp end declare target65 66constexpr bool f() {return false;}67#pragma omp begin declare target indirect(f())68void zoo() {}69void xoo();70#pragma omp end declare target71#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 target77// OMP51: #pragma omp declare target indirect(f())78// OMP51: void xoo();79// OMP51: #pragma omp end declare target80 81}82#endif // _OPENMP83 84#if _OPENMP == 20211185extern "C" {86void boo_c() {}87#pragma omp declare target enter(boo_c) indirect88// OMP52: #pragma omp declare target indirect89// OMP52: void boo_c() {90// OMP52: }91// OMP52: #pragma omp end declare target92#pragma omp declare target indirect93void yoo(){}94#pragma omp end declare target95// OMP52: #pragma omp declare target indirect96// OMP52: void yoo() {97// OMP52: }98// OMP52: #pragma omp end declare target99}100extern "C++" {101void boo_cpp() {}102#pragma omp declare target enter(boo_cpp) indirect103// OMP52: #pragma omp declare target indirect104// OMP52: void boo_cpp() {105// OMP52: }106// OMP52: #pragma omp end declare target107 108constexpr bool f() {return false;}109#pragma omp begin declare target indirect(f())110void zoo() {}111void xoo();112#pragma omp end declare target113#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 target119// OMP52: #pragma omp declare target indirect(f())120// OMP52: void xoo();121// OMP52: #pragma omp end declare target122 123}124#endif // _OPENMP125 126int 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 begin declare target137void lambda () {138#ifdef __cpp_lambdas139  (void)[&] { ++out_decl_target; };140#else141  #pragma clang __debug captured142  (void)out_decl_target;143#endif144};145#pragma omp end declare target146 147#pragma omp begin declare target148// CHECK: #pragma omp declare target{{$}}149void foo() {}150// CHECK-NEXT: void foo()151#pragma omp end declare target152// CHECK: #pragma omp end declare target{{$}}153 154extern "C" {155#pragma omp begin declare target156// CHECK: #pragma omp declare target157void foo_c() {}158// CHECK-NEXT: void foo_c()159#pragma omp end declare target160// CHECK: #pragma omp end declare target161}162 163extern "C++" {164#pragma omp begin declare target165// CHECK: #pragma omp declare target166void foo_cpp() {}167// CHECK-NEXT: void foo_cpp()168#pragma omp end declare target169// CHECK: #pragma omp end declare target170}171 172#pragma omp begin declare target173template <class T>174struct C {175// CHECK: template <class T> struct C {176// CHECK: #pragma omp declare target177// CHECK-NEXT: static T ts;178// CHECK-NEXT: #pragma omp end declare target179 180// CHECK: template<> struct C<int>181  T t;182// CHECK-NEXT: int t;183  static T ts;184// CHECK-NEXT: #pragma omp declare target185// CHECK-NEXT: static int ts;186// CHECK: #pragma omp end declare target187 188  C(T t) : t(t) {189  }190// CHECK: #pragma omp declare target191// CHECK-NEXT: C(int t) : t(t) {192// CHECK-NEXT: }193// CHECK: #pragma omp end declare target194 195  T foo() {196    return t;197  }198// CHECK: #pragma omp declare target199// CHECK-NEXT: int foo() {200// CHECK-NEXT: return this->t;201// CHECK-NEXT: }202// CHECK: #pragma omp end declare target203};204 205template<class T>206T C<T>::ts = 1;207// CHECK: #pragma omp declare target208// CHECK: T ts = 1;209// CHECK: #pragma omp end declare target210 211// CHECK: #pragma omp declare target212// CHECK: int test1()213int test1() {214  C<int> c(1);215  return c.foo() + c.ts;216}217#pragma omp end declare target218// CHECK: #pragma omp end declare target219 220int a1;221void 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 231int b1, b2, b3;232void f2() {233}234#if _OPENMP >= 202111235#pragma omp declare target enter(b1) enter(b2), enter(b3, f2)236#else237#pragma omp declare target to(b1) to(b2), to(b3, f2)238#endif // _OPENMP == 202111239// 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 252int 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 264struct SSSt {265#pragma omp begin declare target266  static int a;267  int b;268#pragma omp end declare target269};270 271// CHECK: struct SSSt {272// CHECK: #pragma omp declare target273// CHECK: static int a;274// CHECK: #pragma omp end declare target275// CHECK: int b;276 277template <class T>278struct SSSTt {279#pragma omp begin declare target280  static T a;281  int b;282#pragma omp end declare target283};284 285// CHECK: template <class T> struct SSSTt {286// CHECK: #pragma omp declare target287// CHECK: static T a;288// CHECK: #pragma omp end declare target289// CHECK: int b;290 291#pragma omp begin declare target292template <typename T>293T baz() { return T(); }294#pragma omp end declare target295 296template <>297int baz() { return 1; }298 299// CHECK: #pragma omp declare target300// CHECK: template <typename T> T baz() {301// CHECK:     return T();302// CHECK: }303// CHECK: #pragma omp end declare target304// CHECK: #pragma omp declare target305// 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 target312 313#pragma omp begin declare target314  #include "declare_target_include.h"315  void xyz();316#pragma omp end declare target317 318// CHECK: #pragma omp declare target319// CHECK: void zyx();320// CHECK: #pragma omp end declare target321// CHECK: #pragma omp declare target322// CHECK: void xyz();323// CHECK: #pragma omp end declare target324 325#pragma omp begin declare target326  #pragma omp begin declare target327    void abc();328  #pragma omp end declare target329  void cba();330#pragma omp end declare target331 332// CHECK: #pragma omp declare target333// CHECK: void abc();334// CHECK: #pragma omp end declare target335// CHECK: #pragma omp declare target336// CHECK: void cba();337// CHECK: #pragma omp end declare target338 339#pragma omp begin declare target340int abc1() { return 1; }341#if _OPENMP >= 202111342#pragma omp declare target enter(abc1) device_type(nohost)343#else344#pragma omp declare target to(abc1) device_type(nohost)345#endif // _OPENMP == 202111346#pragma omp end declare target347 348// CHECK-NEXT: #pragma omp declare target349// 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 target354 355#pragma omp begin declare target356int inner_link;357#pragma omp declare target link(inner_link)358#pragma omp end declare target359 360// CHECK-NEXT: #pragma omp declare target361// CHECK-NEXT: #pragma omp declare target link362// CHECK-NEXT: int inner_link;363// CHECK-NEXT: #pragma omp end declare target364 365void foo2() { return ;}366// CHECK: #pragma omp declare target367// CHECK-NEXT: void foo2() {368// CHECK-NEXT: return;369// CHECK-NEXT: }370 371int x;372// CHECK: #pragma omp declare target link373// CHECK-NEXT: int x;374// CHECK-NEXT: #pragma omp end declare target375 376int 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 >= 202111385#pragma omp declare target enter(foo2)386#else387#pragma omp declare target to (foo2)388#endif389 390  #pragma omp declare target link(x)391  return (0);392}393 394// CHECK: #pragma omp declare target395// CHECK-NEXT: int ts = 1;396// CHECK-NEXT: #pragma omp end declare target397 398// Do not expect anything here since the region is empty.399#pragma omp begin declare target400#pragma omp end declare target401 402#endif403