1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; Test alloca instrumentation when tags are generated by HWASan function.
4 ; RUN: opt < %s -passes=hwasan -hwasan-generate-tags-with-calls -S | FileCheck %s
6 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
7 target triple = "aarch64--linux-android"
9 declare void @use32(ptr)
11 define void @test_alloca() sanitize_hwaddress {
12 ; CHECK-LABEL: define void @test_alloca
13 ; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
15 ; CHECK-NEXT: [[TMP0:%.*]] = call ptr @llvm.thread.pointer()
16 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[TMP0]], i32 48
17 ; CHECK-NEXT: [[TMP2:%.*]] = load i64, ptr [[TMP1]], align 8
18 ; CHECK-NEXT: [[TMP3:%.*]] = ashr i64 [[TMP2]], 3
19 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.read_register.i64(metadata [[META1:![0-9]+]])
20 ; CHECK-NEXT: [[TMP5:%.*]] = call ptr @llvm.frameaddress.p0(i32 0)
21 ; CHECK-NEXT: [[TMP6:%.*]] = ptrtoint ptr [[TMP5]] to i64
22 ; CHECK-NEXT: [[TMP7:%.*]] = shl i64 [[TMP6]], 44
23 ; CHECK-NEXT: [[TMP8:%.*]] = or i64 [[TMP4]], [[TMP7]]
24 ; CHECK-NEXT: [[TMP9:%.*]] = inttoptr i64 [[TMP2]] to ptr
25 ; CHECK-NEXT: store i64 [[TMP8]], ptr [[TMP9]], align 8
26 ; CHECK-NEXT: [[TMP10:%.*]] = ashr i64 [[TMP2]], 56
27 ; CHECK-NEXT: [[TMP11:%.*]] = shl nuw nsw i64 [[TMP10]], 12
28 ; CHECK-NEXT: [[TMP12:%.*]] = xor i64 [[TMP11]], -1
29 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[TMP2]], 8
30 ; CHECK-NEXT: [[TMP14:%.*]] = and i64 [[TMP13]], [[TMP12]]
31 ; CHECK-NEXT: store i64 [[TMP14]], ptr [[TMP1]], align 8
32 ; CHECK-NEXT: [[TMP15:%.*]] = or i64 [[TMP2]], 4294967295
33 ; CHECK-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP15]], 1
34 ; CHECK-NEXT: [[TMP16:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr
35 ; CHECK-NEXT: [[HWASAN_UAR_TAG:%.*]] = lshr i64 [[TMP6]], 56
36 ; CHECK-NEXT: [[X:%.*]] = alloca { i32, [12 x i8] }, align 16
37 ; CHECK-NEXT: [[TMP17:%.*]] = call i8 @__hwasan_generate_tag()
38 ; CHECK-NEXT: [[TMP18:%.*]] = zext i8 [[TMP17]] to i64
39 ; CHECK-NEXT: [[TMP19:%.*]] = ptrtoint ptr [[X]] to i64
40 ; CHECK-NEXT: [[TMP20:%.*]] = and i64 [[TMP19]], 72057594037927935
41 ; CHECK-NEXT: [[TMP21:%.*]] = shl i64 [[TMP18]], 56
42 ; CHECK-NEXT: [[TMP22:%.*]] = or i64 [[TMP20]], [[TMP21]]
43 ; CHECK-NEXT: [[X_HWASAN:%.*]] = inttoptr i64 [[TMP22]] to ptr
44 ; CHECK-NEXT: [[TMP23:%.*]] = trunc i64 [[TMP18]] to i8
45 ; CHECK-NEXT: [[TMP24:%.*]] = ptrtoint ptr [[X]] to i64
46 ; CHECK-NEXT: [[TMP25:%.*]] = and i64 [[TMP24]], 72057594037927935
47 ; CHECK-NEXT: [[TMP26:%.*]] = lshr i64 [[TMP25]], 4
48 ; CHECK-NEXT: [[TMP27:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP26]]
49 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP27]], i8 [[TMP23]], i64 1, i1 false)
50 ; CHECK-NEXT: call void @use32(ptr nonnull [[X_HWASAN]])
51 ; CHECK-NEXT: [[TMP28:%.*]] = trunc i64 [[HWASAN_UAR_TAG]] to i8
52 ; CHECK-NEXT: [[TMP29:%.*]] = ptrtoint ptr [[X]] to i64
53 ; CHECK-NEXT: [[TMP30:%.*]] = and i64 [[TMP29]], 72057594037927935
54 ; CHECK-NEXT: [[TMP31:%.*]] = lshr i64 [[TMP30]], 4
55 ; CHECK-NEXT: [[TMP32:%.*]] = getelementptr i8, ptr [[TMP16]], i64 [[TMP31]]
56 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP32]], i8 [[TMP28]], i64 1, i1 false)
57 ; CHECK-NEXT: ret void
61 %x = alloca i32, align 4
62 call void @use32(ptr nonnull %x)