2016-07-02 05:08:47 +08:00
|
|
|
// RUN: %clang_cc1 %s -std=c++11 -O1 -DWITH_DTOR -triple x86_64 -emit-llvm -o - | FileCheck -check-prefix=CHECK-DTOR %s
|
|
|
|
// RUN: %clang_cc1 %s -std=c++11 -O1 -triple x86_64 -emit-llvm -o - | FileCheck -check-prefix=CHECK-NO-DTOR %s
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
#ifdef WITH_DTOR
|
|
|
|
~A();
|
|
|
|
#endif
|
|
|
|
char a[1024];
|
|
|
|
operator bool() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Foo(T &&);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Bar(T &&);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T Baz();
|
|
|
|
|
|
|
|
void Test1() {
|
|
|
|
// CHECK-DTOR-LABEL: Test1
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIRK1AEvOT_
|
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[VAR]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIRK1AEvOT_
|
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[VAR]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: }
|
|
|
|
|
|
|
|
// CHECK-NO-DTOR-LABEL: Test1
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR:[^ ]+]])
|
|
|
|
// CHECK-NO-DTOR: call void @_Z3FooIRK1AEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR:[^ ]+]])
|
|
|
|
// CHECK-NO-DTOR: call void @_Z3FooIRK1AEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: }
|
|
|
|
{
|
|
|
|
const A &a = A{};
|
|
|
|
Foo(a);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const A &a = A{};
|
|
|
|
Foo(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test2() {
|
|
|
|
// CHECK-DTOR-LABEL: Test2
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR1:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR1:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIRK1AEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR2:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR2:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIRK1AEvOT_
|
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[VAR2]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR2]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[VAR1]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR1]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: }
|
|
|
|
|
|
|
|
// CHECK-NO-DTOR-LABEL: Test2
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR1:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR1:[^ ]+]])
|
|
|
|
// CHECK-NO-DTOR: call void @_Z3FooIRK1AEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR2:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: call void @_ZN1AC1Ev(%struct.A* nonnull %[[VAR2:[^ ]+]])
|
|
|
|
// CHECK-NO-DTOR: call void @_Z3FooIRK1AEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR2]])
|
|
|
|
// CHECK-NO-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR1]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-NO-DTOR: }
|
|
|
|
const A &a = A{};
|
|
|
|
Foo(a);
|
|
|
|
const A &b = A{};
|
|
|
|
Foo(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test3() {
|
|
|
|
// CHECK-DTOR-LABEL: Test3
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start
|
2016-07-02 06:50:00 +08:00
|
|
|
|
|
|
|
// if.then:
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end
|
2016-07-02 06:50:00 +08:00
|
|
|
|
|
|
|
// cleanup:
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end
|
2016-07-02 06:50:00 +08:00
|
|
|
|
|
|
|
// cleanup:
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end
|
|
|
|
// CHECK-DTOR: }
|
|
|
|
const A &a = A{};
|
|
|
|
if (const A &b = A(a)) {
|
|
|
|
Foo(b);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bar(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test4() {
|
|
|
|
// CHECK-DTOR-LABEL: Test4
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start
|
2016-07-02 06:50:00 +08:00
|
|
|
|
|
|
|
// for.cond.cleanup:
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end
|
2016-07-02 06:50:00 +08:00
|
|
|
|
|
|
|
// for.body:
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: }
|
|
|
|
for (const A &a = A{}; a;) {
|
|
|
|
Foo(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int Test5() {
|
|
|
|
// CHECK-DTOR-LABEL: Test5
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start
|
|
|
|
// CHECK-DTOR: call i32 @_Z3BazIiET_v()
|
|
|
|
// CHECK-DTOR: store
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIRKiEvOT_
|
|
|
|
// CHECK-DTOR: load
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end
|
|
|
|
// CHECK-DTOR: }
|
|
|
|
const int &a = Baz<int>();
|
|
|
|
Foo(a);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test6() {
|
|
|
|
// CHECK-DTOR-LABEL: Test6
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 {{[0-9]+}}, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call i32 @_Z3BazIiET_v()
|
|
|
|
// CHECK-DTOR: store
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIiEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 {{[0-9]+}}, i8* nonnull %[[ADDR]])
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 {{[0-9]+}}, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call i32 @_Z3BazIiET_v()
|
|
|
|
// CHECK-DTOR: store
|
|
|
|
// CHECK-DTOR: call void @_Z3FooIiEvOT_
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 {{[0-9]+}}, i8* nonnull %[[ADDR]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: }
|
|
|
|
Foo(Baz<int>());
|
|
|
|
Foo(Baz<int>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test7() {
|
|
|
|
// CHECK-DTOR-LABEL: Test7
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_Z3BazI1AET_v({{.*}} %[[SLOT:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooI1AEvOT_({{.*}} %[[SLOT]])
|
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[SLOT]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.start(i64 1024, i8* nonnull %[[ADDR:[0-9]+]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: call void @_Z3BazI1AET_v({{.*}} %[[SLOT:[^ ]+]])
|
|
|
|
// CHECK-DTOR: call void @_Z3FooI1AEvOT_({{.*}} %[[SLOT]])
|
|
|
|
// CHECK-DTOR: call void @_ZN1AD1Ev(%struct.A* nonnull %[[SLOT]])
|
2016-09-15 14:31:30 +08:00
|
|
|
// CHECK-DTOR: call void @llvm.lifetime.end(i64 1024, i8* nonnull %[[ADDR]])
|
2016-07-02 05:08:47 +08:00
|
|
|
// CHECK-DTOR: }
|
|
|
|
Foo(Baz<A>());
|
|
|
|
Foo(Baz<A>());
|
|
|
|
}
|