From ea47fc5fc93b0fe6315745712dd1a9590404f913 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Tue, 19 Jul 2016 20:16:08 +0000 Subject: [PATCH] [tsan] Don't instrument __llvm_gcov_global_state_pred or __llvm_gcda* r274801 did not go far enough to allow gcov+tsan to cooperate. With this commit it's possible to run the following code without false positives: std::thread T1(fib), T2(fib); T1.join(); T2.join(); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276015 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Instrumentation/ThreadSanitizer.cpp | 5 +++-- .../do-not-instrument-memory-access.ll | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index dcb62d3ed1b..41041c78db9 100644 --- a/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -272,8 +272,9 @@ static bool shouldInstrumentReadWriteFromAddress(Value *Addr) { return false; } - // Check if the global is in a GCOV counter array. - if (GV->getName().startswith("__llvm_gcov_ctr")) + // Check if the global is private gcov data. + if (GV->getName().startswith("__llvm_gcov") || + GV->getName().startswith("__llvm_gcda")) return false; } diff --git a/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll b/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll index db12ec7daec..494df83cabb 100644 --- a/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll +++ b/test/Instrumentation/ThreadSanitizer/do-not-instrument-memory-access.ll @@ -13,6 +13,8 @@ target triple = "x86_64-apple-macosx10.9" @__llvm_gcov_ctr = internal global [1 x i64] zeroinitializer @__llvm_gcov_ctr.1 = internal global [1 x i64] zeroinitializer +@__llvm_gcov_global_state_pred = internal global i32 0 +@__llvm_gcda_foo = internal global i32 0 define i32 @test_gep() sanitize_thread { entry: @@ -42,5 +44,16 @@ entry: ret i32 undef } +define void @test_load() sanitize_thread { +entry: + %0 = load i32, i32* @__llvm_gcov_global_state_pred + store i32 1, i32* @__llvm_gcov_global_state_pred + + %1 = load i32, i32* @__llvm_gcda_foo + store i32 1, i32* @__llvm_gcda_foo + + ret void +} + ; CHECK-NOT: {{call void @__tsan_write}} ; CHECK: __tsan_init