1 ; Test basic address sanitizer instrumentation.
3 ; RUN: opt < %s -hwasan -hwasan-instrument-with-calls -S | FileCheck %s --check-prefixes=CHECK,ABORT
4 ; RUN: opt < %s -hwasan -hwasan-instrument-with-calls -hwasan-recover=1 -S | FileCheck %s --check-prefixes=CHECK,RECOVER
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 define i8 @test_load8(i8* %a) sanitize_hwaddress {
10 ; CHECK-LABEL: @test_load8(
11 ; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
12 ; ABORT: call void @__hwasan_load1(i64 %[[A]])
13 ; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]])
14 ; CHECK: %[[B:[^ ]*]] = load i8, i8* %a
15 ; CHECK: ret i8 %[[B]]
18 %b = load i8, i8* %a, align 4
22 define i16 @test_load16(i16* %a) sanitize_hwaddress {
23 ; CHECK-LABEL: @test_load16(
24 ; CHECK: %[[A:[^ ]*]] = ptrtoint i16* %a to i64
25 ; ABORT: call void @__hwasan_load2(i64 %[[A]])
26 ; RECOVER: call void @__hwasan_load2_noabort(i64 %[[A]])
27 ; CHECK: %[[B:[^ ]*]] = load i16, i16* %a
28 ; CHECK: ret i16 %[[B]]
31 %b = load i16, i16* %a, align 4
35 define i32 @test_load32(i32* %a) sanitize_hwaddress {
36 ; CHECK-LABEL: @test_load32(
37 ; CHECK: %[[A:[^ ]*]] = ptrtoint i32* %a to i64
38 ; ABORT: call void @__hwasan_load4(i64 %[[A]])
39 ; RECOVER: call void @__hwasan_load4_noabort(i64 %[[A]])
40 ; CHECK: %[[B:[^ ]*]] = load i32, i32* %a
41 ; CHECK: ret i32 %[[B]]
44 %b = load i32, i32* %a, align 4
48 define i64 @test_load64(i64* %a) sanitize_hwaddress {
49 ; CHECK-LABEL: @test_load64(
50 ; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64
51 ; ABORT: call void @__hwasan_load8(i64 %[[A]])
52 ; RECOVER: call void @__hwasan_load8_noabort(i64 %[[A]])
53 ; CHECK: %[[B:[^ ]*]] = load i64, i64* %a
54 ; CHECK: ret i64 %[[B]]
57 %b = load i64, i64* %a, align 8
61 define i128 @test_load128(i128* %a) sanitize_hwaddress {
62 ; CHECK-LABEL: @test_load128(
63 ; CHECK: %[[A:[^ ]*]] = ptrtoint i128* %a to i64
64 ; ABORT: call void @__hwasan_load16(i64 %[[A]])
65 ; RECOVER: call void @__hwasan_load16_noabort(i64 %[[A]])
66 ; CHECK: %[[B:[^ ]*]] = load i128, i128* %a
67 ; CHECK: ret i128 %[[B]]
70 %b = load i128, i128* %a, align 16
74 define i40 @test_load40(i40* %a) sanitize_hwaddress {
75 ; CHECK-LABEL: @test_load40(
76 ; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
77 ; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5)
78 ; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5)
79 ; CHECK: %[[B:[^ ]*]] = load i40, i40* %a
80 ; CHECK: ret i40 %[[B]]
83 %b = load i40, i40* %a, align 4
87 define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress {
88 ; CHECK-LABEL: @test_store8(
89 ; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
90 ; ABORT: call void @__hwasan_store1(i64 %[[A]])
91 ; RECOVER: call void @__hwasan_store1_noabort(i64 %[[A]])
92 ; CHECK: store i8 %b, i8* %a
96 store i8 %b, i8* %a, align 4
100 define void @test_store16(i16* %a, i16 %b) sanitize_hwaddress {
101 ; CHECK-LABEL: @test_store16(
102 ; CHECK: %[[A:[^ ]*]] = ptrtoint i16* %a to i64
103 ; ABORT: call void @__hwasan_store2(i64 %[[A]])
104 ; RECOVER: call void @__hwasan_store2_noabort(i64 %[[A]])
105 ; CHECK: store i16 %b, i16* %a
109 store i16 %b, i16* %a, align 4
113 define void @test_store32(i32* %a, i32 %b) sanitize_hwaddress {
114 ; CHECK-LABEL: @test_store32(
115 ; CHECK: %[[A:[^ ]*]] = ptrtoint i32* %a to i64
116 ; ABORT: call void @__hwasan_store4(i64 %[[A]])
117 ; RECOVER: call void @__hwasan_store4_noabort(i64 %[[A]])
118 ; CHECK: store i32 %b, i32* %a
122 store i32 %b, i32* %a, align 4
126 define void @test_store64(i64* %a, i64 %b) sanitize_hwaddress {
127 ; CHECK-LABEL: @test_store64(
128 ; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64
129 ; ABORT: call void @__hwasan_store8(i64 %[[A]])
130 ; RECOVER: call void @__hwasan_store8_noabort(i64 %[[A]])
131 ; CHECK: store i64 %b, i64* %a
135 store i64 %b, i64* %a, align 8
139 define void @test_store128(i128* %a, i128 %b) sanitize_hwaddress {
140 ; CHECK-LABEL: @test_store128(
141 ; CHECK: %[[A:[^ ]*]] = ptrtoint i128* %a to i64
142 ; ABORT: call void @__hwasan_store16(i64 %[[A]])
143 ; RECOVER: call void @__hwasan_store16_noabort(i64 %[[A]])
144 ; CHECK: store i128 %b, i128* %a
148 store i128 %b, i128* %a, align 16
152 define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress {
153 ; CHECK-LABEL: @test_store40(
154 ; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
155 ; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5)
156 ; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5)
157 ; CHECK: store i40 %b, i40* %a
161 store i40 %b, i40* %a, align 4
165 define i8 @test_load_noattr(i8* %a) {
166 ; CHECK-LABEL: @test_load_noattr(
168 ; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
169 ; CHECK-NEXT: ret i8 %[[B]]
172 %b = load i8, i8* %a, align 4
176 define i8 @test_load_notmyattr(i8* %a) sanitize_address {
177 ; CHECK-LABEL: @test_load_notmyattr(
179 ; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
180 ; CHECK-NEXT: ret i8 %[[B]]
183 %b = load i8, i8* %a, align 4
187 define i8 @test_load_addrspace(i8 addrspace(256)* %a) sanitize_hwaddress {
188 ; CHECK-LABEL: @test_load_addrspace(
190 ; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8 addrspace(256)* %a
191 ; CHECK-NEXT: ret i8 %[[B]]
194 %b = load i8, i8 addrspace(256)* %a, align 4
198 ; CHECK: declare void @__hwasan_init()
200 ; CHECK: define internal void @hwasan.module_ctor() comdat {
201 ; CHECK-NEXT: call void @__hwasan_init()
202 ; CHECK-NEXT: ret void