22 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H 23 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H 33 #include "llvm/ADT/DenseMap.h" 34 #include "llvm/ADT/SmallVector.h" 35 #include "llvm/Support/Casting.h" 43 class AbstractConditionalOperator;
44 class ArraySubscriptExpr;
48 class CXXDestructorDecl;
49 class CXXMemberCallExpr;
50 class CXXOperatorCallExpr;
59 namespace threadSafety {
72 if (isa<til::Wildcard>(E1))
73 return isa<til::Wildcard>(E2);
74 if (isa<til::Wildcard>(E2))
75 return isa<til::Wildcard>(E1);
81 const auto *PE1 = dyn_cast_or_null<til::Project>(E1);
84 const auto *PE2 = dyn_cast_or_null<til::Project>(E2);
87 return PE1->clangDecl() == PE2->clangDecl();
106 void enterCFGBlock(
const CFGBlock *B) {}
109 bool visitPredecessors() {
return true; }
112 void handlePredecessor(
const CFGBlock *Pred) {}
115 void handlePredecessorBackEdge(
const CFGBlock *Pred) {}
118 void enterCFGBlockBody(
const CFGBlock *B) {}
121 void handleStatement(
const Stmt *S) {}
127 void exitCFGBlockBody(
const CFGBlock *B) {}
130 bool visitSuccessors() {
return true; }
133 void handleSuccessor(
const CFGBlock *Succ) {}
136 void handleSuccessorBackEdge(
const CFGBlock *Succ) {}
139 void exitCFGBlock(
const CFGBlock *B) {}
159 if (!dyn_cast_or_null<NamedDecl>(AC.
getDecl()))
170 template <
class Visitor>
174 V.enterCFG(CFGraph, getDecl(), &CFGraph->getEntry());
176 for (
const auto *CurrBlock : *SortedGraph) {
177 VisitedBlocks.
insert(CurrBlock);
179 V.enterCFGBlock(CurrBlock);
182 if (V.visitPredecessors()) {
186 SE = CurrBlock->pred_end();
192 BackEdges.push_back(*SI);
195 V.handlePredecessor(*SI);
198 for (
auto *Blk : BackEdges)
199 V.handlePredecessorBackEdge(Blk);
202 V.enterCFGBlockBody(CurrBlock);
205 for (
const auto &BI : *CurrBlock) {
206 switch (BI.getKind()) {
216 V.handleDestructorCall(VD, DD);
224 V.exitCFGBlockBody(CurrBlock);
227 if (V.visitSuccessors()) {
232 SE = CurrBlock->succ_end();
238 ForwardEdges.push_back(*SI);
241 V.handleSuccessorBackEdge(*SI);
244 for (
auto *Blk : ForwardEdges)
245 V.handleSuccessor(Blk);
248 V.exitCFGBlock(CurrBlock);
250 V.exitCFG(&CFGraph->getExit());
257 return dyn_cast<
NamedDecl>(ACtx->getDecl());
263 CFG *CFGraph =
nullptr;
290 return (Negated == other.Negated) &&
sx::equals(CapExpr, other.CapExpr);
294 return (Negated == other.Negated) &&
sx::matches(CapExpr, other.CapExpr);
298 return isUniversal() ||
matches(CapE);
302 return (Negated == other.Negated) &&
307 if (Negated || CapExpr ==
nullptr)
309 if (
const auto *
P = dyn_cast<til::Project>(CapExpr))
310 return P->clangDecl();
311 if (
const auto *
P = dyn_cast<til::LiteralPtr>(CapExpr))
312 return P->clangDecl();
324 bool isInvalid()
const {
return sexpr() && isa<til::Undefined>(sexpr()); }
326 bool isUniversal()
const {
return sexpr() && isa<til::Wildcard>(sexpr()); }
352 unsigned NumArgs = 0;
355 const Expr *
const *FunArgs =
nullptr;
358 bool SelfArrow =
false;
361 : Prev(P), AttrDecl(D) {}
401 const Expr *SelfE =
nullptr);
419 til::SExpr *translateAbstractConditionalOperator(
425 using StatementMap = llvm::DenseMap<const Stmt *, til::SExpr *>;
428 using LVarIndexMap = llvm::DenseMap<const ValueDecl *, unsigned>;
431 using NameVarPair = std::pair<const ValueDecl *, til::SExpr *>;
436 bool HasBackEdges =
false;
439 unsigned UnprocessedSuccessors = 0;
442 unsigned ProcessedPredecessors = 0;
444 BlockInfo() =
default;
445 BlockInfo(BlockInfo &&) =
default;
446 BlockInfo &operator=(BlockInfo &&) =
default;
450 void enterCFGBlock(
const CFGBlock *B);
451 bool visitPredecessors() {
return true; }
452 void handlePredecessor(
const CFGBlock *Pred);
453 void handlePredecessorBackEdge(
const CFGBlock *Pred);
454 void enterCFGBlockBody(
const CFGBlock *B);
455 void handleStatement(
const Stmt *S);
457 void exitCFGBlockBody(
const CFGBlock *B);
458 bool visitSuccessors() {
return true; }
459 void handleSuccessor(
const CFGBlock *Succ);
460 void handleSuccessorBackEdge(
const CFGBlock *Succ);
461 void exitCFGBlock(
const CFGBlock *B);
465 SMap.insert(std::make_pair(S, E));
476 void makePhiNodeVar(
unsigned i,
unsigned NPreds,
til::SExpr *E);
478 void mergeEntryMapBackEdge();
479 void mergePhiNodesBackEdge(
const CFGBlock *Blk);
484 static const bool CapabilityExprMode =
true;
497 LVarIndexMap LVarIdxMap;
500 std::vector<til::BasicBlock *> BlockMap;
503 std::vector<BlockInfo> BBInfo;
506 std::vector<til::Phi *> CurrentArguments;
507 std::vector<til::SExpr *> CurrentInstructions;
508 std::vector<til::Phi *> IncompleteArgs;
510 BlockInfo *CurrentBlockInfo =
nullptr;
519 #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 ...
Expr - 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
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