[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / default_firstprivate_ast_print.cpp
blob4bf9fc664c304764dbae4ee156b760778d58a210
1 // expected-no-diagnostics
3 //RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
4 //RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \
5 //RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
6 //RUN: -ast-print %s | FileCheck %s --check-prefix=PRINT
8 //RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
9 //RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \
10 //RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
11 //RUN: -ast-dump %s | FileCheck %s --check-prefix=DUMP
13 //RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
14 //RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \
15 //RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
16 //RUN: -emit-pch -o %t %s
18 //RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
19 //RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \
20 //RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
21 //RUN: -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
23 //RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp \
24 //RUN: -x c++ -std=c++14 -fexceptions -fcxx-exceptions \
25 //RUN: -Wno-source-uses-openmp -Wno-openmp-clauses \
26 //RUN: -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
28 #ifndef HEADER
29 #define HEADER
31 struct SomeKernel {
32 int targetDev;
33 float devPtr;
34 SomeKernel();
35 ~SomeKernel();
37 template <unsigned int nRHS>
38 void apply() {
39 #pragma omp parallel default(firstprivate)
41 [=]() -> int {
42 return targetDev++;
43 }();
45 // PRINT: #pragma omp parallel default(firstprivate)
46 // PRINT-NEXT: {
47 // PRINT-NEXT: [=]() -> int {
48 // PRINT-NEXT: return this->targetDev++;
49 // PRINT-NEXT: }();
50 // PRINT-NEXT: }
51 // DUMP: -OMPParallelDirective
52 // DUMP-NEXT: -OMPDefaultClause
53 // DUMP-NOT: -OMPFirstprivateClause
55 // PRINT: template<> void apply<32U>()
56 // PRINT: #pragma omp parallel default(firstprivate)
57 // PRINT-NEXT: {
58 // PRINT-NEXT: [=]() -> int {
59 // PRINT-NEXT: return this->targetDev++;
60 // PRINT-NEXT: }();
61 // CHECK-NEXT: }
62 // DUMP: -OMPParallelDirective
63 // DUMP-NEXT: -OMPDefaultClause
64 // DUMP-NEXT: -OMPFirstprivateClause
65 // DUMP-NEXT: -DeclRefExpr {{.*}} 'targetDev'
68 void use_template() {
69 SomeKernel aKern;
70 aKern.apply<32>();
73 void foo() {
74 int a;
75 #pragma omp parallel default(firstprivate)
76 a++;
77 // PRINT: #pragma omp parallel default(firstprivate)
78 // PRINT-NEXT: a++;
79 // DUMP: -OMPParallelDirective
80 // DUMP-NEXT: -OMPDefaultClause
81 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>
82 // DUMP-NEXT: -DeclRefExpr {{.*}} 'a'
85 struct St {
86 int a, b;
87 static int y;
88 St() : a(0), b(0) {}
89 ~St() {}
91 int St::y = 0;
92 void bar() {
93 St a = St();
94 static int yy = 0;
95 #pragma omp parallel default(firstprivate)
97 a.a += 1;
98 a.b += 1;
99 a.y++;
100 yy++;
101 St::y++;
103 // PRINT: #pragma omp parallel default(firstprivate)
104 // DUMP: -OMPParallelDirective
105 // DUMP-NEXT: -OMPDefaultClause
106 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>
107 // DUMP-NEXT: -DeclRefExpr {{.*}} 'a'
108 // DUMP-NEXT: -DeclRefExpr {{.*}} 'yy'
109 // DUMP-NEXT: -DeclRefExpr {{.*}} 'y'
111 void zoo(int);
112 struct A {
113 int z;
114 int f;
115 A();
116 ~A();
117 void foo() {
118 #pragma omp parallel firstprivate(z) default(firstprivate)
120 z++;
121 f++;
122 zoo(z + f);
123 f++;
126 // PRINT: #pragma omp parallel firstprivate(this->z) default(firstprivate)
127 // DUMP: -OMPParallelDirective
128 // DUMP-NEXT: -OMPFirstprivateClause
129 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
130 // DUMP-NEXT: -OMPDefaultClause
131 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>
132 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
133 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this
134 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
135 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
136 void bar() {
137 #pragma omp parallel firstprivate(z) default(firstprivate)
139 #pragma omp parallel private(z) default(firstprivate)
141 z++;
142 f++;
143 zoo(z + f);
144 f++;
148 // PRINT: #pragma omp parallel firstprivate(this->z) default(firstprivate)
149 // PRINT: #pragma omp parallel private(this->z) default(firstprivate)
150 // DUMP: -OMPParallelDirective
151 // DUMP-NEXT: -OMPFirstprivateClause
152 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
153 // DUMP-NEXT: -OMPDefaultClause
154 // DUMP: -OMPParallelDirective
155 // DUMP-NEXT: -OMPPrivateClaus
156 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
157 // DUMP-NEXT: -OMPDefaultClause
158 // DUMP-NEXT: -OMPFirstprivateClause {{.*}} <implicit>
159 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
160 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this
161 // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
162 // DUMP: -MemberExpr {{.*}}
163 // DUMP-NEXT: -CXXThisExpr
164 // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this
165 // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
167 #endif // HEADER