Skip to content

Commit

Permalink
[TSan] Behave the same for functions w/o sanitize_thread attribute an…
Browse files Browse the repository at this point in the history
…d blacklisted functions

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209939 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vonosmas committed May 31, 2014
1 parent c2fe96c commit 269a999
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/Transforms/Instrumentation/ThreadSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ static bool isAtomic(Instruction *I) {

bool ThreadSanitizer::runOnFunction(Function &F) {
if (!DL) return false;
if (BL->isIn(F)) return false;
initializeCallbacks(*F.getParent());
SmallVector<Instruction*, 8> RetVec;
SmallVector<Instruction*, 8> AllLoadsAndStores;
Expand All @@ -331,6 +330,8 @@ bool ThreadSanitizer::runOnFunction(Function &F) {
SmallVector<Instruction*, 8> MemIntrinCalls;
bool Res = false;
bool HasCalls = false;
bool SanitizeFunction =
F.hasFnAttribute(Attribute::SanitizeThread) && !BL->isIn(F);

// Traverse all instructions, collect loads/stores/returns, check for calls.
for (auto &BB : F) {
Expand All @@ -355,19 +356,20 @@ bool ThreadSanitizer::runOnFunction(Function &F) {
// FIXME: many of these accesses do not need to be checked for races
// (e.g. variables that do not escape, etc).

// Instrument memory accesses.
if (ClInstrumentMemoryAccesses && F.hasFnAttribute(Attribute::SanitizeThread))
// Instrument memory accesses only if we want to report bugs in the function.
if (ClInstrumentMemoryAccesses && SanitizeFunction)
for (auto Inst : AllLoadsAndStores) {
Res |= instrumentLoadOrStore(Inst);
}

// Instrument atomic memory accesses.
// Instrument atomic memory accesses in any case (they can be used to
// implement synchronization).
if (ClInstrumentAtomics)
for (auto Inst : AtomicAccesses) {
Res |= instrumentAtomic(Inst);
}

if (ClInstrumentMemIntrinsics)
if (ClInstrumentMemIntrinsics && SanitizeFunction)
for (auto Inst : MemIntrinCalls) {
Res |= instrumentMemIntrinsic(Inst);
}
Expand Down

0 comments on commit 269a999

Please sign in to comment.