clang 8.0.0

Classes | Namespaces | Enumerations | Functions
ThreadSafety.cpp File Reference
`#include "clang/Analysis/Analyses/ThreadSafety.h"`
`#include "clang/AST/Attr.h"`
`#include "clang/AST/Decl.h"`
`#include "clang/AST/DeclCXX.h"`
`#include "clang/AST/DeclGroup.h"`
`#include "clang/AST/Expr.h"`
`#include "clang/AST/ExprCXX.h"`
`#include "clang/AST/OperationKinds.h"`
`#include "clang/AST/Stmt.h"`
`#include "clang/AST/StmtVisitor.h"`
`#include "clang/AST/Type.h"`
`#include "clang/Analysis/Analyses/PostOrderCFGView.h"`
`#include "clang/Analysis/Analyses/ThreadSafetyCommon.h"`
`#include "clang/Analysis/Analyses/ThreadSafetyTIL.h"`
`#include "clang/Analysis/Analyses/ThreadSafetyTraverse.h"`
`#include "clang/Analysis/Analyses/ThreadSafetyUtil.h"`
`#include "clang/Analysis/AnalysisDeclContext.h"`
`#include "clang/Analysis/CFG.h"`
`#include "clang/Basic/Builtins.h"`
`#include "clang/Basic/LLVM.h"`
`#include "clang/Basic/OperatorKinds.h"`
`#include "clang/Basic/SourceLocation.h"`
`#include "clang/Basic/Specifiers.h"`
`#include "llvm/ADT/ArrayRef.h"`
`#include "llvm/ADT/DenseMap.h"`
`#include "llvm/ADT/ImmutableMap.h"`
`#include "llvm/ADT/Optional.h"`
`#include "llvm/ADT/PointerIntPair.h"`
`#include "llvm/ADT/STLExtras.h"`
`#include "llvm/ADT/SmallVector.h"`
`#include "llvm/ADT/StringRef.h"`
`#include "llvm/Support/Allocator.h"`
`#include "llvm/Support/Casting.h"`
`#include "llvm/Support/ErrorHandling.h"`
`#include "llvm/Support/raw_ostream.h"`
`#include <algorithm>`
`#include <cassert>`
`#include <functional>`
`#include <iterator>`
`#include <memory>`
`#include <string>`
`#include <type_traits>`
`#include <utility>`
`#include <vector>`
Include dependency graph for ThreadSafety.cpp:

Go to the source code of this file.

## Classes
class | clang::threadSafety::BeforeSet

## Namespaces
| clang
| Dataflow Directional Tag Classes.
| clang::threadSafety

## Enumerations
enum | CFGBlockSide
| A side (entry or exit) of a CFG node. More...

## Functions
static void | warnInvalidLock (ThreadSafetyHandler &Handler, const Expr *MutexExp, const NamedDecl *D, const Expr *DeclExp, StringRef Kind)
| Issue a warning about an invalid lock expression. More...
static void | findBlockLocations (CFG *CFGraph, const PostOrderCFGView *SortedGraph, std::vector< CFGBlockInfo > &BlockInfo)
| Find the appropriate source locations to use when producing diagnostics for each block in the CFG. More...
static const ValueDecl * | getValueDecl (const Expr *Exp)
| Gets the value decl pointer from DeclRefExprs or MemberExprs. More...
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)
template<typename AttrTy >
static std::enable_if< has_arg_iterator_range< AttrTy >::value, StringRef >::type | ClassifyDiagnostic (const AttrTy *A)
static bool | getStaticBooleanValue (Expr *E, bool &TCond)
static CXXConstructorDecl * | findConstructorForByValueReturn (const CXXRecordDecl *RD)
static Expr * | buildFakeCtorCall (CXXConstructorDecl *CD, ArrayRef< Expr *> Args, SourceLocation Loc)
static bool | neverReturns (const CFGBlock *B)

## Enumeration Type Documentation

## ◆ CFGBlockSide

enum CFGBlockSide

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

