Clang Project

clang_source_code/test/OpenMP/declare_target_ast_print.cpp
1// RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s
2// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s
4
5// RUN: %clang_cc1 -verify -fopenmp-simd -I %S/Inputs -ast-print %s | FileCheck %s
6// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
7// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -I %S/Inputs -verify %s -ast-print | FileCheck %s
8// expected-no-diagnostics
9
10#ifndef HEADER
11#define HEADER
12
13int out_decl_target = 0;
14// CHECK: #pragma omp declare target{{$}}
15// CHECK: int out_decl_target = 0;
16// CHECK: #pragma omp end declare target{{$}}
17// CHECK: #pragma omp declare target{{$}}
18// CHECK: void lambda()
19// CHECK: #pragma omp end declare target{{$}}
20
21#pragma omp declare target
22void lambda () {
23#ifdef __cpp_lambdas
24  (void)[&] { ++out_decl_target; };
25#else
26  #pragma clang __debug captured
27  (void)out_decl_target;
28#endif
29};
30#pragma omp end declare target
31
32#pragma omp declare target
33// CHECK: #pragma omp declare target{{$}}
34void foo() {}
35// CHECK-NEXT: void foo()
36#pragma omp end declare target
37// CHECK: #pragma omp end declare target{{$}}
38
39extern "C" {
40#pragma omp declare target
41// CHECK: #pragma omp declare target
42void foo_c() {}
43// CHECK-NEXT: void foo_c()
44#pragma omp end declare target
45// CHECK: #pragma omp end declare target
46}
47
48extern "C++" {
49#pragma omp declare target
50// CHECK: #pragma omp declare target
51void foo_cpp() {}
52// CHECK-NEXT: void foo_cpp()
53#pragma omp end declare target
54// CHECK: #pragma omp end declare target
55}
56
57#pragma omp declare target
58template <class T>
59struct C {
60// CHECK: template <class T> struct C {
61// CHECK: #pragma omp declare target
62// CHECK-NEXT: static T ts;
63// CHECK-NEXT: #pragma omp end declare target
64
65// CHECK: template<> struct C<int>
66  T t;
67// CHECK-NEXT: int t;
68  static T ts;
69// CHECK-NEXT: #pragma omp declare target
70// CHECK-NEXT: static int ts;
71// CHECK: #pragma omp end declare target
72
73  C(T t) : t(t) {
74  }
75// CHECK: #pragma omp declare target
76// CHECK-NEXT: C(int t) : t(t) {
77// CHECK-NEXT: }
78// CHECK: #pragma omp end declare target
79
80  T foo() {
81    return t;
82  }
83// CHECK: #pragma omp declare target
84// CHECK-NEXT: int foo() {
85// CHECK-NEXT: return this->t;
86// CHECK-NEXT: }
87// CHECK: #pragma omp end declare target
88};
89
90template<class T>
91T C<T>::ts = 1;
92// CHECK: #pragma omp declare target
93// CHECK: T ts = 1;
94// CHECK: #pragma omp end declare target
95
96// CHECK: #pragma omp declare target
97// CHECK: int test1()
98int test1() {
99  C<int> c(1);
100  return c.foo() + c.ts;
101}
102#pragma omp end declare target
103// CHECK: #pragma omp end declare target
104
105int a1;
106void f1() {
107}
108#pragma omp declare target (a1, f1)
109// CHECK: #pragma omp declare target{{$}}
110// CHECK: int a1;
111// CHECK: #pragma omp end declare target{{$}}
112// CHECK: #pragma omp declare target{{$}}
113// CHECK: void f1()
114// CHECK: #pragma omp end declare target{{$}}
115
116int b1, b2, b3;
117void f2() {
118}
119#pragma omp declare target to(b1) to(b2), to(b3, f2)
120// CHECK: #pragma omp declare target{{$}}
121// CHECK: int b1;
122// CHECK: #pragma omp end declare target{{$}}
123// CHECK: #pragma omp declare target{{$}}
124// CHECK: int b2;
125// CHECK: #pragma omp end declare target{{$}}
126// CHECK: #pragma omp declare target{{$}}
127// CHECK: int b3;
128// CHECK: #pragma omp end declare target{{$}}
129// CHECK: #pragma omp declare target{{$}}
130// CHECK: void f2()
131// CHECK: #pragma omp end declare target{{$}}
132
133int c1, c2, c3;
134#pragma omp declare target link(c1) link(c2), link(c3)
135// CHECK: #pragma omp declare target link{{$}}
136// CHECK: int c1;
137// CHECK: #pragma omp end declare target{{$}}
138// CHECK: #pragma omp declare target link{{$}}
139// CHECK: int c2;
140// CHECK: #pragma omp end declare target{{$}}
141// CHECK: #pragma omp declare target link{{$}}
142// CHECK: int c3;
143// CHECK: #pragma omp end declare target{{$}}
144
145struct SSSt {
146#pragma omp declare target
147  static int a;
148  int b;
149#pragma omp end declare target
150};
151
152// CHECK: struct SSSt {
153// CHECK: #pragma omp declare target
154// CHECK: static int a;
155// CHECK: #pragma omp end declare target
156// CHECK: int b;
157
158template <class T>
159struct SSSTt {
160#pragma omp declare target
161  static T a;
162  int b;
163#pragma omp end declare target
164};
165
166// CHECK: template <class T> struct SSSTt {
167// CHECK: #pragma omp declare target
168// CHECK: static T a;
169// CHECK: #pragma omp end declare target
170// CHECK: int b;
171
172#pragma omp declare target
173template <typename T>
174T baz() { return T(); }
175#pragma omp end declare target
176
177template <>
178int baz() { return 1; }
179
180// CHECK: #pragma omp declare target
181// CHECK: template <typename T> T baz() {
182// CHECK:     return T();
183// CHECK: }
184// CHECK: #pragma omp end declare target
185// CHECK: #pragma omp declare target
186// CHECK: template<> float baz<float>() {
187// CHECK:     return float();
188// CHECK: }
189// CHECK: template<> int baz<int>() {
190// CHECK:     return 1;
191// CHECK: }
192// CHECK: #pragma omp end declare target
193
194#pragma omp declare target
195  #include "declare_target_include.h"
196  void xyz();
197#pragma omp end declare target
198
199// CHECK: #pragma omp declare target
200// CHECK: void zyx();
201// CHECK: #pragma omp end declare target
202// CHECK: #pragma omp declare target
203// CHECK: void xyz();
204// CHECK: #pragma omp end declare target
205
206#pragma omp declare target
207  #pragma omp declare target
208    void abc();
209  #pragma omp end declare target
210  void cba();
211#pragma omp end declare target
212
213// CHECK: #pragma omp declare target
214// CHECK: void abc();
215// CHECK: #pragma omp end declare target
216// CHECK: #pragma omp declare target
217// CHECK: void cba();
218// CHECK: #pragma omp end declare target
219
220int main (int argc, char **argv) {
221  foo();
222  foo_c();
223  foo_cpp();
224  test1();
225  baz<float>();
226  baz<int>();
227  return (0);
228}
229
230// CHECK: #pragma omp declare target
231// CHECK-NEXT: int ts = 1;
232// CHECK-NEXT: #pragma omp end declare target
233#endif
234