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