1; Test basic address sanitizer instrumentation. 2; Generic code is covered by ../basic.ll, only the x86_64 specific code is 3; tested here. 4; 5; RUN: opt < %s -hwasan -hwasan-recover=0 -S | FileCheck %s --check-prefixes=CHECK,ABORT 6; RUN: opt < %s -hwasan -hwasan-recover=1 -S | FileCheck %s --check-prefixes=CHECK,RECOVER 7 8target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" 9target triple = "x86_64-unknown-linux-gnu" 10 11define i8 @test_load8(i8* %a) sanitize_hwaddress { 12; CHECK-LABEL: @test_load8( 13; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 14 15; ABORT: call void asm sideeffect "int3\0Anopl 64(%rax)", "{rdi}"(i64 %[[A]]) 16; ABORT: unreachable 17; RECOVER: call void asm sideeffect "int3\0Anopl 96(%rax)", "{rdi}"(i64 %[[A]]) 18; RECOVER: br label 19 20; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 21; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 22; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i8* 23; CHECK: %[[G:[^ ]*]] = load i8, i8* %[[UNTAGGED_PTR]], align 4 24; CHECK: ret i8 %[[G]] 25 26entry: 27 %b = load i8, i8* %a, align 4 28 ret i8 %b 29} 30 31define i40 @test_load40(i40* %a) sanitize_hwaddress { 32; CHECK-LABEL: @test_load40( 33; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 34 35; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5) 36; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5) 37 38; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 39; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 40; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i40* 41; CHECK: %[[B:[^ ]*]] = load i40, i40* %[[UNTAGGED_PTR]] 42; CHECK: ret i40 %[[B]] 43 44entry: 45 %b = load i40, i40* %a, align 4 46 ret i40 %b 47} 48 49define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress { 50; CHECK-LABEL: @test_store8( 51; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 52 53; ABORT: call void asm sideeffect "int3\0Anopl 80(%rax)", "{rdi}"(i64 %[[A]]) 54; ABORT: unreachable 55; RECOVER: call void asm sideeffect "int3\0Anopl 112(%rax)", "{rdi}"(i64 %[[A]]) 56; RECOVER: br label 57 58; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64 59; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 60; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i8* 61; CHECK: store i8 %b, i8* %[[UNTAGGED_PTR]], align 4 62; CHECK: ret void 63 64entry: 65 store i8 %b, i8* %a, align 4 66 ret void 67} 68 69define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress { 70; CHECK-LABEL: @test_store40( 71; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 72 73; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5) 74; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5) 75 76; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64 77; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 78; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i40* 79; CHECK: store i40 %b, i40* %[[UNTAGGED_PTR]] 80; CHECK: ret void 81 82entry: 83 store i40 %b, i40* %a, align 4 84 ret void 85} 86 87define void @test_store_unaligned(i64* %a, i64 %b) sanitize_hwaddress { 88; CHECK-LABEL: @test_store_unaligned( 89; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64 90 91; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 8) 92; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 8) 93 94; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64 95; CHECK: %[[UNTAGGED:[^ ]*]] = and i64 %[[A]], 72057594037927935 96; CHECK: %[[UNTAGGED_PTR:[^ ]*]] = inttoptr i64 %[[UNTAGGED]] to i64* 97; CHECK: store i64 %b, i64* %[[UNTAGGED_PTR]], align 4 98; CHECK: ret void 99 100entry: 101 store i64 %b, i64* %a, align 4 102 ret void 103} 104