Definition at line 321 of file ThreadSafety.cpp.

## Function Documentation

## ◆ buildFakeCtorCall()

static Expr* buildFakeCtorCall | ( | CXXConstructorDecl * | CD,
|  | ArrayRef< Expr *> | Args,
|  | SourceLocation | Loc
| ) |  |
| static

Definition at line 2122 of file ThreadSafety.cpp.

References clang::CXXConstructExpr::CK_Complete, clang::CXXConstructExpr::Create(), findConstructorForByValueReturn(), clang::Type::getAsCXXRecordDecl(), clang::Decl::getASTContext(), clang::Stmt::getBeginLoc(), clang::DeclStmt::getDeclGroup(), clang::VarDecl::getInit(), clang::CXXMethodDecl::getParent(), clang::ASTContext::getRecordType(), clang::Expr::getType(), clang::Decl::hasAttrs(), clang::Expr::IgnoreParens(), clang::Expr::isRValue(), and clang::threadSafety::LK_Exclusive.

## ◆ ClassifyDiagnostic() [1/5]

static StringRef ClassifyDiagnostic | ( | const CapabilityAttr * | A | ) |
| static

Definition at line 1222 of file ThreadSafety.cpp.

Referenced by ClassifyDiagnostic(), and getStaticBooleanValue().

## ◆ ClassifyDiagnostic() [2/5]

static StringRef ClassifyDiagnostic | ( | QualType | VDT | ) |
| static

Definition at line 1226 of file ThreadSafety.cpp.

References ClassifyDiagnostic(), clang::Type::getAs(), clang::Type::getPointeeType(), clang::Type::isPointerType(), and clang::Type::isReferenceType().

## ◆ ClassifyDiagnostic() [3/5]

static StringRef ClassifyDiagnostic | ( | const ValueDecl * | VD | ) |
| static

Definition at line 1244 of file ThreadSafety.cpp.

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

## ◆ ClassifyDiagnostic() [4/5]

template<typename AttrTy >

static std::enable_if<!has_arg_iterator_range<AttrTy>::value, StringRef>::type ClassifyDiagnostic | ( | const AttrTy * | A | ) |
| static

Definition at line 1254 of file ThreadSafety.cpp.

References ClassifyDiagnostic(), and getValueDecl().

## ◆ ClassifyDiagnostic() [5/5]

template<typename AttrTy >

static std::enable_if<has_arg_iterator_range<AttrTy>::value, StringRef>::type ClassifyDiagnostic | ( | const AttrTy * | A | ) |
| static

Definition at line 1263 of file ThreadSafety.cpp.

References ClassifyDiagnostic(), getValueDecl(), clang::threadSafety::CapabilityExpr::isInvalid(), clang::threadSafety::LK_Generic, P, clang::threadSafety::CapabilityExpr::sexpr(), clang::threadSafety::CapabilityExpr::shouldIgnore(), clang::CFGBlock::succ_begin(), clang::CFGBlock::succ_end(), clang::threadSafety::CapabilityExpr::toString(), and warnInvalidLock().

## ◆ findBlockLocations()

static void 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 811 of file ThreadSafety.cpp.

References clang::DeclStmt::getBeginLoc(), clang::CFG::getExit(), clang::threadSafety::ThreadSafetyHandler::handleDoubleLock(), clang::threadSafety::ThreadSafetyHandler::handleMutexHeldEndOfScope(), clang::threadSafety::ThreadSafetyHandler::handleUnmatchedUnlock(), clang::threadSafety::LK_Exclusive, clang::threadSafety::LK_Shared, clang::threadSafety::CapabilityExpr::negative(), clang::threadSafety::CapabilityExpr::sexpr(), clang::threadSafety::sx::toString(), toString(), and clang::threadSafety::CapabilityExpr::toString().

## ◆ findConstructorForByValueReturn()

static CXXConstructorDecl* findConstructorForByValueReturn | ( | const CXXRecordDecl * | RD | ) |
| static

Definition at line 2105 of file ThreadSafety.cpp.

