1 ; Regular stack poisoning.
2 ; RUN: opt < %s -asan -asan-module -asan-use-after-scope=0 -S | FileCheck --check-prefixes=CHECK,ENTRY,EXIT %s
4 ; Stack poisoning with stack-use-after-scope.
5 ; RUN: opt < %s -asan -asan-module -asan-use-after-scope=1 -S | FileCheck --check-prefixes=CHECK,ENTRY-UAS,EXIT-UAS %s
7 target datalayout = "e-i64:64-f80:128-s:64-n8:16:32:64-S128"
8 target triple = "x86_64-unknown-linux-gnu"
10 declare void @Foo(i8*)
12 define void @Bar() uwtable sanitize_address {
14 %x = alloca [650 x i8], align 16
15 %xx = getelementptr inbounds [650 x i8], [650 x i8]* %x, i64 0, i64 0
17 %y = alloca [13 x i8], align 1
18 %yy = getelementptr inbounds [13 x i8], [13 x i8]* %y, i64 0, i64 0
20 %z = alloca [40 x i8], align 1
21 %zz = getelementptr inbounds [40 x i8], [40 x i8]* %z, i64 0, i64 0
23 ; CHECK: [[SHADOW_BASE:%[0-9]+]] = add i64 %{{[0-9]+}}, 2147450880
26 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
27 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
28 ; ENTRY-NEXT: store [[TYPE]] -235802127, [[TYPE]]* [[PTR]], align 1
31 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 85
32 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
33 ; ENTRY-NEXT: store [[TYPE]] -940422246894996990, [[TYPE]]* [[PTR]], align 1
36 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 93
37 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
38 ; ENTRY-NEXT: store [[TYPE]] -940422246894996750, [[TYPE]]* [[PTR]], align 1
41 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 101
42 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
43 ; ENTRY-NEXT: store [[TYPE]] 1043442499826, [[TYPE]]* [[PTR]], align 1
46 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 111
47 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
48 ; ENTRY-NEXT: store [[TYPE]] -202116109, [[TYPE]]* [[PTR]], align 1
51 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 115
52 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i8]]*
53 ; ENTRY-NEXT: store [[TYPE]] -13, [[TYPE]]* [[PTR]], align 1
56 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
57 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
58 ; ENTRY-UAS-NEXT: store [[TYPE]] -235802127, [[TYPE]]* [[PTR]], align 1
61 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 4
62 ; ENTRY-UAS-NEXT: call void @__asan_set_shadow_f8(i64 [[OFFSET]], i64 82)
65 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 86
66 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
67 ; ENTRY-UAS-NEXT: store [[TYPE]] -940422246894996750, [[TYPE]]* [[PTR]], align 1
70 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 94
71 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
72 ; ENTRY-UAS-NEXT: store [[TYPE]] -940422246894996750, [[TYPE]]* [[PTR]], align 1
75 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 102
76 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
77 ; ENTRY-UAS-NEXT: store [[TYPE]] -506381209967593224, [[TYPE]]* [[PTR]], align 1
80 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 110
81 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
82 ; ENTRY-UAS-NEXT: store [[TYPE]] -202116104, [[TYPE]]* [[PTR]], align 1
85 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 114
86 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i16]]*
87 ; ENTRY-UAS-NEXT: store [[TYPE]] -3085, [[TYPE]]* [[PTR]], align 1
89 ; CHECK-LABEL: %xx = getelementptr inbounds
90 ; CHECK-NEXT: %yy = getelementptr inbounds
91 ; CHECK-NEXT: %zz = getelementptr inbounds
94 call void @llvm.lifetime.start.p0i8(i64 650, i8* %xx)
96 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 4
97 ; ENTRY-UAS-NEXT: call void @__asan_set_shadow_00(i64 [[OFFSET]], i64 81)
99 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 85
100 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i8]]*
101 ; ENTRY-UAS-NEXT: store [[TYPE]] 2, [[TYPE]]* [[PTR]], align 1
103 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 650, i8* %xx)
105 call void @Foo(i8* %xx)
106 ; CHECK-NEXT: call void @Foo(i8* %xx)
108 call void @llvm.lifetime.end.p0i8(i64 650, i8* %xx)
109 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 4
110 ; ENTRY-UAS-NEXT: call void @__asan_set_shadow_f8(i64 [[OFFSET]], i64 82)
112 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 650, i8* %xx)
115 call void @llvm.lifetime.start.p0i8(i64 13, i8* %yy)
117 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 102
118 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i16]]*
119 ; ENTRY-UAS-NEXT: store [[TYPE]] 1280, [[TYPE]]* [[PTR]], align 1
121 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 13, i8* %yy)
123 call void @Foo(i8* %yy)
124 ; CHECK-NEXT: call void @Foo(i8* %yy)
126 call void @llvm.lifetime.end.p0i8(i64 13, i8* %yy)
128 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 102
129 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i16]]*
130 ; ENTRY-UAS-NEXT: store [[TYPE]] -1800, [[TYPE]]* [[PTR]], align 1
132 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 13, i8* %yy)
135 call void @llvm.lifetime.start.p0i8(i64 40, i8* %zz)
137 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 106
138 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
139 ; ENTRY-UAS-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
141 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 110
142 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i8]]*
143 ; ENTRY-UAS-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
145 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 40, i8* %zz)
147 call void @Foo(i8* %zz)
148 ; CHECK-NEXT: call void @Foo(i8* %zz)
150 call void @llvm.lifetime.end.p0i8(i64 40, i8* %zz)
152 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 106
153 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
154 ; ENTRY-UAS-NEXT: store [[TYPE]] -117901064, [[TYPE]]* [[PTR]], align 1
156 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 110
157 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i8]]*
158 ; ENTRY-UAS-NEXT: store [[TYPE]] -8, [[TYPE]]* [[PTR]], align 1
160 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 40, i8* %zz)
162 ; CHECK: {{^[0-9]+}}:
164 ; CHECK-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
165 ; CHECK-NEXT: call void @__asan_set_shadow_f5(i64 [[OFFSET]], i64 128)
167 ; CHECK-NOT: add i64 [[SHADOW_BASE]]
169 ; CHECK: {{^[0-9]+}}:
172 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
173 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
174 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
177 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 85
178 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
179 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
182 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 93
183 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
184 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
187 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 101
188 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i64]]*
189 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
192 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 111
193 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i32]]*
194 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
197 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 115
198 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to [[TYPE:i8]]*
199 ; EXIT-NEXT: store [[TYPE]] 0, [[TYPE]]* [[PTR]], align 1
202 ; EXIT-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
203 ; EXIT-UAS-NEXT: call void @__asan_set_shadow_00(i64 [[OFFSET]], i64 116)
205 ; CHECK-NOT: add i64 [[SHADOW_BASE]]
208 ; CHECK: {{^[0-9]+}}:
212 declare void @foo(i32*)
213 define void @PR41481(i1 %b) sanitize_address {
214 ; CHECK-LABEL: @PR41481
218 %q1 = bitcast i32* %p1 to i8*
219 %q2 = bitcast i32* %p2 to i8*
222 ; Since we cannot account for all lifetime intrinsics in this function, we
223 ; might have missed a lifetime.start one and therefore shouldn't poison the
224 ; allocas at function entry.
225 ; ENTRY: store i64 -935356719533264399
226 ; ENTRY-UAS: store i64 -935356719533264399
229 %p = select i1 %b, i32* %p1, i32* %p2
230 %q = select i1 %b, i8* %q1, i8* %q2
231 call void @llvm.lifetime.start.p0i8(i64 4, i8* %q)
232 call void @foo(i32* %p)
233 br i1 %b, label %bb2, label %bb3
236 call void @llvm.lifetime.end.p0i8(i64 4, i8* %q1)
240 call void @llvm.lifetime.end.p0i8(i64 4, i8* %q2)
248 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
249 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
251 ; CHECK-ON: declare void @__asan_set_shadow_00(i64, i64)
252 ; CHECK-ON: declare void @__asan_set_shadow_f1(i64, i64)
253 ; CHECK-ON: declare void @__asan_set_shadow_f2(i64, i64)
254 ; CHECK-ON: declare void @__asan_set_shadow_f3(i64, i64)
255 ; CHECK-ON: declare void @__asan_set_shadow_f5(i64, i64)
256 ; CHECK-ON: declare void @__asan_set_shadow_f8(i64, i64)
258 ; CHECK-OFF-NOT: declare void @__asan_set_shadow_