1 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 -fopenmp -fopenmp-version=45 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 2 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,host5 -fopenmp -fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 3 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,dev5 -fopenmp -fopenmp-is-device -fopenmp-targets=x86_64-apple-macos10.7.0 -aux-triple x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 4 5 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,host5 -fopenmp-simd -fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 6 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5,host5 -fopenmp-simd -fopenmp-is-device -fopenmp-targets=x86_64-apple-macos10.7.0 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 7 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s 8 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -o - %s 9 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -DTESTEND=1 -o - %s 10 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp -fopenmp-version=51 -fnoopenmp-use-tls -ferror-limit 100 -I%S/Inputs -DTESTENDINC=1 -o - %s 11 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s 12 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp51 -fopenmp-version=51 -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s 13 14 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s 15 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}} 16 17 int a, b, z; // omp5-error {{variable captured in declare target region must appear in a to clause}} // omp51-error {{variable captured in declare target region must appear in a to clause}} 18 __thread int t; // expected-note {{defined as threadprivate or thread local}} 19 20 #pragma omp declare target . // expected-error {{expected '(' after 'declare target'}} 21 22 #pragma omp declare target 23 void f(); 24 #pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}} 25 26 #pragma omp declare target map(a) // omp45-error {{expected at least one 'to' or 'link' clause}} omp5-error {{expected at least one 'to' or 'link' clause}} omp51-error {{expected at least one 'to', 'link' or 'indirect' clause}} omp45-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}} omp5-error {{unexpected 'map' clause, only 'to', 'link' or 'device_type' clauses expected}} omp51-error {{unexpected 'map' clause, only 'to', 'link', 'device_type' or 'indirect' clauses expected}} 27 28 #pragma omp declare target to(foo1) // expected-error {{use of undeclared identifier 'foo1'}} 29 30 #pragma omp declare target link(foo2) // expected-error {{use of undeclared identifier 'foo2'}} 31 32 #pragma omp declare target to(f) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note {{marked as 'device_type(host)' here}} 33 34 void q(); 35 #pragma omp declare target to(q) device_type(any) device_type(any) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-warning {{more than one 'device_type' clause is specified}} // omp51-warning {{more than one 'device_type' clause is specified}} 36 37 #if _OPENMP == 202011 38 // omp51-error@+1 {{directive '#pragma omp declare target' cannot contain more than one 'indirect' clause}} 39 #pragma omp declare target to(q) indirect(true) indirect(false) 40 41 int xxx; //expected-note {{declared here}} 42 // omp51-error@+2 {{expression is not an integral constant expression}} 43 // omp51-note@+1 {{read of non-const variable 'xxx' is not allowed in a constant expression}} 44 #pragma omp declare target to(q) indirect(xxx) 45 46 constexpr bool fz() {return true;} 47 // omp51-error@+1 {{unexpected 'to' clause, only 'device_type', 'indirect' clauses expected}} 48 #pragma omp begin declare target to(q) indirect(fz()) device_type(nohost) 49 #pragma omp end declare target 50 51 // omp51-error@+1 {{unexpected 'to' clause, only 'device_type', 'indirect' clauses expected}} 52 #pragma omp begin declare target indirect to(xxx) 53 void bar(); 54 #pragma omp end declare target 55 56 // omp51-error@+2 {{unexpected 'tofrom' clause, only 'to', 'link', 'device_type' or 'indirect' clauses expected}} 57 // omp51-error@+1 {{expected at least one 'to', 'link' or 'indirect' clause}} 58 #pragma omp declare target tofrom(xxx) 59 60 // omp51-error@+1 {{only 'device_type(any)' clause is allowed with indirect clause}} 61 #pragma omp begin declare target device_type(host) indirect 62 void bar(); 63 #pragma omp end declare target 64 #endif // _OPENMP 65 66 void c(); 67 68 void func() {} // expected-note {{'func' defined here}} 69 70 #pragma omp declare target link(func) allocate(a) // expected-error {{function name is not allowed in 'link' clause}} omp45-error {{unexpected 'allocate' clause, only 'to' or 'link' clauses expected}} omp5-error {{unexpected 'allocate' clause, only 'to', 'link' or 'device_type' clauses expected}} omp51-error {{unexpected 'allocate' clause, only 'to', 'link', 'device_type' or 'indirect' clauses expected}} 71 72 void bar(); 73 void baz() {bar();} 74 #pragma omp declare target(bar) // omp5-warning {{declaration marked as declare target after first use, it may lead to incorrect results}} // omp51-warning {{declaration marked as declare target after first use, it may lead to incorrect results}} 75 76 extern int b; 77 78 struct NonT { 79 int a; 80 }; 81 82 typedef int sint; 83 84 template <typename T> 85 T bla1() { return 0; } 86 87 #pragma omp declare target 88 template <typename T> 89 T bla2() { return 0; } 90 #pragma omp end declare target 91 92 template<> 93 float bla2() { return 1.0; } 94 95 #pragma omp declare target 96 void blub2() { 97 bla2<float>(); 98 bla2<int>(); 99 } 100 #pragma omp end declare target 101 102 void t2() { 103 #pragma omp target 104 { 105 bla2<float>(); 106 bla2<long>(); 107 } 108 } 109 110 #pragma omp declare target 111 void abc(); 112 #pragma omp end declare target 113 void cba(); 114 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}} 115 116 #pragma omp declare target 117 #pragma omp declare target 118 void def(); 119 #pragma omp end declare target 120 void fed(); 121 122 #pragma omp declare target 123 #pragma omp threadprivate(a) // expected-note {{defined as threadprivate or thread local}} 124 extern int b; 125 int g; 126 127 struct T { 128 int a; 129 virtual int method(); 130 }; 131 132 class VC { 133 T member; 134 NonT member1; 135 public: 136 virtual int method() { T a; return 0; } 137 }; 138 139 struct C { 140 NonT a; 141 sint b; 142 int method(); 143 int method1(); 144 }; 145 146 int C::method1() { 147 return 0; 148 } 149 150 void foo(int p) { 151 a = 0; // expected-error {{threadprivate variables cannot be used in target constructs}} 152 b = 0; 153 t = 1; // expected-error {{threadprivate variables cannot be used in target constructs}} 154 C object; 155 VC object1; 156 g = object.method(); 157 g += object.method1(); 158 g += object1.method() + p; 159 f(); // dev5-error {{function with 'device_type(host)' is not available on device}} 160 q(); 161 c(); 162 } 163 #pragma omp declare target 164 void foo1() { 165 [&](){ (void)(b+z);}(); // omp5-note {{variable 'z' is captured here}} //omp51-note {{variable 'z' is captured here}} 166 } 167 #pragma omp end declare target 168 169 #pragma omp end declare target 170 #pragma omp end declare target 171 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}} 172 173 int C::method() { 174 return 0; 175 } 176 177 struct S { 178 #pragma omp declare target 179 int v; 180 #pragma omp end declare target 181 }; 182 183 int main (int argc, char **argv) { 184 #pragma omp declare target // expected-error {{unexpected OpenMP directive '#pragma omp declare target'}} 185 int v; 186 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}} 187 foo(v); 188 return (0); 189 } 190 191 namespace { 192 #pragma omp declare target 193 int x; 194 } 195 #pragma omp end declare target 196 197 #pragma omp declare target link(S) // expected-error {{'S' used in declare target directive is not a variable or a function name}} 198 199 #pragma omp declare target (x, x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}} 200 #pragma omp declare target to(x) to(x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}} 201 #pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}} 202 203 void bazz() {} 204 #pragma omp declare target to(bazz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note 3{{marked as 'device_type(nohost)' here}} 205 void bazzz() {bazz();} 206 #pragma omp declare target to(bazzz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} 207 void any() {bazz();} // host5-error {{function with 'device_type(nohost)' is not available on host}} 208 void host1() {bazz();} // host5-error {{function with 'device_type(nohost)' is not available on host}} 209 #pragma omp declare target to(host1) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note 3 {{marked as 'device_type(host)' here}} 210 void host2() {bazz();} //host5-error {{function with 'device_type(nohost)' is not available on host}} 211 #pragma omp declare target to(host2) 212 void device() {host1();} // dev5-error {{function with 'device_type(host)' is not available on device}} 213 #pragma omp declare target to(device) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note 2 {{marked as 'device_type(nohost)' here}} 214 void host3() {host1();} // dev5-error {{function with 'device_type(host)' is not available on device}} 215 #pragma omp declare target to(host3) 216 217 #pragma omp declare target 218 void any1() {any();} 219 void any2() {host1();} // dev5-error {{function with 'device_type(host)' is not available on device}} 220 void any3() {device();} // host5-error {{function with 'device_type(nohost)' is not available on host}} 221 void any4() {any2();} 222 #pragma omp end declare target 223 224 void any5() {any();} 225 void any6() {host1();} 226 void any7() {device();} // host5-error {{function with 'device_type(nohost)' is not available on host}} 227 void any8() {any2();} 228 229 int MultiDevTy; 230 #pragma omp declare target to(MultiDevTy) device_type(any) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} 231 #pragma omp declare target to(MultiDevTy) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-error {{'device_type(host)' does not match previously specified 'device_type(any)' for the same declaration}} omp51-error {{'device_type(host)' does not match previously specified 'device_type(any)' for the same declaration}} 232 #pragma omp declare target to(MultiDevTy) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} omp5-error {{'device_type(nohost)' does not match previously specified 'device_type(any)' for the same declaration}} // omp51-error {{'device_type(nohost)' does not match previously specified 'device_type(any)' for the same declaration}} 233 234 #if TESTENDINC 235 #include "unterminated_declare_target_include.h" 236 #elif TESTEND 237 // expected-warning@+1 {{expected '#pragma omp end declare target' at end of file to match '#pragma omp declare target'}} 238 #pragma omp declare target 239 #else 240 // expected-warning@+1 {{expected '#pragma omp end declare target' at end of file to match '#pragma omp begin declare target'}} 241 #pragma omp begin declare target 242 #endif 243