References clang::CXXRecordDecl::ctors(), and clang::CXXConstructorDecl::isCopyConstructor().

Referenced by buildFakeCtorCall().

## ◆ getStaticBooleanValue()

static bool getStaticBooleanValue | ( | Expr * | E,
|  | bool & | TCond
| ) |  |
| static

Definition at line 1406 of file ThreadSafety.cpp.

References clang::threadSafety::AK_Read, clang::threadSafety::AK_Written, clang::CXXConstructExpr::arg_begin(), clang::CallExpr::arg_begin(), clang::CXXConstructExpr::arg_end(), clang::CallExpr::arg_end(), clang::Decl::attrs(), ClassifyDiagnostic(), clang::CXXConstructExpr::getArg(), clang::Decl::getASTContext(), clang::CFGBlock::getBlockID(), clang::CallExpr::getCalleeDecl(), clang::CastExpr::getCastKind(), clang::CXXConstructExpr::getConstructor(), clang::CallExpr::getDirectCallee(), clang::Expr::getExprLoc(), clang::Attr::getKind(), clang::BinaryOperator::getLHS(), clang::Decl::getLocation(), clang::threadSafety::getLockKindFromAccessKind(), clang::NamedDecl::getNameAsString(), clang::UnaryOperator::getOpcode(), clang::DeclContext::getParent(), clang::UnaryOperator::getSubExpr(), clang::CastExpr::getSubExpr(), clang::CFGBlock::getTerminator(), clang::CFGBlock::getTerminatorCondition(), clang::ValueDecl::getType(), getValueDecl(), clang::Decl::hasAttr(), clang::Decl::hasAttrs(), clang::Expr::IgnoreImplicit(), clang::Expr::IgnoreParenCasts(), clang::BinaryOperator::isAssignmentOp(), clang::CXXConstructorDecl::isCopyConstructor(), clang::threadSafety::CapabilityExpr::isInvalid(), clang::Type::isReferenceType(), clang::threadSafety::LK_Exclusive, clang::threadSafety::LK_Generic, clang::threadSafety::LK_Shared, clang::threadSafety::CapabilityExpr::negative(), clang::FunctionDecl::parameters(), clang::threadSafety::POK_FunctionCall, clang::threadSafety::POK_PassByRef, clang::threadSafety::POK_PtPassByRef, clang::threadSafety::POK_VarAccess, clang::threadSafety::POK_VarDereference, clang::threadSafety::CapabilityExpr::shouldIgnore(), clang::Decl::specific_attrs(), clang::Target, toString(), clang::threadSafety::CapabilityExpr::toString(), clang::VK_LValue, and warnInvalidLock().

## ◆ getValueDecl()

static const ValueDecl* getValueDecl | ( | const Expr * | Exp | ) |
| static

Gets the value decl pointer from DeclRefExprs or MemberExprs.

Definition at line 1190 of file ThreadSafety.cpp.

Referenced by ClassifyDiagnostic(), and getStaticBooleanValue().

## ◆ neverReturns()

static bool neverReturns | ( | const CFGBlock * | B | ) |
| static

Definition at line 2234 of file ThreadSafety.cpp.

References clang::CFGBlock::back(), clang::CFGBlock::empty(), clang::CFGElement::getAs(), clang::threadSafety::CFGWalker::getDecl(), clang::threadSafety::CFGWalker::getGraph(), clang::CFGBlock::hasNoReturnElement(), clang::threadSafety::CFGWalker::init(), and clang::Last.

## ◆ warnInvalidLock()

static void 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 70 of file ThreadSafety.cpp.

References clang::threadSafety::CapabilityExpr::equals(), clang::Expr::getExprLoc(), clang::threadSafety::ThreadSafetyHandler::handleInvalidLockExp(), clang::SourceLocation::isValid(), clang::threadSafety::LK_Exclusive, clang::threadSafety::LK_Shared, and clang::threadSafety::sx::matches().

Referenced by ClassifyDiagnostic(), and getStaticBooleanValue().