clang 22.0.0git
clang::threadSafety Namespace Reference

Namespaces

namespace  lexpr
namespace  sx
namespace  til

Classes

class  BeforeSet
class  CapabilityExpr
class  CFGVisitor
class  CFGWalker
class  CopyOnWriteVector
class  SExprBuilder
class  ThreadSafetyHandler
 Handler class for thread safety warnings. More...

Enumerations

enum  ProtectedOperationKind {
  POK_VarDereference , POK_VarAccess , POK_FunctionCall , POK_PassByRef ,
  POK_PtPassByRef , POK_ReturnByRef , POK_PtReturnByRef , POK_PassPointer ,
  POK_PtPassPointer , POK_ReturnPointer , POK_PtReturnPointer
}
 This enum distinguishes between different kinds of operations that may need to be protected by locks. More...
enum  LockKind { LK_Shared , LK_Exclusive , LK_Generic }
 This enum distinguishes between different kinds of lock actions. More...
enum  AccessKind { AK_Read , AK_Written }
 This enum distinguishes between different ways to access (read or write) a variable. More...
enum  LockErrorKind { LEK_LockedSomeLoopIterations , LEK_LockedSomePredecessors , LEK_LockedAtEndOfFunction , LEK_NotLockedAtEndOfFunction }
 This enum distinguishes between different situations where we warn due to inconsistent locking. More...

Functions

void runThreadSafetyAnalysis (AnalysisDeclContext &AC, ThreadSafetyHandler &Handler, BeforeSet **Bset)
 Check a function's CFG for thread-safety violations.
void threadSafetyCleanup (BeforeSet *Cache)
LockKind getLockKindFromAccessKind (AccessKind AK)
 Helper function that returns a LockKind required for the given level of access.
void printSCFG (CFGWalker &Walker)
std::string getSourceLiteralString (const Expr *CE)
std::ostream & operator<< (std::ostream &ss, const StringRef str)

Enumeration Type Documentation

◆ AccessKind

This enum distinguishes between different ways to access (read or write) a variable.

Enumerator
AK_Read 

Reading a variable.

AK_Written 

Writing a variable.

Definition at line 87 of file ThreadSafety.h.

◆ LockErrorKind

This enum distinguishes between different situations where we warn due to inconsistent locking.

Enumerator
LEK_LockedSomeLoopIterations 

A capability is locked for some but not all loop iterations.

LEK_LockedSomePredecessors 

A capability is locked in some but not all predecessors of a CFGBlock.

LEK_LockedAtEndOfFunction 

A capability is still locked at the end of a function.

LEK_NotLockedAtEndOfFunction 

Expecting a capability to be held at the end of function.

Definition at line 97 of file ThreadSafety.h.

◆ LockKind

This enum distinguishes between different kinds of lock actions.

For example, it is an error to write a variable protected by shared version of a mutex.

Enumerator
LK_Shared 

Shared/reader lock of a mutex.

LK_Exclusive 

Exclusive/writer lock of a mutex.

LK_Generic 

Can be either Shared or Exclusive.

Definition at line 74 of file ThreadSafety.h.

◆ ProtectedOperationKind

This enum distinguishes between different kinds of operations that may need to be protected by locks.

We use this enum in error handling.

Enumerator
POK_VarDereference 

Dereferencing a variable (e.g. p in *p = 5;)

POK_VarAccess 

Reading or writing a variable (e.g. x in x = 5;)

POK_FunctionCall 

Making a function call (e.g. fool())

POK_PassByRef 

Passing a guarded variable by reference.

POK_PtPassByRef 

Passing a pt-guarded variable by reference.

POK_ReturnByRef 

Returning a guarded variable by reference.

POK_PtReturnByRef 

Returning a pt-guarded variable by reference.

POK_PassPointer 

Passing pointer to a guarded variable.

POK_PtPassPointer 

Passing a pt-guarded pointer.

POK_ReturnPointer 

Returning pointer to a guarded variable.

POK_PtReturnPointer 

Returning a pt-guarded pointer.

Definition at line 36 of file ThreadSafety.h.

Function Documentation

◆ getLockKindFromAccessKind()

LockKind clang::threadSafety::getLockKindFromAccessKind ( AccessKind AK)

Helper function that returns a LockKind required for the given level of access.

Definition at line 2905 of file ThreadSafety.cpp.

References AK_Read, AK_Written, LK_Exclusive, and LK_Shared.

◆ getSourceLiteralString()

std::string clang::threadSafety::getSourceLiteralString ( const Expr * CE)

◆ operator<<()

std::ostream & clang::threadSafety::operator<< ( std::ostream & ss,
const StringRef str )
inline

Definition at line 354 of file ThreadSafetyUtil.h.

◆ printSCFG()

void clang::threadSafety::printSCFG ( CFGWalker & Walker)

◆ runThreadSafetyAnalysis()

void clang::threadSafety::runThreadSafetyAnalysis ( AnalysisDeclContext & AC,
ThreadSafetyHandler & Handler,
BeforeSet ** BSet )

Check a function's CFG for thread-safety violations.

We traverse the blocks in the CFG, compute the set of mutexes that are held at the end of each block, and issue warnings for thread safety violations. Each block in the CFG is traversed exactly once.

Definition at line 2892 of file ThreadSafety.cpp.

Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().

◆ threadSafetyCleanup()

void clang::threadSafety::threadSafetyCleanup ( BeforeSet * Cache)

Definition at line 2901 of file ThreadSafety.cpp.

References clang::Cache.

Referenced by clang::Sema::~Sema().