Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions clang/lib/Analysis/ThreadSafety.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2443,6 +2443,22 @@ void ThreadSafetyAnalyzer::intersectAndWarn(FactSet &EntrySet,
if (join(FactMan[*EntryIt], ExitFact, JoinLoc, EntryLEK))
*EntryIt = Fact;
} else if (!ExitFact.managed() || EntryLEK == LEK_LockedAtEndOfFunction) {
if (EntryLEK == LEK_LockedAtEndOfFunction) {
const til::SExpr *Sexp = ExitFact.sexpr();
const VarDecl *MutexVar = nullptr;

if (const auto *Proj = dyn_cast<til::Project>(Sexp)) {
if (const auto *Base = dyn_cast<til::LiteralPtr>(Proj->record()))
MutexVar = dyn_cast_or_null<VarDecl>(Base->clangDecl());
} else if (const auto *LP = dyn_cast<til::LiteralPtr>(Sexp)) {
MutexVar = dyn_cast_or_null<VarDecl>(LP->clangDecl());
}
Comment on lines +2447 to +2455
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scoped lockables should be unlocked by the automatic destructor. I don't think we should add this code.


if (MutexVar && MutexVar->getStorageDuration() == SD_Automatic &&
MutexVar->getDeclContext() == CurrentFunction) {
continue;
}
}
ExitFact.handleRemovalFromIntersection(ExitSet, FactMan, JoinLoc,
EntryLEK, Handler);
}
Expand Down
17 changes: 17 additions & 0 deletions clang/test/PCH/thread-safety-attrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,21 @@ void sls_fun_bad_12() {
expected-warning{{releasing mutex 'sls_mu' that was not held}}
}


template <class T, class... Ts>
void LockMutexes(T &m, Ts &...ms) __attribute__((exclusive_lock_function(m, ms...)));

Mutex m0, m1;
void non_local_mutex_held() {
LockMutexes(m0, m1); // expected-note {{mutex acquired here}} \
// expected-note {{mutex acquired here}}
} // expected-warning{{mutex 'm0' is still held at the end of function}} \
// expected-warning{{mutex 'm1' is still held at the end of function}}

void no_local_mutex_held_warning() {
Mutex local_m0;
Mutex local_m1;
LockMutexes(local_m0, local_m1);
} // No warnings expected at end of function scope as the mutexes are function local.

#endif