[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_data_use_device_ptr_addr_ast_print.cpp
blob43ff9896d3fcf4e46680ece9aab35525143f984e
1 // RUN: %clang_cc1 -verify -fopenmp -std=c++11 -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 -std=c++11 -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 struct ST {
14 int *a;
16 struct SA {
17 int i, j;
18 int *k = &j;
19 int *&z = k;
20 int &y = i;
21 void func(int arg) {
22 #pragma omp target data map(tofrom: i) use_device_ptr(k) use_device_addr(i, j)
24 #pragma omp target data map(tofrom: i) use_device_ptr(z) use_device_addr(k, y)
26 return;
29 // CHECK: struct SA
30 // CHECK: void func(
31 // CHECK: #pragma omp target data map(tofrom: this->i) use_device_ptr(this->k) use_device_addr(this->i,this->j){{$}}
32 // CHECK: #pragma omp target data map(tofrom: this->i) use_device_ptr(this->z) use_device_addr(this->k,this->y)
33 struct SB {
34 unsigned A;
35 unsigned B;
36 float Arr[100];
37 float *Ptr;
38 float *foo() {
39 return &Arr[0];
43 struct SC {
44 unsigned A : 2;
45 unsigned B : 3;
46 unsigned C;
47 unsigned D;
48 float Arr[100];
49 SB S;
50 SB ArrS[100];
51 SB *PtrS;
52 SB *&RPtrS;
53 float *Ptr;
55 SC(SB *&_RPtrS) : RPtrS(_RPtrS) {}
58 union SD {
59 unsigned A;
60 float B;
63 struct S1;
64 extern S1 a;
65 class S2 {
66 mutable int a;
67 public:
68 S2():a(0) { }
69 S2(S2 &s2):a(s2.a) { }
70 static float S2s;
71 static const float S2sc;
73 const float S2::S2sc = 0;
74 const S2 b;
75 const S2 ba[5];
76 class S3 {
77 int a;
78 public:
79 S3():a(0) { }
80 S3(S3 &s3):a(s3.a) { }
82 const S3 c;
83 const S3 ca[5];
84 extern const int f;
85 class S4 {
86 int a;
87 S4();
88 S4(const S4 &s4);
89 public:
90 S4(int v):a(v) { }
92 class S5 {
93 int a;
94 S5():a(0) {}
95 S5(const S5 &s5):a(s5.a) { }
96 public:
97 S5(int v):a(v) { }
100 S3 h;
101 #pragma omp threadprivate(h)
103 typedef int from;
105 template <typename T>
106 T tmain(T argc) {
107 T i;
108 T &j = i;
109 T *k = &j;
110 T *&z = k;
111 #pragma omp target data map(tofrom: i) use_device_ptr(k)
113 #pragma omp target data map(tofrom: i) use_device_ptr(z)
115 return 0;
118 // CHECK: template<> int tmain<int>(int argc) {
119 // CHECK-NEXT: int i;
120 // CHECK-NEXT: int &j = i;
121 // CHECK-NEXT: int *k = &j;
122 // CHECK-NEXT: int *&z = k;
123 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(k)
124 // CHECK-NEXT: {
125 // CHECK-NEXT: }
126 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(z)
128 // CHECK: template<> int *tmain<int *>(int *argc) {
129 // CHECK-NEXT: int *i;
130 // CHECK-NEXT: int *&j = i;
131 // CHECK-NEXT: int **k = &j;
132 // CHECK-NEXT: int **&z = k;
133 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(k)
134 // CHECK-NEXT: {
135 // CHECK-NEXT: }
136 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(z)
138 // CHECK-LABEL: int main(int argc, char **argv) {
139 int main(int argc, char **argv) {
140 int i;
141 int &j = i;
142 int *k = &j;
143 int *&z = k;
144 // CHECK-NEXT: int i;
145 // CHECK-NEXT: int &j = i;
146 // CHECK-NEXT: int *k = &j;
147 // CHECK-NEXT: int *&z = k;
148 #pragma omp target data map(tofrom: i) use_device_ptr(k) use_device_addr(i, j)
149 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(k) use_device_addr(i,j)
151 // CHECK-NEXT: {
152 // CHECK-NEXT: }
153 #pragma omp target data map(tofrom: i) use_device_ptr(z) use_device_addr(i, j, k[:i])
154 // CHECK-NEXT: #pragma omp target data map(tofrom: i) use_device_ptr(z) use_device_addr(i,j,k[:i])
156 return tmain<int>(argc) + (*tmain<int*>(&argc));
159 #endif