clang  17.0.0git
ThreadSafetyCommon.h
Go to the documentation of this file.
1 //===- ThreadSafetyCommon.h -------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Parts of thread safety analysis that are not specific to thread safety
10 // itself have been factored into classes here, where they can be potentially
11 // used by other analyses. Currently these include:
12 //
13 // * Generalize clang CFG visitors.
14 // * Conversion of the clang CFG to SSA form.
15 // * Translation of clang Exprs to TIL SExprs
16 //
17 // UNDER CONSTRUCTION. USE AT YOUR OWN RISK.
18 //
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H
22 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H
23 
24 #include "clang/AST/Decl.h"
30 #include "clang/Analysis/CFG.h"
31 #include "clang/Basic/LLVM.h"
32 #include "llvm/ADT/DenseMap.h"
33 #include "llvm/ADT/PointerIntPair.h"
34 #include "llvm/ADT/PointerUnion.h"
35 #include "llvm/ADT/SmallVector.h"
36 #include "llvm/Support/Casting.h"
37 #include <sstream>
38 #include <string>
39 #include <utility>
40 #include <vector>
41 
42 namespace clang {
43 
44 class AbstractConditionalOperator;
45 class ArraySubscriptExpr;
46 class BinaryOperator;
47 class CallExpr;
48 class CastExpr;
49 class CXXDestructorDecl;
50 class CXXMemberCallExpr;
51 class CXXOperatorCallExpr;
52 class CXXThisExpr;
53 class DeclRefExpr;
54 class DeclStmt;
55 class Expr;
56 class MemberExpr;
57 class Stmt;
58 class UnaryOperator;
59 
60 namespace threadSafety {
61 
62 // Various helper functions on til::SExpr
63 namespace sx {
64 
65 inline bool equals(const til::SExpr *E1, const til::SExpr *E2) {
67 }
68 
69 inline bool matches(const til::SExpr *E1, const til::SExpr *E2) {
70  // We treat a top-level wildcard as the "univsersal" lock.
71  // It matches everything for the purpose of checking locks, but not
72  // for unlocking them.
73  if (isa<til::Wildcard>(E1))
74  return isa<til::Wildcard>(E2);
75  if (isa<til::Wildcard>(E2))
76  return isa<til::Wildcard>(E1);
77 
79 }
80 
81 inline bool partiallyMatches(const til::SExpr *E1, const til::SExpr *E2) {
82  const auto *PE1 = dyn_cast_or_null<til::Project>(E1);
83  if (!PE1)
84  return false;
85  const auto *PE2 = dyn_cast_or_null<til::Project>(E2);
86  if (!PE2)
87  return false;
88  return PE1->clangDecl() == PE2->clangDecl();
89 }
90 
91 inline std::string toString(const til::SExpr *E) {
92  std::stringstream ss;
94  return ss.str();
95 }
96 
97 } // namespace sx
98 
99 // This class defines the interface of a clang CFG Visitor.
100 // CFGWalker will invoke the following methods.
101 // Note that methods are not virtual; the visitor is templatized.
102 class CFGVisitor {
103  // Enter the CFG for Decl D, and perform any initial setup operations.
104  void enterCFG(CFG *Cfg, const NamedDecl *D, const CFGBlock *First) {}
105 
106  // Enter a CFGBlock.
107  void enterCFGBlock(const CFGBlock *B) {}
108 
109  // Returns true if this visitor implements handlePredecessor
110  bool visitPredecessors() { return true; }
111 
112  // Process a predecessor edge.
113  void handlePredecessor(const CFGBlock *Pred) {}
114 
115  // Process a successor back edge to a previously visited block.
116  void handlePredecessorBackEdge(const CFGBlock *Pred) {}
117 
118  // Called just before processing statements.
119  void enterCFGBlockBody(const CFGBlock *B) {}
120 
121  // Process an ordinary statement.
122  void handleStatement(const Stmt *S) {}
123 
124  // Process a destructor call
125  void handleDestructorCall(const VarDecl *VD, const CXXDestructorDecl *DD) {}
126 
127  // Called after all statements have been handled.
128  void exitCFGBlockBody(const CFGBlock *B) {}
129 
130  // Return true
131  bool visitSuccessors() { return true; }
132 
133  // Process a successor edge.
134  void handleSuccessor(const CFGBlock *Succ) {}
135 
136  // Process a successor back edge to a previously visited block.
137  void handleSuccessorBackEdge(const CFGBlock *Succ) {}
138 
139  // Leave a CFGBlock.
140  void exitCFGBlock(const CFGBlock *B) {}
141 
142  // Leave the CFG, and perform any final cleanup operations.
143  void exitCFG(const CFGBlock *Last) {}
144 };
145 
146 // Walks the clang CFG, and invokes methods on a given CFGVisitor.
147 class CFGWalker {
148 public:
149  CFGWalker() = default;
150 
151  // Initialize the CFGWalker. This setup only needs to be done once, even
152  // if there are multiple passes over the CFG.
154  ACtx = &AC;
155  CFGraph = AC.getCFG();
156  if (!CFGraph)
157  return false;
158 
159  // Ignore anonymous functions.
160  if (!isa_and_nonnull<NamedDecl>(AC.getDecl()))
161  return false;
162 
163  SortedGraph = AC.getAnalysis<PostOrderCFGView>();
164  if (!SortedGraph)
165  return false;
166 
167  return true;
168  }
169 
170  // Traverse the CFG, calling methods on V as appropriate.
171  template <class Visitor>
172  void walk(Visitor &V) {
173  PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph);
174 
175  V.enterCFG(CFGraph, getDecl(), &CFGraph->getEntry());
176 
177  for (const auto *CurrBlock : *SortedGraph) {
178  VisitedBlocks.insert(CurrBlock);
179 
180  V.enterCFGBlock(CurrBlock);
181 
182  // Process predecessors, handling back edges last
183  if (V.visitPredecessors()) {
184  SmallVector<CFGBlock*, 4> BackEdges;
185  // Process successors
186  for (CFGBlock::const_pred_iterator SI = CurrBlock->pred_begin(),
187  SE = CurrBlock->pred_end();
188  SI != SE; ++SI) {
189  if (*SI == nullptr)
190  continue;
191 
192  if (!VisitedBlocks.alreadySet(*SI)) {
193  BackEdges.push_back(*SI);
194  continue;
195  }
196  V.handlePredecessor(*SI);
197  }
198 
199  for (auto *Blk : BackEdges)
200  V.handlePredecessorBackEdge(Blk);
201  }
202 
203  V.enterCFGBlockBody(CurrBlock);
204 
205  // Process statements
206  for (const auto &BI : *CurrBlock) {
207  switch (BI.getKind()) {
209  V.handleStatement(BI.castAs<CFGStmt>().getStmt());
210  break;
211 
214  auto *DD = const_cast<CXXDestructorDecl *>(
215  AD.getDestructorDecl(ACtx->getASTContext()));
216  auto *VD = const_cast<VarDecl *>(AD.getVarDecl());
217  V.handleDestructorCall(VD, DD);
218  break;
219  }
220  default:
221  break;
222  }
223  }
224 
225  V.exitCFGBlockBody(CurrBlock);
226 
227  // Process successors, handling back edges first.
228  if (V.visitSuccessors()) {
229  SmallVector<CFGBlock*, 8> ForwardEdges;
230 
231  // Process successors
232  for (CFGBlock::const_succ_iterator SI = CurrBlock->succ_begin(),
233  SE = CurrBlock->succ_end();
234  SI != SE; ++SI) {
235  if (*SI == nullptr)
236  continue;
237 
238  if (!VisitedBlocks.alreadySet(*SI)) {
239  ForwardEdges.push_back(*SI);
240  continue;
241  }
242  V.handleSuccessorBackEdge(*SI);
243  }
244 
245  for (auto *Blk : ForwardEdges)
246  V.handleSuccessor(Blk);
247  }
248 
249  V.exitCFGBlock(CurrBlock);
250  }
251  V.exitCFG(&CFGraph->getExit());
252  }
253 
254  const CFG *getGraph() const { return CFGraph; }
255  CFG *getGraph() { return CFGraph; }
256 
257  const NamedDecl *getDecl() const {
258  return dyn_cast<NamedDecl>(ACtx->getDecl());
259  }
260 
261  const PostOrderCFGView *getSortedGraph() const { return SortedGraph; }
262 
263 private:
264  CFG *CFGraph = nullptr;
265  AnalysisDeclContext *ACtx = nullptr;
266  PostOrderCFGView *SortedGraph = nullptr;
267 };
268 
269 // TODO: move this back into ThreadSafety.cpp
270 // This is specific to thread safety. It is here because
271 // translateAttrExpr needs it, but that should be moved too.
273 private:
274  /// The capability expression and whether it's negated.
275  llvm::PointerIntPair<const til::SExpr *, 1, bool> CapExpr;
276 
277  /// The kind of capability as specified by @ref CapabilityAttr::getName.
278  StringRef CapKind;
279 
280 public:
281  CapabilityExpr() : CapExpr(nullptr, false) {}
282  CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
283  : CapExpr(E, Neg), CapKind(Kind) {}
284 
285  // Don't allow implicitly-constructed StringRefs since we'll capture them.
286  template <typename T> CapabilityExpr(const til::SExpr *, T, bool) = delete;
287 
288  const til::SExpr *sexpr() const { return CapExpr.getPointer(); }
289  StringRef getKind() const { return CapKind; }
290  bool negative() const { return CapExpr.getInt(); }
291 
293  return CapabilityExpr(CapExpr.getPointer(), CapKind, !CapExpr.getInt());
294  }
295 
296  bool equals(const CapabilityExpr &other) const {
297  return (negative() == other.negative()) &&
298  sx::equals(sexpr(), other.sexpr());
299  }
300 
301  bool matches(const CapabilityExpr &other) const {
302  return (negative() == other.negative()) &&
303  sx::matches(sexpr(), other.sexpr());
304  }
305 
306  bool matchesUniv(const CapabilityExpr &CapE) const {
307  return isUniversal() || matches(CapE);
308  }
309 
310  bool partiallyMatches(const CapabilityExpr &other) const {
311  return (negative() == other.negative()) &&
312  sx::partiallyMatches(sexpr(), other.sexpr());
313  }
314 
315  const ValueDecl* valueDecl() const {
316  if (negative() || sexpr() == nullptr)
317  return nullptr;
318  if (const auto *P = dyn_cast<til::Project>(sexpr()))
319  return P->clangDecl();
320  if (const auto *P = dyn_cast<til::LiteralPtr>(sexpr()))
321  return P->clangDecl();
322  return nullptr;
323  }
324 
326  if (negative())
327  return "!" + sx::toString(sexpr());
328  return sx::toString(sexpr());
329  }
330 
331  bool shouldIgnore() const { return sexpr() == nullptr; }
332 
333  bool isInvalid() const { return sexpr() && isa<til::Undefined>(sexpr()); }
334 
335  bool isUniversal() const { return sexpr() && isa<til::Wildcard>(sexpr()); }
336 };
337 
338 // Translate clang::Expr to til::SExpr.
340 public:
341  /// Encapsulates the lexical context of a function call. The lexical
342  /// context includes the arguments to the call, including the implicit object
343  /// argument. When an attribute containing a mutex expression is attached to
344  /// a method, the expression may refer to formal parameters of the method.
345  /// Actual arguments must be substituted for formal parameters to derive
346  /// the appropriate mutex expression in the lexical context where the function
347  /// is called. PrevCtx holds the context in which the arguments themselves
348  /// should be evaluated; multiple calling contexts can be chained together
349  /// by the lock_returned attribute.
350  struct CallingContext {
351  // The previous context; or 0 if none.
353 
354  // The decl to which the attr is attached.
356 
357  // Implicit object argument -- e.g. 'this'
358  llvm::PointerUnion<const Expr *, til::SExpr *> SelfArg = nullptr;
359 
360  // Number of funArgs
361  unsigned NumArgs = 0;
362 
363  // Function arguments
364  const Expr *const *FunArgs = nullptr;
365 
366  // is Self referred to with -> or .?
367  bool SelfArrow = false;
368 
369  CallingContext(CallingContext *P, const NamedDecl *D = nullptr)
370  : Prev(P), AttrDecl(D) {}
371  };
372 
374  // FIXME: we don't always have a self-variable.
375  SelfVar = new (Arena) til::Variable(nullptr);
377  }
378 
379  // Translate a clang expression in an attribute to a til::SExpr.
380  // Constructs the context from D, DeclExp, and SelfDecl.
381  CapabilityExpr translateAttrExpr(const Expr *AttrExp, const NamedDecl *D,
382  const Expr *DeclExp,
383  til::SExpr *Self = nullptr);
384 
385  CapabilityExpr translateAttrExpr(const Expr *AttrExp, CallingContext *Ctx);
386 
387  // Translate a variable reference.
389 
390  // Create placeholder for this: we don't know the VarDecl on construction yet.
391  std::pair<til::LiteralPtr *, StringRef>
392  createThisPlaceholder(const Expr *Exp);
393 
394  // Translate a clang statement or expression to a TIL expression.
395  // Also performs substitution of variables; Ctx provides the context.
396  // Dispatches on the type of S.
397  til::SExpr *translate(const Stmt *S, CallingContext *Ctx);
398  til::SCFG *buildCFG(CFGWalker &Walker);
399 
400  til::SExpr *lookupStmt(const Stmt *S);
401 
403  return BlockMap[B->getBlockID()];
404  }
405 
406  const til::SCFG *getCFG() const { return Scfg; }
407  til::SCFG *getCFG() { return Scfg; }
408 
409 private:
410  // We implement the CFGVisitor API
411  friend class CFGWalker;
412 
413  til::SExpr *translateDeclRefExpr(const DeclRefExpr *DRE,
414  CallingContext *Ctx) ;
415  til::SExpr *translateCXXThisExpr(const CXXThisExpr *TE, CallingContext *Ctx);
416  til::SExpr *translateMemberExpr(const MemberExpr *ME, CallingContext *Ctx);
417  til::SExpr *translateObjCIVarRefExpr(const ObjCIvarRefExpr *IVRE,
418  CallingContext *Ctx);
419  til::SExpr *translateCallExpr(const CallExpr *CE, CallingContext *Ctx,
420  const Expr *SelfE = nullptr);
421  til::SExpr *translateCXXMemberCallExpr(const CXXMemberCallExpr *ME,
422  CallingContext *Ctx);
423  til::SExpr *translateCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE,
424  CallingContext *Ctx);
425  til::SExpr *translateUnaryOperator(const UnaryOperator *UO,
426  CallingContext *Ctx);
427  til::SExpr *translateBinOp(til::TIL_BinaryOpcode Op,
428  const BinaryOperator *BO,
429  CallingContext *Ctx, bool Reverse = false);
430  til::SExpr *translateBinAssign(til::TIL_BinaryOpcode Op,
431  const BinaryOperator *BO,
432  CallingContext *Ctx, bool Assign = false);
433  til::SExpr *translateBinaryOperator(const BinaryOperator *BO,
434  CallingContext *Ctx);
435  til::SExpr *translateCastExpr(const CastExpr *CE, CallingContext *Ctx);
436  til::SExpr *translateArraySubscriptExpr(const ArraySubscriptExpr *E,
437  CallingContext *Ctx);
438  til::SExpr *translateAbstractConditionalOperator(
440 
441  til::SExpr *translateDeclStmt(const DeclStmt *S, CallingContext *Ctx);
442 
443  // Map from statements in the clang CFG to SExprs in the til::SCFG.
444  using StatementMap = llvm::DenseMap<const Stmt *, til::SExpr *>;
445 
446  // Map from clang local variables to indices in a LVarDefinitionMap.
447  using LVarIndexMap = llvm::DenseMap<const ValueDecl *, unsigned>;
448 
449  // Map from local variable indices to SSA variables (or constants).
450  using NameVarPair = std::pair<const ValueDecl *, til::SExpr *>;
452 
453  struct BlockInfo {
454  LVarDefinitionMap ExitMap;
455  bool HasBackEdges = false;
456 
457  // Successors yet to be processed
458  unsigned UnprocessedSuccessors = 0;
459 
460  // Predecessors already processed
461  unsigned ProcessedPredecessors = 0;
462 
463  BlockInfo() = default;
464  BlockInfo(BlockInfo &&) = default;
465  BlockInfo &operator=(BlockInfo &&) = default;
466  };
467 
468  void enterCFG(CFG *Cfg, const NamedDecl *D, const CFGBlock *First);
469  void enterCFGBlock(const CFGBlock *B);
470  bool visitPredecessors() { return true; }
471  void handlePredecessor(const CFGBlock *Pred);
472  void handlePredecessorBackEdge(const CFGBlock *Pred);
473  void enterCFGBlockBody(const CFGBlock *B);
474  void handleStatement(const Stmt *S);
475  void handleDestructorCall(const VarDecl *VD, const CXXDestructorDecl *DD);
476  void exitCFGBlockBody(const CFGBlock *B);
477  bool visitSuccessors() { return true; }
478  void handleSuccessor(const CFGBlock *Succ);
479  void handleSuccessorBackEdge(const CFGBlock *Succ);
480  void exitCFGBlock(const CFGBlock *B);
481  void exitCFG(const CFGBlock *Last);
482 
483  void insertStmt(const Stmt *S, til::SExpr *E) {
484  SMap.insert(std::make_pair(S, E));
485  }
486 
487  til::SExpr *getCurrentLVarDefinition(const ValueDecl *VD);
488 
489  til::SExpr *addStatement(til::SExpr *E, const Stmt *S,
490  const ValueDecl *VD = nullptr);
491  til::SExpr *lookupVarDecl(const ValueDecl *VD);
492  til::SExpr *addVarDecl(const ValueDecl *VD, til::SExpr *E);
493  til::SExpr *updateVarDecl(const ValueDecl *VD, til::SExpr *E);
494 
495  void makePhiNodeVar(unsigned i, unsigned NPreds, til::SExpr *E);
496  void mergeEntryMap(LVarDefinitionMap Map);
497  void mergeEntryMapBackEdge();
498  void mergePhiNodesBackEdge(const CFGBlock *Blk);
499 
500 private:
501  // Set to true when parsing capability expressions, which get translated
502  // inaccurately in order to hack around smart pointers etc.
503  static const bool CapabilityExprMode = true;
504 
505  til::MemRegionRef Arena;
506 
507  // Variable to use for 'this'. May be null.
508  til::Variable *SelfVar = nullptr;
509 
510  til::SCFG *Scfg = nullptr;
511 
512  // Map from Stmt to TIL Variables
513  StatementMap SMap;
514 
515  // Indices of clang local vars.
516  LVarIndexMap LVarIdxMap;
517 
518  // Map from clang to til BBs.
519  std::vector<til::BasicBlock *> BlockMap;
520 
521  // Extra information per BB. Indexed by clang BlockID.
522  std::vector<BlockInfo> BBInfo;
523 
524  LVarDefinitionMap CurrentLVarMap;
525  std::vector<til::Phi *> CurrentArguments;
526  std::vector<til::SExpr *> CurrentInstructions;
527  std::vector<til::Phi *> IncompleteArgs;
528  til::BasicBlock *CurrentBB = nullptr;
529  BlockInfo *CurrentBlockInfo = nullptr;
530 };
531 
532 // Dump an SCFG to llvm::errs().
533 void printSCFG(CFGWalker &Walker);
534 
535 } // namespace threadSafety
536 } // namespace clang
537 
538 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYCOMMON_H
ThreadSafetyUtil.h
clang::CFGImplicitDtor::getDestructorDecl
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
Definition: CFG.cpp:5283
clang::threadSafety::sx::equals
bool equals(const til::SExpr *E1, const til::SExpr *E2)
Definition: ThreadSafetyCommon.h:65
clang::threadSafety::CFGWalker
Definition: ThreadSafetyCommon.h:147
clang::AnalysisDeclContext::getASTContext
ASTContext & getASTContext() const
Definition: AnalysisDeclContext.h:104
clang::threadSafety::SExprBuilder::CallingContext::SelfArg
llvm::PointerUnion< const Expr *, til::SExpr * > SelfArg
Definition: ThreadSafetyCommon.h:358
clang::threadSafety::SExprBuilder::lookupStmt
til::SExpr * lookupStmt(const Stmt *S)
Definition: ThreadSafetyCommon.cpp:72
clang::threadSafety::CapabilityExpr::shouldIgnore
bool shouldIgnore() const
Definition: ThreadSafetyCommon.h:331
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:23
ThreadSafetyTraverse.h
ThreadSafetyTIL.h
clang::threadSafety::CapabilityExpr::CapabilityExpr
CapabilityExpr()
Definition: ThreadSafetyCommon.h:281
clang::threadSafety::SExprBuilder::lookupBlock
til::BasicBlock * lookupBlock(const CFGBlock *B)
Definition: ThreadSafetyCommon.h:402
AnalysisDeclContext.h
llvm::SmallVector
Definition: LLVM.h:38
clang::threadSafety::til::MatchComparator::compareExprs
static bool compareExprs(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:393
clang::threadSafety::CapabilityExpr::matchesUniv
bool matchesUniv(const CapabilityExpr &CapE) const
Definition: ThreadSafetyCommon.h:306
clang::AbstractConditionalOperator
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4114
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::CFGBlock::getBlockID
unsigned getBlockID() const
Definition: CFG.h:1074
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:56
clang::AnalysisDeclContext
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Definition: AnalysisDeclContext.h:72
clang::interp::Neg
bool Neg(InterpState &S, CodePtr OpPC)
Definition: Interp.h:414
PostOrderCFGView.h
clang::ComparisonCategoryType::First
@ First
clang::threadSafety::SExprBuilder::createVariable
til::LiteralPtr * createVariable(const VarDecl *VD)
Definition: ThreadSafetyCommon.cpp:219
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2174
clang::threadSafety::SExprBuilder::createThisPlaceholder
std::pair< til::LiteralPtr *, StringRef > createThisPlaceholder(const Expr *Exp)
Definition: ThreadSafetyCommon.cpp:224
clang::threadSafety::til::TIL_BinaryOpcode
TIL_BinaryOpcode
Opcode for binary arithmetic operations.
Definition: ThreadSafetyTIL.h:91
clang::CFGBlock::const_succ_iterator
AdjacentBlocks::const_iterator const_succ_iterator
Definition: CFG.h:931
clang::CFG
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition: CFG.h:1225
Decl.h
clang::threadSafety::CapabilityExpr::operator!
CapabilityExpr operator!() const
Definition: ThreadSafetyCommon.h:292
clang::CFGAutomaticObjDtor::getVarDecl
const VarDecl * getVarDecl() const
Definition: CFG.h:394
clang::PostOrderCFGView::CFGBlockSet::insert
std::pair< std::nullopt_t, bool > insert(const CFGBlock *Block)
Set the bit associated with a particular CFGBlock.
Definition: PostOrderCFGView.h:50
clang::CFGBlock
Represents a single basic block in a source-level CFG.
Definition: CFG.h:576
clang::threadSafety::CFGWalker::getDecl
const NamedDecl * getDecl() const
Definition: ThreadSafetyCommon.h:257
V
#define V(N, I)
Definition: ASTContext.h:3211
clang::threadSafety::CapabilityExpr::isUniversal
bool isUniversal() const
Definition: ThreadSafetyCommon.h:335
clang::threadSafety::CapabilityExpr::matches
bool matches(const CapabilityExpr &other) const
Definition: ThreadSafetyCommon.h:301
clang::AnalysisDeclContext::getAnalysis
T * getAnalysis()
Definition: AnalysisDeclContext.h:192
clang::threadSafety::printSCFG
void printSCFG(CFGWalker &Walker)
clang::threadSafety::SExprBuilder::SExprBuilder
SExprBuilder(til::MemRegionRef A)
Definition: ThreadSafetyCommon.h:373
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3814
clang::threadSafety::SExprBuilder::buildCFG
til::SCFG * buildCFG(CFGWalker &Walker)
Definition: ThreadSafetyCommon.cpp:79
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:91
clang::threadSafety::sx::partiallyMatches
bool partiallyMatches(const til::SExpr *E1, const til::SExpr *E2)
Definition: ThreadSafetyCommon.h:81
clang::threadSafety::CapabilityExpr::valueDecl
const ValueDecl * valueDecl() const
Definition: ThreadSafetyCommon.h:315
clang::threadSafety::CapabilityExpr::isInvalid
bool isInvalid() const
Definition: ThreadSafetyCommon.h:333
clang::CFGAutomaticObjDtor
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition: CFG.h:389
clang::threadSafety::SExprBuilder::CallingContext::Prev
CallingContext * Prev
Definition: ThreadSafetyCommon.h:352
clang::threadSafety::CapabilityExpr::getKind
StringRef getKind() const
Definition: ThreadSafetyCommon.h:289
clang::threadSafety::SExprBuilder::CallingContext::NumArgs
unsigned NumArgs
Definition: ThreadSafetyCommon.h:361
clang::CXXDestructorDecl
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2715
clang::threadSafety::CopyOnWriteVector< NameVarPair >
clang::threadSafety::CFGWalker::CFGWalker
CFGWalker()=default
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:915
CallingContext
SExprBuilder::CallingContext CallingContext
Definition: ThreadSafetyCommon.cpp:70
clang::threadSafety::CFGWalker::getSortedGraph
const PostOrderCFGView * getSortedGraph() const
Definition: ThreadSafetyCommon.h:261
SMap
llvm::DenseMap< const Stmt *, CFGBlock * > SMap
Definition: CFGStmtMap.cpp:22
clang::threadSafety::CFGWalker::getGraph
const CFG * getGraph() const
Definition: ThreadSafetyCommon.h:254
clang::CFG::getExit
CFGBlock & getExit()
Definition: CFG.h:1333
clang::threadSafety::til::PrettyPrinter< StdPrinter, std::ostream >::print
static void print(const SExpr *E, std::ostream &SS)
Definition: ThreadSafetyTraverse.h:420
clang::PostOrderCFGView
Definition: PostOrderCFGView.h:27
clang::threadSafety::SExprBuilder::CallingContext::CallingContext
CallingContext(CallingContext *P, const NamedDecl *D=nullptr)
Definition: ThreadSafetyCommon.h:369
clang::CFGElement::AutomaticObjectDtor
@ AutomaticObjectDtor
Definition: CFG.h:71
clang::threadSafety::SExprBuilder::translateAttrExpr
CapabilityExpr translateAttrExpr(const Expr *AttrExp, const NamedDecl *D, const Expr *DeclExp, til::SExpr *Self=nullptr)
Translate a clang expression in an attribute to a til::SExpr.
Definition: ThreadSafetyCommon.cpp:119
clang::CFGElement::Statement
@ Statement
Definition: CFG.h:65
clang::threadSafety::SExprBuilder::CallingContext
Encapsulates the lexical context of a function call.
Definition: ThreadSafetyCommon.h:350
P
StringRef P
Definition: ASTMatchersInternal.cpp:564
clang::CFGStmt
Definition: CFG.h:130
clang::CFGElement::castAs
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition: CFG.h:97
false
#define false
Definition: stdbool.h:22
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:703
clang::threadSafety::CapabilityExpr::negative
bool negative() const
Definition: ThreadSafetyCommon.h:290
clang::ArraySubscriptExpr
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2656
LLVM.h
clang::threadSafety::CapabilityExpr
Definition: ThreadSafetyCommon.h:272
clang::CFGStmt::getStmt
const Stmt * getStmt() const
Definition: CFG.h:136
clang::threadSafety::til::Variable
A named variable, e.g.
Definition: ThreadSafetyTIL.h:354
clang::CFG::getEntry
CFGBlock & getEntry()
Definition: CFG.h:1331
clang::threadSafety::CapabilityExpr::CapabilityExpr
CapabilityExpr(const til::SExpr *E, StringRef Kind, bool Neg)
Definition: ThreadSafetyCommon.h:282
clang::threadSafety::sx::matches
bool matches(const til::SExpr *E1, const til::SExpr *E2)
Definition: ThreadSafetyCommon.h:69
clang::threadSafety::til::Variable::VK_SFun
@ VK_SFun
SFunction (self) parameter.
Definition: ThreadSafetyTIL.h:364
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::DeclStmt
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1311
clang::CXXThisExpr
Represents the this expression in C++.
Definition: ExprCXX.h:1148
clang::threadSafety::til::MemRegionRef
Definition: ThreadSafetyUtil.h:38
clang::threadSafety::til::BasicBlock
A basic block is part of an SCFG.
Definition: ThreadSafetyTIL.h:1499
clang
Definition: CalledOnceCheck.h:17
clang::threadSafety::SExprBuilder::CallingContext::FunArgs
const Expr *const * FunArgs
Definition: ThreadSafetyCommon.h:364
clang::threadSafety::CapabilityExpr::partiallyMatches
bool partiallyMatches(const CapabilityExpr &other) const
Definition: ThreadSafetyCommon.h:310
CFG.h
clang::AnalysisDeclContext::getDecl
const Decl * getDecl() const
Definition: AnalysisDeclContext.h:106
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:72
clang::ComparisonCategoryType::Last
@ Last
clang::threadSafety::SExprBuilder
Definition: ThreadSafetyCommon.h:339
clang::threadSafety::CapabilityExpr::equals
bool equals(const CapabilityExpr &other) const
Definition: ThreadSafetyCommon.h:296
clang::threadSafety::SExprBuilder::CallingContext::AttrDecl
const NamedDecl * AttrDecl
Definition: ThreadSafetyCommon.h:355
clang::threadSafety::CapabilityExpr::toString
std::string toString() const
Definition: ThreadSafetyCommon.h:325
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3171
clang::threadSafety::SExprBuilder::translate
til::SExpr * translate(const Stmt *S, CallingContext *Ctx)
Definition: ThreadSafetyCommon.cpp:232
clang::threadSafety::CFGWalker::init
bool init(AnalysisDeclContext &AC)
Definition: ThreadSafetyCommon.h:153
clang::PostOrderCFGView::CFGBlockSet
Implements a set of CFGBlocks using a BitVector.
Definition: PostOrderCFGView.h:37
clang::AnalysisDeclContext::getCFG
CFG * getCFG()
Definition: AnalysisDeclContext.cpp:213
clang::threadSafety::CFGWalker::walk
void walk(Visitor &V)
Definition: ThreadSafetyCommon.h:172
clang::threadSafety::til::EqualsComparator::compareExprs
static bool compareExprs(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:355
clang::Expr
This represents one expression.
Definition: Expr.h:110
clang::threadSafety::CFGWalker::getGraph
CFG * getGraph()
Definition: ThreadSafetyCommon.h:255
clang::threadSafety::til::SCFG
An SCFG is a control-flow graph.
Definition: ThreadSafetyTIL.h:1686
clang::threadSafety::SExprBuilder::CallingContext::SelfArrow
bool SelfArrow
Definition: ThreadSafetyCommon.h:367
clang::threadSafety::SExprBuilder::getCFG
const til::SCFG * getCFG() const
Definition: ThreadSafetyCommon.h:406
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3482
clang::PostOrderCFGView::CFGBlockSet::alreadySet
bool alreadySet(const CFGBlock *Block)
Check if the bit for a CFGBlock has been already set.
Definition: PostOrderCFGView.h:67
clang::threadSafety::til::LiteralPtr
A Literal pointer to an object allocated in memory.
Definition: ThreadSafetyTIL.h:634
clang::threadSafety::SExprBuilder::getCFG
til::SCFG * getCFG()
Definition: ThreadSafetyCommon.h:407
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1234
clang::threadSafety::CFGVisitor
Definition: ThreadSafetyCommon.h:102
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2812
clang::CXXOperatorCallExpr
A call to an overloaded operator written using operator syntax.
Definition: ExprCXX.h:81
clang::threadSafety::CapabilityExpr::sexpr
const til::SExpr * sexpr() const
Definition: ThreadSafetyCommon.h:288
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
clang::CXXMemberCallExpr
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
clang::CFGBlock::const_pred_iterator
AdjacentBlocks::const_iterator const_pred_iterator
Definition: CFG.h:924
clang::threadSafety::til::Variable::setKind
void setKind(VariableKind K)
Definition: ThreadSafetyTIL.h:401
clang::threadSafety::til::SExpr
Base class for AST nodes in the typed intermediate language.
Definition: ThreadSafetyTIL.h:276