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; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -hwasan-match-all-tag=0 -S | FileCheck %s --check-prefixes=CHECK,MATCH-ALL-TAG-ABORT 6; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -hwasan-recover=1 -hwasan-match-all-tag=0 -S | FileCheck %s --check-prefixes=CHECK,MATCH-ALL-TAG-RECOVER 7 8target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" 9target triple = "aarch64--linux-android" 10 11define i8 @test_load8(ptr %a) sanitize_hwaddress { 12; CHECK-LABEL: @test_load8( 13; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 14; ABORT: call void @__hwasan_load1(i64 %[[A]]) 15; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]]) 16; MATCH-ALL-TAG-ABORT: call void @__hwasan_load1_match_all(i64 %[[A]], i8 0) 17; MATCH-ALL-TAG-RECOVER: call void @__hwasan_load1_match_all_noabort(i64 %[[A]], i8 0) 18; CHECK: %[[B:[^ ]*]] = load i8, ptr %a 19; CHECK: ret i8 %[[B]] 20 21entry: 22 %b = load i8, ptr %a, align 4 23 ret i8 %b 24} 25 26define i16 @test_load16(ptr %a) sanitize_hwaddress { 27; CHECK-LABEL: @test_load16( 28; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 29; ABORT: call void @__hwasan_load2(i64 %[[A]]) 30; RECOVER: call void @__hwasan_load2_noabort(i64 %[[A]]) 31; MATCH-ALL-TAG-ABORT: call void @__hwasan_load2_match_all(i64 %[[A]], i8 0) 32; MATCH-ALL-TAG-RECOVER: call void @__hwasan_load2_match_all_noabort(i64 %[[A]], i8 0) 33; CHECK: %[[B:[^ ]*]] = load i16, ptr %a 34; CHECK: ret i16 %[[B]] 35 36entry: 37 %b = load i16, ptr %a, align 4 38 ret i16 %b 39} 40 41define i32 @test_load32(ptr %a) sanitize_hwaddress { 42; CHECK-LABEL: @test_load32( 43; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 44; ABORT: call void @__hwasan_load4(i64 %[[A]]) 45; RECOVER: call void @__hwasan_load4_noabort(i64 %[[A]]) 46; MATCH-ALL-TAG-ABORT: call void @__hwasan_load4_match_all(i64 %[[A]], i8 0) 47; MATCH-ALL-TAG-RECOVER: call void @__hwasan_load4_match_all_noabort(i64 %[[A]], i8 0) 48; CHECK: %[[B:[^ ]*]] = load i32, ptr %a 49; CHECK: ret i32 %[[B]] 50 51entry: 52 %b = load i32, ptr %a, align 4 53 ret i32 %b 54} 55 56define i64 @test_load64(ptr %a) sanitize_hwaddress { 57; CHECK-LABEL: @test_load64( 58; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 59; ABORT: call void @__hwasan_load8(i64 %[[A]]) 60; RECOVER: call void @__hwasan_load8_noabort(i64 %[[A]]) 61; MATCH-ALL-TAG-ABORT: call void @__hwasan_load8_match_all(i64 %[[A]], i8 0) 62; MATCH-ALL-TAG-RECOVER: call void @__hwasan_load8_match_all_noabort(i64 %[[A]], i8 0) 63; CHECK: %[[B:[^ ]*]] = load i64, ptr %a 64; CHECK: ret i64 %[[B]] 65 66entry: 67 %b = load i64, ptr %a, align 8 68 ret i64 %b 69} 70 71define i128 @test_load128(ptr %a) sanitize_hwaddress { 72; CHECK-LABEL: @test_load128( 73; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 74; ABORT: call void @__hwasan_load16(i64 %[[A]]) 75; RECOVER: call void @__hwasan_load16_noabort(i64 %[[A]]) 76; MATCH-ALL-TAG-ABORT: call void @__hwasan_load16_match_all(i64 %[[A]], i8 0) 77; MATCH-ALL-TAG-RECOVER: call void @__hwasan_load16_match_all_noabort(i64 %[[A]], i8 0) 78; CHECK: %[[B:[^ ]*]] = load i128, ptr %a 79; CHECK: ret i128 %[[B]] 80 81entry: 82 %b = load i128, ptr %a, align 16 83 ret i128 %b 84} 85 86define i40 @test_load40(ptr %a) sanitize_hwaddress { 87; CHECK-LABEL: @test_load40( 88; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 89; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5) 90; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5) 91; MATCH-ALL-TAG-ABORT: call void @__hwasan_loadN_match_all(i64 %[[A]], i64 5, i8 0) 92; MATCH-ALL-TAG-RECOVER: call void @__hwasan_loadN_match_all_noabort(i64 %[[A]], i64 5, i8 0) 93; CHECK: %[[B:[^ ]*]] = load i40, ptr %a 94; CHECK: ret i40 %[[B]] 95 96entry: 97 %b = load i40, ptr %a, align 4 98 ret i40 %b 99} 100 101define void @test_store8(ptr %a, i8 %b) sanitize_hwaddress { 102; CHECK-LABEL: @test_store8( 103; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 104; ABORT: call void @__hwasan_store1(i64 %[[A]]) 105; RECOVER: call void @__hwasan_store1_noabort(i64 %[[A]]) 106; MATCH-ALL-TAG-ABORT: call void @__hwasan_store1_match_all(i64 %[[A]], i8 0) 107; MATCH-ALL-TAG-RECOVER: call void @__hwasan_store1_match_all_noabort(i64 %[[A]], i8 0) 108; CHECK: store i8 %b, ptr %a 109; CHECK: ret void 110 111entry: 112 store i8 %b, ptr %a, align 4 113 ret void 114} 115 116define void @test_store16(ptr %a, i16 %b) sanitize_hwaddress { 117; CHECK-LABEL: @test_store16( 118; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 119; ABORT: call void @__hwasan_store2(i64 %[[A]]) 120; RECOVER: call void @__hwasan_store2_noabort(i64 %[[A]]) 121; MATCH-ALL-TAG-ABORT: call void @__hwasan_store2_match_all(i64 %[[A]], i8 0) 122; MATCH-ALL-TAG-RECOVER: call void @__hwasan_store2_match_all_noabort(i64 %[[A]], i8 0) 123; CHECK: store i16 %b, ptr %a 124; CHECK: ret void 125 126entry: 127 store i16 %b, ptr %a, align 4 128 ret void 129} 130 131define void @test_store32(ptr %a, i32 %b) sanitize_hwaddress { 132; CHECK-LABEL: @test_store32( 133; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 134; ABORT: call void @__hwasan_store4(i64 %[[A]]) 135; RECOVER: call void @__hwasan_store4_noabort(i64 %[[A]]) 136; MATCH-ALL-TAG-ABORT: call void @__hwasan_store4_match_all(i64 %[[A]], i8 0) 137; MATCH-ALL-TAG-RECOVER: call void @__hwasan_store4_match_all_noabort(i64 %[[A]], i8 0) 138; CHECK: store i32 %b, ptr %a 139; CHECK: ret void 140 141entry: 142 store i32 %b, ptr %a, align 4 143 ret void 144} 145 146define void @test_store64(ptr %a, i64 %b) sanitize_hwaddress { 147; CHECK-LABEL: @test_store64( 148; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 149; ABORT: call void @__hwasan_store8(i64 %[[A]]) 150; RECOVER: call void @__hwasan_store8_noabort(i64 %[[A]]) 151; MATCH-ALL-TAG-ABORT: call void @__hwasan_store8_match_all(i64 %[[A]], i8 0) 152; MATCH-ALL-TAG-RECOVER: call void @__hwasan_store8_match_all_noabort(i64 %[[A]], i8 0) 153; CHECK: store i64 %b, ptr %a 154; CHECK: ret void 155 156entry: 157 store i64 %b, ptr %a, align 8 158 ret void 159} 160 161define void @test_store128(ptr %a, i128 %b) sanitize_hwaddress { 162; CHECK-LABEL: @test_store128( 163; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 164; ABORT: call void @__hwasan_store16(i64 %[[A]]) 165; RECOVER: call void @__hwasan_store16_noabort(i64 %[[A]]) 166; MATCH-ALL-TAG-ABORT: call void @__hwasan_store16_match_all(i64 %[[A]], i8 0) 167; MATCH-ALL-TAG-RECOVER: call void @__hwasan_store16_match_all_noabort(i64 %[[A]], i8 0) 168; CHECK: store i128 %b, ptr %a 169; CHECK: ret void 170 171entry: 172 store i128 %b, ptr %a, align 16 173 ret void 174} 175 176define void @test_store40(ptr %a, i40 %b) sanitize_hwaddress { 177; CHECK-LABEL: @test_store40( 178; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64 179; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5) 180; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5) 181; MATCH-ALL-TAG-ABORT: call void @__hwasan_storeN_match_all(i64 %[[A]], i64 5, i8 0) 182; MATCH-ALL-TAG-RECOVER: call void @__hwasan_storeN_match_all_noabort(i64 %[[A]], i64 5, i8 0) 183; CHECK: store i40 %b, ptr %a 184; CHECK: ret void 185 186entry: 187 store i40 %b, ptr %a, align 4 188 ret void 189} 190 191define i8 @test_load_noattr(ptr %a) { 192; CHECK-LABEL: @test_load_noattr( 193; CHECK-NEXT: entry: 194; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr %a 195; CHECK-NEXT: ret i8 %[[B]] 196 197entry: 198 %b = load i8, ptr %a, align 4 199 ret i8 %b 200} 201 202define i8 @test_load_notmyattr(ptr %a) sanitize_address { 203; CHECK-LABEL: @test_load_notmyattr( 204; CHECK-NEXT: entry: 205; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr %a 206; CHECK-NEXT: ret i8 %[[B]] 207 208entry: 209 %b = load i8, ptr %a, align 4 210 ret i8 %b 211} 212 213define i8 @test_load_addrspace(ptr addrspace(256) %a) sanitize_hwaddress { 214; CHECK-LABEL: @test_load_addrspace( 215; CHECK-NEXT: entry: 216; CHECK-NEXT: %[[B:[^ ]*]] = load i8, ptr addrspace(256) %a 217; CHECK-NEXT: ret i8 %[[B]] 218 219entry: 220 %b = load i8, ptr addrspace(256) %a, align 4 221 ret i8 %b 222} 223 224; CHECK: declare void @__hwasan_init() 225 226; CHECK: define internal void @hwasan.module_ctor() #[[#]] comdat { 227; CHECK-NEXT: call void @__hwasan_init() 228; CHECK-NEXT: ret void 229; CHECK-NEXT: } 230