[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / reverse_ast_print.cpp
blob3ff6d18cfdf8bcc54fb0ec94688ec989020b9f8c
1 // Check no warnings/errors
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -fsyntax-only -verify %s
3 // expected-no-diagnostics
5 // Check AST and unparsing
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-dump %s | FileCheck %s --check-prefix=DUMP
7 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -ast-print %s | FileCheck %s --check-prefix=PRINT
9 // Check same results after serialization round-trip
10 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -emit-pch -o %t %s
11 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=60 -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT
14 #ifndef HEADER
15 #define HEADER
17 // placeholder for loop body code.
18 extern "C" void body(...);
20 // PRINT-LABEL: void foo1(
21 // DUMP-LABEL: FunctionDecl {{.*}} foo1
22 void foo1() {
23 // PRINT: #pragma omp reverse
24 // DUMP: OMPReverseDirective
25 #pragma omp reverse
26 // PRINT: for (int i = 7; i < 17; i += 3)
27 // DUMP-NEXT: ForStmt
28 for (int i = 7; i < 17; i += 3)
29 // PRINT: body(i);
30 // DUMP: CallExpr
31 body(i);
35 // PRINT-LABEL: void foo2(
36 // DUMP-LABEL: FunctionDecl {{.*}} foo2
37 void foo2(int start, int end, int step) {
38 // PRINT: #pragma omp reverse
39 // DUMP: OMPReverseDirective
40 #pragma omp reverse
41 // PRINT: for (int i = start; i < end; i += step)
42 // DUMP-NEXT: ForStmt
43 for (int i = start; i < end; i += step)
44 // PRINT: body(i);
45 // DUMP: CallExpr
46 body(i);
50 // PRINT-LABEL: void foo3(
51 // DUMP-LABEL: FunctionDecl {{.*}} foo3
52 void foo3() {
53 // PRINT: #pragma omp for
54 // DUMP: OMPForDirective
55 // DUMP-NEXT: CapturedStmt
56 // DUMP-NEXT: CapturedDecl
57 #pragma omp for
58 // PRINT: #pragma omp reverse
59 // DUMP-NEXT: OMPReverseDirective
60 #pragma omp reverse
61 for (int i = 7; i < 17; i += 3)
62 // PRINT: body(i);
63 // DUMP: CallExpr
64 body(i);
68 // PRINT-LABEL: void foo4(
69 // DUMP-LABEL: FunctionDecl {{.*}} foo4
70 void foo4() {
71 // PRINT: #pragma omp for collapse(2)
72 // DUMP: OMPForDirective
73 // DUMP-NEXT: OMPCollapseClause
74 // DUMP-NEXT: ConstantExpr
75 // DUMP-NEXT: value: Int 2
76 // DUMP-NEXT: IntegerLiteral {{.*}} 2
77 // DUMP-NEXT: CapturedStmt
78 // DUMP-NEXT: CapturedDecl
79 #pragma omp for collapse(2)
80 // PRINT: #pragma omp reverse
81 // DUMP: OMPReverseDirective
82 #pragma omp reverse
83 // PRINT: for (int i = 7; i < 17; i += 1)
84 // DUMP-NEXT: ForStmt
85 for (int i = 7; i < 17; i += 1)
86 // PRINT: for (int j = 7; j < 17; j += 1)
87 // DUMP: ForStmt
88 for (int j = 7; j < 17; j += 1)
89 // PRINT: body(i, j);
90 // DUMP: CallExpr
91 body(i, j);
95 // PRINT-LABEL: void foo5(
96 // DUMP-LABEL: FunctionDecl {{.*}} foo5
97 void foo5(int start, int end, int step) {
98 // PRINT: #pragma omp for collapse(2)
99 // DUMP: OMPForDirective
100 // DUMP-NEXT: OMPCollapseClause
101 // DUMP-NEXT: ConstantExpr
102 // DUMP-NEXT: value: Int 2
103 // DUMP-NEXT: IntegerLiteral {{.*}} 2
104 // DUMP-NEXT: CapturedStmt
105 // DUMP-NEXT: CapturedDecl
106 #pragma omp for collapse(2)
107 // PRINT: for (int i = 7; i < 17; i += 1)
108 // DUMP-NEXT: ForStmt
109 for (int i = 7; i < 17; i += 1)
110 // PRINT: #pragma omp reverse
111 // DUMP: OMPReverseDirective
112 #pragma omp reverse
113 // PRINT: for (int j = 7; j < 17; j += 1)
114 // DUMP-NEXT: ForStmt
115 for (int j = 7; j < 17; j += 1)
116 // PRINT: body(i, j);
117 // DUMP: CallExpr
118 body(i, j);
122 // PRINT-LABEL: void foo6(
123 // DUMP-LABEL: FunctionTemplateDecl {{.*}} foo6
124 template<typename T, T Step>
125 void foo6(T start, T end) {
126 // PRINT: #pragma omp reverse
127 // DUMP: OMPReverseDirective
128 #pragma omp reverse
129 // PRINT-NEXT: for (T i = start; i < end; i += Step)
130 // DUMP-NEXT: ForStmt
131 for (T i = start; i < end; i += Step)
132 // PRINT-NEXT: body(i);
133 // DUMP: CallExpr
134 body(i);
137 // Also test instantiating the template.
138 void tfoo6() {
139 foo6<int,3>(0, 42);
143 // PRINT-LABEL: void foo7(
144 // DUMP-LABEL: FunctionDecl {{.*}} foo7
145 void foo7() {
146 double arr[128];
147 // PRINT: #pragma omp reverse
148 // DUMP: OMPReverseDirective
149 #pragma omp reverse
150 // PRINT-NEXT: for (auto &&v : arr)
151 // DUMP-NEXT: CXXForRangeStmt
152 for (auto &&v : arr)
153 // PRINT-NEXT: body(v);
154 // DUMP: CallExpr
155 body(v);
158 #endif