Skip to content

Commit

Permalink
HWAsan: Convert tests to opaque pointers
Browse files Browse the repository at this point in the history
Fixups needed in:
  X86/alloca-with-calls.ll
  X86/alloca.ll
  alloca-with-calls.ll
  atomic.ll
  basic.ll
  dbg-value-tag-offset.ll
  kernel-alloca.ll
  prologue.ll
  use-after-scope.ll
  • Loading branch information
arsenm committed Nov 28, 2022
1 parent 1ab6fa5 commit 6f3335f
Show file tree
Hide file tree
Showing 33 changed files with 1,597 additions and 1,695 deletions.
Expand Up @@ -3,13 +3,13 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare void @use(i8*, i8*)
declare void @use(ptr, ptr)

define void @test_alloca() sanitize_hwaddress {
; CHECK: alloca { [4 x i8], [12 x i8] }, align 16
%x = alloca i8, i64 4
; CHECK: alloca i8, i64 16, align 16
%y = alloca i8, i64 16
call void @use(i8* %x, i8* %y)
call void @use(ptr %x, ptr %y)
ret void
}
Expand Up @@ -5,19 +5,18 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare void @use32(i32*)
declare void @use32(ptr)

define void @test_alloca() sanitize_hwaddress {
; CHECK-LABEL: @test_alloca(
; CHECK: %[[BC:[^ ]*]] = bitcast { i32, [12 x i8] }* %x to i32*
; CHECK: %[[T1:[^ ]*]] = call i8 @__hwasan_generate_tag()
; CHECK: %[[A:[^ ]*]] = zext i8 %[[T1]] to i64
; CHECK: %[[B:[^ ]*]] = ptrtoint i32* %[[BC]] to i64
; CHECK: %[[B:[^ ]*]] = ptrtoint ptr %x to i64
; CHECK: %[[C:[^ ]*]] = shl i64 %[[A]], 57
; CHECK: or i64 %[[B]], %[[C]]

entry:
%x = alloca i32, align 4
call void @use32(i32* nonnull %x)
call void @use32(ptr nonnull %x)
ret void
}
23 changes: 10 additions & 13 deletions llvm/test/Instrumentation/HWAddressSanitizer/X86/alloca.ll
Expand Up @@ -6,40 +6,37 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

declare void @use32(i32*)
declare void @use32(ptr)

define void @test_alloca() sanitize_hwaddress {
; CHECK-LABEL: @test_alloca(
; CHECK: %[[FP:[^ ]*]] = call i8* @llvm.frameaddress.p0i8(i32 0)
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %[[FP]] to i64
; CHECK: %[[FP:[^ ]*]] = call ptr @llvm.frameaddress.p0(i32 0)
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %[[FP]] to i64
; CHECK: %[[B:[^ ]*]] = lshr i64 %[[A]], 20
; CHECK: %[[A_XOR_B:[^ ]*]] = xor i64 %[[A]], %[[B]]
; CHECK: %[[BASE_TAG:[^ ]*]] = and i64 %[[A_XOR_B]], 63

; CHECK: %[[X:[^ ]*]] = alloca { i32, [12 x i8] }, align 16
; CHECK: %[[X_BC:[^ ]*]] = bitcast { i32, [12 x i8] }* %[[X]] to i32*
; CHECK: %[[X_TAG:[^ ]*]] = xor i64 %[[BASE_TAG]], 0
; CHECK: %[[X1:[^ ]*]] = ptrtoint i32* %[[X_BC]] to i64
; CHECK: %[[X1:[^ ]*]] = ptrtoint ptr %[[X]] to i64
; CHECK: %[[C:[^ ]*]] = shl i64 %[[X_TAG]], 57
; CHECK: %[[D:[^ ]*]] = or i64 %[[X1]], %[[C]]
; CHECK: %[[X_HWASAN:[^ ]*]] = inttoptr i64 %[[D]] to i32*
; CHECK: %[[X_HWASAN:[^ ]*]] = inttoptr i64 %[[D]] to ptr

; CHECK: %[[X_TAG2:[^ ]*]] = trunc i64 %[[X_TAG]] to i8
; CHECK: %[[X_I8:[^ ]*]] = bitcast i32* %[[X_BC]] to i8*
; CHECK: call void @__hwasan_tag_memory(i8* %[[X_I8]], i8 %[[X_TAG2]], i64 16)
; CHECK: call void @__hwasan_tag_memory(ptr %[[X]], i8 %[[X_TAG2]], i64 16)

; CHECK: call void @use32(i32* nonnull %[[X_HWASAN]])
; CHECK: call void @use32(ptr nonnull %[[X_HWASAN]])

; UAR-TAGS: %[[BASE_TAG_COMPL:[^ ]*]] = xor i64 %[[BASE_TAG]], 63
; UAR-TAGS: %[[X_TAG_UAR:[^ ]*]] = trunc i64 %[[BASE_TAG_COMPL]] to i8
; CHECK: %[[X_I8_2:[^ ]*]] = bitcast i32* %[[X_BC]] to i8*
; NO-UAR-TAGS: call void @__hwasan_tag_memory(i8* %[[X_I8_2]], i8 0, i64 16)
; UAR-TAGS: call void @__hwasan_tag_memory(i8* %[[X_I8_2]], i8 %[[X_TAG_UAR]], i64 16)
; NO-UAR-TAGS: call void @__hwasan_tag_memory(ptr %[[X]], i8 0, i64 16)
; UAR-TAGS: call void @__hwasan_tag_memory(ptr %[[X]], i8 %[[X_TAG_UAR]], i64 16)
; CHECK: ret void


entry:
%x = alloca i32, align 4
call void @use32(i32* nonnull %x)
call void @use32(ptr nonnull %x)
ret void
}
16 changes: 8 additions & 8 deletions llvm/test/Instrumentation/HWAddressSanitizer/X86/atomic.ll
Expand Up @@ -5,30 +5,30 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define void @atomicrmw(i64* %ptr) sanitize_hwaddress {
define void @atomicrmw(ptr %ptr) sanitize_hwaddress {
; CHECK-LABEL: @atomicrmw(
; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %ptr to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %ptr to i64

; CHECK: call void @__hwasan_store8(i64 %[[A]])

; CHECK: atomicrmw add i64* %ptr, i64 1 seq_cst
; CHECK: atomicrmw add ptr %ptr, i64 1 seq_cst
; CHECK: ret void

entry:
%0 = atomicrmw add i64* %ptr, i64 1 seq_cst
%0 = atomicrmw add ptr %ptr, i64 1 seq_cst
ret void
}

define void @cmpxchg(i64* %ptr, i64 %compare_to, i64 %new_value) sanitize_hwaddress {
define void @cmpxchg(ptr %ptr, i64 %compare_to, i64 %new_value) sanitize_hwaddress {
; CHECK-LABEL: @cmpxchg(
; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %ptr to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %ptr to i64

; CHECK: call void @__hwasan_store8(i64 %[[A]])

; CHECK: cmpxchg i64* %ptr, i64 %compare_to, i64 %new_value seq_cst seq_cst
; CHECK: cmpxchg ptr %ptr, i64 %compare_to, i64 %new_value seq_cst seq_cst
; CHECK: ret void

entry:
%0 = cmpxchg i64* %ptr, i64 %compare_to, i64 %new_value seq_cst seq_cst
%0 = cmpxchg ptr %ptr, i64 %compare_to, i64 %new_value seq_cst seq_cst
ret void
}
40 changes: 20 additions & 20 deletions llvm/test/Instrumentation/HWAddressSanitizer/X86/basic.ll
Expand Up @@ -8,77 +8,77 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i8 @test_load8(i8* %a) sanitize_hwaddress {
define i8 @test_load8(ptr %a) sanitize_hwaddress {
; CHECK-LABEL: @test_load8(
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_load1(i64 %[[A]])
; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]])

; CHECK: %[[G:[^ ]*]] = load i8, i8* %a, align 4
; CHECK: %[[G:[^ ]*]] = load i8, ptr %a, align 4
; CHECK: ret i8 %[[G]]

entry:
%b = load i8, i8* %a, align 4
%b = load i8, ptr %a, align 4
ret i8 %b
}

define i40 @test_load40(i40* %a) sanitize_hwaddress {
define i40 @test_load40(ptr %a) sanitize_hwaddress {
; CHECK-LABEL: @test_load40(
; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5)
; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5)

; CHECK: %[[B:[^ ]*]] = load i40, i40* %a
; CHECK: %[[B:[^ ]*]] = load i40, ptr %a
; CHECK: ret i40 %[[B]]

entry:
%b = load i40, i40* %a, align 4
%b = load i40, ptr %a, align 4
ret i40 %b
}

define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress {
define void @test_store8(ptr %a, i8 %b) sanitize_hwaddress {
; CHECK-LABEL: @test_store8(
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_store1(i64 %[[A]])
; RECOVER: call void @__hwasan_store1_noabort(i64 %[[A]])

; CHECK: store i8 %b, i8* %a, align 4
; CHECK: store i8 %b, ptr %a, align 4
; CHECK: ret void

entry:
store i8 %b, i8* %a, align 4
store i8 %b, ptr %a, align 4
ret void
}

define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress {
define void @test_store40(ptr %a, i40 %b) sanitize_hwaddress {
; CHECK-LABEL: @test_store40(
; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5)
; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5)

; CHECK: store i40 %b, i40* %a
; CHECK: store i40 %b, ptr %a
; CHECK: ret void

entry:
store i40 %b, i40* %a, align 4
store i40 %b, ptr %a, align 4
ret void
}

define void @test_store_unaligned(i64* %a, i64 %b) sanitize_hwaddress {
define void @test_store_unaligned(ptr %a, i64 %b) sanitize_hwaddress {
; CHECK-LABEL: @test_store_unaligned(
; CHECK: %[[A:[^ ]*]] = ptrtoint i64* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 8)
; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 8)

; CHECK: store i64 %b, i64* %a, align 4
; CHECK: store i64 %b, ptr %a, align 4
; CHECK: ret void

entry:
store i64 %b, i64* %a, align 4
store i64 %b, ptr %a, align 4
ret void
}
8 changes: 4 additions & 4 deletions llvm/test/Instrumentation/HWAddressSanitizer/X86/kernel.ll
Expand Up @@ -11,18 +11,18 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i8 @test_load(i8* %a) sanitize_hwaddress {
define i8 @test_load(ptr %a) sanitize_hwaddress {
; CHECK-LABEL: @test_load(
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_load1(i64 %[[A]])
; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]])

; CHECK: %[[G:[^ ]*]] = load i8, i8* %a, align 4
; CHECK: %[[G:[^ ]*]] = load i8, ptr %a, align 4
; CHECK: ret i8 %[[G]]

entry:
%b = load i8, i8* %a, align 4
%b = load i8, ptr %a, align 4
ret i8 %b
}

Expand Down
32 changes: 16 additions & 16 deletions llvm/test/Instrumentation/HWAddressSanitizer/X86/with-calls.ll
Expand Up @@ -6,62 +6,62 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i8 @test_load8(i8* %a) sanitize_hwaddress {
define i8 @test_load8(ptr %a) sanitize_hwaddress {
; CHECK-LABEL: @test_load8(
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_load1(i64 %[[A]])
; RECOVER: call void @__hwasan_load1_noabort(i64 %[[A]])

; CHECK: %[[B:[^ ]*]] = load i8, i8* %a
; CHECK: %[[B:[^ ]*]] = load i8, ptr %a
; CHECK: ret i8 %[[B]]

entry:
%b = load i8, i8* %a, align 4
%b = load i8, ptr %a, align 4
ret i8 %b
}

define i40 @test_load40(i40* %a) sanitize_hwaddress {
define i40 @test_load40(ptr %a) sanitize_hwaddress {
; CHECK-LABEL: @test_load40(
; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_loadN(i64 %[[A]], i64 5)
; RECOVER: call void @__hwasan_loadN_noabort(i64 %[[A]], i64 5)

; CHECK: %[[B:[^ ]*]] = load i40, i40* %a
; CHECK: %[[B:[^ ]*]] = load i40, ptr %a
; CHECK: ret i40 %[[B]]

entry:
%b = load i40, i40* %a, align 4
%b = load i40, ptr %a, align 4
ret i40 %b
}

define void @test_store8(i8* %a, i8 %b) sanitize_hwaddress {
define void @test_store8(ptr %a, i8 %b) sanitize_hwaddress {
; CHECK-LABEL: @test_store8(
; CHECK: %[[A:[^ ]*]] = ptrtoint i8* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_store1(i64 %[[A]])
; RECOVER: call void @__hwasan_store1_noabort(i64 %[[A]])

; CHECK: store i8 %b, i8* %a
; CHECK: store i8 %b, ptr %a
; CHECK: ret void

entry:
store i8 %b, i8* %a, align 4
store i8 %b, ptr %a, align 4
ret void
}

define void @test_store40(i40* %a, i40 %b) sanitize_hwaddress {
define void @test_store40(ptr %a, i40 %b) sanitize_hwaddress {
; CHECK-LABEL: @test_store40(
; CHECK: %[[A:[^ ]*]] = ptrtoint i40* %a to i64
; CHECK: %[[A:[^ ]*]] = ptrtoint ptr %a to i64

; ABORT: call void @__hwasan_storeN(i64 %[[A]], i64 5)
; RECOVER: call void @__hwasan_storeN_noabort(i64 %[[A]], i64 5)

; CHECK: store i40 %b, i40* %a
; CHECK: store i40 %b, ptr %a
; CHECK: ret void

entry:
store i40 %b, i40* %a, align 4
store i40 %b, ptr %a, align 4
ret void
}
4 changes: 2 additions & 2 deletions llvm/test/Instrumentation/HWAddressSanitizer/alloca-array.ll
Expand Up @@ -3,13 +3,13 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-android"

declare void @use(i8*, i8*)
declare void @use(ptr, ptr)

define void @test_alloca() sanitize_hwaddress {
; CHECK: alloca { [4 x i8], [12 x i8] }, align 16
%x = alloca i8, i64 4
; CHECK: alloca i8, i64 16, align 16
%y = alloca i8, i64 16
call void @use(i8* %x, i8* %y)
call void @use(ptr %x, ptr %y)
ret void
}
6 changes: 3 additions & 3 deletions llvm/test/Instrumentation/HWAddressSanitizer/alloca-compat.ll
Expand Up @@ -5,13 +5,13 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-android"

declare void @use32(i32*)
declare void @use32(ptr)

define void @test_alloca() sanitize_hwaddress {
; CHECK-LABEL: @test_alloca(
; CHECK: %[[X_TAG:[^ ]*]] = trunc i64 {{.*}} to i8
; CHECK: call void @llvm.memset.p0i8.i64(i8* align 1 {{.*}}, i8 %[[X_TAG]], i64 1, i1 false)
; CHECK: call void @llvm.memset.p0.i64(ptr align 1 {{.*}}, i8 %[[X_TAG]], i64 1, i1 false)
%x = alloca i32, align 4
call void @use32(i32* nonnull %x)
call void @use32(ptr nonnull %x)
ret void
}
Expand Up @@ -7,21 +7,21 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-android10000"

declare void @use32(i32*)
declare void @use32(ptr)

define void @test_dyn_alloca(i32 %n) sanitize_hwaddress !dbg !15 {
; CHECK-LABEL: @test_dyn_alloca(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[X:%.*]] = alloca i32, i32 [[N:%.*]], align 4
; CHECK-NEXT: call void @llvm.dbg.value(metadata !DIArgList(i32* [[X]], i32* [[X]]), metadata [[META10:![0-9]+]], metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)), !dbg [[DBG12:![0-9]+]]
; CHECK-NEXT: call void @use32(i32* nonnull [[X]]), !dbg [[DBG13:![0-9]+]]
; CHECK-NEXT: call void @llvm.dbg.value(metadata !DIArgList(ptr [[X]], ptr [[X]]), metadata [[META10:![0-9]+]], metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)), !dbg [[DBG12:![0-9]+]]
; CHECK-NEXT: call void @use32(ptr nonnull [[X]]), !dbg [[DBG13:![0-9]+]]
; CHECK-NEXT: ret void, !dbg [[DBG14:![0-9]+]]
;

entry:
%x = alloca i32, i32 %n, align 4
call void @llvm.dbg.value(metadata !DIArgList(i32* %x, i32* %x), metadata !22, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)), !dbg !21
call void @use32(i32* nonnull %x), !dbg !23
call void @llvm.dbg.value(metadata !DIArgList(ptr %x, ptr %x), metadata !22, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)), !dbg !21
call void @use32(ptr nonnull %x), !dbg !23
ret void, !dbg !24
}

Expand Down

0 comments on commit 6f3335f

Please sign in to comment.