1 ; Regular stack poisoning.
2 ; RUN: opt < %s -passes=asan -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 -passes=asan -asan-use-after-scope=1 -S | FileCheck --check-prefixes=CHECK,ENTRY-UAS,EXIT-UAS %s
7 target datalayout = "E-m:e-i64:64-n32:64"
8 target triple = "powerpc64-unknown-linux-gnu"
10 declare void @Foo(ptr)
12 define void @Bar() uwtable sanitize_address {
14 %x = alloca [650 x i8], align 16
15 %xx = getelementptr inbounds [650 x i8], ptr %x, i64 0, i64 0
17 %y = alloca [13 x i8], align 1
18 %yy = getelementptr inbounds [13 x i8], ptr %y, i64 0, i64 0
20 %z = alloca [40 x i8], align 1
21 %zz = getelementptr inbounds [40 x i8], ptr %z, i64 0, i64 0
23 ; CHECK: [[SHADOW_BASE:%[0-9]+]] = add i64 %{{[0-9]+}}, 17592186044416
26 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 0
27 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
28 ; ENTRY-NEXT: store i32 -235802127, ptr [[PTR]], align 1
31 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 85
32 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
33 ; ENTRY-NEXT: store i64 212499257711850226, ptr [[PTR]], align 1
36 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 93
37 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
38 ; ENTRY-NEXT: store i64 -940422246894996750, ptr [[PTR]], align 1
41 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 101
42 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
43 ; ENTRY-NEXT: store i64 -1008799775530680320, ptr [[PTR]], align 1
46 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 111
47 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
48 ; ENTRY-NEXT: store i32 -202116109, ptr [[PTR]], align 1
51 ; ENTRY-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 115
52 ; ENTRY-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
53 ; ENTRY-NEXT: store i8 -13, ptr [[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 ptr
58 ; ENTRY-UAS-NEXT: store i32 -235802127, ptr [[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 ptr
67 ; ENTRY-UAS-NEXT: store i64 -940422246894996750, ptr [[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 ptr
72 ; ENTRY-UAS-NEXT: store i64 -940422246894996750, ptr [[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 ptr
77 ; ENTRY-UAS-NEXT: store i64 -506387832706107144, ptr [[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 ptr
82 ; ENTRY-UAS-NEXT: store i32 -118230029, ptr [[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 ptr
87 ; ENTRY-UAS-NEXT: store i16 -3085, ptr [[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.p0(i64 650, ptr %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 ptr
101 ; ENTRY-UAS-NEXT: store i8 2, ptr [[PTR]], align 1
103 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 650, ptr %xx)
105 call void @Foo(ptr %xx)
106 ; CHECK-NEXT: call void @Foo(ptr %xx)
108 call void @llvm.lifetime.end.p0(i64 650, ptr %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.p0(i64 650, ptr %xx)
115 call void @llvm.lifetime.start.p0(i64 13, ptr %yy)
117 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 102
118 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
119 ; ENTRY-UAS-NEXT: store i16 5, ptr [[PTR]], align 1
121 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 13, ptr %yy)
123 call void @Foo(ptr %yy)
124 ; CHECK-NEXT: call void @Foo(ptr %yy)
126 call void @llvm.lifetime.end.p0(i64 13, ptr %yy)
128 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 102
129 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
130 ; ENTRY-UAS-NEXT: store i16 -1800, ptr [[PTR]], align 1
132 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 13, ptr %yy)
135 call void @llvm.lifetime.start.p0(i64 40, ptr %zz)
137 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 106
138 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
139 ; ENTRY-UAS-NEXT: store i32 0, ptr [[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 ptr
143 ; ENTRY-UAS-NEXT: store i8 0, ptr [[PTR]], align 1
145 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 40, ptr %zz)
147 call void @Foo(ptr %zz)
148 ; CHECK-NEXT: call void @Foo(ptr %zz)
150 call void @llvm.lifetime.end.p0(i64 40, ptr %zz)
152 ; ENTRY-UAS-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 106
153 ; ENTRY-UAS-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
154 ; ENTRY-UAS-NEXT: store i32 -117901064, ptr [[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 ptr
158 ; ENTRY-UAS-NEXT: store i8 -8, ptr [[PTR]], align 1
160 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 40, ptr %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 ptr
174 ; EXIT-NEXT: store i32 0, ptr [[PTR]], align 1
177 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 85
178 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
179 ; EXIT-NEXT: store i64 0, ptr [[PTR]], align 1
182 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 93
183 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
184 ; EXIT-NEXT: store i64 0, ptr [[PTR]], align 1
187 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 101
188 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
189 ; EXIT-NEXT: store i64 0, ptr [[PTR]], align 1
192 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 111
193 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
194 ; EXIT-NEXT: store i32 0, ptr [[PTR]], align 1
197 ; EXIT-NEXT: [[OFFSET:%[0-9]+]] = add i64 [[SHADOW_BASE]], 115
198 ; EXIT-NEXT: [[PTR:%[0-9]+]] = inttoptr i64 [[OFFSET]] to ptr
199 ; EXIT-NEXT: store i8 0, ptr [[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 @llvm.lifetime.start.p0(i64, ptr nocapture)
213 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
215 ; CHECK-ON: declare void @__asan_set_shadow_00(i64, i64)
216 ; CHECK-ON: declare void @__asan_set_shadow_f1(i64, i64)
217 ; CHECK-ON: declare void @__asan_set_shadow_f2(i64, i64)
218 ; CHECK-ON: declare void @__asan_set_shadow_f3(i64, i64)
219 ; CHECK-ON: declare void @__asan_set_shadow_f5(i64, i64)
220 ; CHECK-ON: declare void @__asan_set_shadow_f8(i64, i64)
222 ; CHECK-OFF-NOT: declare void @__asan_set_shadow_