[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CodeGen / lifetime2.c
blob88c35fca029dae638f2517b86ce9b3ae4b6db04e
1 // RUN: %clang_cc1 -emit-llvm -o - -O2 -disable-llvm-passes %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK,O2
2 // RUN: %clang_cc1 -emit-llvm -o - -O2 -disable-lifetime-markers %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK
3 // RUN: %clang_cc1 -emit-llvm -o - -O0 %s | FileCheck %s --implicit-check-not="call void @llvm.lifetime" --check-prefixes=CHECK
5 extern int bar(char *A, int n);
7 // CHECK-LABEL: @foo
8 int foo (int n) {
9 if (n) {
10 // O2: call void @llvm.lifetime.start.p0(i64 100,
11 char A[100];
12 return bar(A, 1);
13 // O2: call void @llvm.lifetime.end.p0(i64 100,
14 } else {
15 // O2: call void @llvm.lifetime.start.p0(i64 100,
16 char A[100];
17 return bar(A, 2);
18 // O2: call void @llvm.lifetime.end.p0(i64 100,
22 // CHECK-LABEL: @no_goto_bypass
23 void no_goto_bypass(void) {
24 // O2: call void @llvm.lifetime.start.p0(i64 1,
25 char x;
26 l1:
27 bar(&x, 1);
28 char y[5];
29 bar(y, 5);
30 goto l1;
31 // Infinite loop
34 // CHECK-LABEL: @goto_bypass
35 void goto_bypass(void) {
37 char x;
38 l1:
39 bar(&x, 1);
41 goto l1;
44 // CHECK-LABEL: @no_switch_bypass
45 void no_switch_bypass(int n) {
46 switch (n) {
47 case 1: {
48 // O2: call void @llvm.lifetime.start.p0(i64 1,
49 // O2: call void @llvm.lifetime.end.p0(i64 1,
50 char x;
51 bar(&x, 1);
52 break;
54 case 2:
55 n = n;
56 // O2: call void @llvm.lifetime.start.p0(i64 5,
57 // O2: call void @llvm.lifetime.end.p0(i64 5,
58 char y[5];
59 bar(y, 5);
60 break;
64 // CHECK-LABEL: @switch_bypass
65 void switch_bypass(int n) {
66 switch (n) {
67 case 1:
68 n = n;
69 char x;
70 bar(&x, 1);
71 break;
72 case 2:
73 bar(&x, 1);
74 break;
78 // CHECK-LABEL: @indirect_jump
79 void indirect_jump(int n) {
80 char x;
81 void *T[] = {&&L};
82 goto *T[n];
84 bar(&x, 1);
87 extern void foo2(int p);
89 // O2-LABEL: @jump_backward_over_declaration(
90 int jump_backward_over_declaration(int a) {
91 int *p = 0;
92 // O2: call void @llvm.lifetime.start.p0(
93 label1:
94 if (p) {
95 foo2(*p);
96 return 0;
99 int i = 999;
100 if (a != 2) {
101 p = &i;
102 goto label1;
104 return -1;
105 // O2: call void @llvm.lifetime.end.p0(