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>
156 V.enterCFG(CFGraph, getDecl(), &CFGraph->getEntry());
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());
239 return dyn_cast<
NamedDecl>(ACtx->getDecl());
273 return (Negated == other.Negated) &&
sx::equals(CapExpr, other.CapExpr);
277 return (Negated == other.Negated) &&
sx::matches(CapExpr, other.CapExpr);
281 return isUniversal() ||
matches(CapE);
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();
307 bool isInvalid()
const {
return sexpr() && isa<til::Undefined>(sexpr()); }
309 bool isUniversal()
const {
return sexpr() && isa<til::Wildcard>(sexpr()); }
335 : Prev(P), AttrDecl(D), SelfArg(nullptr),
336 NumArgs(0), FunArgs(nullptr), SelfArrow(
false)
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 &&) =
default;
419 BlockInfo &operator=(BlockInfo &&) =
default;
426 void enterCFGBlock(
const CFGBlock *B);
427 bool visitPredecessors() {
return true; }
428 void handlePredecessor(
const CFGBlock *Pred);
429 void handlePredecessorBackEdge(
const CFGBlock *Pred);
430 void enterCFGBlockBody(
const CFGBlock *B);
431 void handleStatement(
const Stmt *S);
433 void exitCFGBlockBody(
const CFGBlock *B);
434 bool visitSuccessors() {
return true; }
435 void handleSuccessor(
const CFGBlock *Succ);
436 void handleSuccessorBackEdge(
const CFGBlock *Succ);
437 void exitCFGBlock(
const CFGBlock *B);
441 SMap.insert(std::make_pair(S, E));
451 void makePhiNodeVar(
unsigned i,
unsigned NPreds,
til::SExpr *E);
452 void mergeEntryMap(LVarDefinitionMap Map);
453 void mergeEntryMapBackEdge();
454 void mergePhiNodesBackEdge(
const CFGBlock *Blk);
459 static const bool CapabilityExprMode =
true;
466 LVarIndexMap LVarIdxMap;
467 std::vector<til::BasicBlock *> BlockMap;
468 std::vector<BlockInfo> BBInfo;
471 LVarDefinitionMap CurrentLVarMap;
472 std::vector<til::Phi*> CurrentArguments;
473 std::vector<til::SExpr*> CurrentInstructions;
474 std::vector<til::Phi*> IncompleteArgs;
476 BlockInfo *CurrentBlockInfo;
488 #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
VarDecl - An instance of this class is created to represent 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.
CFGAutomaticObjDtor - Represents C++ object destructor implicitly generated for automatic object or t...
AdjacentBlocks::const_iterator const_succ_iterator
bool alreadySet(const CFGBlock *Block)
Check if the bit for a CFGBlock has been already set.
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)
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.
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
const Expr *const * FunArgs
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
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)
NamedDecl - This represents a decl with a name.
SFunction (self) parameter.
llvm::DenseMap< const Stmt *, CFGBlock * > SMap