[llvm] r192871 - tsan: implement no_sanitize_thread attribute
Dmitry Vyukov
dvyukov at google.com
Thu Oct 17 00:20:06 PDT 2013
Author: dvyukov
Date: Thu Oct 17 02:20:06 2013
New Revision: 192871
URL: http://llvm.org/viewvc/llvm-project?rev=192871&view=rev
Log:
tsan: implement no_sanitize_thread attribute
If a function has no_sanitize_thread attribute,
do not instrument memory accesses in it.
Added:
llvm/trunk/test/Instrumentation/ThreadSanitizer/no_sanitize_thread.ll
Modified:
llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
llvm/trunk/test/Instrumentation/ThreadSanitizer/read_before_write.ll
llvm/trunk/test/Instrumentation/ThreadSanitizer/read_from_global.ll
llvm/trunk/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_read.ll
llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll
Modified: llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/ThreadSanitizer.cpp Thu Oct 17 02:20:06 2013
@@ -358,7 +358,7 @@ bool ThreadSanitizer::runOnFunction(Func
// (e.g. variables that do not escape, etc).
// Instrument memory accesses.
- if (ClInstrumentMemoryAccesses)
+ if (ClInstrumentMemoryAccesses && F.hasFnAttribute(Attribute::SanitizeThread))
for (size_t i = 0, n = AllLoadsAndStores.size(); i < n; ++i) {
Res |= instrumentLoadOrStore(AllLoadsAndStores[i]);
}
Added: llvm/trunk/test/Instrumentation/ThreadSanitizer/no_sanitize_thread.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/no_sanitize_thread.ll?rev=192871&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/no_sanitize_thread.ll (added)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/no_sanitize_thread.ll Thu Oct 17 02:20:06 2013
@@ -0,0 +1,36 @@
+; 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"
+
+; no sanitize_thread attribute here
+define i32 @read_4_bytes(i32* %a) {
+entry:
+ %tmp1 = load i32* %a, align 4
+ ret i32 %tmp1
+}
+
+; CHECK: define i32 @read_4_bytes(i32* %a) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %tmp1 = load i32* %a, align 4
+; CHECK: ret i32 %tmp1
+
+; no sanitize_thread attribute here
+define i32 @read_4_bytes_and_call(i32* %a) {
+entry:
+ call void @foo()
+ %tmp1 = load i32* %a, align 4
+ ret i32 %tmp1
+}
+
+; CHECK: define i32 @read_4_bytes_and_call(i32* %a) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %0 = call i8* @llvm.returnaddress(i32 0)
+; CHECK-NEXT: call void @__tsan_func_entry(i8* %0)
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: %tmp1 = load i32* %a, align 4
+; CHECK-NEXT: call void @__tsan_func_exit()
+; CHECK-NEXT: ret i32 %tmp1
+
+declare void @foo()
+
Modified: llvm/trunk/test/Instrumentation/ThreadSanitizer/read_before_write.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/read_before_write.ll?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/read_before_write.ll (original)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/read_before_write.ll Thu Oct 17 02:20:06 2013
@@ -2,7 +2,7 @@
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-S128"
-define void @IncrementMe(i32* nocapture %ptr) nounwind uwtable {
+define void @IncrementMe(i32* nocapture %ptr) nounwind uwtable sanitize_thread {
entry:
%0 = load i32* %ptr, align 4
%inc = add nsw i32 %0, 1
@@ -14,7 +14,7 @@ entry:
; CHECK: __tsan_write
; CHECK: ret void
-define void @IncrementMeWithCallInBetween(i32* nocapture %ptr) nounwind uwtable {
+define void @IncrementMeWithCallInBetween(i32* nocapture %ptr) nounwind uwtable sanitize_thread {
entry:
%0 = load i32* %ptr, align 4
%inc = add nsw i32 %0, 1
Modified: llvm/trunk/test/Instrumentation/ThreadSanitizer/read_from_global.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/read_from_global.ll?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/read_from_global.ll (original)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/read_from_global.ll Thu Oct 17 02:20:06 2013
@@ -4,7 +4,7 @@
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-S128"
@const_global = external constant i32
-define i32 @read_from_const_global() nounwind uwtable readnone {
+define i32 @read_from_const_global() nounwind uwtable sanitize_thread readnone {
entry:
%0 = load i32* @const_global, align 4
ret i32 %0
@@ -14,7 +14,7 @@ entry:
; CHECK: ret i32
@non_const_global = global i32 0, align 4
-define i32 @read_from_non_const_global() nounwind uwtable readonly {
+define i32 @read_from_non_const_global() nounwind uwtable sanitize_thread readonly {
entry:
%0 = load i32* @non_const_global, align 4
ret i32 %0
@@ -25,7 +25,7 @@ entry:
; CHECK: ret i32
@const_global_array = external constant [10 x i32]
-define i32 @read_from_const_global_array(i32 %idx) nounwind uwtable readnone {
+define i32 @read_from_const_global_array(i32 %idx) nounwind uwtable sanitize_thread readnone {
entry:
%idxprom = sext i32 %idx to i64
%arrayidx = getelementptr inbounds [10 x i32]* @const_global_array, i64 0, i64 %idxprom
@@ -38,7 +38,7 @@ entry:
; CHECK: ret i32
%struct.Foo = type { i32 (...)** }
-define void @call_virtual_func(%struct.Foo* %f) uwtable {
+define void @call_virtual_func(%struct.Foo* %f) uwtable sanitize_thread {
entry:
%0 = bitcast %struct.Foo* %f to void (%struct.Foo*)***
%vtable = load void (%struct.Foo*)*** %0, align 8, !tbaa !2
Modified: llvm/trunk/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/tsan_basic.ll?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/tsan_basic.ll (original)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/tsan_basic.ll Thu Oct 17 02:20:06 2013
@@ -3,7 +3,7 @@
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) sanitize_thread {
entry:
%tmp1 = load i32* %a, align 4
ret i32 %tmp1
@@ -11,7 +11,7 @@ entry:
; CHECK: @llvm.global_ctors = {{.*}}@__tsan_init
-; CHECK: define i32 @read_4_bytes(i32* %a) {
+; 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)
Modified: llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_read.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_read.ll?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_read.ll (original)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_read.ll Thu Oct 17 02:20:06 2013
@@ -2,7 +2,7 @@
; Check that vptr reads are treated in a special way.
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-S128"
-define i8 @Foo(i8* %a) nounwind uwtable {
+define i8 @Foo(i8* %a) nounwind uwtable sanitize_thread {
entry:
; CHECK: call void @__tsan_vptr_read
%0 = load i8* %a, align 8, !tbaa !0
Modified: llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll?rev=192871&r1=192870&r2=192871&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll (original)
+++ llvm/trunk/test/Instrumentation/ThreadSanitizer/vptr_update.ll Thu Oct 17 02:20:06 2013
@@ -2,7 +2,7 @@
; Check that vtable pointer updates are treated in a special way.
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-S128"
-define void @Foo(i8** nocapture %a, i8* %b) nounwind uwtable {
+define void @Foo(i8** nocapture %a, i8* %b) nounwind uwtable sanitize_thread {
entry:
; CHECK: call void @__tsan_vptr_update
store i8* %b, i8** %a, align 8, !tbaa !0
More information about the llvm-commits
mailing list