21 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H 22 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H 32 #include "llvm/ADT/DenseMap.h" 33 #include "llvm/ADT/SmallVector.h" 34 #include "llvm/Support/Casting.h" 42 class AbstractConditionalOperator;
43 class ArraySubscriptExpr;
47 class CXXDestructorDecl;
48 class CXXMemberCallExpr;
49 class CXXOperatorCallExpr;
58 namespace threadSafety {
71 if (isa<til::Wildcard>(E1))
72 return isa<til::Wildcard>(E2);
73 if (isa<til::Wildcard>(E2))
74 return isa<til::Wildcard>(E1);
80 const auto *PE1 = dyn_cast_or_null<til::Project>(E1);
83 const auto *PE2 = dyn_cast_or_null<til::Project>(E2);
86 return PE1->clangDecl() == PE2->clangDecl();
105 void enterCFGBlock(
const CFGBlock *B) {}
108 bool visitPredecessors() {
return true; }
111 void handlePredecessor(
const CFGBlock *Pred) {}
114 void handlePredecessorBackEdge(
const CFGBlock *Pred) {}
117 void enterCFGBlockBody(
const CFGBlock *B) {}
120 void handleStatement(
const Stmt *S) {}
126 void exitCFGBlockBody(
const CFGBlock *B) {}
129 bool visitSuccessors() {
return true; }
132 void handleSuccessor(
const CFGBlock *Succ) {}
135 void handleSuccessorBackEdge(
const CFGBlock *Succ) {}
138 void exitCFGBlock(
const CFGBlock *B) {}
158 if (!dyn_cast_or_null<NamedDecl>(AC.
getDecl()))
169 template <
class Visitor>
173 V.enterCFG(CFGraph, getDecl(), &CFGraph->getEntry());
175 for (
const auto *CurrBlock : *SortedGraph) {
176 VisitedBlocks.
insert(CurrBlock);
178 V.enterCFGBlock(CurrBlock);
181 if (V.visitPredecessors()) {
185 SE = CurrBlock->pred_end();
191 BackEdges.push_back(*SI);
194 V.handlePredecessor(*SI);
197 for (
auto *Blk : BackEdges)
198 V.handlePredecessorBackEdge(Blk);
201 V.enterCFGBlockBody(CurrBlock);
204 for (
const auto &BI : *CurrBlock) {
205 switch (BI.getKind()) {
215 V.handleDestructorCall(VD, DD);
223 V.exitCFGBlockBody(CurrBlock);
226 if (V.visitSuccessors()) {
231 SE = CurrBlock->succ_end();
237 ForwardEdges.push_back(*SI);
240 V.handleSuccessorBackEdge(*SI);
243 for (
auto *Blk : ForwardEdges)
244 V.handleSuccessor(Blk);
247 V.exitCFGBlock(CurrBlock);
249 V.exitCFG(&CFGraph->getExit());
256 return dyn_cast<
NamedDecl>(ACtx->getDecl());
262 CFG *CFGraph =
nullptr;
289 return (Negated == other.Negated) &&
sx::equals(CapExpr, other.CapExpr);
293 return (Negated == other.Negated) &&
sx::matches(CapExpr, other.CapExpr);
297 return isUniversal() ||
matches(CapE);
301 return (Negated == other.Negated) &&
306 if (Negated || CapExpr ==
nullptr)
308 if (
const auto *
P = dyn_cast<til::Project>(CapExpr))
309 return P->clangDecl();
310 if (
const auto *
P = dyn_cast<til::LiteralPtr>(CapExpr))
311 return P->clangDecl();
323 bool isInvalid()
const {
return sexpr() && isa<til::Undefined>(sexpr()); }
325 bool isUniversal()
const {
return sexpr() && isa<til::Wildcard>(sexpr()); }
351 unsigned NumArgs = 0;
354 const Expr *
const *FunArgs =
nullptr;
357 bool SelfArrow =
false;
360 : Prev(P), AttrDecl(D) {}
402 const Expr *SelfE =
nullptr);
420 til::SExpr *translateAbstractConditionalOperator(
426 using StatementMap = llvm::DenseMap<const Stmt *, til::SExpr *>;
429 using LVarIndexMap = llvm::DenseMap<const ValueDecl *, unsigned>;
432 using NameVarPair = std::pair<const ValueDecl *, til::SExpr *>;
437 bool HasBackEdges =
false;
440 unsigned UnprocessedSuccessors = 0;
443 unsigned ProcessedPredecessors = 0;
445 BlockInfo() =
default;
446 BlockInfo(BlockInfo &&) =
default;
447 BlockInfo &operator=(BlockInfo &&) =
default;
451 void enterCFGBlock(
const CFGBlock *B);
452 bool visitPredecessors() {
return true; }
453 void handlePredecessor(
const CFGBlock *Pred);
454 void handlePredecessorBackEdge(
const CFGBlock *Pred);
455 void enterCFGBlockBody(
const CFGBlock *B);
456 void handleStatement(
const Stmt *S);
458 void exitCFGBlockBody(
const CFGBlock *B);
459 bool visitSuccessors() {
return true; }
460 void handleSuccessor(
const CFGBlock *Succ);
461 void handleSuccessorBackEdge(
const CFGBlock *Succ);
462 void exitCFGBlock(
const CFGBlock *B);
466 SMap.insert(std::make_pair(S, E));
477 void makePhiNodeVar(
unsigned i,
unsigned NPreds,
til::SExpr *E);
479 void mergeEntryMapBackEdge();
480 void mergePhiNodesBackEdge(
const CFGBlock *Blk);
485 static const bool CapabilityExprMode =
true;
498 LVarIndexMap LVarIdxMap;
501 std::vector<til::BasicBlock *> BlockMap;
504 std::vector<BlockInfo> BBInfo;
507 std::vector<til::Phi *> CurrentArguments;
508 std::vector<til::SExpr *> CurrentInstructions;
509 std::vector<til::Phi *> IncompleteArgs;
511 BlockInfo *CurrentBlockInfo =
nullptr;
520 #endif // LLVM_CLANG_THREAD_SAFETY_COMMON_H A call to an overloaded operator written using operator syntax.
SExprBuilder(til::MemRegionRef A)
const PostOrderCFGView * getSortedGraph() const
bool equals(const CapabilityExpr &other) const
AdjacentBlocks::const_iterator const_pred_iterator
const Stmt * getStmt() const
const CFG * getGraph() const
Stmt - This represents one statement.
bool partiallyMatches(const CapabilityExpr &other) const
unsigned getBlockID() const
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
std::string toString() const
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
Represents a variable declaration or definition.
const til::SCFG * getCFG() const
const til::SExpr * sexpr() const
AnalysisDeclContext contains the context data for the function or method under analysis.
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
AdjacentBlocks::const_iterator const_succ_iterator
bool alreadySet(const CFGBlock *Block)
Check if the bit for a CFGBlock has been already set.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Implements a set of CFGBlocks using a BitVector.
T * getAnalysis()
Return the specified analysis object, lazily running the analysis if necessary.
A builtin binary operation expression such as "x + y" or "x <= y".
static void print(const SExpr *E, std::ostream &SS)
A basic block is part of an SCFG.
const VarDecl * getVarDecl() const
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Represents the this expression in C++.
An SCFG is a control-flow graph.
bool init(AnalysisDeclContext &AC)
Represents a single basic block in a source-level CFG.
bool equals(const til::SExpr *E1, const til::SExpr *E2)
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Represents a C++ destructor within a class.
void printSCFG(CFGWalker &Walker)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
bool matches(const CapabilityExpr &other) const
static bool compareExprs(const SExpr *E1, const SExpr *E2)
bool matchesUniv(const CapabilityExpr &CapE) const
TIL_BinaryOpcode
Opcode for binary arithmetic operations.
std::pair< llvm::NoneType, bool > insert(const CFGBlock *Block)
Set the bit associated with a particular CFGBlock.
bool partiallyMatches(const til::SExpr *E1, const til::SExpr *E2)
Represents a call to a member function that may be written either with member call syntax (e...
DeclStmt - Adaptor class for mixing declarations with statements and expressions. ...
void setKind(VariableKind K)
const Decl * getDecl() const
Encapsulates the lexical context of a function call.
bool shouldIgnore() const
CapabilityExpr(const til::SExpr *E, bool Neg)
Dataflow Directional Tag Classes.
CapabilityExpr operator!() const
til::BasicBlock * lookupBlock(const CFGBlock *B)
std::string toString(const til::SExpr *E)
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
const NamedDecl * getDecl() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
CallingContext(CallingContext *P, const NamedDecl *D=nullptr)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
A reference to a declared variable, function, enum, etc.
const ValueDecl * valueDecl() const
const NamedDecl * AttrDecl
Base class for AST nodes in the typed intermediate language.
bool matches(const til::SExpr *E1, const til::SExpr *E2)
static bool compareExprs(const SExpr *E1, const SExpr *E2)
This represents a decl that may have a name.
SFunction (self) parameter.
llvm::DenseMap< const Stmt *, CFGBlock * > SMap