[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / declare_mapper_ast_print.cpp
blob422fa9981672e5d5222f7a238afbc231adf8be64
1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
5 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
6 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
7 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s -ast-print | FileCheck %s
8 // expected-no-diagnostics
10 #ifndef HEADER
11 #define HEADER
13 // CHECK: namespace N1 {
14 namespace N1
16 // CHECK: class vec {
17 class vec {
18 public:
19 int len;
20 double *data;
22 // CHECK: };
24 // CHECK: class vecchild : public vec {
25 class vecchild : public vec {
26 public:
27 int lenc;
29 // CHECK: };
31 #pragma omp declare mapper(id: vec v) map(v.len)
32 // CHECK: #pragma omp declare mapper (id : vec v) map(tofrom: v.len){{$}}
34 // CHECK: }
35 // CHECK: ;
37 template <class T>
38 class dat {
39 public:
40 class datin {
41 public:
42 T in;
44 int i;
45 T d;
46 #pragma omp declare mapper(id: N1::vec v) map(v.len)
47 #pragma omp declare mapper(id: datin v) map(v.in)
50 // CHECK: template <class T> class dat {
51 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len){{$}}
52 // CHECK: #pragma omp declare mapper (id : datin v) map(tofrom: v.in){{$}}
53 // CHECK: };
54 // CHECK: template<> class dat<double> {
55 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len){{$}}
56 // CHECK: #pragma omp declare mapper (id : datin v) map(tofrom: v.in){{$}}
57 // CHECK: };
59 constexpr int N = 2;
60 #pragma omp declare mapper(default : N1::vec kk) map(kk.len) map(kk.data[0:N])
61 // CHECK: #pragma omp declare mapper (default : N1::vec kk) map(tofrom: kk.len) map(tofrom: kk.data[0:N]){{$}}
62 #pragma omp declare mapper(dat<double> d) map(to: d.d)
63 // CHECK: #pragma omp declare mapper (default : dat<double> d) map(to: d.d){{$}}
65 template <typename T>
66 T foo(T a) {
67 struct foodatchild {
68 T k;
70 struct foodat {
71 T a;
72 struct foodatchild b;
74 #pragma omp declare mapper(id: struct foodat v) map(v.a)
75 #pragma omp declare mapper(idd: struct foodatchild v) map(v.k)
76 #pragma omp declare mapper(id: N1::vec v) map(v.len)
78 #pragma omp declare mapper(id: N1::vec v) map(v.len)
80 struct foodat fd;
81 #pragma omp target map(mapper(id) alloc: fd)
82 { fd.a++; }
83 #pragma omp target map(mapper(idd) alloc: fd.b)
84 { fd.b.k++; }
85 #pragma omp target update to(mapper(id): fd)
86 #pragma omp target update to(mapper(idd): fd.b)
87 #pragma omp target update from(mapper(id): fd)
88 #pragma omp target update from(mapper(idd): fd.b)
89 return 0;
92 // CHECK: template <typename T> T foo(T a) {
93 // CHECK: #pragma omp declare mapper (id : struct foodat v) map(tofrom: v.a)
94 // CHECK: #pragma omp declare mapper (idd : struct foodatchild v) map(tofrom: v.k)
95 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
96 // CHECK: {
97 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
98 // CHECK: }
99 // CHECK: #pragma omp target map(mapper(id),alloc: fd)
100 // CHECK: #pragma omp target map(mapper(idd),alloc: fd.b)
101 // CHECK: #pragma omp target update to(mapper(id): fd)
102 // CHECK: #pragma omp target update to(mapper(idd): fd.b)
103 // CHECK: #pragma omp target update from(mapper(id): fd)
104 // CHECK: #pragma omp target update from(mapper(idd): fd.b)
105 // CHECK: }
106 // CHECK: template<> int foo<int>(int a) {
107 // CHECK: #pragma omp declare mapper (id : struct foodat v) map(tofrom: v.a)
108 // CHECK: #pragma omp declare mapper (idd : struct foodatchild v) map(tofrom: v.k)
109 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
110 // CHECK: {
111 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
112 // CHECK: }
113 // CHECK: #pragma omp target map(mapper(id),alloc: fd)
114 // CHECK: #pragma omp target map(mapper(idd),alloc: fd.b)
115 // CHECK: #pragma omp target update to(mapper(id): fd)
116 // CHECK: #pragma omp target update to(mapper(idd): fd.b)
117 // CHECK: #pragma omp target update from(mapper(id): fd)
118 // CHECK: #pragma omp target update from(mapper(idd): fd.b)
119 // CHECK: }
121 // CHECK: int main() {
122 int main() {
123 N1::vec vv, vvv;
124 N1::vecchild vc;
125 dat<double> dd;
126 #pragma omp target map(mapper(N1::id) tofrom: vv) map(mapper(dat<double>::id) alloc: vvv)
127 // CHECK: #pragma omp target map(mapper(N1::id),tofrom: vv) map(mapper(dat<double>::id),alloc: vvv)
128 { vv.len++; }
129 #pragma omp target map(mapper(N1::id) tofrom: vc)
130 // CHECK: #pragma omp target map(mapper(N1::id),tofrom: vc)
131 { vc.len++; }
132 #pragma omp target map(mapper(default) tofrom: dd)
133 // CHECK: #pragma omp target map(mapper(default),tofrom: dd)
134 { dd.d++; }
136 #pragma omp target update to(mapper(N1::id) : vc)
137 // CHECK: #pragma omp target update to(mapper(N1::id): vc)
138 #pragma omp target update to(mapper(dat<double>::id): vvv)
139 // CHECK: #pragma omp target update to(mapper(dat<double>::id): vvv)
141 #pragma omp target update from(mapper(N1::id) : vc)
142 // CHECK: #pragma omp target update from(mapper(N1::id): vc)
143 #pragma omp target update from(mapper(dat<double>::id): vvv)
144 // CHECK: #pragma omp target update from(mapper(dat<double>::id): vvv)
146 #pragma omp declare mapper(id: N1::vec v) map(v.len)
147 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
149 #pragma omp declare mapper(id: N1::vec v) map(v.len)
150 // CHECK: #pragma omp declare mapper (id : N1::vec v) map(tofrom: v.len)
152 return foo<int>(0);
154 // CHECK: }
156 #endif