1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --global-value-regex "![0-9]+" --version 2
2 ; Test -hwasan-with-ifunc flag.
4 ; RUN: opt -passes=hwasan -S < %s | \
6 ; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=instr < %s | \
7 ; RUN: FileCheck %s --check-prefixes=NOIFUNC-TLS-HISTORY
8 ; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=1 -hwasan-record-stack-history=none < %s | \
9 ; RUN: FileCheck %s --check-prefixes=NOIFUNC-TLS-NOHISTORY
10 ; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=0 -hwasan-with-tls=0 < %s | \
11 ; RUN: FileCheck %s --check-prefixes=NOIFUNC-NOTLS
12 ; RUN: opt -passes=hwasan -S -hwasan-with-ifunc=1 -hwasan-with-tls=0 < %s | \
13 ; RUN: FileCheck %s --check-prefixes=IFUNC-NOTLS
14 ; RUN: opt -passes=hwasan -S -mtriple=aarch64-fuchsia < %s | \
15 ; RUN: FileCheck %s --check-prefixes=FUCHSIA
16 ; RUN: opt -passes=hwasan -S -mtriple=aarch64-fuchsia -hwasan-record-stack-history=libcall < %s | \
17 ; RUN: FileCheck %s --check-prefixes=FUCHSIA-LIBCALL
19 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
20 target triple = "aarch64--linux-android22"
23 define i32 @test_load(ptr %a) sanitize_hwaddress {
24 ; First instrumentation in the function must be to load the dynamic shadow
25 ; address into a local variable.
26 ; "store i64" is only used to update stack history (this input IR intentionally does not use any i64)
27 ; W/o any allocas, the history is not updated, even if it is enabled explicitly with -hwasan-record-stack-history=1
28 ; CHECK-LABEL: define i32 @test_load
29 ; CHECK-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
31 ; CHECK-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
32 ; CHECK-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
33 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
34 ; CHECK-NEXT: ret i32 [[X]]
36 ; NOIFUNC-TLS-HISTORY-LABEL: define i32 @test_load
37 ; NOIFUNC-TLS-HISTORY-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
38 ; NOIFUNC-TLS-HISTORY-NEXT: entry:
39 ; NOIFUNC-TLS-HISTORY-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
40 ; NOIFUNC-TLS-HISTORY-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
41 ; NOIFUNC-TLS-HISTORY-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
42 ; NOIFUNC-TLS-HISTORY-NEXT: ret i32 [[X]]
44 ; NOIFUNC-TLS-NOHISTORY-LABEL: define i32 @test_load
45 ; NOIFUNC-TLS-NOHISTORY-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
46 ; NOIFUNC-TLS-NOHISTORY-NEXT: entry:
47 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
48 ; NOIFUNC-TLS-NOHISTORY-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
49 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
50 ; NOIFUNC-TLS-NOHISTORY-NEXT: ret i32 [[X]]
52 ; NOIFUNC-NOTLS-LABEL: define i32 @test_load
53 ; NOIFUNC-NOTLS-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
54 ; NOIFUNC-NOTLS-NEXT: entry:
55 ; NOIFUNC-NOTLS-NEXT: [[TMP0:%.*]] = load ptr, ptr @__hwasan_shadow_memory_dynamic_address, align 8
56 ; NOIFUNC-NOTLS-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[TMP0]], ptr [[A]], i32 2)
57 ; NOIFUNC-NOTLS-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
58 ; NOIFUNC-NOTLS-NEXT: ret i32 [[X]]
60 ; IFUNC-NOTLS-LABEL: define i32 @test_load
61 ; IFUNC-NOTLS-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
62 ; IFUNC-NOTLS-NEXT: entry:
63 ; IFUNC-NOTLS-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
64 ; IFUNC-NOTLS-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
65 ; IFUNC-NOTLS-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
66 ; IFUNC-NOTLS-NEXT: ret i32 [[X]]
68 ; FUCHSIA-LABEL: define i32 @test_load
69 ; FUCHSIA-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
70 ; FUCHSIA-NEXT: entry:
71 ; FUCHSIA-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr null)
72 ; FUCHSIA-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
73 ; FUCHSIA-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
74 ; FUCHSIA-NEXT: ret i32 [[X]]
76 ; FUCHSIA-LIBCALL-LABEL: define i32 @test_load
77 ; FUCHSIA-LIBCALL-SAME: (ptr [[A:%.*]]) #[[ATTR0:[0-9]+]] {
78 ; FUCHSIA-LIBCALL-NEXT: entry:
79 ; FUCHSIA-LIBCALL-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr null)
80 ; FUCHSIA-LIBCALL-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[DOTHWASAN_SHADOW]], ptr [[A]], i32 2)
81 ; FUCHSIA-LIBCALL-NEXT: [[X:%.*]] = load i32, ptr [[A]], align 4
82 ; FUCHSIA-LIBCALL-NEXT: ret i32 [[X]]
85 %x = load i32, ptr %a, align 4
89 declare void @use(ptr %p)
91 define void @test_alloca() sanitize_hwaddress {
92 ; First instrumentation in the function must be to load the dynamic shadow
93 ; address into a local variable.
94 ; When watching stack history, all code paths attempt to get PC and SP and mix them together.
95 ; CHECK-LABEL: define void @test_alloca
96 ; CHECK-SAME: () #[[ATTR0]] {
98 ; CHECK-NEXT: [[TMP0:%.*]] = call ptr @llvm.thread.pointer()
99 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[TMP0]], i32 48
100 ; CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
101 ; CHECK-NEXT: [[TMP3:%.*]] = ashr i64 [[TMP2]], 3
102 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.read_register.i64(metadata [[META1:![0-9]+]])
103 ; CHECK-NEXT: [[TMP5:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
104 ; CHECK-NEXT: [[TMP6:%.*]] = ptrtoint ptr [[TMP5]] to i64
105 ; CHECK-NEXT: [[TMP7:%.*]] = shl i64 [[TMP6]], 44
106 ; CHECK-NEXT: [[TMP8:%.*]] = or i64 [[TMP4]], [[TMP7]]
107 ; CHECK-NEXT: [[TMP9:%.*]] = inttoptr i64 [[TMP2]] to ptr
108 ; CHECK-NEXT: store i64 [[TMP8]], ptr [[TMP9]], align 8
109 ; CHECK-NEXT: [[TMP10:%.*]] = ashr i64 [[TMP2]], 56
110 ; CHECK-NEXT: [[TMP11:%.*]] = shl nuw nsw i64 [[TMP10]], 12
111 ; CHECK-NEXT: [[TMP12:%.*]] = xor i64 [[TMP11]], -1
112 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[TMP2]], 8
113 ; CHECK-NEXT: [[TMP14:%.*]] = and i64 [[TMP13]], [[TMP12]]
114 ; CHECK-NEXT: store i64 [[TMP14]], ptr [[TMP1]], align 8
115 ; CHECK-NEXT: [[TMP15:%.*]] = or i64 [[TMP2]], 4294967295
116 ; CHECK-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP15]], 1
117 ; CHECK-NEXT: [[TMP16:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
118 ; CHECK-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP6]], 56
119 ; CHECK-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
120 ; CHECK-NEXT: [[TMP17:%.*]] = xor i64 [[TMP3]], 0
121 ; CHECK-NEXT: [[TMP18:%.*]] = ptrtoint ptr [[X]] to i64
122 ; CHECK-NEXT: [[TMP19:%.*]] = and i64 [[TMP18]], 72057594037927935
123 ; CHECK-NEXT: [[TMP20:%.*]] = shl i64 [[TMP17]], 56
124 ; CHECK-NEXT: [[TMP21:%.*]] = or i64 [[TMP19]], [[TMP20]]
125 ; CHECK-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP21]] to ptr
126 ; CHECK-NEXT: [[TMP22:%.*]] = trunc i64 [[TMP17]] to i8
127 ; CHECK-NEXT: [[TMP23:%.*]] = ptrtoint ptr [[X]] to i64
128 ; CHECK-NEXT: [[TMP24:%.*]] = and i64 [[TMP23]], 72057594037927935
129 ; CHECK-NEXT: [[TMP25:%.*]] = lshr i64 [[TMP24]], 4
130 ; CHECK-NEXT: [[TMP26:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP25]]
131 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP26]], i8 [[TMP22]], i64 1, i1 false)
132 ; CHECK-NEXT: call void @use(ptr [[X_HWASAN]])
133 ; CHECK-NEXT: [[TMP27:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
134 ; CHECK-NEXT: [[TMP28:%.*]] = ptrtoint ptr [[X]] to i64
135 ; CHECK-NEXT: [[TMP29:%.*]] = and i64 [[TMP28]], 72057594037927935
136 ; CHECK-NEXT: [[TMP30:%.*]] = lshr i64 [[TMP29]], 4
137 ; CHECK-NEXT: [[TMP31:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP30]]
138 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP31]], i8 [[TMP27]], i64 1, i1 false)
139 ; CHECK-NEXT: ret void
141 ; NOIFUNC-TLS-HISTORY-LABEL: define void @test_alloca
142 ; NOIFUNC-TLS-HISTORY-SAME: () #[[ATTR0]] {
143 ; NOIFUNC-TLS-HISTORY-NEXT: entry:
144 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP0:%.*]] = call ptr @llvm.thread.pointer()
145 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[TMP0]], i32 48
146 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
147 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP3:%.*]] = ashr i64 [[TMP2]], 3
148 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP4:%.*]] = call i64 @llvm.read_register.i64(metadata [[META1:![0-9]+]])
149 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP5:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
150 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP6:%.*]] = ptrtoint ptr [[TMP5]] to i64
151 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP7:%.*]] = shl i64 [[TMP6]], 44
152 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP8:%.*]] = or i64 [[TMP4]], [[TMP7]]
153 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP9:%.*]] = inttoptr i64 [[TMP2]] to ptr
154 ; NOIFUNC-TLS-HISTORY-NEXT: store i64 [[TMP8]], ptr [[TMP9]], align 8
155 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP10:%.*]] = ashr i64 [[TMP2]], 56
156 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP11:%.*]] = shl nuw nsw i64 [[TMP10]], 12
157 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP12:%.*]] = xor i64 [[TMP11]], -1
158 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP13:%.*]] = add i64 [[TMP2]], 8
159 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP14:%.*]] = and i64 [[TMP13]], [[TMP12]]
160 ; NOIFUNC-TLS-HISTORY-NEXT: store i64 [[TMP14]], ptr [[TMP1]], align 8
161 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP15:%.*]] = or i64 [[TMP2]], 4294967295
162 ; NOIFUNC-TLS-HISTORY-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP15]], 1
163 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP16:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
164 ; NOIFUNC-TLS-HISTORY-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP6]], 56
165 ; NOIFUNC-TLS-HISTORY-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
166 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP17:%.*]] = xor i64 [[TMP3]], 0
167 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP18:%.*]] = ptrtoint ptr [[X]] to i64
168 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP19:%.*]] = and i64 [[TMP18]], 72057594037927935
169 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP20:%.*]] = shl i64 [[TMP17]], 56
170 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP21:%.*]] = or i64 [[TMP19]], [[TMP20]]
171 ; NOIFUNC-TLS-HISTORY-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP21]] to ptr
172 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP22:%.*]] = trunc i64 [[TMP17]] to i8
173 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP23:%.*]] = ptrtoint ptr [[X]] to i64
174 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP24:%.*]] = and i64 [[TMP23]], 72057594037927935
175 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP25:%.*]] = lshr i64 [[TMP24]], 4
176 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP26:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP25]]
177 ; NOIFUNC-TLS-HISTORY-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP26]], i8 [[TMP22]], i64 1, i1 false)
178 ; NOIFUNC-TLS-HISTORY-NEXT: call void @use(ptr [[X_HWASAN]])
179 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP27:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
180 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP28:%.*]] = ptrtoint ptr [[X]] to i64
181 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP29:%.*]] = and i64 [[TMP28]], 72057594037927935
182 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP30:%.*]] = lshr i64 [[TMP29]], 4
183 ; NOIFUNC-TLS-HISTORY-NEXT: [[TMP31:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP30]]
184 ; NOIFUNC-TLS-HISTORY-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP31]], i8 [[TMP27]], i64 1, i1 false)
185 ; NOIFUNC-TLS-HISTORY-NEXT: ret void
187 ; NOIFUNC-TLS-NOHISTORY-LABEL: define void @test_alloca
188 ; NOIFUNC-TLS-NOHISTORY-SAME: () #[[ATTR0]] {
189 ; NOIFUNC-TLS-NOHISTORY-NEXT: entry:
190 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
191 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP0:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
192 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[TMP0]] to i64
193 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP1]], 20
194 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[HWASAN_STACK_BASE_TAG:%.*]] = xor i64 [[TMP1]], [[TMP2]]
195 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP1]], 56
196 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
197 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP3:%.*]] = xor i64 [[HWASAN_STACK_BASE_TAG]], 0
198 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP4:%.*]] = ptrtoint ptr [[X]] to i64
199 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP5:%.*]] = and i64 [[TMP4]], 72057594037927935
200 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP6:%.*]] = shl i64 [[TMP3]], 56
201 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP7:%.*]] = or i64 [[TMP5]], [[TMP6]]
202 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP7]] to ptr
203 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP8:%.*]] = trunc i64 [[TMP3]] to i8
204 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP9:%.*]] = ptrtoint ptr [[X]] to i64
205 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP10:%.*]] = and i64 [[TMP9]], 72057594037927935
206 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP11:%.*]] = lshr i64 [[TMP10]], 4
207 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP12:%.*]] = getelementptr i8, ptr [[DOTHWASAN_SHADOW]], i64 [[TMP11]]
208 ; NOIFUNC-TLS-NOHISTORY-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP12]], i8 [[TMP8]], i64 1, i1 false)
209 ; NOIFUNC-TLS-NOHISTORY-NEXT: call void @use(ptr [[X_HWASAN]])
210 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP13:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
211 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP14:%.*]] = ptrtoint ptr [[X]] to i64
212 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP15:%.*]] = and i64 [[TMP14]], 72057594037927935
213 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP16:%.*]] = lshr i64 [[TMP15]], 4
214 ; NOIFUNC-TLS-NOHISTORY-NEXT: [[TMP17:%.*]] = getelementptr i8, ptr [[DOTHWASAN_SHADOW]], i64 [[TMP16]]
215 ; NOIFUNC-TLS-NOHISTORY-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP17]], i8 [[TMP13]], i64 1, i1 false)
216 ; NOIFUNC-TLS-NOHISTORY-NEXT: ret void
218 ; NOIFUNC-NOTLS-LABEL: define void @test_alloca
219 ; NOIFUNC-NOTLS-SAME: () #[[ATTR0]] {
220 ; NOIFUNC-NOTLS-NEXT: entry:
221 ; NOIFUNC-NOTLS-NEXT: [[TMP0:%.*]] = load ptr, ptr @__hwasan_shadow_memory_dynamic_address, align 8
222 ; NOIFUNC-NOTLS-NEXT: [[TMP1:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
223 ; NOIFUNC-NOTLS-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TMP1]] to i64
224 ; NOIFUNC-NOTLS-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP2]], 20
225 ; NOIFUNC-NOTLS-NEXT: [[HWASAN_STACK_BASE_TAG:%.*]] = xor i64 [[TMP2]], [[TMP3]]
226 ; NOIFUNC-NOTLS-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP2]], 56
227 ; NOIFUNC-NOTLS-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
228 ; NOIFUNC-NOTLS-NEXT: [[TMP4:%.*]] = xor i64 [[HWASAN_STACK_BASE_TAG]], 0
229 ; NOIFUNC-NOTLS-NEXT: [[TMP5:%.*]] = ptrtoint ptr [[X]] to i64
230 ; NOIFUNC-NOTLS-NEXT: [[TMP6:%.*]] = and i64 [[TMP5]], 72057594037927935
231 ; NOIFUNC-NOTLS-NEXT: [[TMP7:%.*]] = shl i64 [[TMP4]], 56
232 ; NOIFUNC-NOTLS-NEXT: [[TMP8:%.*]] = or i64 [[TMP6]], [[TMP7]]
233 ; NOIFUNC-NOTLS-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP8]] to ptr
234 ; NOIFUNC-NOTLS-NEXT: [[TMP9:%.*]] = trunc i64 [[TMP4]] to i8
235 ; NOIFUNC-NOTLS-NEXT: [[TMP10:%.*]] = ptrtoint ptr [[X]] to i64
236 ; NOIFUNC-NOTLS-NEXT: [[TMP11:%.*]] = and i64 [[TMP10]], 72057594037927935
237 ; NOIFUNC-NOTLS-NEXT: [[TMP12:%.*]] = lshr i64 [[TMP11]], 4
238 ; NOIFUNC-NOTLS-NEXT: [[TMP13:%.*]] = getelementptr i8, ptr [[TMP0]], i64 [[TMP12]]
239 ; NOIFUNC-NOTLS-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP13]], i8 [[TMP9]], i64 1, i1 false)
240 ; NOIFUNC-NOTLS-NEXT: call void @use(ptr [[X_HWASAN]])
241 ; NOIFUNC-NOTLS-NEXT: [[TMP14:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
242 ; NOIFUNC-NOTLS-NEXT: [[TMP15:%.*]] = ptrtoint ptr [[X]] to i64
243 ; NOIFUNC-NOTLS-NEXT: [[TMP16:%.*]] = and i64 [[TMP15]], 72057594037927935
244 ; NOIFUNC-NOTLS-NEXT: [[TMP17:%.*]] = lshr i64 [[TMP16]], 4
245 ; NOIFUNC-NOTLS-NEXT: [[TMP18:%.*]] = getelementptr i8, ptr [[TMP0]], i64 [[TMP17]]
246 ; NOIFUNC-NOTLS-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP18]], i8 [[TMP14]], i64 1, i1 false)
247 ; NOIFUNC-NOTLS-NEXT: ret void
249 ; IFUNC-NOTLS-LABEL: define void @test_alloca
250 ; IFUNC-NOTLS-SAME: () #[[ATTR0]] {
251 ; IFUNC-NOTLS-NEXT: entry:
252 ; IFUNC-NOTLS-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr @__hwasan_shadow)
253 ; IFUNC-NOTLS-NEXT: [[TMP0:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
254 ; IFUNC-NOTLS-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[TMP0]] to i64
255 ; IFUNC-NOTLS-NEXT: [[TMP2:%.*]] = lshr i64 [[TMP1]], 20
256 ; IFUNC-NOTLS-NEXT: [[HWASAN_STACK_BASE_TAG:%.*]] = xor i64 [[TMP1]], [[TMP2]]
257 ; IFUNC-NOTLS-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP1]], 56
258 ; IFUNC-NOTLS-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
259 ; IFUNC-NOTLS-NEXT: [[TMP3:%.*]] = xor i64 [[HWASAN_STACK_BASE_TAG]], 0
260 ; IFUNC-NOTLS-NEXT: [[TMP4:%.*]] = ptrtoint ptr [[X]] to i64
261 ; IFUNC-NOTLS-NEXT: [[TMP5:%.*]] = and i64 [[TMP4]], 72057594037927935
262 ; IFUNC-NOTLS-NEXT: [[TMP6:%.*]] = shl i64 [[TMP3]], 56
263 ; IFUNC-NOTLS-NEXT: [[TMP7:%.*]] = or i64 [[TMP5]], [[TMP6]]
264 ; IFUNC-NOTLS-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP7]] to ptr
265 ; IFUNC-NOTLS-NEXT: [[TMP8:%.*]] = trunc i64 [[TMP3]] to i8
266 ; IFUNC-NOTLS-NEXT: [[TMP9:%.*]] = ptrtoint ptr [[X]] to i64
267 ; IFUNC-NOTLS-NEXT: [[TMP10:%.*]] = and i64 [[TMP9]], 72057594037927935
268 ; IFUNC-NOTLS-NEXT: [[TMP11:%.*]] = lshr i64 [[TMP10]], 4
269 ; IFUNC-NOTLS-NEXT: [[TMP12:%.*]] = getelementptr i8, ptr [[DOTHWASAN_SHADOW]], i64 [[TMP11]]
270 ; IFUNC-NOTLS-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP12]], i8 [[TMP8]], i64 1, i1 false)
271 ; IFUNC-NOTLS-NEXT: call void @use(ptr [[X_HWASAN]])
272 ; IFUNC-NOTLS-NEXT: [[TMP13:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
273 ; IFUNC-NOTLS-NEXT: [[TMP14:%.*]] = ptrtoint ptr [[X]] to i64
274 ; IFUNC-NOTLS-NEXT: [[TMP15:%.*]] = and i64 [[TMP14]], 72057594037927935
275 ; IFUNC-NOTLS-NEXT: [[TMP16:%.*]] = lshr i64 [[TMP15]], 4
276 ; IFUNC-NOTLS-NEXT: [[TMP17:%.*]] = getelementptr i8, ptr [[DOTHWASAN_SHADOW]], i64 [[TMP16]]
277 ; IFUNC-NOTLS-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP17]], i8 [[TMP13]], i64 1, i1 false)
278 ; IFUNC-NOTLS-NEXT: ret void
280 ; FUCHSIA-LABEL: define void @test_alloca
281 ; FUCHSIA-SAME: () #[[ATTR0]] personality ptr @__hwasan_personality_thunk {
282 ; FUCHSIA-NEXT: entry:
283 ; FUCHSIA-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr null)
284 ; FUCHSIA-NEXT: [[TMP0:%.*]] = load i64, ptr @__hwasan_tls, align 8
285 ; FUCHSIA-NEXT: [[TMP1:%.*]] = ashr i64 [[TMP0]], 3
286 ; FUCHSIA-NEXT: [[TMP2:%.*]] = call i64 @llvm.read_register.i64(metadata [[META1:![0-9]+]])
287 ; FUCHSIA-NEXT: [[TMP3:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
288 ; FUCHSIA-NEXT: [[TMP4:%.*]] = ptrtoint ptr [[TMP3]] to i64
289 ; FUCHSIA-NEXT: [[TMP5:%.*]] = shl i64 [[TMP4]], 44
290 ; FUCHSIA-NEXT: [[TMP6:%.*]] = or i64 [[TMP2]], [[TMP5]]
291 ; FUCHSIA-NEXT: [[TMP7:%.*]] = inttoptr i64 [[TMP0]] to ptr
292 ; FUCHSIA-NEXT: store i64 [[TMP6]], ptr [[TMP7]], align 8
293 ; FUCHSIA-NEXT: [[TMP8:%.*]] = ashr i64 [[TMP0]], 56
294 ; FUCHSIA-NEXT: [[TMP9:%.*]] = shl nuw nsw i64 [[TMP8]], 12
295 ; FUCHSIA-NEXT: [[TMP10:%.*]] = xor i64 [[TMP9]], -1
296 ; FUCHSIA-NEXT: [[TMP11:%.*]] = add i64 [[TMP0]], 8
297 ; FUCHSIA-NEXT: [[TMP12:%.*]] = and i64 [[TMP11]], [[TMP10]]
298 ; FUCHSIA-NEXT: store i64 [[TMP12]], ptr @__hwasan_tls, align 8
299 ; FUCHSIA-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP4]], 56
300 ; FUCHSIA-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
301 ; FUCHSIA-NEXT: [[TMP13:%.*]] = xor i64 [[TMP1]], 0
302 ; FUCHSIA-NEXT: [[TMP14:%.*]] = ptrtoint ptr [[X]] to i64
303 ; FUCHSIA-NEXT: [[TMP15:%.*]] = and i64 [[TMP14]], 72057594037927935
304 ; FUCHSIA-NEXT: [[TMP16:%.*]] = shl i64 [[TMP13]], 56
305 ; FUCHSIA-NEXT: [[TMP17:%.*]] = or i64 [[TMP15]], [[TMP16]]
306 ; FUCHSIA-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP17]] to ptr
307 ; FUCHSIA-NEXT: [[TMP18:%.*]] = trunc i64 [[TMP13]] to i8
308 ; FUCHSIA-NEXT: [[TMP19:%.*]] = ptrtoint ptr [[X]] to i64
309 ; FUCHSIA-NEXT: [[TMP20:%.*]] = and i64 [[TMP19]], 72057594037927935
310 ; FUCHSIA-NEXT: [[TMP21:%.*]] = lshr i64 [[TMP20]], 4
311 ; FUCHSIA-NEXT: [[TMP22:%.*]] = inttoptr i64 [[TMP21]] to ptr
312 ; FUCHSIA-NEXT: [[TMP23:%.*]] = getelementptr i8, ptr [[TMP22]], i32 0
313 ; FUCHSIA-NEXT: store i8 4, ptr [[TMP23]], align 1
314 ; FUCHSIA-NEXT: [[TMP24:%.*]] = getelementptr i8, ptr [[X]], i32 15
315 ; FUCHSIA-NEXT: store i8 [[TMP18]], ptr [[TMP24]], align 1
316 ; FUCHSIA-NEXT: call void @use(ptr [[X_HWASAN]])
317 ; FUCHSIA-NEXT: [[TMP25:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
318 ; FUCHSIA-NEXT: [[TMP26:%.*]] = ptrtoint ptr [[X]] to i64
319 ; FUCHSIA-NEXT: [[TMP27:%.*]] = and i64 [[TMP26]], 72057594037927935
320 ; FUCHSIA-NEXT: [[TMP28:%.*]] = lshr i64 [[TMP27]], 4
321 ; FUCHSIA-NEXT: [[TMP29:%.*]] = inttoptr i64 [[TMP28]] to ptr
322 ; FUCHSIA-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP29]], i8 [[TMP25]], i64 1, i1 false)
323 ; FUCHSIA-NEXT: ret void
325 ; FUCHSIA-LIBCALL-LABEL: define void @test_alloca
326 ; FUCHSIA-LIBCALL-SAME: () #[[ATTR0]] personality ptr @__hwasan_personality_thunk {
327 ; FUCHSIA-LIBCALL-NEXT: entry:
328 ; FUCHSIA-LIBCALL-NEXT: [[DOTHWASAN_SHADOW:%.*]] = call ptr asm "", "=r,0"(ptr null)
329 ; FUCHSIA-LIBCALL-NEXT: [[TMP0:%.*]] = call i64 @llvm.read_register.i64(metadata [[META1:![0-9]+]])
330 ; FUCHSIA-LIBCALL-NEXT: [[TMP1:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
331 ; FUCHSIA-LIBCALL-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TMP1]] to i64
332 ; FUCHSIA-LIBCALL-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 44
333 ; FUCHSIA-LIBCALL-NEXT: [[TMP4:%.*]] = or i64 [[TMP0]], [[TMP3]]
334 ; FUCHSIA-LIBCALL-NEXT: call void @__hwasan_add_frame_record(i64 [[TMP4]])
335 ; FUCHSIA-LIBCALL-NEXT: [[TMP5:%.*]] = lshr i64 [[TMP2]], 20
336 ; FUCHSIA-LIBCALL-NEXT: [[HWASAN_STACK_BASE_TAG:%.*]] = xor i64 [[TMP2]], [[TMP5]]
337 ; FUCHSIA-LIBCALL-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP2]], 56
338 ; FUCHSIA-LIBCALL-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
339 ; FUCHSIA-LIBCALL-NEXT: [[TMP6:%.*]] = xor i64 [[HWASAN_STACK_BASE_TAG]], 0
340 ; FUCHSIA-LIBCALL-NEXT: [[TMP7:%.*]] = ptrtoint ptr [[X]] to i64
341 ; FUCHSIA-LIBCALL-NEXT: [[TMP8:%.*]] = and i64 [[TMP7]], 72057594037927935
342 ; FUCHSIA-LIBCALL-NEXT: [[TMP9:%.*]] = shl i64 [[TMP6]], 56
343 ; FUCHSIA-LIBCALL-NEXT: [[TMP10:%.*]] = or i64 [[TMP8]], [[TMP9]]
344 ; FUCHSIA-LIBCALL-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP10]] to ptr
345 ; FUCHSIA-LIBCALL-NEXT: [[TMP11:%.*]] = trunc i64 [[TMP6]] to i8
346 ; FUCHSIA-LIBCALL-NEXT: [[TMP12:%.*]] = ptrtoint ptr [[X]] to i64
347 ; FUCHSIA-LIBCALL-NEXT: [[TMP13:%.*]] = and i64 [[TMP12]], 72057594037927935
348 ; FUCHSIA-LIBCALL-NEXT: [[TMP14:%.*]] = lshr i64 [[TMP13]], 4
349 ; FUCHSIA-LIBCALL-NEXT: [[TMP15:%.*]] = inttoptr i64 [[TMP14]] to ptr
350 ; FUCHSIA-LIBCALL-NEXT: [[TMP16:%.*]] = getelementptr i8, ptr [[TMP15]], i32 0
351 ; FUCHSIA-LIBCALL-NEXT: store i8 4, ptr [[TMP16]], align 1
352 ; FUCHSIA-LIBCALL-NEXT: [[TMP17:%.*]] = getelementptr i8, ptr [[X]], i32 15
353 ; FUCHSIA-LIBCALL-NEXT: store i8 [[TMP11]], ptr [[TMP17]], align 1
354 ; FUCHSIA-LIBCALL-NEXT: call void @use(ptr [[X_HWASAN]])
355 ; FUCHSIA-LIBCALL-NEXT: [[TMP18:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
356 ; FUCHSIA-LIBCALL-NEXT: [[TMP19:%.*]] = ptrtoint ptr [[X]] to i64
357 ; FUCHSIA-LIBCALL-NEXT: [[TMP20:%.*]] = and i64 [[TMP19]], 72057594037927935
358 ; FUCHSIA-LIBCALL-NEXT: [[TMP21:%.*]] = lshr i64 [[TMP20]], 4
359 ; FUCHSIA-LIBCALL-NEXT: [[TMP22:%.*]] = inttoptr i64 [[TMP21]] to ptr
360 ; FUCHSIA-LIBCALL-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP22]], i8 [[TMP18]], i64 1, i1 false)
361 ; FUCHSIA-LIBCALL-NEXT: ret void
364 %x = alloca i32, align 4
365 call void @use(ptr %x)