1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O1 -emit-llvm -o - %s | FileCheck %s --check-prefixes=O1
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O0 -emit-llvm -o - %s | FileCheck %s --check-prefix=O0
4 // Ensure that we place appropriate lifetime markers around indirectly returned
5 // temporaries, and that the lifetime.ends appear in a timely manner.
7 // -O1 is used so lifetime markers actually get emitted and optnone is added
8 // to avoid elimination of lifetime markers by optimizations.
16 // CHECK-LABEL: define dso_local void @bar
17 __attribute__((optnone
))
19 // O0-NOT: @llvm.lifetime.start
20 // O0-NOT: @llvm.lifetime.end
23 // O1: %[[TMP1_ALLOCA:[^ ]+]] = alloca %struct.S
24 // O1: %[[TMP2_ALLOCA:[^ ]+]] = alloca %struct.S
25 // O1: %[[TMP3_ALLOCA:[^ ]+]] = alloca %struct.S
27 // O1: call void @llvm.lifetime.start.p0({{[^,]*}}, ptr %[[TMP1_ALLOCA]])
31 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP1_ALLOCA]])
33 // O1: call void @llvm.lifetime.start.p0({{[^,]*}}, ptr %[[TMP2_ALLOCA]])
37 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP2_ALLOCA]])
39 // O1: call void @llvm.lifetime.start.p0({{[^,]*}}, ptr %[[TMP3_ALLOCA]])
43 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP3_ALLOCA]])
48 struct S
foo_int(int);
50 // Be sure that we're placing the lifetime.end so that all paths go through it.
51 // CHECK-LABEL: define dso_local void @baz
52 __attribute__((optnone
))
53 struct S
baz(int i
, volatile int *j
) {
54 // O0-NOT: @llvm.lifetime.start
55 // O0-NOT: @llvm.lifetime.end
58 // O1: %[[TMP1_ALLOCA:[^ ]+]] = alloca %struct.S
59 // O1: %[[TMP2_ALLOCA:[^ ]+]] = alloca %struct.S
62 // O1: call void @llvm.lifetime.start.p0({{[^,]*}}, ptr %[[TMP1_ALLOCA]])
64 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP1_ALLOCA]])
66 // O1: call void @foo_int(ptr dead_on_unwind writable sret(%struct.S) align 4 %[[TMP1_ALLOCA]],
67 // O1: call void @llvm.memcpy
68 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP1_ALLOCA]])
69 // O1: call void @llvm.lifetime.start.p0({{[^,]*}}, ptr %[[TMP2_ALLOCA]])
70 // O1: call void @foo_int(ptr dead_on_unwind writable sret(%struct.S) align 4 %[[TMP2_ALLOCA]],
71 // O1: call void @llvm.memcpy
72 // O1: call void @llvm.lifetime.end.p0({{[^,]*}}, ptr %[[TMP2_ALLOCA]])