diff options
Diffstat (limited to 'test/Instrumentation')
9 files changed, 144 insertions, 6 deletions
diff --git a/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll b/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll new file mode 100644 index 0000000..c0fe15e --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/asan-vs-gvn.ll @@ -0,0 +1,56 @@ +; RUN: opt < %s -basicaa -gvn -asan -S | FileCheck %s +; ASAN conflicts with load widening iff the widened load accesses data out of bounds +; (while the original unwidened loads do not). +; http://code.google.com/p/address-sanitizer/issues/detail?id=20#c1 + + +; 32-bit little endian target. +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" + +%struct_of_7_bytes_4_aligned = type { i32, i8, i8, i8} + +@f = global %struct_of_7_bytes_4_aligned zeroinitializer, align 4 + +; Accessing bytes 4 and 6, not ok to widen to i32 if address_safety is set. + +define i32 @test_widening_bad(i8* %P) nounwind ssp noredzone address_safety { +entry: + %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4 + %conv = zext i8 %tmp to i32 + %tmp1 = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 3), align 1 + %conv2 = zext i8 %tmp1 to i32 + %add = add nsw i32 %conv, %conv2 + ret i32 %add +; CHECK: @test_widening_bad +; CHECK: __asan_report_load1 +; CHECK: __asan_report_load1 +; CHECK-NOT: __asan_report +; We can not use check for "ret" here because __asan_report_load1 calls live after ret. +; CHECK: end_test_widening_bad +} + +define void @end_test_widening_bad() { + entry: + ret void +} + +;; Accessing bytes 4 and 5. Ok to widen to i16. + +define i32 @test_widening_ok(i8* %P) nounwind ssp noredzone address_safety { +entry: + %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4 + %conv = zext i8 %tmp to i32 + %tmp1 = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 2), align 1 + %conv2 = zext i8 %tmp1 to i32 + %add = add nsw i32 %conv, %conv2 + ret i32 %add +; CHECK: @test_widening_ok +; CHECK: __asan_report_load2 +; CHECK-NOT: __asan_report +; CHECK: end_test_widening_ok +} + +define void @end_test_widening_ok() { + entry: + ret void +} diff --git a/test/Instrumentation/AddressSanitizer/bug_11395.ll b/test/Instrumentation/AddressSanitizer/bug_11395.ll index c53c385..35c5c4a 100644 --- a/test/Instrumentation/AddressSanitizer/bug_11395.ll +++ b/test/Instrumentation/AddressSanitizer/bug_11395.ll @@ -36,14 +36,14 @@ target triple = "i386-unknown-linux-gnu" @ff_mlp_firorder_7 = external global i8 @ff_mlp_firorder_8 = external global i8 -define void @ff_mlp_init_x86(%struct.DSPContext* nocapture %c, %struct.AVCodecContext* nocapture %avctx) nounwind { +define void @ff_mlp_init_x86(%struct.DSPContext* nocapture %c, %struct.AVCodecContext* nocapture %avctx) nounwind address_safety { entry: %mlp_filter_channel = getelementptr inbounds %struct.DSPContext* %c, i32 0, i32 131 store void (i32*, i32*, i32, i32, i32, i32, i32, i32*)* @mlp_filter_channel_x86, void (i32*, i32*, i32, i32, i32, i32, i32, i32*)** %mlp_filter_channel, align 4, !tbaa !0 ret void } -define internal void @mlp_filter_channel_x86(i32* %state, i32* %coeff, i32 %firorder, i32 %iirorder, i32 %filter_shift, i32 %mask, i32 %blocksize, i32* %sample_buffer) nounwind { +define internal void @mlp_filter_channel_x86(i32* %state, i32* %coeff, i32 %firorder, i32 %iirorder, i32 %filter_shift, i32 %mask, i32 %blocksize, i32* %sample_buffer) nounwind address_safety { entry: %filter_shift.addr = alloca i32, align 4 %mask.addr = alloca i32, align 4 diff --git a/test/Instrumentation/AddressSanitizer/dg.exp b/test/Instrumentation/AddressSanitizer/dg.exp deleted file mode 100644 index f200589..0000000 --- a/test/Instrumentation/AddressSanitizer/dg.exp +++ /dev/null @@ -1,3 +0,0 @@ -load_lib llvm.exp - -RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] diff --git a/test/Instrumentation/AddressSanitizer/instrument-no-return.ll b/test/Instrumentation/AddressSanitizer/instrument-no-return.ll new file mode 100644 index 0000000..80f1b1c --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/instrument-no-return.ll @@ -0,0 +1,17 @@ +; RUN: opt < %s -asan -S | FileCheck %s +; AddressSanitizer must insert __asan_handle_no_return +; before every noreturn call. + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" + +declare void @MyNoReturnFunc(i32) noreturn + +define i32 @_Z5ChildPv(i8* nocapture %arg) uwtable address_safety { +entry: + call void @MyNoReturnFunc(i32 1) noreturn + unreachable +} + +; CHECK: call void @__asan_handle_no_return +; CHECK-NEXT: call void @MyNoReturnFunc diff --git a/test/Instrumentation/AddressSanitizer/instrument_global.ll b/test/Instrumentation/AddressSanitizer/instrument_global.ll new file mode 100644 index 0000000..ba8d65a --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/instrument_global.ll @@ -0,0 +1,20 @@ +; RUN: opt < %s -asan -S | FileCheck %s +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" +@xxx = global i32 0, align 4 + +; If a global is present, __asan_[un]register_globals should be called from +; module ctor/dtor + +; CHECK: llvm.global_dtors +; CHECK: llvm.global_ctors + +; CHECK: define internal void @asan.module_ctor +; CHECK-NOT: ret +; CHECK: call void @__asan_register_globals +; CHECK: ret + +; CHECK: define internal void @asan.module_dtor +; CHECK-NOT: ret +; CHECK: call void @__asan_unregister_globals +; CHECK: ret diff --git a/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll b/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll new file mode 100644 index 0000000..633bf9a --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/instrument_load_then_store.ll @@ -0,0 +1,25 @@ +; Test that AddressSanitizer instruments "(*a)++" only once. +; RUN: opt < %s -asan -S -asan-opt=1 | FileCheck %s -check-prefix=OPT1 +; RUN: opt < %s -asan -S -asan-opt=0 | FileCheck %s -check-prefix=OPT0 + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" +define void @IncrementMe(i32* %a) address_safety { +entry: + %tmp1 = load i32* %a, align 4 + %tmp2 = add i32 %tmp1, 1 + store i32 %tmp2, i32* %a, align 4 + ret void +} + +; With optimizations enabled we should see only one call to __asan_report_* +; OPT1: IncrementMe +; OPT1: __asan_report_ +; OPT1-NOT: __asan_report_ +; OPT1: asan.module_ctor + +; Without optimizations we should see two calls to __asan_report_* +; OPT0: IncrementMe +; OPT0: __asan_report_ +; OPT0: __asan_report_ +; OPT0: asan.module_ctor diff --git a/test/Instrumentation/AddressSanitizer/lit.local.cfg b/test/Instrumentation/AddressSanitizer/lit.local.cfg new file mode 100644 index 0000000..19eebc0 --- /dev/null +++ b/test/Instrumentation/AddressSanitizer/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes = ['.ll', '.c', '.cpp'] diff --git a/test/Instrumentation/AddressSanitizer/test64.ll b/test/Instrumentation/AddressSanitizer/test64.ll index e26fb3d..fc27de9 100644 --- a/test/Instrumentation/AddressSanitizer/test64.ll +++ b/test/Instrumentation/AddressSanitizer/test64.ll @@ -1,7 +1,7 @@ ; RUN: opt < %s -asan -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" -define i32 @read_4_bytes(i32* %a) { +define i32 @read_4_bytes(i32* %a) address_safety { entry: %tmp1 = load i32* %a, align 4 ret i32 %tmp1 diff --git a/test/Instrumentation/ThreadSanitizer/tsan_basic.ll b/test/Instrumentation/ThreadSanitizer/tsan_basic.ll new file mode 100644 index 0000000..33c703b --- /dev/null +++ b/test/Instrumentation/ThreadSanitizer/tsan_basic.ll @@ -0,0 +1,22 @@ +; RUN: opt < %s -tsan -S | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" +target triple = "x86_64-unknown-linux-gnu" + +define i32 @read_4_bytes(i32* %a) { +entry: + %tmp1 = load i32* %a, align 4 + ret i32 %tmp1 +} + +; CHECK: @llvm.global_ctors = {{.*}}@__tsan_init + +; CHECK: define i32 @read_4_bytes(i32* %a) { +; CHECK: call void @__tsan_func_entry(i8* %0) +; CHECK-NEXT: %1 = bitcast i32* %a to i8* +; CHECK-NEXT: call void @__tsan_read4(i8* %1) +; CHECK-NEXT: %tmp1 = load i32* %a, align 4 +; CHECK-NEXT: call void @__tsan_func_exit() +; CHECK: ret i32 + + |