[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / attr-mustprogress.c
blob2e8b871912e364d8c751f1048012bdac95d6ee09
1 // RUN: %clang_cc1 -std=c89 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
2 // RUN: %clang_cc1 -std=c99 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
3 // RUN: %clang_cc1 -std=c11 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C11 %s
4 // RUN: %clang_cc1 -std=c18 -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C11 %s
5 // RUN: %clang_cc1 -std=c2x -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C11 %s
6 //
7 // Check -ffinite-loops option in combination with various standard versions.
8 // RUN: %clang_cc1 -std=c89 -ffinite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
9 // RUN: %clang_cc1 -std=c99 -ffinite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
10 // RUN: %clang_cc1 -std=c11 -ffinite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
11 // RUN: %clang_cc1 -std=c18 -ffinite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
12 // RUN: %clang_cc1 -std=c2x -ffinite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=FINITE %s
14 // Check -fno-finite-loops option in combination with various standard versions.
15 // RUN: %clang_cc1 -std=c89 -fno-finite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
16 // RUN: %clang_cc1 -std=c99 -fno-finite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
17 // RUN: %clang_cc1 -std=c11 -fno-finite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
18 // RUN: %clang_cc1 -std=c18 -fno-finite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
19 // RUN: %clang_cc1 -std=c2x -fno-finite-loops -triple=x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix=CHECK --check-prefix=C99 %s
21 int a = 0;
22 int b = 0;
24 // CHECK: datalayout
26 // CHECK-NOT: mustprogress
27 // CHECK-LABEL: @f0(
28 // CHECK-NEXT: entry:
29 // CHECK-NEXT: br label %for.cond
30 // CHECK: for.cond:
31 // C99-NOT: br {{.*}}!llvm.loop
32 // C11-NOT: br {{.*}}!llvm.loop
33 // FINITE-NOR: br {{.*}}!llvm.loop
35 void f0(void) {
36 for (; ;) ;
39 // CHECK-NOT: mustprogress
40 // CHECK-LABEL: @f1(
41 // CHECK-NEXT: entry:
42 // CHECK-NEXT: br label %for.cond
43 // CHECK: for.cond:
44 // CHECK-NEXT: br i1 true, label %for.body, label %for.end
45 // CHECK: for.body:
46 // C99-NOT: br {{.*}}, !llvm.loop
47 // C11-NOT: br {{.*}}, !llvm.loop
48 // FINITE-NOT: br {{.*}}, !llvm.loop
49 // CHECK: for.end:
50 // CHECK-NEXT: ret void
52 void f1(void) {
53 for (; 1;) {
57 // CHECK-NOT: mustprogress
58 // CHECK-LABEL: @f2(
59 // CHECK-NEXT: entry:
60 // CHECK-NEXT: br label %for.cond
61 // CHECK: for.cond:
62 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
63 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
64 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
65 // CHECK-NEXT: br i1 [[CMP]], label %for.body, label %for.end
66 // CHECK: for.body:
67 // C99-NOT: br {{.*}} !llvm.loop
68 // C11: br label %for.cond, !llvm.loop [[LOOP1:!.*]]
69 // FINITE: br label %for.cond, !llvm.loop [[LOOP1:!.*]]
70 // CHECK: for.end:
71 // CHECK-NEXT: ret void
73 void f2(void) {
74 for (; a == b;) {
78 // CHECK-NOT: mustprogress
79 // CHECK-LABEL: @F(
80 // CHECK-NEXT: entry:
81 // CHECK-NEXT: br label %for.cond
82 // CHECK: for.cond:
83 // CHECK-NEXT: br i1 true, label %for.body, label %for.end
84 // CHECK: for.body:
85 // C99-NOT: br {{.*}}, !llvm.loop
86 // C11-NOT: br {{.*}}, !llvm.loop
87 // FINITE-NOT: br {{.*}}, !llvm.loop
88 // CHECK: for.end:
89 // CHECK-NEXT: br label %for.cond1
90 // CHECK: for.cond1:
91 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
92 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
93 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
94 // CHECK-NEXT: br i1 [[CMP]], label %for.body2, label %for.end3
95 // CHECK: for.body2:
96 // C99-NOT: br {{.*}}, !llvm.loop
97 // C11: br label %for.cond1, !llvm.loop [[LOOP2:!.*]]
98 // FINITE: br label %for.cond1, !llvm.loop [[LOOP2:!.*]]
99 // CHECK: for.end3:
100 // CHECK-NEXT: ret void
102 void F(void) {
103 for (; 1;) {
105 for (; a == b;) {
109 // CHECK-NOT: mustprogress
110 // CHECK-LABEL: @w1(
111 // CHECK-NEXT: entry:
112 // CHECK-NEXT: br label %while.body
113 // CHECK: while.body:
114 // C99-NOT: br {{.*}}, !llvm.loop
115 // C11-NOT: br {{.*}}, !llvm.loop
116 // FINITE-NOT: br {{.*}}, !llvm.loop
118 void w1(void) {
119 while (1) {
123 // CHECK-NOT: mustprogress
124 // CHECK-LABEL: @w2(
125 // CHECK-NEXT: entry:
126 // CHECK-NEXT: br label %while.cond
127 // CHECK: while.cond:
128 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
129 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
130 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
131 // CHECK-NEXT: br i1 [[CMP]], label %while.body, label %while.end
132 // CHECK: while.body:
133 // C99-NOT: br {{.*}}, !llvm.loop
134 // C11: br label %while.cond, !llvm.loop [[LOOP3:!.*]]
135 // FINITE: br label %while.cond, !llvm.loop [[LOOP3:!.*]]
136 // CHECK: while.end:
137 // CHECK-NEXT: ret void
139 void w2(void) {
140 while (a == b) {
144 // CHECK-NOT: mustprogress
145 // CHECK-LABEL: @W(
146 // CHECK-NEXT: entry:
147 // CHECK-NEXT: br label [[WHILE_COND:%.*]]
148 // CHECK: while.cond:
149 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
150 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
151 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
152 // CHECK-NEXT: br i1 [[CMP]], label %while.body, label %while.end
153 // CHECK: while.body:
154 // C99-NOT: br {{.*}} !llvm.loop
155 // C11-NEXT: br label %while.cond, !llvm.loop [[LOOP4:!.*]]
156 // FINITE-NEXT: br label %while.cond, !llvm.loop [[LOOP4:!.*]]
157 // CHECK: while.end:
158 // CHECK-NEXT: br label %while.body2
159 // CHECK: while.body2:
160 // C99-NOT: br {{.*}} !llvm.loop
161 // C11-NOT: br {{.*}} !llvm.loop
162 // FINITE-NOT: br {{.*}} !llvm.loop
164 void W(void) {
165 while (a == b) {
167 while (1) {
171 // CHECK-NOT: mustprogress
172 // CHECK-LABEL: @d1(
173 // CHECK-NEXT: entry:
174 // CHECK-NEXT: br label %do.body
175 // CHECK: do.body:
176 // CHECK-NEXT: br label %do.cond
177 // CHECK: do.cond:
178 // C99-NOT: br {{.*}}, !llvm.loop
179 // C11-NOT: br {{.*}}, !llvm.loop
180 // FINITE-NOT: br {{.*}}, !llvm.loop
181 // CHECK: do.end:
182 // CHECK-NEXT: ret void
184 void d1(void) {
185 do {
186 } while (1);
189 // CHECK-NOT: mustprogress
190 // CHECK-LABEL: @d2(
191 // CHECK-NEXT: entry:
192 // CHECK-NEXT: br label %do.body
193 // CHECK: do.body:
194 // CHECK-NEXT: br label %do.cond
195 // CHECK: do.cond:
196 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
197 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
198 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
199 // C99-NOT: br {{.*}}, !llvm.loop
200 // C11: br i1 [[CMP]], label %do.body, label %do.end, !llvm.loop [[LOOP5:!.*]]
201 // FINITE: br i1 [[CMP]], label %do.body, label %do.end, !llvm.loop [[LOOP5:!.*]]
202 // CHECK: do.end:
203 // CHECK-NEXT: ret void
205 void d2(void) {
206 do {
207 } while (a == b);
210 // CHECK-NOT: mustprogress
211 // CHECK-LABEL: @D(
212 // CHECK-NEXT: entry:
213 // CHECK-NEXT: br label %do.body
214 // CHECK: do.body:
215 // CHECK-NEXT: br label %do.cond
216 // CHECK: do.cond:
217 // CHECK-NOT: br label {{.*}}, !llvm.loop
218 // CHECK: do.end:
219 // CHECK-NEXT: br label %do.body1
220 // CHECK: do.body1:
221 // CHECK-NEXT: br label %do.cond2
222 // CHECK: do.cond2:
223 // CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @a, align 4
224 // CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr @b, align 4
225 // CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
226 // C99-NOT: br {{.*}}, !llvm.loop
227 // C11: br i1 [[CMP]], label %do.body1, label %do.end3, !llvm.loop [[LOOP6:!.*]]
228 // FINITE: br i1 [[CMP]], label %do.body1, label %do.end3, !llvm.loop [[LOOP6:!.*]]
229 // CHECK: do.end3:
230 // CHECK-NEXT: ret void
232 void D(void) {
233 do {
234 } while (1);
235 do {
236 } while (a == b);
239 // C11: [[LOOP1]] = distinct !{[[LOOP1]], [[MP:!.*]]}
240 // C11: [[MP]] = !{!"llvm.loop.mustprogress"}
241 // C11: [[LOOP2]] = distinct !{[[LOOP2]], [[MP]]}
242 // C11: [[LOOP3]] = distinct !{[[LOOP3]], [[MP]]}
243 // C11: [[LOOP4]] = distinct !{[[LOOP4]], [[MP]]}
244 // C11: [[LOOP5]] = distinct !{[[LOOP5]], [[MP]]}
245 // C11: [[LOOP6]] = distinct !{[[LOOP6]], [[MP]]}