clang API Documentation

Public Member Functions | Friends
clang::threadSafety::ThreadSafetyAnalyzer Class Reference

Class which implements the core thread safety analysis routines. More...

List of all members.

Public Member Functions

 ThreadSafetyAnalyzer (ThreadSafetyHandler &H)
bool inCurrentScope (const CapabilityExpr &CapE)
void addLock (FactSet &FSet, std::unique_ptr< FactEntry > Entry, StringRef DiagKind, bool ReqAttr=false)
 Add a new lock to the lockset, warning if the lock is already there.
void removeLock (FactSet &FSet, const CapabilityExpr &CapE, SourceLocation UnlockLoc, bool FullyRemove, LockKind Kind, StringRef DiagKind)
 Remove a lock from the lockset, warning if the lock is not there.
template<typename AttrType >
void getMutexIDs (CapExprSet &Mtxs, AttrType *Attr, Expr *Exp, const NamedDecl *D, VarDecl *SelfDecl=nullptr)
 Extract the list of mutexIDs from the attribute on an expression, and push them onto Mtxs, discarding any duplicates.
template<class AttrType >
void getMutexIDs (CapExprSet &Mtxs, AttrType *Attr, Expr *Exp, const NamedDecl *D, const CFGBlock *PredBlock, const CFGBlock *CurrBlock, Expr *BrE, bool Neg)
 Extract the list of mutexIDs from a trylock attribute. If the trylock applies to the given edge, then push them onto Mtxs, discarding any duplicates.
const CallExprgetTrylockCallExpr (const Stmt *Cond, LocalVarContext C, bool &Negate)
void getEdgeLockset (FactSet &Result, const FactSet &ExitSet, const CFGBlock *PredBlock, const CFGBlock *CurrBlock)
 Find the lockset that holds on the edge between PredBlock and CurrBlock. The edge set is the exit set of PredBlock (passed as the ExitSet parameter) plus any trylocks, which are conditionally held.
void intersectAndWarn (FactSet &FSet1, const FactSet &FSet2, SourceLocation JoinLoc, LockErrorKind LEK1, LockErrorKind LEK2, bool Modify=true)
 Compute the intersection of two locksets and issue warnings for any locks in the symmetric difference.
void intersectAndWarn (FactSet &FSet1, const FactSet &FSet2, SourceLocation JoinLoc, LockErrorKind LEK1, bool Modify=true)
void runAnalysis (AnalysisDeclContext &AC)
 Check a function's CFG for thread-safety violations.

Friends

class BuildLockset

Detailed Description

Class which implements the core thread safety analysis routines.

Definition at line 854 of file ThreadSafety.cpp.


Constructor & Destructor Documentation

Definition at line 868 of file ThreadSafety.cpp.


Member Function Documentation

void clang::threadSafety::ThreadSafetyAnalyzer::addLock ( FactSet FSet,
std::unique_ptr< FactEntry Entry,
StringRef  DiagKind,
bool  ReqAttr = false 
)
void clang::threadSafety::ThreadSafetyAnalyzer::getEdgeLockset ( FactSet Result,
const FactSet ExitSet,
const CFGBlock PredBlock,
const CFGBlock CurrBlock 
)

Find the lockset that holds on the edge between PredBlock and CurrBlock. The edge set is the exit set of PredBlock (passed as the ExitSet parameter) plus any trylocks, which are conditionally held.

Definition at line 1205 of file ThreadSafety.cpp.

References addLock(), clang::threadSafety::ClassifyDiagnostic(), clang::threadSafety::CFGBlockInfo::ExitContext, clang::Decl::getAttrs(), clang::CFGBlock::getBlockID(), clang::CallExpr::getCalleeDecl(), clang::Expr::getExprLoc(), clang::Attr::getKind(), getMutexIDs(), clang::CFGBlock::getTerminatorCondition(), getTrylockCallExpr(), clang::Decl::hasAttrs(), clang::threadSafety::LK_Exclusive, and clang::threadSafety::LK_Shared.

Referenced by runAnalysis().

template<typename AttrType >
void clang::threadSafety::ThreadSafetyAnalyzer::getMutexIDs ( CapExprSet Mtxs,
AttrType *  Attr,
Expr Exp,
const NamedDecl D,
VarDecl SelfDecl = nullptr 
)
template<class AttrType >
void clang::threadSafety::ThreadSafetyAnalyzer::getMutexIDs ( CapExprSet Mtxs,
AttrType *  Attr,
Expr Exp,
const NamedDecl D,
const CFGBlock PredBlock,
const CFGBlock CurrBlock,
Expr BrE,
bool  Neg 
)

Extract the list of mutexIDs from a trylock attribute. If the trylock applies to the given edge, then push them onto Mtxs, discarding any duplicates.

Definition at line 1097 of file ThreadSafety.cpp.

References getMutexIDs(), clang::CFGBlock::succ_begin(), and clang::CFGBlock::succ_end().

Definition at line 989 of file ThreadSafety.cpp.

References clang::Decl::getDeclContext(), P, and clang::threadSafety::CapabilityExpr::sexpr().

