| 1 |
; Test basic address sanitizer instrumentation. |
| 2 |
; |
| 3 |
; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -S | FileCheck %s --check-prefixes=CHECK,ABORT |
| 4 |
; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -hwasan-recover=1 -S | FileCheck %s --check-prefixes=CHECK,RECOVER |
| 5 |
|
| 6 |
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" |
| 7 |
target triple = "riscv64-unknown-linux" |
| 8 |
|
| 9 |
define i8 @test_load8(ptr %a) sanitize_hwaddress { |
| 10 |
; CHECK-LABEL: @test_load8( |
| 11 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 15 |
; CHECK: ret i8 %[[B]] |
| 16 |
|
| 17 |
entry: |
| 18 |
%b = load i8, ptr %a, align 4 |
| 19 |
ret i8 %b |
| 20 |
} |
| 21 |
|
| 22 |
define i16 @test_load16(ptr %a) sanitize_hwaddress { |
| 23 |
; CHECK-LABEL: @test_load16( |
| 24 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 28 |
; CHECK: ret i16 %[[B]] |
| 29 |
|
| 30 |
entry: |
| 31 |
%b = load i16, ptr %a, align 4 |
| 32 |
ret i16 %b |
| 33 |
} |
| 34 |
|
| 35 |
define i32 @test_load32(ptr %a) sanitize_hwaddress { |
| 36 |
; CHECK-LABEL: @test_load32( |
| 37 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 41 |
; CHECK: ret i32 %[[B]] |
| 42 |
|
| 43 |
entry: |
| 44 |
%b = load i32, ptr %a, align 4 |
| 45 |
ret i32 %b |
| 46 |
} |
| 47 |
|
| 48 |
define i64 @test_load64(ptr %a) sanitize_hwaddress { |
| 49 |
; CHECK-LABEL: @test_load64( |
| 50 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 54 |
; CHECK: ret i64 %[[B]] |
| 55 |
|
| 56 |
entry: |
| 57 |
%b = load i64, ptr %a, align 8 |
| 58 |
ret i64 %b |
| 59 |
} |
| 60 |
|
| 61 |
define i128 @test_load128(ptr %a) sanitize_hwaddress { |
| 62 |
; CHECK-LABEL: @test_load128( |
| 63 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 67 |
; CHECK: ret i128 %[[B]] |
| 68 |
|
| 69 |
entry: |
| 70 |
%b = load i128, ptr %a, align 16 |
| 71 |
ret i128 %b |
| 72 |
} |
| 73 |
|
| 74 |
define i40 @test_load40(ptr %a) sanitize_hwaddress { |
| 75 |
; CHECK-LABEL: @test_load40( |
| 76 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 80 |
; CHECK: ret i40 %[[B]] |
| 81 |
|
| 82 |
entry: |
| 83 |
%b = load i40, ptr %a, align 4 |
| 84 |
ret i40 %b |
| 85 |
} |
| 86 |
|
| 87 |
define void @test_store8(ptr %a, i8 %b) sanitize_hwaddress { |
| 88 |
; CHECK-LABEL: @test_store8( |
| 89 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 93 |
; CHECK: ret void |
| 94 |
|
| 95 |
entry: |
| 96 |
store i8 %b, ptr %a, align 4 |
| 97 |
ret void |
| 98 |
} |
| 99 |
|
| 100 |
define void @test_store16(ptr %a, i16 %b) sanitize_hwaddress { |
| 101 |
; CHECK-LABEL: @test_store16( |
| 102 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 106 |
; CHECK: ret void |
| 107 |
|
| 108 |
entry: |
| 109 |
store i16 %b, ptr %a, align 4 |
| 110 |
ret void |
| 111 |
} |
| 112 |
|
| 113 |
define void @test_store32(ptr %a, i32 %b) sanitize_hwaddress { |
| 114 |
; CHECK-LABEL: @test_store32( |
| 115 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 119 |
; CHECK: ret void |
| 120 |
|
| 121 |
entry: |
| 122 |
store i32 %b, ptr %a, align 4 |
| 123 |
ret void |
| 124 |
} |
| 125 |
|
| 126 |
define void @test_store64(ptr %a, i64 %b) sanitize_hwaddress { |
| 127 |
; CHECK-LABEL: @test_store64( |
| 128 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 132 |
; CHECK: ret void |
| 133 |
|
| 134 |
entry: |
| 135 |
store i64 %b, ptr %a, align 8 |
| 136 |
ret void |
| 137 |
} |
| 138 |
|
| 139 |
define void @test_store128(ptr %a, i128 %b) sanitize_hwaddress { |
| 140 |
; CHECK-LABEL: @test_store128( |
| 141 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 145 |
; CHECK: ret void |
| 146 |
|
| 147 |
entry: |
| 148 |
store i128 %b, ptr %a, align 16 |
| 149 |
ret void |
| 150 |
} |
| 151 |
|
| 152 |
define void @test_store40(ptr %a, i40 %b) sanitize_hwaddress { |
| 153 |
; CHECK-LABEL: @test_store40( |
| 154 |
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %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, ptr %a |
| 158 |
; CHECK: ret void |
| 159 |
|
| 160 |
entry: |
| 161 |
store i40 %b, ptr %a, align 4 |
| 162 |
ret void |
| 163 |
} |
| 164 |
|
| 165 |
define i8 @test_load_noattr(ptr %a) { |
| 166 |
; CHECK-LABEL: @test_load_noattr( |
| 167 |
; CHECK-NEXT: entry: |
| 168 |
; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr %a |
| 169 |
; CHECK-NEXT: ret i8 %[[B]] |
| 170 |
|
| 171 |
entry: |
| 172 |
%b = load i8, ptr %a, align 4 |
| 173 |
ret i8 %b |
| 174 |
} |
| 175 |
|
| 176 |
define i8 @test_load_notmyattr(ptr %a) sanitize_address { |
| 177 |
; CHECK-LABEL: @test_load_notmyattr( |
| 178 |
; CHECK-NEXT: entry: |
| 179 |
; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr %a |
| 180 |
; CHECK-NEXT: ret i8 %[[B]] |
| 181 |
|
| 182 |
entry: |
| 183 |
%b = load i8, ptr %a, align 4 |
| 184 |
ret i8 %b |
| 185 |
} |
| 186 |
|
| 187 |
define i8 @test_load_addrspace(ptr addrspace(256) %a) sanitize_hwaddress { |
| 188 |
; CHECK-LABEL: @test_load_addrspace( |
| 189 |
; CHECK-NEXT: entry: |
| 190 |
; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr addrspace(256) %a |
| 191 |
; CHECK-NEXT: ret i8 %[[B]] |
| 192 |
|
| 193 |
entry: |
| 194 |
%b = load i8, ptr 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() #[[#]] comdat { |
| 201 |
; CHECK-NEXT: call void @__hwasan_init() |
| 202 |
; CHECK-NEXT: ret void |
| 203 |
; CHECK-NEXT: } |