Skip to content

Commit

Permalink
Properly add shared locks to the initial list of locks being tracked,…
Browse files Browse the repository at this point in the history
… instead of assuming unlock functions always use exclusive locks.

Patch by Aaron Puchert.

llvm-svn: 338912
  • Loading branch information
AaronBallman committed Aug 3, 2018
1 parent 397985d commit eaa18e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Analysis/ThreadSafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,8 +2242,8 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) {
// We must ignore such methods.
if (A->args_size() == 0)
return;
// FIXME -- deal with exclusive vs. shared unlock functions?
getMutexIDs(ExclusiveLocksToAdd, A, nullptr, D);
getMutexIDs(A->isShared() ? SharedLocksToAdd : ExclusiveLocksToAdd, A,
nullptr, D);
getMutexIDs(LocksReleased, A, nullptr, D);
CapDiagKind = ClassifyDiagnostic(A);
} else if (const auto *A = dyn_cast<AcquireCapabilityAttr>(Attr)) {
Expand Down
8 changes: 8 additions & 0 deletions clang/test/SemaCXX/warn-thread-safety-analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4078,6 +4078,14 @@ class Foo {
mu_.Unlock();
}

void unlockExclusive() EXCLUSIVE_UNLOCK_FUNCTION(mu_) {
mu_.Unlock();
}

void unlockShared() SHARED_UNLOCK_FUNCTION(mu_) {
mu_.ReaderUnlock();
}

// Check failure to lock.
void lockBad() EXCLUSIVE_LOCK_FUNCTION(mu_) { // expected-note {{mutex acquired here}}
mu2_.Lock();
Expand Down

0 comments on commit eaa18e6

Please sign in to comment.