/// \param Kind -- the capability's name parameter (role, mutex, etc).
/// \param Expected -- the kind of lock expected.
/// \param Received -- the kind of lock received.
+ /// \param LocLocked -- The SourceLocation of the Lock.
/// \param Loc -- The SourceLocation of the Unlock.
virtual void handleIncorrectUnlockKind(StringRef Kind, Name LockName,
LockKind Expected, LockKind Received,
+ SourceLocation LocLocked,
SourceLocation Loc) {}
/// Warn about lock function calls for locks which are already held.
// Generic lock removal doesn't care about lock kind mismatches, but
// otherwise diagnose when the lock kinds are mismatched.
if (ReceivedKind != LK_Generic && LDat->kind() != ReceivedKind) {
- Handler.handleIncorrectUnlockKind(DiagKind, Cp.toString(),
- LDat->kind(), ReceivedKind, UnlockLoc);
+ Handler.handleIncorrectUnlockKind(DiagKind, Cp.toString(), LDat->kind(),
+ ReceivedKind, LDat->loc(), UnlockLoc);
}
LDat->handleUnlock(FSet, FactMan, Cp, UnlockLoc, FullyRemove, Handler,
return ONS;
}
+ OptionalNotes makeLockedHereNote(SourceLocation LocLocked, StringRef Kind) {
+ return LocLocked.isValid()
+ ? getNotes(PartialDiagnosticAt(
+ LocLocked, S.PDiag(diag::note_locked_here) << Kind))
+ : getNotes();
+ }
+
public:
ThreadSafetyReporter(Sema &S, SourceLocation FL, SourceLocation FEL)
: S(S), FunLocation(FL), FunEndLocation(FEL),
void handleIncorrectUnlockKind(StringRef Kind, Name LockName,
LockKind Expected, LockKind Received,
+ SourceLocation LocLocked,
SourceLocation Loc) override {
if (Loc.isInvalid())
Loc = FunLocation;
PartialDiagnosticAt Warning(Loc, S.PDiag(diag::warn_unlock_kind_mismatch)
<< Kind << LockName << Received
<< Expected);
- Warnings.emplace_back(std::move(Warning), getNotes());
+ Warnings.emplace_back(std::move(Warning),
+ makeLockedHereNote(LocLocked, Kind));
}
void handleDoubleLock(StringRef Kind, Name LockName, SourceLocation LocLocked,
Loc = FunLocation;
PartialDiagnosticAt Warning(Loc, S.PDiag(diag::warn_double_lock)
<< Kind << LockName);
- OptionalNotes Notes =
- LocLocked.isValid()
- ? getNotes(PartialDiagnosticAt(
- LocLocked, S.PDiag(diag::note_locked_here) << Kind))
- : getNotes();
- Warnings.emplace_back(std::move(Warning), std::move(Notes));
+ Warnings.emplace_back(std::move(Warning),
+ makeLockedHereNote(LocLocked, Kind));
}
void handleMutexHeldEndOfScope(StringRef Kind, Name LockName,
PartialDiagnosticAt Warning(LocEndOfScope, S.PDiag(DiagID) << Kind
<< LockName);
- if (LocLocked.isValid()) {
- PartialDiagnosticAt Note(LocLocked, S.PDiag(diag::note_locked_here)
- << Kind);
- Warnings.emplace_back(std::move(Warning), getNotes(Note));
- return;
- }
- Warnings.emplace_back(std::move(Warning), getNotes());
+ Warnings.emplace_back(std::move(Warning),
+ makeLockedHereNote(LocLocked, Kind));
}
void handleExclusiveAndShared(StringRef Kind, Name LockName,
(void)(*d_ == 1);
mutex_unlock(foo_.mu_);
- mutex_exclusive_lock(&mu1);
+ mutex_exclusive_lock(&mu1); // expected-note {{mutex acquired here}}
mutex_shared_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using shared access, expected exclusive access}}
mutex_exclusive_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' that was not held}}
- mutex_shared_lock(&mu1);
+ mutex_shared_lock(&mu1); // expected-note {{mutex acquired here}}
mutex_exclusive_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' using exclusive access, expected shared access}}
mutex_shared_unlock(&mu1); // expected-warning {{releasing mutex 'mu1' that was not held}}
}
void shared_bad_3() {
- sls_mu.Lock();
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
sls_mu.ReaderUnlock(); // \
// expected-warning {{releasing mutex 'sls_mu' using shared access, expected exclusive access}}
}
void shared_bad_4() {
- sls_mu.ReaderLock();
+ sls_mu.ReaderLock(); // expected-note {{mutex acquired here}}
sls_mu.ExclusiveUnlock(); // \
// expected-warning {{releasing mutex 'sls_mu' using exclusive access, expected shared access}}
}
void shared_bad_5() {
- sls_mu.Lock();
+ sls_mu.Lock(); // expected-note {{mutex acquired here}}
sls_mu.PromoteShared(); // \
// expected-warning {{releasing mutex 'sls_mu' using shared access, expected exclusive access}}
sls_mu.ExclusiveUnlock();
}
void shared_bad_6() {
- sls_mu.ReaderLock();
+ sls_mu.ReaderLock(); // expected-note {{mutex acquired here}}
sls_mu.DemoteExclusive(); // \
// expected-warning {{releasing mutex 'sls_mu' using exclusive access, expected shared access}}
sls_mu.ReaderUnlock();