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 -fopenmp-version=50 -I %S/Inputs -ast-print %s | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50 6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s 7 // RUN: %clang_cc1 -fopenmp -fopenmp-version=50 -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 #if _OPENMP == 201811 37 #pragma omp declare target (out_decl_target) 38 #endif // _OPENMP 39 40 // CHECK: #pragma omp declare target{{$}} 41 // CHECK: int out_decl_target = 0; 42 // CHECK: #pragma omp end declare target{{$}} 43 // CHECK: #pragma omp declare target{{$}} 44 // CHECK: void lambda() 45 // CHECK: #pragma omp end declare target{{$}} 46 47 #pragma omp declare target 48 void lambda () { 49 #ifdef __cpp_lambdas 50 (void)[&] { ++out_decl_target; }; 51 #else 52 #pragma clang __debug captured 53 (void)out_decl_target; 54 #endif 55 }; 56 #pragma omp end declare target 57 58 #pragma omp declare target 59 // CHECK: #pragma omp declare target{{$}} 60 void foo() {} 61 // CHECK-NEXT: void foo() 62 #pragma omp end declare target 63 // CHECK: #pragma omp end declare target{{$}} 64 65 extern "C" { 66 #pragma omp declare target 67 // CHECK: #pragma omp declare target 68 void foo_c() {} 69 // CHECK-NEXT: void foo_c() 70 #pragma omp end declare target 71 // CHECK: #pragma omp end declare target 72 } 73 74 extern "C++" { 75 #pragma omp declare target 76 // CHECK: #pragma omp declare target 77 void foo_cpp() {} 78 // CHECK-NEXT: void foo_cpp() 79 #pragma omp end declare target 80 // CHECK: #pragma omp end declare target 81 } 82 83 #pragma omp declare target 84 template <class T> 85 struct C { 86 // CHECK: template <class T> struct C { 87 // CHECK: #pragma omp declare target 88 // CHECK-NEXT: static T ts; 89 // CHECK-NEXT: #pragma omp end declare target 90 91 // CHECK: template<> struct C<int> 92 T t; 93 // CHECK-NEXT: int t; 94 static T ts; 95 // CHECK-NEXT: #pragma omp declare target 96 // CHECK-NEXT: static int ts; 97 // CHECK: #pragma omp end declare target 98 99 C(T t) : t(t) { 100 } 101 // CHECK: #pragma omp declare target 102 // CHECK-NEXT: C(int t) : t(t) { 103 // CHECK-NEXT: } 104 // CHECK: #pragma omp end declare target 105 106 T foo() { 107 return t; 108 } 109 // CHECK: #pragma omp declare target 110 // CHECK-NEXT: int foo() { 111 // CHECK-NEXT: return this->t; 112 // CHECK-NEXT: } 113 // CHECK: #pragma omp end declare target 114 }; 115 116 template<class T> 117 T C<T>::ts = 1; 118 // CHECK: #pragma omp declare target 119 // CHECK: T ts = 1; 120 // CHECK: #pragma omp end declare target 121 122 // CHECK: #pragma omp declare target 123 // CHECK: int test1() 124 int test1() { 125 C<int> c(1); 126 return c.foo() + c.ts; 127 } 128 #pragma omp end declare target 129 // CHECK: #pragma omp end declare target 130 131 int a1; 132 void f1() { 133 } 134 #pragma omp declare target (a1, f1) 135 // CHECK: #pragma omp declare target{{$}} 136 // CHECK: int a1; 137 // CHECK: #pragma omp end declare target{{$}} 138 // CHECK: #pragma omp declare target{{$}} 139 // CHECK: void f1() 140 // CHECK: #pragma omp end declare target{{$}} 141 142 int b1, b2, b3; 143 void f2() { 144 } 145 #pragma omp declare target to(b1) to(b2), to(b3, f2) 146 // CHECK: #pragma omp declare target{{$}} 147 // CHECK: int b1; 148 // CHECK: #pragma omp end declare target{{$}} 149 // CHECK: #pragma omp declare target{{$}} 150 // CHECK: int b2; 151 // CHECK: #pragma omp end declare target{{$}} 152 // CHECK: #pragma omp declare target{{$}} 153 // CHECK: int b3; 154 // CHECK: #pragma omp end declare target{{$}} 155 // CHECK: #pragma omp declare target{{$}} 156 // CHECK: void f2() 157 // CHECK: #pragma omp end declare target{{$}} 158 159 int c1, c2, c3; 160 #pragma omp declare target link(c1) link(c2), link(c3) 161 // CHECK: #pragma omp declare target link{{$}} 162 // CHECK: int c1; 163 // CHECK: #pragma omp end declare target{{$}} 164 // CHECK: #pragma omp declare target link{{$}} 165 // CHECK: int c2; 166 // CHECK: #pragma omp end declare target{{$}} 167 // CHECK: #pragma omp declare target link{{$}} 168 // CHECK: int c3; 169 // CHECK: #pragma omp end declare target{{$}} 170 171 struct SSSt { 172 #pragma omp declare target 173 static int a; 174 int b; 175 #pragma omp end declare target 176 }; 177 178 // CHECK: struct SSSt { 179 // CHECK: #pragma omp declare target 180 // CHECK: static int a; 181 // CHECK: #pragma omp end declare target 182 // CHECK: int b; 183 184 template <class T> 185 struct SSSTt { 186 #pragma omp declare target 187 static T a; 188 int b; 189 #pragma omp end declare target 190 }; 191 192 // CHECK: template <class T> struct SSSTt { 193 // CHECK: #pragma omp declare target 194 // CHECK: static T a; 195 // CHECK: #pragma omp end declare target 196 // CHECK: int b; 197 198 #pragma omp declare target 199 template <typename T> 200 T baz() { return T(); } 201 #pragma omp end declare target 202 203 template <> 204 int baz() { return 1; } 205 206 // CHECK: #pragma omp declare target 207 // CHECK: template <typename T> T baz() { 208 // CHECK: return T(); 209 // CHECK: } 210 // CHECK: #pragma omp end declare target 211 // CHECK: #pragma omp declare target 212 // CHECK: template<> float baz<float>() { 213 // CHECK: return float(); 214 // CHECK: } 215 // CHECK: template<> int baz<int>() { 216 // CHECK: return 1; 217 // CHECK: } 218 // CHECK: #pragma omp end declare target 219 220 #pragma omp declare target 221 #include "declare_target_include.h" 222 void xyz(); 223 #pragma omp end declare target 224 225 // CHECK: #pragma omp declare target 226 // CHECK: void zyx(); 227 // CHECK: #pragma omp end declare target 228 // CHECK: #pragma omp declare target 229 // CHECK: void xyz(); 230 // CHECK: #pragma omp end declare target 231 232 #pragma omp declare target 233 #pragma omp declare target 234 void abc(); 235 #pragma omp end declare target 236 void cba(); 237 #pragma omp end declare target 238 239 // CHECK: #pragma omp declare target 240 // CHECK: void abc(); 241 // CHECK: #pragma omp end declare target 242 // CHECK: #pragma omp declare target 243 // CHECK: void cba(); 244 // CHECK: #pragma omp end declare target 245 246 int main (int argc, char **argv) { 247 foo(); 248 foo_c(); 249 foo_cpp(); 250 test1(); 251 baz<float>(); 252 baz<int>(); 253 return (0); 254 } 255 256 // CHECK: #pragma omp declare target 257 // CHECK-NEXT: int ts = 1; 258 // CHECK-NEXT: #pragma omp end declare target 259 #endif 260