clang API Documentation
Class which implements the core thread safety analysis routines. More...
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 CallExpr * | getTrylockCallExpr (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 |
Class which implements the core thread safety analysis routines.
Definition at line 854 of file ThreadSafety.cpp.
Definition at line 868 of file ThreadSafety.cpp.
void clang::threadSafety::ThreadSafetyAnalyzer::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.
ReqAttr | -- true if this is part of an initial Requires attribute. |
Definition at line 1003 of file ThreadSafety.cpp.
References clang::threadSafety::FactSet::addLock(), clang::threadSafety::FactSet::findLock(), clang::threadSafety::ThreadSafetyHandler::handleDoubleLock(), clang::threadSafety::ThreadSafetyHandler::handleNegativeNotHeld(), inCurrentScope(), clang::threadSafety::FactSet::removeLock(), and clang::threadSafety::CapabilityExpr::toString().
Referenced by getEdgeLockset(), and runAnalysis().
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().
void clang::threadSafety::ThreadSafetyAnalyzer::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.
Definition at line 1064 of file ThreadSafety.cpp.
References clang::threadSafety::ClassifyDiagnostic(), clang::threadSafety::CapabilityExpr::isInvalid(), clang::threadSafety::CapExprSet::push_back_nodup(), clang::threadSafety::CapabilityExpr::shouldIgnore(), clang::threadSafety::SExprBuilder::translateAttrExpr(), and clang::threadSafety::warnInvalidLock().
Referenced by getEdgeLockset(), getMutexIDs(), and runAnalysis().
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().
const CallExpr * clang::threadSafety::ThreadSafetyAnalyzer::getTrylockCallExpr | ( | const Stmt * | Cond, |
LocalVarContext | C, | ||
bool & | Negate | ||
) |
Definition at line 1143 of file ThreadSafety.cpp.
References clang::BO_EQ, clang::BO_LAnd, clang::BO_LOr, clang::BO_NE, AttributeLangSupport::C, clang::threadSafety::getStaticBooleanValue(), clang::threadSafety::LocalVariableMap::lookupExpr(), and clang::UO_LNot.
Referenced by getEdgeLockset().
bool clang::threadSafety::ThreadSafetyAnalyzer::inCurrentScope | ( | const CapabilityExpr & | CapE | ) | [inline] |
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.
FSet1 | The first lockset. |
FSet2 | The second lockset. |
JoinLoc | The location of the join point for error reporting |
LEK1 | The error message to report if a mutex is missing from LSet1 |
LEK2 | The 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 | ||
) |
Remove a lock from the lockset, warning if the lock is not there.
UnlockLoc | The source location of the unlock (only used in error msg) |
Definition at line 1036 of file ThreadSafety.cpp.
References clang::threadSafety::FactSet::findLock(), clang::threadSafety::ThreadSafetyHandler::handleIncorrectUnlockKind(), clang::threadSafety::FactEntry::handleUnlock(), clang::threadSafety::ThreadSafetyHandler::handleUnmatchedUnlock(), clang::threadSafety::FactEntry::kind(), clang::threadSafety::LK_Generic, clang::threadSafety::CapabilityExpr::shouldIgnore(), and clang::threadSafety::CapabilityExpr::toString().
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().
friend class BuildLockset [friend] |
Definition at line 855 of file ThreadSafety.cpp.