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