1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -o - -emit-llvm -O1 \
2 // RUN: -fexceptions -fcxx-exceptions -mllvm -simplifycfg-sink-common=false | FileCheck %s
4 // We should emit lifetime.ends for these temporaries in both the 'exception'
5 // and 'normal' paths in functions.
7 // -O1 is necessary to make lifetime markers appear.
15 // Used to ensure we emit invokes.
16 struct NontrivialDtor
{
21 // CHECK-LABEL: define{{.*}} void @_Z33cleanupsAreEmittedWithoutTryCatchv
22 void cleanupsAreEmittedWithoutTryCatch() {
23 // CHECK: %[[CLEAN:[^ ]+]] = bitcast %struct.NontrivialDtor* %{{[^ ]+}} to i8*
24 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
25 // CHECK: %[[T1:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
26 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
27 // CHECK-NEXT: invoke void @_Z8getLargev
28 // CHECK-NEXT: to label %[[CONT:[^ ]+]] unwind label %[[LPAD:[^ ]+]]
31 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
32 // CHECK: %[[T2:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
33 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
34 // CHECK-NEXT: invoke void @_Z8getLargev
35 // CHECK-NEXT: to label %[[CONT2:[^ ]+]] unwind label %[[LPAD2:.+]]
38 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
39 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
43 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
44 // CHECK: br label %[[EHCLEANUP:.+]]
47 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
48 // CHECK: br label %[[EHCLEANUP]]
50 // CHECK: [[EHCLEANUP]]:
51 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
59 // CHECK-LABEL: define{{.*}} void @_Z30cleanupsAreEmittedWithTryCatchv
60 void cleanupsAreEmittedWithTryCatch() {
61 // CHECK: %[[CLEAN:[^ ]+]] = bitcast %struct.NontrivialDtor* %{{[^ ]+}} to i8*
62 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
63 // CHECK: %[[T1:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
64 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
65 // CHECK-NEXT: invoke void @_Z8getLargev
66 // CHECK-NEXT: to label %[[CONT:[^ ]+]] unwind label %[[LPAD:[^ ]+]]
69 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
70 // CHECK: %[[T2:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
71 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
72 // CHECK-NEXT: invoke void @_Z8getLargev
73 // CHECK-NEXT: to label %[[CONT2:[^ ]+]] unwind label %[[LPAD2:.+]]
76 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
77 // CHECK: br label %[[TRY_CONT:.+]]
80 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
81 // CHECK: br label %[[CATCH:.+]]
84 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
85 // CHECK: br label %[[CATCH]]
88 // CHECK-NOT: call void @llvm.lifetime
90 // CHECK-NEXT: to label %[[TRY_CONT]] unwind label %[[OUTER_LPAD:.+]]
92 // CHECK: [[TRY_CONT]]:
93 // CHECK: %[[T_OUTER:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
94 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T_OUTER]])
95 // CHECK-NEXT: invoke void @_Z8getLargev
96 // CHECK-NEXT: to label %[[OUTER_CONT:[^ ]+]] unwind label %[[OUTER_LPAD2:.+]]
98 // CHECK: [[OUTER_CONT]]:
99 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T_OUTER]])
100 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
103 // CHECK: [[OUTER_LPAD]]:
104 // CHECK-NOT: call void @llvm.lifetime
105 // CHECK: br label %[[EHCLEANUP:.+]]
107 // CHECK: [[OUTER_LPAD2]]:
108 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T_OUTER]])
109 // CHECK: br label %[[EHCLEANUP]]
111 // CHECK: [[EHCLEANUP]]:
112 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[CLEAN]])
114 NontrivialDtor clean
;
124 // CHECK-LABEL: define{{.*}} void @_Z39cleanupInTryHappensBeforeCleanupInCatchv
125 void cleanupInTryHappensBeforeCleanupInCatch() {
126 // CHECK: %[[T1:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
127 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
128 // CHECK-NEXT: invoke void @_Z8getLargev
129 // CHECK-NEXT: to label %[[CONT:[^ ]+]] unwind label %[[LPAD:[^ ]+]]
132 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
133 // CHECK: br label %[[TRY_CONT]]
136 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T1]])
137 // CHECK: br i1 {{[^,]+}}, label %[[CATCH_INT_MATCH:[^,]+]], label %[[CATCH_ALL:.+]]
139 // CHECK: [[CATCH_INT_MATCH]]:
140 // CHECK: %[[T2:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
141 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
142 // CHECK-NEXT: invoke void @_Z8getLargev
143 // CHECK-NEXT: to label %[[CATCH_INT_CONT:[^ ]+]] unwind label %[[CATCH_INT_LPAD:[^ ]+]]
145 // CHECK: [[CATCH_INT_CONT]]:
146 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
147 // CHECK: br label %[[TRY_CONT]]
149 // CHECK: [[TRY_CONT]]:
152 // CHECK: [[CATCH_ALL]]:
153 // CHECK: %[[T3:[^ ]+]] = bitcast %struct.Large* %{{[^ ]+}} to i8*
154 // CHECK: call void @llvm.lifetime.start.p0i8({{[^,]+}}, i8* nonnull %[[T3]])
155 // CHECK-NEXT: invoke void @_Z8getLargev
156 // CHECK-NEXT: to label %[[CATCH_ALL_CONT:[^ ]+]] unwind label %[[CATCH_ALL_LPAD:[^ ]+]]
158 // CHECK: [[CATCH_ALL_CONT]]:
159 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T3]])
160 // CHECK: br label %[[TRY_CONT]]
162 // CHECK: [[CATCH_ALL_LPAD]]:
163 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T3]])
165 // CHECK: [[CATCH_INT_LPAD]]:
166 // CHECK: call void @llvm.lifetime.end.p0i8({{[^,]+}}, i8* nonnull %[[T2]])
167 // CHECK-NOT: call void @llvm.lifetime
171 } catch (const int &) {
178 // FIXME: We don't currently emit lifetime markers for aggregate by-value
179 // temporaries (e.g. given a function `Large combine(Large, Large);`
180 // combine(getLarge(), getLarge()) "leaks" two `Large`s). We probably should. We
181 // also don't emit markers for things like:
184 // Large L = getLarge();
188 // Though this arguably isn't as bad, since we pass a pointer to `L` as one of