Skip to content

Commit 0314dba

Browse files
committed
Thread safety analysis: Don't pass capability kind where not needed (NFC)
If no capability is held, or the capability expression is invalid, there is obviously no capability kind and so none would be reported. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D124132
1 parent f8afb8f commit 0314dba

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

clang/include/clang/Analysis/Analyses/ThreadSafety.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ class ThreadSafetyHandler {
9898
virtual ~ThreadSafetyHandler();
9999

100100
/// Warn about lock expressions which fail to resolve to lockable objects.
101-
/// \param Kind -- the capability's name parameter (role, mutex, etc).
102101
/// \param Loc -- the SourceLocation of the unresolved expression.
103-
virtual void handleInvalidLockExp(StringRef Kind, SourceLocation Loc) {}
102+
virtual void handleInvalidLockExp(SourceLocation Loc) {}
104103

105104
/// Warn about unlock function calls that do not have a prior matching lock
106105
/// expression.
@@ -169,14 +168,12 @@ class ThreadSafetyHandler {
169168
SourceLocation Loc2) {}
170169

171170
/// Warn when a protected operation occurs while no locks are held.
172-
/// \param Kind -- the capability's name parameter (role, mutex, etc).
173171
/// \param D -- The decl for the protected variable or function
174172
/// \param POK -- The kind of protected operation (e.g. variable access)
175173
/// \param AK -- The kind of access (i.e. read or write) that occurred
176174
/// \param Loc -- The location of the protected operation.
177-
virtual void handleNoMutexHeld(StringRef Kind, const NamedDecl *D,
178-
ProtectedOperationKind POK, AccessKind AK,
179-
SourceLocation Loc) {}
175+
virtual void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
176+
AccessKind AK, SourceLocation Loc) {}
180177

181178
/// Warn when a protected operation occurs while the specific mutex protecting
182179
/// the operation is not locked.

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void warnInvalidLock(ThreadSafetyHandler &Handler,
7474

7575
// FIXME: add a note about the attribute location in MutexExp or D
7676
if (Loc.isValid())
77-
Handler.handleInvalidLockExp(Kind, Loc);
77+
Handler.handleInvalidLockExp(Loc);
7878
}
7979

8080
namespace {
@@ -1696,7 +1696,7 @@ void BuildLockset::checkAccess(const Expr *Exp, AccessKind AK,
16961696
return;
16971697

16981698
if (D->hasAttr<GuardedVarAttr>() && FSet.isEmpty(Analyzer->FactMan)) {
1699-
Analyzer->Handler.handleNoMutexHeld("mutex", D, POK, AK, Loc);
1699+
Analyzer->Handler.handleNoMutexHeld(D, POK, AK, Loc);
17001700
}
17011701

17021702
for (const auto *I : D->specific_attrs<GuardedByAttr>())
@@ -1734,8 +1734,7 @@ void BuildLockset::checkPtAccess(const Expr *Exp, AccessKind AK,
17341734
return;
17351735

17361736
if (D->hasAttr<PtGuardedVarAttr>() && FSet.isEmpty(Analyzer->FactMan))
1737-
Analyzer->Handler.handleNoMutexHeld("mutex", D, PtPOK, AK,
1738-
Exp->getExprLoc());
1737+
Analyzer->Handler.handleNoMutexHeld(D, PtPOK, AK, Exp->getExprLoc());
17391738

17401739
for (auto const *I : D->specific_attrs<PtGuardedByAttr>())
17411740
warnIfMutexNotHeld(D, Exp, AK, I->getArg(), PtPOK, Exp->getExprLoc());

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
18441844
}
18451845
}
18461846

1847-
void handleInvalidLockExp(StringRef Kind, SourceLocation Loc) override {
1847+
void handleInvalidLockExp(SourceLocation Loc) override {
18481848
PartialDiagnosticAt Warning(Loc, S.PDiag(diag::warn_cannot_resolve_lock)
18491849
<< Loc);
18501850
Warnings.emplace_back(std::move(Warning), getNotes());
@@ -1922,9 +1922,8 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {
19221922
Warnings.emplace_back(std::move(Warning), getNotes(Note));
19231923
}
19241924

1925-
void handleNoMutexHeld(StringRef Kind, const NamedDecl *D,
1926-
ProtectedOperationKind POK, AccessKind AK,
1927-
SourceLocation Loc) override {
1925+
void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK,
1926+
AccessKind AK, SourceLocation Loc) override {
19281927
assert((POK == POK_VarAccess || POK == POK_VarDereference) &&
19291928
"Only works for variables");
19301929
unsigned DiagID = POK == POK_VarAccess?

0 commit comments

Comments
 (0)