230 lines · plain
1; Test basic address sanitizer instrumentation.2;3; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -S | FileCheck %s --check-prefixes=CHECK,ABORT4; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -hwasan-recover=1 -S | FileCheck %s --check-prefixes=CHECK,RECOVER5; RUN: opt < %s -passes=hwasan -hwasan-instrument-with-calls -hwasan-match-all-tag=0 -S | FileCheck %s --check-prefixes=CHECK,MATCH-ALL-TAG-ABORT6; 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-RECOVER7 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 i6414; 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 %a19; CHECK: ret i8 %[[B]]20 21entry:22 %b = load i8, ptr %a, align 423 ret i8 %b24}25 26define i16 @test_load16(ptr %a) sanitize_hwaddress {27; CHECK-LABEL: @test_load16(28; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i6429; 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 %a34; CHECK: ret i16 %[[B]]35 36entry:37 %b = load i16, ptr %a, align 438 ret i16 %b39}40 41define i32 @test_load32(ptr %a) sanitize_hwaddress {42; CHECK-LABEL: @test_load32(43; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i6444; 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 %a49; CHECK: ret i32 %[[B]]50 51entry:52 %b = load i32, ptr %a, align 453 ret i32 %b54}55 56define i64 @test_load64(ptr %a) sanitize_hwaddress {57; CHECK-LABEL: @test_load64(58; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i6459; 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 %a64; CHECK: ret i64 %[[B]]65 66entry:67 %b = load i64, ptr %a, align 868 ret i64 %b69}70 71define i128 @test_load128(ptr %a) sanitize_hwaddress {72; CHECK-LABEL: @test_load128(73; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i6474; 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 %a79; CHECK: ret i128 %[[B]]80 81entry:82 %b = load i128, ptr %a, align 1683 ret i128 %b84}85 86define i40 @test_load40(ptr %a) sanitize_hwaddress {87; CHECK-LABEL: @test_load40(88; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i6489; 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 %a94; CHECK: ret i40 %[[B]]95 96entry:97 %b = load i40, ptr %a, align 498 ret i40 %b99}100 101define void @test_store8(ptr %a, i8 %b) sanitize_hwaddress {102; CHECK-LABEL: @test_store8(103; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64104; 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 %a109; CHECK: ret void110 111entry:112 store i8 %b, ptr %a, align 4113 ret void114}115 116define void @test_store16(ptr %a, i16 %b) sanitize_hwaddress {117; CHECK-LABEL: @test_store16(118; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64119; 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 %a124; CHECK: ret void125 126entry:127 store i16 %b, ptr %a, align 4128 ret void129}130 131define void @test_store32(ptr %a, i32 %b) sanitize_hwaddress {132; CHECK-LABEL: @test_store32(133; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64134; 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 %a139; CHECK: ret void140 141entry:142 store i32 %b, ptr %a, align 4143 ret void144}145 146define void @test_store64(ptr %a, i64 %b) sanitize_hwaddress {147; CHECK-LABEL: @test_store64(148; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64149; 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 %a154; CHECK: ret void155 156entry:157 store i64 %b, ptr %a, align 8158 ret void159}160 161define void @test_store128(ptr %a, i128 %b) sanitize_hwaddress {162; CHECK-LABEL: @test_store128(163; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64164; 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 %a169; CHECK: ret void170 171entry:172 store i128 %b, ptr %a, align 16173 ret void174}175 176define void @test_store40(ptr %a, i40 %b) sanitize_hwaddress {177; CHECK-LABEL: @test_store40(178; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64179; 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 %a184; CHECK: ret void185 186entry:187 store i40 %b, ptr %a, align 4188 ret void189}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 %a195; CHECK-NEXT: ret i8 %[[B]]196 197entry:198 %b = load i8, ptr %a, align 4199 ret i8 %b200}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 %a206; CHECK-NEXT: ret i8 %[[B]]207 208entry:209 %b = load i8, ptr %a, align 4210 ret i8 %b211}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) %a217; CHECK-NEXT: ret i8 %[[B]]218 219entry:220 %b = load i8, ptr addrspace(256) %a, align 4221 ret i8 %b222}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 void229; CHECK-NEXT: }230