blob: 93129a51d741de90760e874bac4aa8c8aef03c53 [file] [log] [blame]
Evgeniy Stepanovc667c1f2017-12-09 00:21:41 +00001; Test basic address sanitizer instrumentation.
2;
3; RUN: opt < %s -hwasan -S | FileCheck %s
4
5target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
6target triple = "aarch64--linux-android"
7
8define i8 @test_load8(i8* %a) sanitize_hwaddress {
9; CHECK-LABEL: @test_load8(
10; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
11; CHECK: call void @__hwasan_load1(i64 %[[A]])
12; CHECK: %[[B:[^ ]*]] = load i8, i8* %a
13; CHECK: ret i8 %[[B]]
14
15entry:
16 %b = load i8, i8* %a, align 4
17 ret i8 %b
18}
19
20define i16 @test_load16(i16* %a) sanitize_hwaddress {
21; CHECK-LABEL: @test_load16(
22; CHECK: %[[A:[^ ]*]] = ptrtoint i16* %a to i64
23; CHECK: call void @__hwasan_load2(i64 %[[A]])
24; CHECK: %[[B:[^ ]*]] = load i16, i16* %a
25; CHECK: ret i16 %[[B]]
26
27entry:
28 %b = load i16, i16* %a, align 4
29 ret i16 %b
30}
31
32define i32 @test_load32(i32* %a) sanitize_hwaddress {
33; CHECK-LABEL: @test_load32(
34; CHECK: %[[A:[^ ]*]] = ptrtoint i32* %a to i64
35; CHECK: call void @__hwasan_load4(i64 %[[A]])
36; CHECK: %[[B:[^ ]*]] = load i32, i32* %a
37; CHECK: ret i32 %[[B]]
38
39entry:
40 %b = load i32, i32* %a, align 4
41 ret i32 %b
42}
43
44define i64 @test_load64(i64* %a) sanitize_hwaddress {
45; CHECK-LABEL: @test_load64(
46; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64
47; CHECK: call void @__hwasan_load8(i64 %[[A]])
48; CHECK: %[[B:[^ ]*]] = load i64, i64* %a
49; CHECK: ret i64 %[[B]]
50
51entry:
52 %b = load i64, i64* %a, align 8
53 ret i64 %b
54}
55
56define i128 @test_load128(i128* %a) sanitize_hwaddress {
57; CHECK-LABEL: @test_load128(
58; CHECK: %[[A:[^ ]*]] = ptrtoint i128* %a to i64
59; CHECK: call void @__hwasan_load16(i64 %[[A]])
60; CHECK: %[[B:[^ ]*]] = load i128, i128* %a
61; CHECK: ret i128 %[[B]]
62
63entry:
64 %b = load i128, i128* %a, align 16
65 ret i128 %b
66}
67
68define i40 @test_load40(i40* %a) sanitize_hwaddress {
69; CHECK-LABEL: @test_load40(
70; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
71; CHECK: call void @__hwasan_load(i64 %[[A]], i64 5)
72; CHECK: %[[B:[^ ]*]] = load i40, i40* %a
73; CHECK: ret i40 %[[B]]
74
75entry:
76 %b = load i40, i40* %a, align 4
77 ret i40 %b
78}
79
80define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress {
81; CHECK-LABEL: @test_store8(
82; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
83; CHECK: call void @__hwasan_store1(i64 %[[A]])
84; CHECK: store i8 %b, i8* %a
85; CHECK: ret void
86
87entry:
88 store i8 %b, i8* %a, align 4
89 ret void
90}
91
92define void @test_store16(i16* %a, i16 %b) sanitize_hwaddress {
93; CHECK-LABEL: @test_store16(
94; CHECK: %[[A:[^ ]*]] = ptrtoint i16* %a to i64
95; CHECK: call void @__hwasan_store2(i64 %[[A]])
96; CHECK: store i16 %b, i16* %a
97; CHECK: ret void
98
99entry:
100 store i16 %b, i16* %a, align 4
101 ret void
102}
103
104define void @test_store32(i32* %a, i32 %b) sanitize_hwaddress {
105; CHECK-LABEL: @test_store32(
106; CHECK: %[[A:[^ ]*]] = ptrtoint i32* %a to i64
107; CHECK: call void @__hwasan_store4(i64 %[[A]])
108; CHECK: store i32 %b, i32* %a
109; CHECK: ret void
110
111entry:
112 store i32 %b, i32* %a, align 4
113 ret void
114}
115
116define void @test_store64(i64* %a, i64 %b) sanitize_hwaddress {
117; CHECK-LABEL: @test_store64(
118; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64
119; CHECK: call void @__hwasan_store8(i64 %[[A]])
120; CHECK: store i64 %b, i64* %a
121; CHECK: ret void
122
123entry:
124 store i64 %b, i64* %a, align 4
125 ret void
126}
127
128define void @test_store128(i128* %a, i128 %b) sanitize_hwaddress {
129; CHECK-LABEL: @test_store128(
130; CHECK: %[[A:[^ ]*]] = ptrtoint i128* %a to i64
131; CHECK: call void @__hwasan_store16(i64 %[[A]])
132; CHECK: store i128 %b, i128* %a
133; CHECK: ret void
134
135entry:
136 store i128 %b, i128* %a, align 4
137 ret void
138}
139
140define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress {
141; CHECK-LABEL: @test_store40(
142; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
143; CHECK: call void @__hwasan_store(i64 %[[A]], i64 5)
144; CHECK: store i40 %b, i40* %a
145; CHECK: ret void
146
147entry:
148 store i40 %b, i40* %a, align 4
149 ret void
150}
151
152define i8 @test_load_noattr(i8* %a) {
153; CHECK-LABEL: @test_load_noattr(
154; CHECK-NEXT: entry:
155; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
156; CHECK-NEXT: ret i8 %[[B]]
157
158entry:
159 %b = load i8, i8* %a, align 4
160 ret i8 %b
161}
162
163define i8 @test_load_notmyattr(i8* %a) sanitize_address {
164; CHECK-LABEL: @test_load_notmyattr(
165; CHECK-NEXT: entry:
166; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8* %a
167; CHECK-NEXT: ret i8 %[[B]]
168
169entry:
170 %b = load i8, i8* %a, align 4
171 ret i8 %b
172}
173
174define i8 @test_load_addrspace(i8 addrspace(256)* %a) sanitize_hwaddress {
175; CHECK-LABEL: @test_load_addrspace(
176; CHECK-NEXT: entry:
177; CHECK-NEXT: %[[B:[^ ]*]] = load i8, i8 addrspace(256)* %a
178; CHECK-NEXT: ret i8 %[[B]]
179
180entry:
181 %b = load i8, i8 addrspace(256)* %a, align 4
182 ret i8 %b
183}
184
185; CHECK: declare void @__hwasan_init()
186
187; CHECK: define internal void @hwasan.module_ctor() {
188; CHECK-NEXT: call void @__hwasan_init()
189; CHECK-NEXT: ret void
190; CHECK-NEXT: }