clang API Documentation
Namespaces | |
namespace | lexpr |
namespace | sx |
namespace | til |
Classes | |
class | ThreadSafetyHandler |
Handler class for thread safety warnings. More... | |
class | CFGVisitor |
class | CFGWalker |
class | CapabilityExpr |
class | SExprBuilder |
class | CopyOnWriteVector |
class | TILPrinter |
class | CapExprSet |
A set of CapabilityInfo objects, which are compiled from the requires attributes on a function. More... | |
class | FactEntry |
This is a helper class that stores a fact that is known at a particular point in program execution. Currently, a fact is a capability, along with additional information, such as where it was acquired, whether it is exclusive or shared, etc. More... | |
class | FactManager |
FactManager manages the memory for all facts that are created during the analysis of a single routine. More... | |
class | FactSet |
A FactSet is the set of facts that are known to be true at a particular program point. FactSets must be small, because they are frequently copied, and are thus implemented as a set of indices into a table maintained by a FactManager. A typical FactSet only holds 1 or 2 locks, so we can get away with doing a linear search for lookup. Note that a hashtable or map is inappropriate in this case, because lookups may involve partial pattern matches, rather than exact matches. More... | |
struct | CFGBlockInfo |
class | LocalVariableMap |
class | VarMapBuilder |
Visitor which builds a LocalVariableMap. More... | |
class | LockableFactEntry |
class | ScopedLockableFactEntry |
class | ThreadSafetyAnalyzer |
Class which implements the core thread safety analysis routines. More... | |
class | has_arg_iterator_range |
class | BuildLockset |
We use this class to visit different types of expressions in CFGBlocks, and build up the lockset. An expression may cause us to add or remove locks from the lockset, or else output error messages related to missing locks. FIXME: In future, we may be able to not inherit from a visitor. More... | |
class | ThreadSafetyReporter |
Typedefs | |
typedef unsigned short | FactID |
typedef llvm::ImmutableMap < const NamedDecl *, unsigned > | LocalVarContext |
typedef SExprBuilder::CallingContext | CallingContext |
Enumerations | |
enum | ProtectedOperationKind { POK_VarDereference, POK_VarAccess, POK_FunctionCall, POK_PassByRef, POK_PtPassByRef } |
enum | LockKind { LK_Shared, LK_Exclusive, LK_Generic } |
enum | AccessKind { AK_Read, AK_Written } |
enum | LockErrorKind { LEK_LockedSomeLoopIterations, LEK_LockedSomePredecessors, LEK_LockedAtEndOfFunction, LEK_NotLockedAtEndOfFunction } |
enum | CFGBlockSide { CBS_Entry, CBS_Exit } |
A side (entry or exit) of a CFG node. More... | |
Functions | |
void | runThreadSafetyAnalysis (AnalysisDeclContext &AC, ThreadSafetyHandler &Handler) |
Check a function's CFG for thread-safety violations. | |
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 clang::Expr *CE) |
std::ostream & | operator<< (std::ostream &ss, const StringRef str) |
static void | warnInvalidLock (ThreadSafetyHandler &Handler, const Expr *MutexExp, const NamedDecl *D, const Expr *DeclExp, StringRef Kind) |
Issue a warning about an invalid lock expression. | |
static void | findBlockLocations (CFG *CFGraph, const PostOrderCFGView *SortedGraph, std::vector< CFGBlockInfo > &BlockInfo) |
static const ValueDecl * | getValueDecl (const Expr *Exp) |
Gets the value decl pointer from DeclRefExprs or MemberExprs. | |
static StringRef | ClassifyDiagnostic (const CapabilityAttr *A) |
static StringRef | ClassifyDiagnostic (QualType VDT) |
static StringRef | ClassifyDiagnostic (const ValueDecl *VD) |
template<typename AttrTy > | |
static std::enable_if <!has_arg_iterator_range < AttrTy >::value, StringRef > ::type | ClassifyDiagnostic (const AttrTy *A) |
bool | getStaticBooleanValue (Expr *E, bool &TCond) |
bool | neverReturns (const CFGBlock *B) |
bool | isCalleeArrow (const Expr *E) |
const ValueDecl * | getValueDeclFromSExpr (const til::SExpr *E) |
bool | hasCppPointerType (const til::SExpr *E) |
const CXXMethodDecl * | getFirstVirtualDecl (const CXXMethodDecl *D) |
void | maybeUpdateVD (til::SExpr *E, const ValueDecl *VD) |
Definition at line 75 of file ThreadSafetyCommon.cpp.
typedef unsigned short clang::threadSafety::FactID |
Definition at line 132 of file ThreadSafety.cpp.
typedef llvm::ImmutableMap<const NamedDecl*, unsigned> clang::threadSafety::LocalVarContext |
Definition at line 242 of file ThreadSafety.cpp.
This enum distinguishes between different ways to access (read or write) a variable.
Definition at line 50 of file ThreadSafety.h.
A side (entry or exit) of a CFG node.
Definition at line 246 of file ThreadSafety.cpp.
LEK_LockedSomeLoopIterations | |
LEK_LockedSomePredecessors | |
LEK_LockedAtEndOfFunction | |
LEK_NotLockedAtEndOfFunction |
Definition at line 63 of file ThreadSafety.h.
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.
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 42 of file ThreadSafety.h.
This enum distinguishes between different kinds of operations that may need to be protected by locks. We use this enum in error handling.
Definition at line 31 of file ThreadSafety.h.
static StringRef clang::threadSafety::ClassifyDiagnostic | ( | const CapabilityAttr * | A | ) | [static] |
Definition at line 939 of file ThreadSafety.cpp.
Referenced by ClassifyDiagnostic(), clang::threadSafety::ThreadSafetyAnalyzer::getEdgeLockset(), clang::threadSafety::ThreadSafetyAnalyzer::getMutexIDs(), and clang::threadSafety::ThreadSafetyAnalyzer::runAnalysis().
static StringRef clang::threadSafety::ClassifyDiagnostic | ( | QualType | VDT | ) | [static] |
Definition at line 943 of file ThreadSafety.cpp.
References ClassifyDiagnostic(), clang::Type::getAs(), clang::Type::getPointeeType(), clang::Type::isPointerType(), and clang::Type::isReferenceType().
static StringRef clang::threadSafety::ClassifyDiagnostic | ( | const ValueDecl * | VD | ) | [static] |
Definition at line 961 of file ThreadSafety.cpp.
References ClassifyDiagnostic(), and clang::ValueDecl::getType().
static std::enable_if< has_arg_iterator_range< AttrTy >::value, StringRef >::type clang::threadSafety::ClassifyDiagnostic | ( | const AttrTy * | A | ) | [static] |
Definition at line 971 of file ThreadSafety.cpp.
References ClassifyDiagnostic(), and getValueDecl().
static void clang::threadSafety::findBlockLocations | ( | CFG * | CFGraph, |
const PostOrderCFGView * | SortedGraph, | ||
std::vector< CFGBlockInfo > & | BlockInfo | ||
) | [static] |
Find the appropriate source locations to use when producing diagnostics for each block in the CFG.
Definition at line 719 of file ThreadSafety.cpp.
References clang::threadSafety::CFGBlockInfo::EntryLoc, clang::threadSafety::CFGBlockInfo::ExitLoc, clang::CFG::getExit(), clang::SourceLocation::isInvalid(), and S.
Referenced by clang::threadSafety::ThreadSafetyAnalyzer::runAnalysis().
const CXXMethodDecl* clang::threadSafety::getFirstVirtualDecl | ( | const CXXMethodDecl * | D | ) |
Definition at line 342 of file ThreadSafetyCommon.cpp.
References clang::CXXMethodDecl::begin_overridden_methods(), clang::CXXMethodDecl::end_overridden_methods(), and clang::CXXMethodDecl::getCanonicalDecl().
LockKind clang::threadSafety::getLockKindFromAccessKind | ( | AccessKind | AK | ) |
Helper function that returns a LockKind required for the given level of access.
Definition at line 2190 of file ThreadSafety.cpp.
References AK_Read, AK_Written, LK_Exclusive, and LK_Shared.
Referenced by clang::threadSafety::ThreadSafetyReporter::handleNoMutexHeld().
std::string clang::threadSafety::getSourceLiteralString | ( | const clang::Expr * | CE | ) |
Definition at line 41 of file ThreadSafetyCommon.cpp.
References clang::Stmt::getStmtClass(), and getValue().
Referenced by clang::threadSafety::til::PrettyPrinter< StdPrinter, std::ostream >::printLiteral().
bool clang::threadSafety::getStaticBooleanValue | ( | Expr * | E, |
bool & | TCond | ||
) |
Definition at line 1123 of file ThreadSafety.cpp.
Referenced by clang::threadSafety::ThreadSafetyAnalyzer::getTrylockCallExpr().
static const ValueDecl* clang::threadSafety::getValueDecl | ( | const Expr * | Exp | ) | [static] |
Gets the value decl pointer from DeclRefExprs or MemberExprs.
Definition at line 911 of file ThreadSafety.cpp.
Referenced by ClassifyDiagnostic().
const ValueDecl* clang::threadSafety::getValueDeclFromSExpr | ( | const til::SExpr * | E | ) |
Definition at line 318 of file ThreadSafetyCommon.cpp.
References P.
Referenced by hasCppPointerType().
bool clang::threadSafety::hasCppPointerType | ( | const til::SExpr * | E | ) |
Definition at line 330 of file ThreadSafetyCommon.cpp.
References AttributeLangSupport::C, clang::threadSafety::til::CAST_objToPtr, clang::ValueDecl::getType(), getValueDeclFromSExpr(), and clang::Type::isPointerType().
bool clang::threadSafety::isCalleeArrow | ( | const Expr * | E | ) | [inline] |
Definition at line 93 of file ThreadSafetyCommon.cpp.
References clang::Expr::IgnoreParenCasts(), and clang::MemberExpr::isArrow().
Referenced by clang::threadSafety::SExprBuilder::translateAttrExpr().
void clang::threadSafety::maybeUpdateVD | ( | til::SExpr * | E, |
const ValueDecl * | VD | ||
) | [inline] |
Definition at line 667 of file ThreadSafetyCommon.cpp.
bool clang::threadSafety::neverReturns | ( | const CFGBlock * | B | ) | [inline] |
Definition at line 1866 of file ThreadSafety.cpp.
References clang::CFGBlock::back(), clang::CFGBlock::empty(), clang::CFGElement::getAs(), clang::CFGBlock::hasNoReturnElement(), clang::LangAS::Last, and S.
Referenced by clang::threadSafety::ThreadSafetyAnalyzer::runAnalysis().
std::ostream& clang::threadSafety::operator<< | ( | std::ostream & | ss, |
const StringRef | str | ||
) | [inline] |
Definition at line 363 of file ThreadSafetyUtil.h.
void clang::threadSafety::printSCFG | ( | CFGWalker & | Walker | ) |
void clang::threadSafety::runThreadSafetyAnalysis | ( | AnalysisDeclContext & | AC, |
ThreadSafetyHandler & | Handler | ||
) |
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 2182 of file ThreadSafety.cpp.
References clang::threadSafety::ThreadSafetyAnalyzer::runAnalysis().
Referenced by clang::sema::AnalysisBasedWarnings::IssueWarnings().
static void clang::threadSafety::warnInvalidLock | ( | ThreadSafetyHandler & | Handler, |
const Expr * | MutexExp, | ||
const NamedDecl * | D, | ||
const Expr * | DeclExp, | ||
StringRef | Kind | ||
) | [static] |
Issue a warning about an invalid lock expression.
Definition at line 60 of file ThreadSafety.cpp.
References clang::Expr::getExprLoc(), clang::threadSafety::ThreadSafetyHandler::handleInvalidLockExp(), and clang::SourceLocation::isValid().
Referenced by clang::threadSafety::ThreadSafetyAnalyzer::getMutexIDs().