Referenced by addLock().

void clang::threadSafety::ThreadSafetyAnalyzer::intersectAndWarn ( FactSet FSet1,
const FactSet FSet2,
SourceLocation  JoinLoc,
LockErrorKind  LEK1,
LockErrorKind  LEK2,
bool  Modify = true 
)

Compute the intersection of two locksets and issue warnings for any locks in the symmetric difference.

This function is used at a merge point in the CFG when comparing the lockset of each branch being merged. For example, given the following sequence: A; if () then B; else C; D; we need to check that the lockset after B and C are the same. In the event of a difference, we use the intersection of these two locksets at the start of D.

Parameters:
FSet1The first lockset.
FSet2The second lockset.
JoinLocThe location of the join point for error reporting
LEK1The error message to report if a mutex is missing from LSet1
LEK2The error message to report if a mutex is missing from Lset2

Definition at line 1816 of file ThreadSafety.cpp.

References clang::threadSafety::FactEntry::asserted(), clang::threadSafety::FactSet::end(), clang::threadSafety::FactSet::findLockIter(), clang::threadSafety::ThreadSafetyHandler::handleExclusiveAndShared(), clang::threadSafety::FactEntry::handleRemovalFromIntersection(), clang::threadSafety::FactEntry::kind(), clang::threadSafety::LK_Exclusive, clang::threadSafety::FactEntry::loc(), clang::threadSafety::FactSet::removeLock(), and clang::threadSafety::CapabilityExpr::toString().

Referenced by intersectAndWarn(), and runAnalysis().

void clang::threadSafety::ThreadSafetyAnalyzer::intersectAndWarn ( FactSet FSet1,
const FactSet FSet2,
SourceLocation  JoinLoc,
LockErrorKind  LEK1,
bool  Modify = true 
) [inline]

Definition at line 901 of file ThreadSafety.cpp.

References intersectAndWarn().

void clang::threadSafety::ThreadSafetyAnalyzer::removeLock ( FactSet FSet,
const CapabilityExpr Cp,
SourceLocation  UnlockLoc,
bool  FullyRemove,
LockKind  ReceivedKind,
StringRef  DiagKind 
)

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 1886 of file ThreadSafety.cpp.

References clang::threadSafety::FactSet::addLock(), addLock(), clang::PostOrderCFGView::CFGBlockSet::alreadySet(), clang::CFGElement::AutomaticObjectDtor, clang::PostOrderCFGView::begin(), clang::CFGElement::castAs(), clang::threadSafety::ClassifyDiagnostic(), clang::PostOrderCFGView::empty(), clang::threadSafety::ThreadSafetyHandler::enterFunction(), clang::threadSafety::CFGBlockInfo::EntryLoc, clang::threadSafety::CFGBlockInfo::EntrySet, clang::threadSafety::CFGBlockInfo::ExitLoc, clang::threadSafety::CFGBlockInfo::ExitSet, clang::threadSafety::findBlockLocations(), clang::AnalysisDeclContext::getASTContext(), clang::Decl::getAttrs(), clang::CFGBlock::getBlockID(), clang::threadSafety::CFGWalker::getDecl(), clang::CFGImplicitDtor::getDestructorDecl(), getEdgeLockset(), clang::threadSafety::CFGBlockInfo::getEmptyBlockInfo(), clang::CFG::getEntry(), clang::CFG::getExit(), clang::threadSafety::CFGWalker::getGraph(), clang::Attr::getLocation(), clang::Decl::getLocation(), clang::Stmt::getLocEnd(), getMutexIDs(), clang::CFG::getNumBlockIDs(), clang::threadSafety::CFGWalker::getSortedGraph(), clang::CFGStmt::getStmt(), clang::CFGAutomaticObjDtor::getTriggerStmt(), clang::ValueDecl::getType(), clang::CFGAutomaticObjDtor::getVarDecl(), clang::Decl::hasAttr(), clang::Decl::hasAttrs(), clang::threadSafety::CFGWalker::init(), clang::PostOrderCFGView::CFGBlockSet::insert(), intersectAndWarn(), clang::threadSafety::ThreadSafetyHandler::leaveFunction(), clang::threadSafety::LEK_LockedAtEndOfFunction, clang::threadSafety::LEK_LockedSomeLoopIterations, clang::threadSafety::LEK_LockedSomePredecessors, clang::threadSafety::LEK_NotLockedAtEndOfFunction, clang::threadSafety::LK_Exclusive, clang::threadSafety::LK_Shared, clang::threadSafety::neverReturns(), clang::threadSafety::CFGBlockInfo::Reachable, clang::threadSafety::FactSet::removeLock(), clang::CFGElement::Statement, clang::threadSafety::LocalVariableMap::traverseCFG(), clang::StmtVisitorBase< Ptr, ImplClass, RetTy >::Visit(), and clang::VK_LValue.

Referenced by clang::threadSafety::runThreadSafetyAnalysis().


Friends And Related Function Documentation

friend class BuildLockset [friend]

Definition at line 855 of file ThreadSafety.cpp.


The documentation for this class was generated from the following file: