1 ; Test handling of llvm.lifetime intrinsics.
2 ; RUN: opt < %s -passes=asan -asan-use-after-scope -asan-use-after-return=never -asan-use-stack-safety=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-DEFAULT
3 ; RUN: opt < %s -passes=asan -asan-use-after-scope -asan-use-after-return=never -asan-use-stack-safety=0 -asan-instrument-dynamic-allocas=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-NO-DYNAMIC
5 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
6 target triple = "x86_64-unknown-linux-gnu"
8 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
9 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
11 ; CHECK-LABEL: define void @lifetime_no_size(
12 define void @lifetime_no_size(i64 %i) sanitize_address {
14 %a = alloca [2 x i32], align 4
16 ; Poison memory in prologue: 0xf3f3f300f1f1f1f1
17 ; CHECK: store i64 -868083117767659023, ptr %[[#]]
19 call void @llvm.lifetime.start.p0(i64 -1, ptr %a)
20 ; Check that lifetime with no size are ignored.
22 ; CHECK: call void @llvm.lifetime.start
24 %ai = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 %i
25 store volatile i8 0, ptr %ai, align 4
26 ; CHECK: store volatile
28 call void @llvm.lifetime.end.p0(i64 -1, ptr %a)
29 ; Check that lifetime with no size are ignored.
31 ; CHECK: call void @llvm.lifetime.end
33 ; Unpoison stack frame on exit.
34 ; CHECK: store i64 0, ptr %{{[0-9]+}}
39 ; Generic case of lifetime analysis.
40 define void @lifetime() sanitize_address {
41 ; CHECK-LABEL: define void @lifetime()
43 ; Regular variable lifetime intrinsics.
44 %i = alloca i32, align 4
46 ; Poison memory in prologue: F1F1F1F1F8F3F3F3
47 ; CHECK: store i64 -868082052615769615, ptr %{{[0-9]+}}
49 ; Memory is unpoisoned at llvm.lifetime.start
50 call void @llvm.lifetime.start.p0(i64 3, ptr %i)
51 ; CHECK: store i8 4, ptr %{{[0-9]+}}
52 ; CHECK-NEXT: llvm.lifetime.start
54 store volatile i8 0, ptr %i
55 ; CHECK: store volatile
57 call void @llvm.lifetime.end.p0(i64 4, ptr %i)
58 ; CHECK: store i8 -8, ptr %{{[0-9]+}}
59 ; CHECK-NEXT: call void @llvm.lifetime.end
61 ; Memory is poisoned at every call to llvm.lifetime.end
62 call void @llvm.lifetime.end.p0(i64 2, ptr %i)
63 ; CHECK: store i8 -8, ptr %{{[0-9]+}}
64 ; CHECK-NEXT: call void @llvm.lifetime.end
66 ; Lifetime intrinsics for array.
67 %arr = alloca [10 x i32], align 16
69 call void @llvm.lifetime.start.p0(i64 40, ptr %arr)
70 ; CHECK-DEFAULT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
71 ; CHECK-NO-DYNAMIC-NOT: call void @__asan_unpoison_stack_memory(i64 %{{[^ ]+}}, i64 40)
73 store volatile i8 0, ptr %arr
74 ; CHECK: store volatile
76 call void @llvm.lifetime.end.p0(i64 40, ptr %arr)
77 ; CHECK-DEFAULT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
78 ; CHECK-NO-DYNAMIC-NOT: call void @__asan_poison_stack_memory(i64 %{{[^ ]+}}, i64 40)
80 ; One more lifetime start/end for the same variable %i.
81 call void @llvm.lifetime.start.p0(i64 2, ptr %i)
82 ; CHECK: store i8 4, ptr %{{[0-9]+}}
83 ; CHECK-NEXT: llvm.lifetime.start
85 store volatile i8 0, ptr %i
86 ; CHECK: store volatile
88 call void @llvm.lifetime.end.p0(i64 4, ptr %i)
89 ; CHECK: store i8 -8, ptr %{{[0-9]+}}
90 ; CHECK-NEXT: llvm.lifetime.end
92 ; Memory is unpoisoned at function exit (only once).
93 ; CHECK: store i64 0, ptr %{{[0-9]+}}
94 ; CHECK-NEXT: ret void
98 ; Check that arguments of lifetime may come from phi nodes.
99 define void @phi_args(i1 %x) sanitize_address {
100 ; CHECK-LABEL: define void @phi_args(i1 %x)
103 %i = alloca i64, align 4
105 ; Poison memory in prologue: F1F1F1F1F8F3F3F3
106 ; CHECK: store i64 -868082052615769615, ptr %{{[0-9]+}}
108 call void @llvm.lifetime.start.p0(i64 8, ptr %i)
109 ; CHECK: store i8 0, ptr %{{[0-9]+}}
110 ; CHECK-NEXT: llvm.lifetime.start
112 store volatile i8 0, ptr %i
113 ; CHECK: store volatile
115 br i1 %x, label %bb0, label %bb1
121 %i.phi = phi ptr [ %i, %entry ], [ %i, %bb0 ]
122 call void @llvm.lifetime.end.p0(i64 8, ptr %i.phi)
123 ; CHECK: store i8 -8, ptr %{{[0-9]+}}
124 ; CHECK-NEXT: llvm.lifetime.end
127 ; CHECK: store i64 0, ptr %{{[0-9]+}}
128 ; CHECK-NEXT: ret void
131 ; Check that arguments of lifetime may come from getelementptr nodes.
132 define void @getelementptr_args(i64 %i) sanitize_address{
133 ; CHECK-LABEL: define void @getelementptr_args
135 %x = alloca [1024 x i8], align 16
136 %a = alloca [2 x ptr], align 8
139 ; CHECK: store i32 -235802127, ptr %{{[0-9]+}}
140 ; CHECK: call void @__asan_set_shadow_f8(i64 %[[#]], i64 128)
142 ; CHECK: store i64 -940422246894996750, ptr %[[#]]
144 ; CHECK: store i64 -940422246894996750, ptr %[[#]]
146 call void @llvm.lifetime.start.p0(i64 1024, ptr %x)
147 ; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 128)
148 ; CHECK-NEXT: call void @llvm.lifetime.start
150 %ai = getelementptr inbounds [2 x ptr], ptr %a, i64 0, i64 %i
151 store ptr %x, ptr %ai, align 8
154 call void @llvm.lifetime.end.p0(i64 1024, ptr %x)
155 ; CHECK: call void @__asan_set_shadow_f8(i64 %{{[0-9]+}}, i64 128)
156 ; CHECK-NEXT: call void @llvm.lifetime.end
159 ; CHECK: call void @__asan_set_shadow_00(i64 %{{[0-9]+}}, i64 148)
160 ; CHECK: store i16 0, ptr %[[#]], align 1
161 ; CHECK-NEXT: ret void
164 define void @zero_sized(i64 %a) #0 {
165 ; CHECK-LABEL: define void @zero_sized(i64 %a)
168 %a.addr = alloca i64, align 8
169 %b = alloca [0 x i8], align 1
170 store i64 %a, ptr %a.addr, align 8
172 call void @llvm.lifetime.start.p0(i64 0, ptr %b) #2
173 ; CHECK: call void @llvm.lifetime.start
175 call void @llvm.lifetime.end.p0(i64 0, ptr %b) #2
176 ; CHECK: call void @llvm.lifetime.end
179 ; CHECK-NEXT: ret void