[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / unroll_ast_print.cpp
blobdb4acbbf6a6dcd6bc3fe34dce2dea4d311a05b5a
1 // Check no warnings/errors
2 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fsyntax-only -verify %s
3 // expected-no-diagnostics
5 // Check AST and unparsing
6 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-dump %s | FileCheck %s --check-prefix=DUMP
7 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -ast-print %s | FileCheck %s --check-prefix=PRINT --match-full-lines
9 // Check same results after serialization round-trip
10 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -emit-pch -o %t %s
11 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -ast-dump-all %s | FileCheck %s --check-prefix=DUMP
12 // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -ast-print %s | FileCheck %s --check-prefix=PRINT --match-full-lines
14 #ifndef HEADER
15 #define HEADER
17 // placeholder for loop body code.
18 void body(...);
21 // PRINT-LABEL: void func_unroll() {
22 // DUMP-LABEL: FunctionDecl {{.*}} func_unroll
23 void func_unroll() {
24 // PRINT: #pragma omp unroll
25 // DUMP: OMPUnrollDirective
26 #pragma omp unroll
27 // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
28 // DUMP-NEXT: ForStmt
29 for (int i = 7; i < 17; i += 3)
30 // PRINT-NEXT: body(i);
31 // DUMP: CallExpr
32 body(i);
36 // PRINT-LABEL: void func_unroll_full() {
37 // DUMP-LABEL: FunctionDecl {{.*}} func_unroll_full
38 void func_unroll_full() {
39 // PRINT: #pragma omp unroll full
40 // DUMP: OMPUnrollDirective
41 // DUMP-NEXT: OMPFullClause
42 #pragma omp unroll full
43 // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
44 // DUMP-NEXT: ForStmt
45 for (int i = 7; i < 17; i += 3)
46 // PRINT-NEXT: body(i);
47 // DUMP: CallExpr
48 body(i);
52 // PRINT-LABEL: void func_unroll_partial() {
53 // DUMP-LABEL: FunctionDecl {{.*}} func_unroll_partial
54 void func_unroll_partial() {
55 // PRINT: #pragma omp unroll partial
56 // DUMP: OMPUnrollDirective
57 // DUMP-NEXT: OMPPartialClause
58 // DUMP-NEXT: <<<NULL>>>
59 #pragma omp unroll partial
60 // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
61 // DUMP-NEXT: ForStmt
62 for (int i = 7; i < 17; i += 3)
63 // PRINT: body(i);
64 // DUMP: CallExpr
65 body(i);
69 // PRINT-LABEL: void func_unroll_partial_factor() {
70 // DUMP-LABEL: FunctionDecl {{.*}} func_unroll_partial_factor
71 void func_unroll_partial_factor() {
72 // PRINT: #pragma omp unroll partial(4)
73 // DUMP: OMPUnrollDirective
74 // DUMP-NEXT: OMPPartialClause
75 // DUMP-NEXT: ConstantExpr
76 // DUMP-NEXT: value: Int 4
77 // DUMP-NEXT: IntegerLiteral {{.*}} 4
78 #pragma omp unroll partial(4)
79 // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
80 // DUMP-NEXT: ForStmt
81 for (int i = 7; i < 17; i += 3)
82 // PRINT-NEXT: body(i);
83 // DUMP: CallExpr
84 body(i);
88 // PRINT-LABEL: void func_unroll_partial_factor_for() {
89 // DUMP-LABEL: FunctionDecl {{.*}} func_unroll_partial_factor_for
90 void func_unroll_partial_factor_for() {
91 // PRINT: #pragma omp for
92 // DUMP: OMPForDirective
93 #pragma omp for
94 // PRINT: #pragma omp unroll partial(2)
95 // DUMP: OMPUnrollDirective
96 // DUMP-NEXT: OMPPartialClause
97 #pragma omp unroll partial(2)
98 // PRINT-NEXT: for (int i = 7; i < 17; i += 3)
99 // DUMP: ForStmt
100 for (int i = 7; i < 17; i += 3)
101 // PRINT-NEXT: body(i);
102 // DUMP: CallExpr
103 body(i);
107 // PRINT-LABEL: template <typename T, T Start, T End, T Step, int Factor> void unroll_templated() {
108 // DUMP-LABEL: FunctionTemplateDecl {{.*}} unroll_templated
109 template<typename T, T Start, T End, T Step, int Factor>
110 void unroll_templated() {
111 // PRINT: #pragma omp unroll partial(Factor)
112 // DUMP: OMPUnrollDirective
113 // DUMP-NEXT: OMPPartialClause
114 // DUMP-NEXT: DeclRefExpr {{.*}} 'Factor' 'int'
115 #pragma omp unroll partial(Factor)
116 // PRINT-NEXT: for (T i = Start; i < End; i += Step)
117 // DUMP-NEXT: ForStmt
118 for (T i = Start; i < End; i += Step)
119 // PRINT-NEXT: body(i);
120 // DUMP: CallExpr
121 body(i);
123 void unroll_template() {
124 unroll_templated<int,0,1024,1,4>();
128 // PRINT-LABEL: template <int Factor> void unroll_templated_factor(int start, int stop, int step) {
129 // DUMP-LABEL: FunctionTemplateDecl {{.*}} unroll_templated_factor
130 template <int Factor>
131 void unroll_templated_factor(int start, int stop, int step) {
132 // PRINT: #pragma omp unroll partial(Factor)
133 // DUMP: OMPUnrollDirective
134 // DUMP-NEXT: OMPPartialClause
135 // DUMP-NEXT: DeclRefExpr {{.*}} 'Factor' 'int'
136 #pragma omp unroll partial(Factor)
137 // PRINT-NEXT: for (int i = start; i < stop; i += step)
138 // DUMP-NEXT: ForStmt
139 for (int i = start; i < stop; i += step)
140 // PRINT-NEXT: body(i);
141 // DUMP: CallExpr
142 body(i);
144 void unroll_template_factor() {
145 unroll_templated_factor<4>(0, 42, 2);
149 #endif