22 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H
23 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H
37 namespace threadSafety {
51 if (isa<til::Wildcard>(E1))
52 return isa<til::Wildcard>(E2);
53 if (isa<til::Wildcard>(E2))
54 return isa<til::Wildcard>(E1);
60 const auto *PE1 = dyn_cast_or_null<til::Project>(E1);
63 const auto *PE2 = dyn_cast_or_null<til::Project>(E2);
66 return PE1->clangDecl() == PE2->clangDecl();
87 void enterCFGBlock(
const CFGBlock *B) {}
90 bool visitPredecessors() {
return true; }
93 void handlePredecessor(
const CFGBlock *Pred) {}
96 void handlePredecessorBackEdge(
const CFGBlock *Pred) {}
99 void enterCFGBlockBody(
const CFGBlock *B) {}
102 void handleStatement(
const Stmt *
S) {}
108 void exitCFGBlockBody(
const CFGBlock *B) {}
111 bool visitSuccessors() {
return true; }
114 void handleSuccessor(
const CFGBlock *Succ) {}
117 void handleSuccessorBackEdge(
const CFGBlock *Succ) {}
120 void exitCFGBlock(
const CFGBlock *B) {}
130 CFGWalker() : CFGraph(nullptr), ACtx(nullptr), SortedGraph(nullptr) {}
141 if (!dyn_cast_or_null<NamedDecl>(AC.
getDecl()))
152 template <
class Visitor>
158 for (
const auto *CurrBlock : *SortedGraph) {
159 VisitedBlocks.
insert(CurrBlock);
161 V.enterCFGBlock(CurrBlock);
164 if (V.visitPredecessors()) {
168 SE = CurrBlock->pred_end();
174 BackEdges.push_back(*SI);
177 V.handlePredecessor(*SI);
180 for (
auto *Blk : BackEdges)
181 V.handlePredecessorBackEdge(Blk);
184 V.enterCFGBlockBody(CurrBlock);
187 for (
const auto &BI : *CurrBlock) {
188 switch (BI.getKind()) {
198 V.handleDestructorCall(VD, DD);
206 V.exitCFGBlockBody(CurrBlock);
209 if (V.visitSuccessors()) {
214 SE = CurrBlock->succ_end();
220 ForwardEdges.push_back(*SI);
223 V.handleSuccessorBackEdge(*SI);
226 for (
auto *Blk : ForwardEdges)
227 V.handleSuccessor(Blk);
230 V.exitCFGBlock(CurrBlock);
232 V.exitCFG(&CFGraph->
getExit());
273 return (Negated == other.Negated) &&
sx::equals(CapExpr, other.CapExpr);
277 return (Negated == other.Negated) &&
sx::matches(CapExpr, other.CapExpr);
285 return (Negated == other.Negated) &&
290 if (Negated || CapExpr ==
nullptr)
292 if (
auto *
P = dyn_cast<til::Project>(CapExpr))
293 return P->clangDecl();
294 if (
auto *
P = dyn_cast<til::LiteralPtr>(CapExpr))
295 return P->clangDecl();
341 : Arena(A), SelfVar(nullptr), Scfg(nullptr), CurrentBB(nullptr),
342 CurrentBlockInfo(nullptr) {
376 const Expr *SelfE =
nullptr);
394 til::SExpr *translateAbstractConditionalOperator(
400 typedef llvm::DenseMap<const Stmt*, til::SExpr*> StatementMap;
403 typedef llvm::DenseMap<const ValueDecl *, unsigned> LVarIndexMap;
406 typedef std::pair<const ValueDecl *, til::SExpr *> NameVarPair;
410 LVarDefinitionMap ExitMap;
412 unsigned UnprocessedSuccessors;
413 unsigned ProcessedPredecessors;
416 : HasBackEdges(
false), UnprocessedSuccessors(0),
417 ProcessedPredecessors(0) {}
418 BlockInfo(BlockInfo &&RHS)
419 : ExitMap(std::move(RHS.ExitMap)),
420 HasBackEdges(RHS.HasBackEdges),
421 UnprocessedSuccessors(RHS.UnprocessedSuccessors),
422 ProcessedPredecessors(RHS.ProcessedPredecessors) {}
424 BlockInfo &operator=(BlockInfo &&RHS) {
426 ExitMap = std::move(RHS.ExitMap);
427 HasBackEdges = RHS.HasBackEdges;
428 UnprocessedSuccessors = RHS.UnprocessedSuccessors;
429 ProcessedPredecessors = RHS.ProcessedPredecessors;
435 BlockInfo(
const BlockInfo &) =
delete;
436 void operator=(
const BlockInfo &) =
delete;
443 void enterCFGBlock(
const CFGBlock *B);
444 bool visitPredecessors() {
return true; }
445 void handlePredecessor(
const CFGBlock *Pred);
446 void handlePredecessorBackEdge(
const CFGBlock *Pred);
447 void enterCFGBlockBody(
const CFGBlock *B);
448 void handleStatement(
const Stmt *
S);
450 void exitCFGBlockBody(
const CFGBlock *B);
451 bool visitSuccessors() {
return true; }
452 void handleSuccessor(
const CFGBlock *Succ);
453 void handleSuccessorBackEdge(
const CFGBlock *Succ);
454 void exitCFGBlock(
const CFGBlock *B);
457 void insertStmt(
const Stmt *
S, til::SExpr *
E) {
458 SMap.insert(std::make_pair(S, E));
460 til::SExpr *getCurrentLVarDefinition(
const ValueDecl *VD);
462 til::SExpr *addStatement(til::SExpr *E,
const Stmt *S,
463 const ValueDecl *VD =
nullptr);
464 til::SExpr *lookupVarDecl(
const ValueDecl *VD);
465 til::SExpr *addVarDecl(
const ValueDecl *VD, til::SExpr *E);
466 til::SExpr *updateVarDecl(
const ValueDecl *VD, til::SExpr *E);
468 void makePhiNodeVar(
unsigned i,
unsigned NPreds, til::SExpr *E);
469 void mergeEntryMap(LVarDefinitionMap
Map);
470 void mergeEntryMapBackEdge();
471 void mergePhiNodesBackEdge(
const CFGBlock *Blk);
476 static const bool CapabilityExprMode =
true;
478 til::MemRegionRef Arena;
479 til::Variable *SelfVar;
483 LVarIndexMap LVarIdxMap;
484 std::vector<til::BasicBlock *> BlockMap;
485 std::vector<BlockInfo> BBInfo;
488 LVarDefinitionMap CurrentLVarMap;
489 std::vector<til::Phi*> CurrentArguments;
490 std::vector<til::SExpr*> CurrentInstructions;
491 std::vector<til::Phi*> IncompleteArgs;
492 til::BasicBlock *CurrentBB;
493 BlockInfo *CurrentBlockInfo;
505 #endif // LLVM_CLANG_THREAD_SAFETY_COMMON_H
A call to an overloaded operator written using operator syntax.
SExprBuilder(til::MemRegionRef A)
til::SExpr * lookupStmt(const Stmt *S)
ASTContext & getASTContext() const
bool partiallyMatches(const CapabilityExpr &other) const
til::SExpr * translate(const Stmt *S, CallingContext *Ctx)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
bool equals(const CapabilityExpr &other) const
const ValueDecl * valueDecl() const
til::SCFG * buildCFG(CFGWalker &Walker)
const til::SCFG * getCFG() const
AnalysisDeclContext contains the context data for the function or method under analysis.
CFGAutomaticObjDtor - Represents C++ object destructor implicitly generated for automatic object or t...
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type...
bool alreadySet(const CFGBlock *Block)
Check if the bit for a CFGBlock has been already set.
const VarDecl * getVarDecl() const
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)
bool shouldIgnore() const
const NamedDecl * getDecl() const
A basic block is part of an SCFG.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
const Decl * getDecl() const
Represents the this expression in C++.
An SCFG is a control-flow graph.
bool init(AnalysisDeclContext &AC)
CFGBlock - Represents a single basic block in a source-level CFG.
bool equals(const til::SExpr *E1, const til::SExpr *E2)
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Represents a C++ destructor within a class.
Defines an enumeration for C++ overloaded operators.
bool matchesUniv(const CapabilityExpr &CapE) const
void printSCFG(CFGWalker &Walker)
AdjacentBlocks::const_iterator const_pred_iterator
unsigned getBlockID() const
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
std::string toString() const
const PostOrderCFGView * getSortedGraph() const
bool matches(const CapabilityExpr &other) const
static bool compareExprs(const SExpr *E1, const SExpr *E2)
const til::SExpr * sexpr() 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. ...
const Stmt * getStmt() const
void setKind(VariableKind K)
const CFG * getGraph() const
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
Encapsulates the lexical context of a function call.
AdjacentBlocks::const_iterator const_succ_iterator
CapabilityExpr(const til::SExpr *E, bool Neg)
const Expr *const * FunArgs
CapabilityExpr operator!() const
detail::InMemoryDirectory::const_iterator E
unsigned Map[Count]
The type of a lookup table which maps from language-specific address spaces to target-specific ones...
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...
CapabilityExpr translateAttrExpr(const Expr *AttrExp, const NamedDecl *D, const Expr *DeclExp, VarDecl *SelfD=nullptr)
Translate a clang expression in an attribute to a til::SExpr.
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 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)
NamedDecl - This represents a decl with a name.
SFunction (self) parameter.
llvm::DenseMap< const Stmt *, CFGBlock * > SMap