diff options
Diffstat (limited to 'test/Instrumentation/ThreadSanitizer')
4 files changed, 154 insertions, 1 deletions
diff --git a/test/Instrumentation/ThreadSanitizer/atomic.ll b/test/Instrumentation/ThreadSanitizer/atomic.ll index a10ca6c91a89..30c58fea4cb7 100644 --- a/test/Instrumentation/ThreadSanitizer/atomic.ll +++ b/test/Instrumentation/ThreadSanitizer/atomic.ll @@ -1186,6 +1186,16 @@ entry: ; CHECK-LABEL: atomic64_load_seq_cst ; CHECK: call i64 @__tsan_atomic64_load(i64* %a, i32 5), !dbg +define i8* @atomic64_load_seq_cst_ptr_ty(i8** %a) nounwind uwtable { +entry: + %0 = load atomic i8*, i8** %a seq_cst, align 8, !dbg !7 + ret i8* %0, !dbg !7 +} +; CHECK-LABEL: atomic64_load_seq_cst +; CHECK: bitcast i8** %{{.+}} to i64* +; CHECK-NEXT: call i64 @__tsan_atomic64_load(i64* %{{.+}}, i32 5), !dbg +; CHECK-NEXT: inttoptr i64 %{{.+}} to i8* + define void @atomic64_store_unordered(i64* %a) nounwind uwtable { entry: store atomic i64 0, i64* %a unordered, align 8, !dbg !7 @@ -1218,6 +1228,16 @@ entry: ; CHECK-LABEL: atomic64_store_seq_cst ; CHECK: call void @__tsan_atomic64_store(i64* %a, i64 0, i32 5), !dbg +define void @atomic64_store_seq_cst_ptr_ty(i8** %a, i8* %v) nounwind uwtable { +entry: + store atomic i8* %v, i8** %a seq_cst, align 8, !dbg !7 + ret void, !dbg !7 +} +; CHECK-LABEL: atomic64_store_seq_cst +; CHECK: %{{.*}} = bitcast i8** %{{.*}} to i64* +; CHECK-NEXT: %{{.*}} = ptrtoint i8* %{{.*}} to i64 +; CHECK-NEXT: call void @__tsan_atomic64_store(i64* %{{.*}}, i64 %{{.*}}, i32 5), !dbg + define void @atomic64_xchg_monotonic(i64* %a) nounwind uwtable { entry: atomicrmw xchg i64* %a, i64 0 monotonic, !dbg !7 @@ -1538,6 +1558,21 @@ entry: ; CHECK-LABEL: atomic64_cas_seq_cst ; CHECK: call i64 @__tsan_atomic64_compare_exchange_val(i64* %a, i64 0, i64 1, i32 5, i32 5), !dbg +define void @atomic64_cas_seq_cst_ptr_ty(i8** %a, i8* %v1, i8* %v2) nounwind uwtable { +entry: + cmpxchg i8** %a, i8* %v1, i8* %v2 seq_cst seq_cst, !dbg !7 + ret void +} +; CHECK-LABEL: atomic64_cas_seq_cst +; CHECK: {{.*}} = ptrtoint i8* %v1 to i64 +; CHECK-NEXT: {{.*}} = ptrtoint i8* %v2 to i64 +; CHECK-NEXT: {{.*}} = bitcast i8** %a to i64* +; CHECK-NEXT: {{.*}} = call i64 @__tsan_atomic64_compare_exchange_val(i64* {{.*}}, i64 {{.*}}, i64 {{.*}}, i32 5, i32 5), !dbg +; CHECK-NEXT: {{.*}} = icmp eq i64 +; CHECK-NEXT: {{.*}} = inttoptr i64 {{.*}} to i8* +; CHECK-NEXT: {{.*}} = insertvalue { i8*, i1 } undef, i8* {{.*}}, 0 +; CHECK-NEXT: {{.*}} = insertvalue { i8*, i1 } {{.*}}, i1 {{.*}}, 1 + define i128 @atomic128_load_unordered(i128* %a) nounwind uwtable { entry: %0 = load atomic i128, i128* %a unordered, align 16, !dbg !7 @@ -1987,6 +2022,7 @@ entry: ; CHECK: call void @__tsan_atomic_thread_fence(i32 5), !dbg !llvm.module.flags = !{!0, !1, !2} +!llvm.dbg.cu = !{!8} !0 = !{i32 2, !"Dwarf Version", i32 4} !1 = !{i32 2, !"Debug Info Version", i32 3} !2 = !{i32 1, !"PIC Level", i32 2} @@ -1994,5 +2030,10 @@ entry: !3 = !{} !4 = !DISubroutineType(types: !3) !5 = !DIFile(filename: "atomic.cpp", directory: "/tmp") -!6 = distinct !DISubprogram(name: "test", scope: !5, file: !5, line: 99, type: !4, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, variables: !3) +!6 = distinct !DISubprogram(name: "test", scope: !5, file: !5, line: 99, type: !4, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, unit: !8, variables: !3) !7 = !DILocation(line: 100, column: 1, scope: !6) + +!8 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", + file: !5, + isOptimized: true, flags: "-O2", + splitDebugFilename: "abc.debug", emissionKind: 2) diff --git a/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll b/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll new file mode 100644 index 000000000000..db12ec7daec3 --- /dev/null +++ b/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll @@ -0,0 +1,46 @@ +; This test checks that we are not instrumenting unwanted acesses to globals: +; - Instruction profiler counter instrumentation has known intended races. +; - The gcov counters array has a known intended race. +; +; RUN: opt < %s -tsan -S | FileCheck %s + +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.9" + +@__profc_test_gep = private global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +@__profc_test_bitcast = private global [2 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 +@__profc_test_bitcast_foo = private global [1 x i64] zeroinitializer, section "__DATA,__llvm_prf_cnts", align 8 + +@__llvm_gcov_ctr = internal global [1 x i64] zeroinitializer +@__llvm_gcov_ctr.1 = internal global [1 x i64] zeroinitializer + +define i32 @test_gep() sanitize_thread { +entry: + %pgocount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test_gep, i64 0, i64 0) + %0 = add i64 %pgocount, 1 + store i64 %0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test_gep, i64 0, i64 0) + + %gcovcount = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0) + %1 = add i64 %gcovcount, 1 + store i64 %1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr, i64 0, i64 0) + + %gcovcount.1 = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr.1, i64 0, i64 0) + %2 = add i64 %gcovcount.1, 1 + store i64 %2, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__llvm_gcov_ctr.1, i64 0, i64 0) + + ret i32 1 +} + +define i32 @test_bitcast() sanitize_thread { +entry: + %0 = load <2 x i64>, <2 x i64>* bitcast ([2 x i64]* @__profc_test_bitcast to <2 x i64>*), align 8 + %.promoted5 = load i64, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test_bitcast_foo, i64 0, i64 0), align 8 + %1 = add i64 %.promoted5, 10 + %2 = add <2 x i64> %0, <i64 1, i64 10> + store <2 x i64> %2, <2 x i64>* bitcast ([2 x i64]* @__profc_test_bitcast to <2 x i64>*), align 8 + store i64 %1, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_test_bitcast_foo, i64 0, i64 0), align 8 + ret i32 undef +} + +; CHECK-NOT: {{call void @__tsan_write}} +; CHECK: __tsan_init diff --git a/test/Instrumentation/ThreadSanitizer/str-nobuiltin.ll b/test/Instrumentation/ThreadSanitizer/str-nobuiltin.ll new file mode 100644 index 000000000000..452d7becaaab --- /dev/null +++ b/test/Instrumentation/ThreadSanitizer/str-nobuiltin.ll @@ -0,0 +1,33 @@ +; Test marking string functions as nobuiltin in thread sanitizer. +; +; 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" + +declare i8* @memchr(i8* %a, i32 %b, i64 %c) +declare i32 @memcmp(i8* %a, i8* %b, i64 %c) +declare i32 @strcmp(i8* %a, i8* %b) +declare i8* @strcpy(i8* %a, i8* %b) +declare i8* @stpcpy(i8* %a, i8* %b) +declare i64 @strlen(i8* %a) +declare i64 @strnlen(i8* %a, i64 %b) + +; CHECK: call{{.*}}@memchr{{.*}} #[[ATTR:[0-9]+]] +; CHECK: call{{.*}}@memcmp{{.*}} #[[ATTR]] +; CHECK: call{{.*}}@strcmp{{.*}} #[[ATTR]] +; CHECK: call{{.*}}@strcpy{{.*}} #[[ATTR]] +; CHECK: call{{.*}}@stpcpy{{.*}} #[[ATTR]] +; CHECK: call{{.*}}@strlen{{.*}} #[[ATTR]] +; CHECK: call{{.*}}@strnlen{{.*}} #[[ATTR]] +; attributes #[[ATTR]] = { nobuiltin } + +define void @f1(i8* %a, i8* %b) nounwind uwtable sanitize_thread { + tail call i8* @memchr(i8* %a, i32 1, i64 12) + tail call i32 @memcmp(i8* %a, i8* %b, i64 12) + tail call i32 @strcmp(i8* %a, i8* %b) + tail call i8* @strcpy(i8* %a, i8* %b) + tail call i8* @stpcpy(i8* %a, i8* %b) + tail call i64 @strlen(i8* %a) + tail call i64 @strnlen(i8* %a, i64 12) + ret void +} diff --git a/test/Instrumentation/ThreadSanitizer/tsan_address_space_attr.ll b/test/Instrumentation/ThreadSanitizer/tsan_address_space_attr.ll new file mode 100644 index 000000000000..1495a989bc56 --- /dev/null +++ b/test/Instrumentation/ThreadSanitizer/tsan_address_space_attr.ll @@ -0,0 +1,33 @@ +; RUN: opt < %s -tsan -S | FileCheck %s +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +; Checks that we do not instrument loads and stores comming from custom address space. +; These result in crashing the compiler. +; int foo(int argc, const char * argv[]) { +; void *__attribute__((address_space(256))) *gs_base = (((void * __attribute__((address_space(256))) *)0)); +; void *somevalue = gs_base[-1]; +; return somevalue; +; } + +define i32 @foo(i32 %argc, i8** %argv) sanitize_thread { +entry: + %retval = alloca i32, align 4 + %argc.addr = alloca i32, align 4 + %argv.addr = alloca i8**, align 8 + %gs_base = alloca i8* addrspace(256)*, align 8 + %somevalue = alloca i8*, align 8 + store i32 0, i32* %retval, align 4 + store i32 %argc, i32* %argc.addr, align 4 + store i8** %argv, i8*** %argv.addr, align 8 + store i8* addrspace(256)* null, i8* addrspace(256)** %gs_base, align 8 + %0 = load i8* addrspace(256)*, i8* addrspace(256)** %gs_base, align 8 + %arrayidx = getelementptr inbounds i8*, i8* addrspace(256)* %0, i64 -1 + %1 = load i8*, i8* addrspace(256)* %arrayidx, align 8 + store i8* %1, i8** %somevalue, align 8 + %2 = load i8*, i8** %somevalue, align 8 + %3 = ptrtoint i8* %2 to i32 + ret i32 %3 +} +; CHECK-NOT: call void @__tsan_read +; CHECK-NOT: addrspacecast |