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