clang API Documentation

Namespaces | Classes | Typedefs | Enumerations | Functions
clang::threadSafety Namespace Reference

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 ValueDeclgetValueDecl (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 ValueDeclgetValueDeclFromSExpr (const til::SExpr *E)
bool hasCppPointerType (const til::SExpr *E)
const CXXMethodDeclgetFirstVirtualDecl (const CXXMethodDecl *D)
void maybeUpdateVD (til::SExpr *E, const ValueDecl *VD)

Typedef Documentation

Definition at line 75 of file ThreadSafetyCommon.cpp.

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.


Enumeration Type Documentation

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 50 of file ThreadSafety.h.

A side (entry or exit) of a CFG node.

Enumerator:
CBS_Entry 
CBS_Exit 

Definition at line 246 of file ThreadSafety.cpp.

Enumerator:
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.

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 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.

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.

Definition at line 31 of file ThreadSafety.h.


Function Documentation

static StringRef clang::threadSafety::ClassifyDiagnostic ( const CapabilityAttr *  A) [static]
static StringRef clang::threadSafety::ClassifyDiagnostic ( QualType  VDT) [static]
static StringRef clang::threadSafety::ClassifyDiagnostic ( const ValueDecl *  VD) [static]

Definition at line 961 of file ThreadSafety.cpp.

References ClassifyDiagnostic(), and clang::ValueDecl::getType().

template<typename AttrTy >
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)

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().

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)
bool clang::threadSafety::isCalleeArrow ( const Expr *  E) [inline]
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]
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]