• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Test basic address sanitizer instrumentation.
2;
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
5
6target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
7target triple = "aarch64--linux-android"
8
9define 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]]
16
17entry:
18  %b = load i8, i8* %a, align 4
19  ret i8 %b
20}
21
22define 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]]
29
30entry:
31  %b = load i16, i16* %a, align 4
32  ret i16 %b
33}
34
35define 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]]
42
43entry:
44  %b = load i32, i32* %a, align 4
45  ret i32 %b
46}
47
48define 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]]
55
56entry:
57  %b = load i64, i64* %a, align 8
58  ret i64 %b
59}
60
61define 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]]
68
69entry:
70  %b = load i128, i128* %a, align 16
71  ret i128 %b
72}
73
74define 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]]
81
82entry:
83  %b = load i40, i40* %a, align 4
84  ret i40 %b
85}
86
87define 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
93; CHECK: ret void
94
95entry:
96  store i8 %b, i8* %a, align 4
97  ret void
98}
99
100define 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
106; CHECK: ret void
107
108entry:
109  store i16 %b, i16* %a, align 4
110  ret void
111}
112
113define 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
119; CHECK: ret void
120
121entry:
122  store i32 %b, i32* %a, align 4
123  ret void
124}
125
126define 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
132; CHECK: ret void
133
134entry:
135  store i64 %b, i64* %a, align 8
136  ret void
137}
138
139define 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
145; CHECK: ret void
146
147entry:
148  store i128 %b, i128* %a, align 16
149  ret void
150}
151
152define 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
158; CHECK: ret void
159
160entry:
161  store i40 %b, i40* %a, align 4
162  ret void
163}
164
165define i8 @test_load_noattr(i8* %a) {
166; CHECK-LABEL: @test_load_noattr(
167; CHECK-NEXT: entry:
168; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
169; CHECK-NEXT: ret i8 %[[B]]
170
171entry:
172  %b = load i8, i8* %a, align 4
173  ret i8 %b
174}
175
176define i8 @test_load_notmyattr(i8* %a) sanitize_address {
177; CHECK-LABEL: @test_load_notmyattr(
178; CHECK-NEXT: entry:
179; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
180; CHECK-NEXT: ret i8 %[[B]]
181
182entry:
183  %b = load i8, i8* %a, align 4
184  ret i8 %b
185}
186
187define i8 @test_load_addrspace(i8 addrspace(256)* %a) sanitize_hwaddress {
188; CHECK-LABEL: @test_load_addrspace(
189; CHECK-NEXT: entry:
190; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8 addrspace(256)* %a
191; CHECK-NEXT: ret i8 %[[B]]
192
193entry:
194  %b = load i8, i8 addrspace(256)* %a, align 4
195  ret i8 %b
196}
197
198; CHECK: declare void @__hwasan_init()
199
200; CHECK:      define internal void @hwasan.module_ctor() {
201; CHECK-NEXT:   call void @__hwasan_init()
202; CHECK-NEXT:   ret void
203; CHECK-NEXT: }
204