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