1 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
2 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify=expected,omp5 -fopenmp -fopenmp-version=50 -fnoopenmp-use-tls -ferror-limit 100 -o - %s
3 
4 // RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp-simd -fnoopenmp-use-tls -ferror-limit 100 -o - %s
5 
6 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
7 
8 int a, b, z; // omp5-error {{variable captured in declare target region must appear in a to clause}}
9 __thread int t; // expected-note {{defined as threadprivate or thread local}}
10 
11 #pragma omp declare target . // expected-error {{expected '(' after 'declare target'}}
12 
13 #pragma omp declare target
14 void f();
15 #pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
16 
17 #pragma omp declare target map(a) // expected-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}}
18 
19 #pragma omp declare target to(foo1) // expected-error {{use of undeclared identifier 'foo1'}}
20 
21 #pragma omp declare target link(foo2) // expected-error {{use of undeclared identifier 'foo2'}}
22 
23 void c();
24 
25 void func() {} // expected-note {{'func' defined here}}
26 
27 #pragma omp declare target link(func) allocate(a) // expected-error {{function name is not allowed in 'link' clause}} expected-error {{unexpected 'allocate' clause, only 'to' or 'link' clauses expected}}
28 
29 extern int b;
30 
31 struct NonT {
32   int a;
33 };
34 
35 typedef int sint;
36 
37 template <typename T>
38 T bla1() { return 0; }
39 
40 #pragma omp declare target
41 template <typename T>
42 T bla2() { return 0; }
43 #pragma omp end declare target
44 
45 template<>
46 float bla2() { return 1.0; }
47 
48 #pragma omp declare target
49 void blub2() {
50   bla2<float>();
51   bla2<int>();
52 }
53 #pragma omp end declare target
54 
55 void t2() {
56 #pragma omp target
57   {
58     bla2<float>();
59     bla2<long>();
60   }
61 }
62 
63 #pragma omp declare target
64   void abc();
65 #pragma omp end declare target
66 void cba();
67 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
68 
69 #pragma omp declare target
70 #pragma omp declare target
71 void def();
72 #pragma omp end declare target
73 void fed();
74 
75 #pragma omp declare target
76 #pragma omp threadprivate(a) // expected-note {{defined as threadprivate or thread local}}
77 extern int b;
78 int g;
79 
80 struct T {
81   int a;
82   virtual int method();
83 };
84 
85 class VC {
86   T member;
87   NonT member1;
88   public:
89     virtual int method() { T a; return 0; }
90 };
91 
92 struct C {
93   NonT a;
94   sint b;
95   int method();
96   int method1();
97 };
98 
99 int C::method1() {
100   return 0;
101 }
102 
103 void foo(int p) {
104   a = 0; // expected-error {{threadprivate variables cannot be used in target constructs}}
105   b = 0;
106   t = 1; // expected-error {{threadprivate variables cannot be used in target constructs}}
107   C object;
108   VC object1;
109   g = object.method();
110   g += object.method1();
111   g += object1.method() + p;
112   f();
113   c();
114 }
115 #pragma omp declare target
116 void foo1() {
117   [&](){ (void)(b+z);}(); // omp5-note {{variable 'z' is captured here}}
118 }
119 #pragma omp end declare target
120 
121 #pragma omp end declare target
122 #pragma omp end declare target
123 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
124 
125 int C::method() {
126   return 0;
127 }
128 
129 struct S {
130 #pragma omp declare target
131   int v;
132 #pragma omp end declare target
133 };
134 
135 int main (int argc, char **argv) {
136 #pragma omp declare target // expected-error {{unexpected OpenMP directive '#pragma omp declare target'}}
137   int v;
138 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
139   foo(v);
140   return (0);
141 }
142 
143 namespace {
144 #pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
145   int x;
146 } //  expected-error {{expected '#pragma omp end declare target'}}
147 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
148 
149 #pragma omp declare target link(S) // expected-error {{'S' used in declare target directive is not a variable or a function name}}
150 
151 #pragma omp declare target (x, x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}}
152 #pragma omp declare target to(x) to(x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}}
153 #pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}}
154 
155 #pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} expected-note {{to match this '#pragma omp declare target'}}
156