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) &&
292 if (
auto *
P = dyn_cast<til::Project>(CapExpr))
293 return P->clangDecl();
339 : Arena(A), SelfVar(nullptr), Scfg(nullptr), CurrentBB(nullptr),
340 CurrentBlockInfo(nullptr) {
374 const Expr *SelfE =
nullptr);
392 til::SExpr *translateAbstractConditionalOperator(
398 typedef llvm::DenseMap<const Stmt*, til::SExpr*> StatementMap;
401 typedef llvm::DenseMap<const ValueDecl *, unsigned> LVarIndexMap;
404 typedef std::pair<const ValueDecl *, til::SExpr *> NameVarPair;
408 LVarDefinitionMap ExitMap;
410 unsigned UnprocessedSuccessors;
411 unsigned ProcessedPredecessors;
414 : HasBackEdges(
false), UnprocessedSuccessors(0),
415 ProcessedPredecessors(0) {}
416 BlockInfo(BlockInfo &&RHS)
417 : ExitMap(std::move(RHS.ExitMap)),
418 HasBackEdges(RHS.HasBackEdges),
419 UnprocessedSuccessors(RHS.UnprocessedSuccessors),
420 ProcessedPredecessors(RHS.ProcessedPredecessors) {}
422 BlockInfo &operator=(BlockInfo &&RHS) {
424 ExitMap = std::move(RHS.ExitMap);
425 HasBackEdges = RHS.HasBackEdges;
426 UnprocessedSuccessors = RHS.UnprocessedSuccessors;
427 ProcessedPredecessors = RHS.ProcessedPredecessors;
433 BlockInfo(
const BlockInfo &) =
delete;
434 void operator=(
const BlockInfo &) =
delete;
441 void enterCFGBlock(
const CFGBlock *B);
442 bool visitPredecessors() {
return true; }
443 void handlePredecessor(
const CFGBlock *Pred);
444 void handlePredecessorBackEdge(
const CFGBlock *Pred);
445 void enterCFGBlockBody(
const CFGBlock *B);
446 void handleStatement(
const Stmt *
S);
448 void exitCFGBlockBody(
const CFGBlock *B);
449 bool visitSuccessors() {
return true; }
450 void handleSuccessor(
const CFGBlock *Succ);
451 void handleSuccessorBackEdge(
const CFGBlock *Succ);
452 void exitCFGBlock(
const CFGBlock *B);
455 void insertStmt(
const Stmt *
S, til::SExpr *E) {
456 SMap.insert(std::make_pair(S, E));
458 til::SExpr *getCurrentLVarDefinition(
const ValueDecl *VD);
460 til::SExpr *addStatement(til::SExpr *E,
const Stmt *S,
461 const ValueDecl *VD =
nullptr);
462 til::SExpr *lookupVarDecl(
const ValueDecl *VD);
463 til::SExpr *addVarDecl(
const ValueDecl *VD, til::SExpr *E);
464 til::SExpr *updateVarDecl(
const ValueDecl *VD, til::SExpr *E);
466 void makePhiNodeVar(
unsigned i,
unsigned NPreds, til::SExpr *E);
467 void mergeEntryMap(LVarDefinitionMap
Map);
468 void mergeEntryMapBackEdge();
469 void mergePhiNodesBackEdge(
const CFGBlock *Blk);
474 static const bool CapabilityExprMode =
true;
476 til::MemRegionRef Arena;
477 til::Variable *SelfVar;
481 LVarIndexMap LVarIdxMap;
482 std::vector<til::BasicBlock *> BlockMap;
483 std::vector<BlockInfo> BBInfo;
486 LVarDefinitionMap CurrentLVarMap;
487 std::vector<til::Phi*> CurrentArguments;
488 std::vector<til::SExpr*> CurrentInstructions;
489 std::vector<til::Phi*> IncompleteArgs;
490 til::BasicBlock *CurrentBB;
491 BlockInfo *CurrentBlockInfo;
503 #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)
bool equals(const CapabilityExpr &other) const
const ValueDecl * valueDecl() const
til::SCFG * buildCFG(CFGWalker &Walker)
const til::SCFG * getCFG() const
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. This method is for tracking visited blocks in t...
const VarDecl * getVarDecl() const
Implements a set of CFGBlocks using a BitVector.
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
const Decl * getDecl() const
Represents the this expression in C++.
bool init(AnalysisDeclContext &AC)
bool equals(const til::SExpr *E1, const til::SExpr *E2)
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
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. This is the important method for the SetType templ...
bool partiallyMatches(const til::SExpr *E1, const til::SExpr *E2)
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. The lexical context includes the arguments to th...
AdjacentBlocks::const_iterator const_succ_iterator
CapabilityExpr(const til::SExpr *E, bool Neg)
const Expr *const * FunArgs
CapabilityExpr operator!() const
til::BasicBlock * lookupBlock(const CFGBlock *B)
std::string toString(const til::SExpr *E)
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
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. Constructs the context from D...
CallingContext(CallingContext *P, const NamedDecl *D=nullptr)
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
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)
SFunction (self) parameter.
llvm::DenseMap< const Stmt *, CFGBlock * > SMap