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 = "x86_64-unknown-linux-gnu" 8 9define i8 @test_load8(i8* %a) sanitize_hwaddress { 10; CHECK-LABEL: @test_load8( 11; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 12 13; ABORT: call void @__hwasan_load1(i64 %[[A]]) 14; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]]) 15 16; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 17; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 18; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i8* 19; CHECK: %[[B:[^ ]*]] = load i8, i8* %[[UNTAGGED_PTR]] 20; CHECK: ret i8 %[[B]] 21 22entry: 23 %b = load i8, i8* %a, align 4 24 ret i8 %b 25} 26 27define i40 @test_load40(i40* %a) sanitize_hwaddress { 28; CHECK-LABEL: @test_load40( 29; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 30 31; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5) 32; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5) 33 34; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 35; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 36; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i40* 37; CHECK: %[[B:[^ ]*]] = load i40, i40* %[[UNTAGGED_PTR]] 38; CHECK: ret i40 %[[B]] 39 40entry: 41 %b = load i40, i40* %a, align 4 42 ret i40 %b 43} 44 45define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress { 46; CHECK-LABEL: @test_store8( 47; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 48 49; ABORT: call void @__hwasan_store1(i64 %[[A]]) 50; RECOVER: call void @__hwasan_store1_noabort(i64 %[[A]]) 51 52; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 53; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 54; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i8* 55; CHECK: store i8 %b, i8* %[[UNTAGGED_PTR]] 56; CHECK: ret void 57 58entry: 59 store i8 %b, i8* %a, align 4 60 ret void 61} 62 63define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress { 64; CHECK-LABEL: @test_store40( 65; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 66 67; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5) 68; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5) 69 70; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 71; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 72; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i40* 73; CHECK: store i40 %b, i40* %[[UNTAGGED_PTR]] 74; CHECK: ret void 75 76entry: 77 store i40 %b, i40* %a, align 4 78 ret void 79} 80