Go to the documentation of this file.
18 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H
19 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H
22 #include "llvm/ADT/StringRef.h"
26 class AnalysisDeclContext;
30 namespace threadSafety {
190 Name *PossibleMatch =
nullptr) {}
238 bool IssueBetaWarnings =
false;
247 ThreadSafetyHandler &Handler,
259 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETY_H
@ LEK_LockedAtEndOfFunction
void setIssueBetaWarnings(bool b)
@ POK_FunctionCall
Making a function call (e.g. fool())
@ LK_Exclusive
Exclusive/writer lock of a mutex.
AccessKind
This enum distinguishes between different ways to access (read or write) a variable.
virtual void handleInvalidLockExp(SourceLocation Loc)
Warn about lock expressions which fail to resolve to lockable objects.
Encodes a location in the source.
This represents a decl that may have a name.
AnalysisDeclContext contains the context data for the function, method or block under analysis.
@ LEK_NotLockedAtEndOfFunction
@ POK_VarAccess
Reading or writing a variable (e.g. x in x = 5;)
@ AK_Read
Reading a variable.
ProtectedOperationKind
This enum distinguishes between different kinds of operations that may need to be protected by locks.
@ LK_Generic
Can be either Shared or Exclusive.
@ LEK_LockedSomeLoopIterations
virtual void handleFunExcludesLock(StringRef Kind, Name FunName, Name LockName, SourceLocation Loc)
Warn when a function is called while an excluded mutex is locked.
@ POK_PtPassByRef
Passing a pt-guarded variable by reference.
virtual void handleNoMutexHeld(const NamedDecl *D, ProtectedOperationKind POK, AccessKind AK, SourceLocation Loc)
Warn when a protected operation occurs while no locks are held.
virtual void handleNegativeNotHeld(StringRef Kind, Name LockName, Name Neg, SourceLocation Loc)
Warn when acquiring a lock that the negative capability is not held.
@ AK_Written
Writing a variable.
Handler class for thread safety warnings.
virtual ~ThreadSafetyHandler()
virtual void handleUnmatchedUnlock(StringRef Kind, Name LockName, SourceLocation Loc, SourceLocation LocPreviousUnlock)
Warn about unlock function calls that do not have a prior matching lock expression.
ThreadSafetyHandler()=default
virtual void enterFunction(const FunctionDecl *FD)
Called by the analysis when starting analysis of a function.
virtual void handleDoubleLock(StringRef Kind, Name LockName, SourceLocation LocLocked, SourceLocation LocDoubleLock)
Warn about lock function calls for locks which are already held.
@ POK_PassByRef
Passing a guarded variable by reference.
LockKind
This enum distinguishes between different kinds of lock actions.
TypePropertyCache< Private > Cache
virtual void handleBeforeAfterCycle(Name L1Name, SourceLocation Loc)
Warn that there is a cycle in acquired_before/after dependencies.
@ POK_VarDereference
Dereferencing a variable (e.g. p in *p = 5;)
virtual void handleIncorrectUnlockKind(StringRef Kind, Name LockName, LockKind Expected, LockKind Received, SourceLocation LocLocked, SourceLocation LocUnlock)
Warn about an unlock function call that attempts to unlock a lock with the incorrect lock kind.
virtual void handleLockAcquiredBefore(StringRef Kind, Name L1Name, Name L2Name, SourceLocation Loc)
Warn that L1 cannot be acquired before L2.
void threadSafetyCleanup(BeforeSet *Cache)
virtual void handleMutexNotHeld(StringRef Kind, const NamedDecl *D, ProtectedOperationKind POK, Name LockName, LockKind LK, SourceLocation Loc, Name *PossibleMatch=nullptr)
Warn when a protected operation occurs while the specific mutex protecting the operation is not locke...
virtual void leaveFunction(const FunctionDecl *FD)
Called by the analysis when finishing analysis of a function.
LockKind getLockKindFromAccessKind(AccessKind AK)
Helper function that returns a LockKind required for the given level of access.
@ LEK_LockedSomePredecessors
void runThreadSafetyAnalysis(AnalysisDeclContext &AC, ThreadSafetyHandler &Handler, BeforeSet **Bset)
Check a function's CFG for thread-safety violations.
virtual void handleMutexHeldEndOfScope(StringRef Kind, Name LockName, SourceLocation LocLocked, SourceLocation LocEndOfScope, LockErrorKind LEK)
Warn about situations where a mutex is sometimes held and sometimes not.
virtual void handleExclusiveAndShared(StringRef Kind, Name LockName, SourceLocation Loc1, SourceLocation Loc2)
Warn when a mutex is held exclusively and shared at the same point.
Represents a function declaration or definition.
@ LK_Shared
Shared/reader lock of a mutex.
virtual void handleNegativeNotHeld(const NamedDecl *D, Name LockName, SourceLocation Loc)
Warn when calling a function that a negative capability is not held.