| 1 | // RUN: %clang_cc1 -triple armv7l-unknown-linux-gnueabihf -emit-llvm -O1 -disable-llvm-passes -std=c++03 %s -o - | FileCheck %s --implicit-check-not=llvm.lifetime |
| 2 | |
| 3 | class S { |
| 4 | char *ptr; |
| 5 | unsigned int len; |
| 6 | }; |
| 7 | |
| 8 | class T { |
| 9 | S left; |
| 10 | S right; |
| 11 | |
| 12 | public: |
| 13 | T(const char s[]); |
| 14 | T(S); |
| 15 | |
| 16 | T concat(const T &Suffix) const; |
| 17 | const char * str() const; |
| 18 | }; |
| 19 | |
| 20 | const char * f(S s) |
| 21 | { |
| 22 | // It's essential that the lifetimes of all three T temporaries here are |
| 23 | // overlapping. They must all remain alive through the call to str(). |
| 24 | // |
| 25 | // CHECK: [[T1:%.*]] = alloca %class.T, align 4 |
| 26 | // CHECK: [[T2:%.*]] = alloca %class.T, align 4 |
| 27 | // CHECK: [[T3:%.*]] = alloca %class.T, align 4 |
| 28 | // |
| 29 | // FIXME: We could defer starting the lifetime of the return object of concat |
| 30 | // until the call. |
| 31 | // CHECK: [[T1i8:%.*]] = bitcast %class.T* [[T1]] to i8* |
| 32 | // CHECK: call void @llvm.lifetime.start.p0i8(i64 16, i8* [[T1i8]]) |
| 33 | // |
| 34 | // CHECK: [[T2i8:%.*]] = bitcast %class.T* [[T2]] to i8* |
| 35 | // CHECK: call void @llvm.lifetime.start.p0i8(i64 16, i8* [[T2i8]]) |
| 36 | // CHECK: [[T4:%.*]] = call %class.T* @_ZN1TC1EPKc(%class.T* [[T2]], i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0)) |
| 37 | // |
| 38 | // CHECK: [[T3i8:%.*]] = bitcast %class.T* [[T3]] to i8* |
| 39 | // CHECK: call void @llvm.lifetime.start.p0i8(i64 16, i8* [[T3i8]]) |
| 40 | // CHECK: [[T5:%.*]] = call %class.T* @_ZN1TC1E1S(%class.T* [[T3]], [2 x i32] %{{.*}}) |
| 41 | // |
| 42 | // CHECK: call void @_ZNK1T6concatERKS_(%class.T* sret [[T1]], %class.T* [[T2]], %class.T* dereferenceable(16) [[T3]]) |
| 43 | // CHECK: [[T6:%.*]] = call i8* @_ZNK1T3strEv(%class.T* [[T1]]) |
| 44 | // |
| 45 | // CHECK: call void @llvm.lifetime.end.p0i8( |
| 46 | // CHECK: call void @llvm.lifetime.end.p0i8( |
| 47 | // CHECK: call void @llvm.lifetime.end.p0i8( |
| 48 | // CHECK: ret i8* [[T6]] |
| 49 | |
| 50 | return T("[").concat(T(s)).str(); |
| 51 | } |
| 52 | |
| 53 | // CHECK: declare {{.*}}llvm.lifetime.start |
| 54 | // CHECK: declare {{.*}}llvm.lifetime.end |
| 55 | |