|
| 1 | +// RUN: %clang -cc1 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s \ |
| 2 | +// RUN: -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime |
| 3 | +// RUN: %clang -cc1 -xc++ -std=c++17 -triple x86_64-apple-macos -O1 \ |
| 4 | +// RUN: -disable-llvm-passes %s -emit-llvm -o - -Wno-return-type-c-linkage | \ |
| 5 | +// RUN: FileCheck %s --implicit-check-not=llvm.lifetime --check-prefixes=CHECK,CXX |
| 6 | +// RUN: %clang -cc1 -xobjective-c -triple x86_64-apple-macos -O1 \ |
| 7 | +// RUN: -disable-llvm-passes %s -emit-llvm -o - | \ |
| 8 | +// RUN: FileCheck %s --implicit-check-not=llvm.lifetime --check-prefixes=CHECK,OBJC |
| 9 | +// RUN: %clang -cc1 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s \ |
| 10 | +// RUN: -emit-llvm -o - -sloppy-temporary-lifetimes | \ |
| 11 | +// RUN: FileCheck %s --implicit-check-not=llvm.lifetime --check-prefixes=SLOPPY |
| 12 | + |
| 13 | +typedef struct { int x[100]; } aggregate; |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | + |
| 19 | +void takes_aggregate(aggregate); |
| 20 | +aggregate gives_aggregate(); |
| 21 | + |
| 22 | +// CHECK-LABEL: define void @t1 |
| 23 | +void t1() { |
| 24 | + takes_aggregate(gives_aggregate()); |
| 25 | + |
| 26 | + // CHECK: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8 |
| 27 | + // CHECK: call void @llvm.lifetime.start.p0(ptr [[AGGTMP]]) |
| 28 | + // CHECK: call void{{.*}} @gives_aggregate(ptr{{.*}}sret(%struct.aggregate) align 4 [[AGGTMP]]) |
| 29 | + // CHECK: call void @takes_aggregate(ptr noundef byval(%struct.aggregate) align 8 [[AGGTMP]]) |
| 30 | + // CHECK: call void @llvm.lifetime.end.p0(ptr [[AGGTMP]]) |
| 31 | + |
| 32 | + // SLOPPY: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8 |
| 33 | + // SLOPPY-NEXT: call void (ptr, ...) @gives_aggregate(ptr{{.*}}sret(%struct.aggregate) align 4 [[AGGTMP]]) |
| 34 | + // SLOPPY-NEXT: call void @takes_aggregate(ptr noundef byval(%struct.aggregate) align 8 [[AGGTMP]]) |
| 35 | +} |
| 36 | + |
| 37 | +// CHECK: declare {{.*}}llvm.lifetime.start |
| 38 | +// CHECK: declare {{.*}}llvm.lifetime.end |
| 39 | + |
| 40 | +#ifdef __cplusplus |
| 41 | +// CXX: define void @t2 |
| 42 | +void t2() { |
| 43 | + struct S { |
| 44 | + S(aggregate) {} |
| 45 | + }; |
| 46 | + S{gives_aggregate()}; |
| 47 | + |
| 48 | + // CXX: [[AGG:%.*]] = alloca %struct.aggregate |
| 49 | + // CXX: call void @llvm.lifetime.start.p0(ptr [[AGG]] |
| 50 | + // CXX: call void @gives_aggregate(ptr{{.*}}sret(%struct.aggregate) align 4 [[AGG]]) |
| 51 | + // CXX: call void @_ZZ2t2EN1SC1E9aggregate(ptr {{.*}}, ptr {{.*}} byval(%struct.aggregate) align 8 [[AGG]]) |
| 52 | + // CXX: call void @llvm.lifetime.end.p0(ptr [[AGG]] |
| 53 | +} |
| 54 | + |
| 55 | +struct Dtor { |
| 56 | + ~Dtor(); |
| 57 | +}; |
| 58 | + |
| 59 | +void takes_dtor(Dtor); |
| 60 | +Dtor gives_dtor(); |
| 61 | + |
| 62 | +// CXX: define void @t3 |
| 63 | +void t3() { |
| 64 | + takes_dtor(gives_dtor()); |
| 65 | + |
| 66 | + // CXX: [[AGG:%.*]] = alloca %struct.Dtor |
| 67 | + // CXX: call void @llvm.lifetime.start.p0(ptr [[AGG]]) |
| 68 | + // CXX: call void @gives_dtor(ptr{{.*}}sret(%struct.Dtor) align 1 [[AGG]]) |
| 69 | + // CXX: call void @takes_dtor(ptr noundef [[AGG]]) |
| 70 | + // CXX: call void @_ZN4DtorD1Ev(ptr {{.*}} [[AGG]]) |
| 71 | + // CXX: call void @llvm.lifetime.end.p0(ptr [[AGG]]) |
| 72 | + // CXX: ret void |
| 73 | +} |
| 74 | + |
| 75 | +#endif |
| 76 | + |
| 77 | +#ifdef __OBJC__ |
| 78 | + |
| 79 | +@interface X |
| 80 | +-m:(aggregate)x; |
| 81 | +@end |
| 82 | + |
| 83 | +// OBJC: define void @t4 |
| 84 | +void t4(X *x) { |
| 85 | + [x m: gives_aggregate()]; |
| 86 | + |
| 87 | + // OBJC: [[AGG:%.*]] = alloca %struct.aggregate |
| 88 | + // OBJC: call void @llvm.lifetime.start.p0(ptr [[AGG]] |
| 89 | + // OBJC: call void{{.*}} @gives_aggregate(ptr{{.*}}sret(%struct.aggregate) align 4 [[AGGTMP]]) |
| 90 | + // OBJC: call {{.*}}@objc_msgSend |
| 91 | + // OBJC: call void @llvm.lifetime.end.p0(ptr [[AGG]] |
| 92 | +} |
| 93 | + |
| 94 | +#endif |
| 95 | + |
| 96 | +#ifdef __cplusplus |
| 97 | +} |
| 98 | +#endif |
0 commit comments