Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / stack-reuse-miscompile.cpp
blobdbeea5e32cfb803863d8f1c5ba0fcda94dba2da2
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
3 class S {
4 char *ptr;
5 unsigned int len;
6 };
8 class T {
9 S left;
10 S right;
12 public:
13 T(const char s[]);
14 T(S);
16 T concat(const T &Suffix) const;
17 const char * str() const;
20 const char * f(S s)
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().
25 // CHECK: [[T1:%.*]] = alloca %class.T, align 4
26 // CHECK: [[T2:%.*]] = alloca %class.T, align 4
27 // CHECK: [[T3:%.*]] = alloca %class.T, align 4
29 // FIXME: We could defer starting the lifetime of the return object of concat
30 // until the call.
31 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T1]])
33 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T2]])
34 // CHECK: [[T4:%.*]] = call noundef ptr @_ZN1TC1EPKc(ptr {{[^,]*}} [[T2]], ptr noundef @.str)
36 // CHECK: call void @llvm.lifetime.start.p0(i64 16, ptr [[T3]])
37 // CHECK: [[T5:%.*]] = call noundef ptr @_ZN1TC1E1S(ptr {{[^,]*}} [[T3]], [2 x i32] %{{.*}})
39 // CHECK: call void @_ZNK1T6concatERKS_(ptr sret(%class.T) align 4 [[T1]], ptr {{[^,]*}} [[T2]], ptr noundef nonnull align 4 dereferenceable(16) [[T3]])
40 // CHECK: [[T6:%.*]] = call noundef ptr @_ZNK1T3strEv(ptr {{[^,]*}} [[T1]])
42 // CHECK: call void @llvm.lifetime.end.p0(
43 // CHECK: call void @llvm.lifetime.end.p0(
44 // CHECK: call void @llvm.lifetime.end.p0(
45 // CHECK: ret ptr [[T6]]
47 return T("[").concat(T(s)).str();
50 // CHECK: declare {{.*}}llvm.lifetime.start
51 // CHECK: declare {{.*}}llvm.lifetime.end