clang  14.0.0git
ThreadSafetyTraverse.h
Go to the documentation of this file.
1 //===- ThreadSafetyTraverse.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 // This file defines a framework for doing generic traversals and rewriting
10 // operations over the Thread Safety TIL.
11 //
12 // UNDER CONSTRUCTION. USE AT YOUR OWN RISK.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTRAVERSE_H
17 #define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTRAVERSE_H
18 
19 #include "clang/AST/Decl.h"
22 #include "clang/Basic/LLVM.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/Casting.h"
25 #include <cstdint>
26 #include <ostream>
27 
28 namespace clang {
29 namespace threadSafety {
30 namespace til {
31 
32 // Defines an interface used to traverse SExprs. Traversals have been made as
33 // generic as possible, and are intended to handle any kind of pass over the
34 // AST, e.g. visitors, copying, non-destructive rewriting, destructive
35 // (in-place) rewriting, hashing, typing, etc.
36 //
37 // Traversals implement the functional notion of a "fold" operation on SExprs.
38 // Each SExpr class provides a traverse method, which does the following:
39 // * e->traverse(v):
40 // // compute a result r_i for each subexpression e_i
41 // for (i = 1..n) r_i = v.traverse(e_i);
42 // // combine results into a result for e, where X is the class of e
43 // return v.reduceX(*e, r_1, .. r_n).
44 //
45 // A visitor can control the traversal by overriding the following methods:
46 // * v.traverse(e):
47 // return v.traverseByCase(e), which returns v.traverseX(e)
48 // * v.traverseX(e): (X is the class of e)
49 // return e->traverse(v).
50 // * v.reduceX(*e, r_1, .. r_n):
51 // compute a result for a node of type X
52 //
53 // The reduceX methods control the kind of traversal (visitor, copy, etc.).
54 // They are defined in derived classes.
55 //
56 // Class R defines the basic interface types (R_SExpr).
57 template <class Self, class R>
58 class Traversal {
59 public:
60  Self *self() { return static_cast<Self *>(this); }
61 
62  // Traverse an expression -- returning a result of type R_SExpr.
63  // Override this method to do something for every expression, regardless
64  // of which kind it is.
65  // E is a reference, so this can be use for in-place updates.
66  // The type T must be a subclass of SExpr.
67  template <class T>
68  typename R::R_SExpr traverse(T* &E, typename R::R_Ctx Ctx) {
69  return traverseSExpr(E, Ctx);
70  }
71 
72  // Override this method to do something for every expression.
73  // Does not allow in-place updates.
74  typename R::R_SExpr traverseSExpr(SExpr *E, typename R::R_Ctx Ctx) {
75  return traverseByCase(E, Ctx);
76  }
77 
78  // Helper method to call traverseX(e) on the appropriate type.
79  typename R::R_SExpr traverseByCase(SExpr *E, typename R::R_Ctx Ctx) {
80  switch (E->opcode()) {
81 #define TIL_OPCODE_DEF(X) \
82  case COP_##X: \
83  return self()->traverse##X(cast<X>(E), Ctx);
84 #include "ThreadSafetyOps.def"
85 #undef TIL_OPCODE_DEF
86  }
87  return self()->reduceNull();
88  }
89 
90 // Traverse e, by static dispatch on the type "X" of e.
91 // Override these methods to do something for a particular kind of term.
92 #define TIL_OPCODE_DEF(X) \
93  typename R::R_SExpr traverse##X(X *e, typename R::R_Ctx Ctx) { \
94  return e->traverse(*self(), Ctx); \
95  }
96 #include "ThreadSafetyOps.def"
97 #undef TIL_OPCODE_DEF
98 };
99 
100 // Base class for simple reducers that don't much care about the context.
102 public:
104  // Ordinary subexpressions.
106 
107  // Declarations (e.g. function bodies).
109 
110  // Expressions that require lazy evaluation.
112 
113  // Type expressions.
115  };
116 
117  // R_Ctx defines a "context" for the traversal, which encodes information
118  // about where a term appears. This can be used to encoding the
119  // "current continuation" for CPS transforms, or other information.
121 
122  // Create context for an ordinary subexpression.
123  R_Ctx subExprCtx(R_Ctx Ctx) { return TRV_Normal; }
124 
125  // Create context for a subexpression that occurs in a declaration position
126  // (e.g. function body).
127  R_Ctx declCtx(R_Ctx Ctx) { return TRV_Decl; }
128 
129  // Create context for a subexpression that occurs in a position that
130  // should be reduced lazily. (e.g. code body).
131  R_Ctx lazyCtx(R_Ctx Ctx) { return TRV_Lazy; }
132 
133  // Create context for a subexpression that occurs in a type position.
134  R_Ctx typeCtx(R_Ctx Ctx) { return TRV_Type; }
135 };
136 
137 // Base class for traversals that rewrite an SExpr to another SExpr.
139 public:
140  // R_SExpr is the result type for a traversal.
141  // A copy or non-destructive rewrite returns a newly allocated term.
142  using R_SExpr = SExpr *;
144 
145  // Container is a minimal interface used to store results when traversing
146  // SExprs of variable arity, such as Phi, Goto, and SCFG.
147  template <class T> class Container {
148  public:
149  // Allocate a new container with a capacity for n elements.
150  Container(CopyReducerBase &S, unsigned N) : Elems(S.Arena, N) {}
151 
152  // Push a new element onto the container.
153  void push_back(T E) { Elems.push_back(E); }
154 
156  };
157 
159 
160 protected:
162 };
163 
164 // Base class for visit traversals.
166 public:
167  // A visitor returns a bool, representing success or failure.
168  using R_SExpr = bool;
170 
171  // A visitor "container" is a single bool, which accumulates success.
172  template <class T> class Container {
173  public:
174  bool Success = true;
175 
176  Container(VisitReducerBase &S, unsigned N) {}
177 
178  void push_back(bool E) { Success = Success && E; }
179  };
180 };
181 
182 // Implements a traversal that visits each subexpression, and returns either
183 // true or false.
184 template <class Self>
185 class VisitReducer : public Traversal<Self, VisitReducerBase>,
186  public VisitReducerBase {
187 public:
188  VisitReducer() = default;
189 
190 public:
191  R_SExpr reduceNull() { return true; }
192  R_SExpr reduceUndefined(Undefined &Orig) { return true; }
193  R_SExpr reduceWildcard(Wildcard &Orig) { return true; }
194 
195  R_SExpr reduceLiteral(Literal &Orig) { return true; }
196  template<class T>
197  R_SExpr reduceLiteralT(LiteralT<T> &Orig) { return true; }
198  R_SExpr reduceLiteralPtr(Literal &Orig) { return true; }
199 
201  return Nvd && E0;
202  }
203 
205  return Nvd && E0;
206  }
207 
209  return E0 && E1;
210  }
211 
213  return E0 && E1;
214  }
215 
217  return E0 && E1;
218  }
219 
221  return E0 && E1;
222  }
223 
224  R_SExpr reduceProject(Project &Orig, R_SExpr E0) { return E0; }
225  R_SExpr reduceCall(Call &Orig, R_SExpr E0) { return E0; }
226  R_SExpr reduceAlloc(Alloc &Orig, R_SExpr E0) { return E0; }
227  R_SExpr reduceLoad(Load &Orig, R_SExpr E0) { return E0; }
228  R_SExpr reduceStore(Store &Orig, R_SExpr E0, R_SExpr E1) { return E0 && E1; }
229 
231  return E0 && E1;
232  }
233 
235  return E0 && E1;
236  }
237 
238  R_SExpr reduceUnaryOp(UnaryOp &Orig, R_SExpr E0) { return E0; }
239 
241  return E0 && E1;
242  }
243 
244  R_SExpr reduceCast(Cast &Orig, R_SExpr E0) { return E0; }
245 
247  return Bbs.Success;
248  }
249 
251  Container<R_SExpr> &Is, R_SExpr T) {
252  return (As.Success && Is.Success && T);
253  }
254 
256  return As.Success;
257  }
258 
260  return true;
261  }
262 
264  return C;
265  }
266 
268  return E;
269  }
270 
272  return true;
273  }
274 
276  return C && T && E;
277  }
278 
280  return Nvd && B;
281  }
282 
283  Variable *enterScope(Variable &Orig, R_SExpr E0) { return &Orig; }
284  void exitScope(const Variable &Orig) {}
285  void enterCFG(SCFG &Cfg) {}
286  void exitCFG(SCFG &Cfg) {}
289 
290  Variable *reduceVariableRef(Variable *Ovd) { return Ovd; }
292 
293 public:
295  Success = Success && this->traverseByCase(E);
296  return Success;
297  }
298 
299  static bool visit(SExpr *E) {
300  Self Visitor;
301  return Visitor.traverse(E, TRV_Normal);
302  }
303 
304 private:
305  bool Success;
306 };
307 
308 // Basic class for comparison operations over expressions.
309 template <typename Self>
310 class Comparator {
311 protected:
312  Self *self() { return reinterpret_cast<Self *>(this); }
313 
314 public:
315  bool compareByCase(const SExpr *E1, const SExpr* E2) {
316  switch (E1->opcode()) {
317 #define TIL_OPCODE_DEF(X) \
318  case COP_##X: \
319  return cast<X>(E1)->compare(cast<X>(E2), *self());
320 #include "ThreadSafetyOps.def"
321 #undef TIL_OPCODE_DEF
322  }
323  return false;
324  }
325 };
326 
327 class EqualsComparator : public Comparator<EqualsComparator> {
328 public:
329  // Result type for the comparison, e.g. bool for simple equality,
330  // or int for lexigraphic comparison (-1, 0, 1). Must have one value which
331  // denotes "true".
332  using CType = bool;
333 
334  CType trueResult() { return true; }
335  bool notTrue(CType ct) { return !ct; }
336 
337  bool compareIntegers(unsigned i, unsigned j) { return i == j; }
338  bool compareStrings (StringRef s, StringRef r) { return s == r; }
339  bool comparePointers(const void* P, const void* Q) { return P == Q; }
340 
341  bool compare(const SExpr *E1, const SExpr* E2) {
342  if (E1->opcode() != E2->opcode())
343  return false;
344  return compareByCase(E1, E2);
345  }
346 
347  // TODO -- handle alpha-renaming of variables
348  void enterScope(const Variable *V1, const Variable *V2) {}
349  void leaveScope() {}
350 
351  bool compareVariableRefs(const Variable *V1, const Variable *V2) {
352  return V1 == V2;
353  }
354 
355  static bool compareExprs(const SExpr *E1, const SExpr* E2) {
357  return Eq.compare(E1, E2);
358  }
359 };
360 
361 class MatchComparator : public Comparator<MatchComparator> {
362 public:
363  // Result type for the comparison, e.g. bool for simple equality,
364  // or int for lexigraphic comparison (-1, 0, 1). Must have one value which
365  // denotes "true".
366  using CType = bool;
367 
368  CType trueResult() { return true; }
369  bool notTrue(CType ct) { return !ct; }
370 
371  bool compareIntegers(unsigned i, unsigned j) { return i == j; }
372  bool compareStrings (StringRef s, StringRef r) { return s == r; }
373  bool comparePointers(const void *P, const void *Q) { return P == Q; }
374 
375  bool compare(const SExpr *E1, const SExpr *E2) {
376  // Wildcards match anything.
377  if (E1->opcode() == COP_Wildcard || E2->opcode() == COP_Wildcard)
378  return true;
379  // otherwise normal equality.
380  if (E1->opcode() != E2->opcode())
381  return false;
382  return compareByCase(E1, E2);
383  }
384 
385  // TODO -- handle alpha-renaming of variables
386  void enterScope(const Variable* V1, const Variable* V2) {}
387  void leaveScope() {}
388 
389  bool compareVariableRefs(const Variable* V1, const Variable* V2) {
390  return V1 == V2;
391  }
392 
393  static bool compareExprs(const SExpr *E1, const SExpr* E2) {
394  MatchComparator Matcher;
395  return Matcher.compare(E1, E2);
396  }
397 };
398 
399 // inline std::ostream& operator<<(std::ostream& SS, StringRef R) {
400 // return SS.write(R.data(), R.size());
401 // }
402 
403 // Pretty printer for TIL expressions
404 template <typename Self, typename StreamType>
406 private:
407  // Print out additional information.
408  bool Verbose;
409 
410  // Omit redundant decls.
411  bool Cleanup;
412 
413  // Print exprs in C-like syntax.
414  bool CStyle;
415 
416 public:
417  PrettyPrinter(bool V = false, bool C = true, bool CS = true)
418  : Verbose(V), Cleanup(C), CStyle(CS) {}
419 
420  static void print(const SExpr *E, StreamType &SS) {
421  Self printer;
422  printer.printSExpr(E, SS, Prec_MAX);
423  }
424 
425 protected:
426  Self *self() { return reinterpret_cast<Self *>(this); }
427 
428  void newline(StreamType &SS) {
429  SS << "\n";
430  }
431 
432  // TODO: further distinguish between binary operations.
433  static const unsigned Prec_Atom = 0;
434  static const unsigned Prec_Postfix = 1;
435  static const unsigned Prec_Unary = 2;
436  static const unsigned Prec_Binary = 3;
437  static const unsigned Prec_Other = 4;
438  static const unsigned Prec_Decl = 5;
439  static const unsigned Prec_MAX = 6;
440 
441  // Return the precedence of a given node, for use in pretty printing.
442  unsigned precedence(const SExpr *E) {
443  switch (E->opcode()) {
444  case COP_Future: return Prec_Atom;
445  case COP_Undefined: return Prec_Atom;
446  case COP_Wildcard: return Prec_Atom;
447 
448  case COP_Literal: return Prec_Atom;
449  case COP_LiteralPtr: return Prec_Atom;
450  case COP_Variable: return Prec_Atom;
451  case COP_Function: return Prec_Decl;
452  case COP_SFunction: return Prec_Decl;
453  case COP_Code: return Prec_Decl;
454  case COP_Field: return Prec_Decl;
455 
456  case COP_Apply: return Prec_Postfix;
457  case COP_SApply: return Prec_Postfix;
458  case COP_Project: return Prec_Postfix;
459 
460  case COP_Call: return Prec_Postfix;
461  case COP_Alloc: return Prec_Other;
462  case COP_Load: return Prec_Postfix;
463  case COP_Store: return Prec_Other;
464  case COP_ArrayIndex: return Prec_Postfix;
465  case COP_ArrayAdd: return Prec_Postfix;
466 
467  case COP_UnaryOp: return Prec_Unary;
468  case COP_BinaryOp: return Prec_Binary;
469  case COP_Cast: return Prec_Atom;
470 
471  case COP_SCFG: return Prec_Decl;
472  case COP_BasicBlock: return Prec_MAX;
473  case COP_Phi: return Prec_Atom;
474  case COP_Goto: return Prec_Atom;
475  case COP_Branch: return Prec_Atom;
476  case COP_Return: return Prec_Other;
477 
478  case COP_Identifier: return Prec_Atom;
479  case COP_IfThenElse: return Prec_Other;
480  case COP_Let: return Prec_Decl;
481  }
482  return Prec_MAX;
483  }
484 
485  void printBlockLabel(StreamType & SS, const BasicBlock *BB, int index) {
486  if (!BB) {
487  SS << "BB_null";
488  return;
489  }
490  SS << "BB_";
491  SS << BB->blockID();
492  if (index >= 0) {
493  SS << ":";
494  SS << index;
495  }
496  }
497 
498  void printSExpr(const SExpr *E, StreamType &SS, unsigned P, bool Sub=true) {
499  if (!E) {
500  self()->printNull(SS);
501  return;
502  }
503  if (Sub && E->block() && E->opcode() != COP_Variable) {
504  SS << "_x" << E->id();
505  return;
506  }
507  if (self()->precedence(E) > P) {
508  // Wrap expr in () if necessary.
509  SS << "(";
510  self()->printSExpr(E, SS, Prec_MAX);
511  SS << ")";
512  return;
513  }
514 
515  switch (E->opcode()) {
516 #define TIL_OPCODE_DEF(X) \
517  case COP_##X: \
518  self()->print##X(cast<X>(E), SS); \
519  return;
520 #include "ThreadSafetyOps.def"
521 #undef TIL_OPCODE_DEF
522  }
523  }
524 
525  void printNull(StreamType &SS) {
526  SS << "#null";
527  }
528 
529  void printFuture(const Future *E, StreamType &SS) {
530  self()->printSExpr(E->maybeGetResult(), SS, Prec_Atom);
531  }
532 
533  void printUndefined(const Undefined *E, StreamType &SS) {
534  SS << "#undefined";
535  }
536 
537  void printWildcard(const Wildcard *E, StreamType &SS) {
538  SS << "*";
539  }
540 
541  template<class T>
542  void printLiteralT(const LiteralT<T> *E, StreamType &SS) {
543  SS << E->value();
544  }
545 
546  void printLiteralT(const LiteralT<uint8_t> *E, StreamType &SS) {
547  SS << "'" << E->value() << "'";
548  }
549 
550  void printLiteral(const Literal *E, StreamType &SS) {
551  if (E->clangExpr()) {
552  SS << getSourceLiteralString(E->clangExpr());
553  return;
554  }
555  else {
556  ValueType VT = E->valueType();
557  switch (VT.Base) {
558  case ValueType::BT_Void:
559  SS << "void";
560  return;
561  case ValueType::BT_Bool:
562  if (E->as<bool>().value())
563  SS << "true";
564  else
565  SS << "false";
566  return;
567  case ValueType::BT_Int:
568  switch (VT.Size) {
569  case ValueType::ST_8:
570  if (VT.Signed)
571  printLiteralT(&E->as<int8_t>(), SS);
572  else
573  printLiteralT(&E->as<uint8_t>(), SS);
574  return;
575  case ValueType::ST_16:
576  if (VT.Signed)
577  printLiteralT(&E->as<int16_t>(), SS);
578  else
579  printLiteralT(&E->as<uint16_t>(), SS);
580  return;
581  case ValueType::ST_32:
582  if (VT.Signed)
583  printLiteralT(&E->as<int32_t>(), SS);
584  else
585  printLiteralT(&E->as<uint32_t>(), SS);
586  return;
587  case ValueType::ST_64:
588  if (VT.Signed)
589  printLiteralT(&E->as<int64_t>(), SS);
590  else
591  printLiteralT(&E->as<uint64_t>(), SS);
592  return;
593  default:
594  break;
595  }
596  break;
597  case ValueType::BT_Float:
598  switch (VT.Size) {
599  case ValueType::ST_32:
600  printLiteralT(&E->as<float>(), SS);
601  return;
602  case ValueType::ST_64:
603  printLiteralT(&E->as<double>(), SS);
604  return;
605  default:
606  break;
607  }
608  break;
610  SS << "\"";
611  printLiteralT(&E->as<StringRef>(), SS);
612  SS << "\"";
613  return;
615  SS << "#ptr";
616  return;
618  SS << "#vref";
619  return;
620  }
621  }
622  SS << "#lit";
623  }
624 
625  void printLiteralPtr(const LiteralPtr *E, StreamType &SS) {
626  SS << E->clangDecl()->getNameAsString();
627  }
628 
629  void printVariable(const Variable *V, StreamType &SS, bool IsVarDecl=false) {
630  if (CStyle && V->kind() == Variable::VK_SFun)
631  SS << "this";
632  else
633  SS << V->name() << V->id();
634  }
635 
636  void printFunction(const Function *E, StreamType &SS, unsigned sugared = 0) {
637  switch (sugared) {
638  default:
639  SS << "\\("; // Lambda
640  break;
641  case 1:
642  SS << "("; // Slot declarations
643  break;
644  case 2:
645  SS << ", "; // Curried functions
646  break;
647  }
648  self()->printVariable(E->variableDecl(), SS, true);
649  SS << ": ";
650  self()->printSExpr(E->variableDecl()->definition(), SS, Prec_MAX);
651 
652  const SExpr *B = E->body();
653  if (B && B->opcode() == COP_Function)
654  self()->printFunction(cast<Function>(B), SS, 2);
655  else {
656  SS << ")";
657  self()->printSExpr(B, SS, Prec_Decl);
658  }
659  }
660 
661  void printSFunction(const SFunction *E, StreamType &SS) {
662  SS << "@";
663  self()->printVariable(E->variableDecl(), SS, true);
664  SS << " ";
665  self()->printSExpr(E->body(), SS, Prec_Decl);
666  }
667 
668  void printCode(const Code *E, StreamType &SS) {
669  SS << ": ";
670  self()->printSExpr(E->returnType(), SS, Prec_Decl-1);
671  SS << " -> ";
672  self()->printSExpr(E->body(), SS, Prec_Decl);
673  }
674 
675  void printField(const Field *E, StreamType &SS) {
676  SS << ": ";
677  self()->printSExpr(E->range(), SS, Prec_Decl-1);
678  SS << " = ";
679  self()->printSExpr(E->body(), SS, Prec_Decl);
680  }
681 
682  void printApply(const Apply *E, StreamType &SS, bool sugared = false) {
683  const SExpr *F = E->fun();
684  if (F->opcode() == COP_Apply) {
685  printApply(cast<Apply>(F), SS, true);
686  SS << ", ";
687  } else {
688  self()->printSExpr(F, SS, Prec_Postfix);
689  SS << "(";
690  }
691  self()->printSExpr(E->arg(), SS, Prec_MAX);
692  if (!sugared)
693  SS << ")$";
694  }
695 
696  void printSApply(const SApply *E, StreamType &SS) {
697  self()->printSExpr(E->sfun(), SS, Prec_Postfix);
698  if (E->isDelegation()) {
699  SS << "@(";
700  self()->printSExpr(E->arg(), SS, Prec_MAX);
701  SS << ")";
702  }
703  }
704 
705  void printProject(const Project *E, StreamType &SS) {
706  if (CStyle) {
707  // Omit the this->
708  if (const auto *SAP = dyn_cast<SApply>(E->record())) {
709  if (const auto *V = dyn_cast<Variable>(SAP->sfun())) {
710  if (!SAP->isDelegation() && V->kind() == Variable::VK_SFun) {
711  SS << E->slotName();
712  return;
713  }
714  }
715  }
716  if (isa<Wildcard>(E->record())) {
717  // handle existentials
718  SS << "&";
719  SS << E->clangDecl()->getQualifiedNameAsString();
720  return;
721  }
722  }
723  self()->printSExpr(E->record(), SS, Prec_Postfix);
724  if (CStyle && E->isArrow())
725  SS << "->";
726  else
727  SS << ".";
728  SS << E->slotName();
729  }
730 
731  void printCall(const Call *E, StreamType &SS) {
732  const SExpr *T = E->target();
733  if (T->opcode() == COP_Apply) {
734  self()->printApply(cast<Apply>(T), SS, true);
735  SS << ")";
736  }
737  else {
738  self()->printSExpr(T, SS, Prec_Postfix);
739  SS << "()";
740  }
741  }
742 
743  void printAlloc(const Alloc *E, StreamType &SS) {
744  SS << "new ";
745  self()->printSExpr(E->dataType(), SS, Prec_Other-1);
746  }
747 
748  void printLoad(const Load *E, StreamType &SS) {
749  self()->printSExpr(E->pointer(), SS, Prec_Postfix);
750  if (!CStyle)
751  SS << "^";
752  }
753 
754  void printStore(const Store *E, StreamType &SS) {
755  self()->printSExpr(E->destination(), SS, Prec_Other-1);
756  SS << " := ";
757  self()->printSExpr(E->source(), SS, Prec_Other-1);
758  }
759 
760  void printArrayIndex(const ArrayIndex *E, StreamType &SS) {
761  self()->printSExpr(E->array(), SS, Prec_Postfix);
762  SS << "[";
763  self()->printSExpr(E->index(), SS, Prec_MAX);
764  SS << "]";
765  }
766 
767  void printArrayAdd(const ArrayAdd *E, StreamType &SS) {
768  self()->printSExpr(E->array(), SS, Prec_Postfix);
769  SS << " + ";
770  self()->printSExpr(E->index(), SS, Prec_Atom);
771  }
772 
773  void printUnaryOp(const UnaryOp *E, StreamType &SS) {
774  SS << getUnaryOpcodeString(E->unaryOpcode());
775  self()->printSExpr(E->expr(), SS, Prec_Unary);
776  }
777 
778  void printBinaryOp(const BinaryOp *E, StreamType &SS) {
779  self()->printSExpr(E->expr0(), SS, Prec_Binary-1);
780  SS << " " << getBinaryOpcodeString(E->binaryOpcode()) << " ";
781  self()->printSExpr(E->expr1(), SS, Prec_Binary-1);
782  }
783 
784  void printCast(const Cast *E, StreamType &SS) {
785  if (!CStyle) {
786  SS << "cast[";
787  switch (E->castOpcode()) {
788  case CAST_none:
789  SS << "none";
790  break;
791  case CAST_extendNum:
792  SS << "extendNum";
793  break;
794  case CAST_truncNum:
795  SS << "truncNum";
796  break;
797  case CAST_toFloat:
798  SS << "toFloat";
799  break;
800  case CAST_toInt:
801  SS << "toInt";
802  break;
803  case CAST_objToPtr:
804  SS << "objToPtr";
805  break;
806  }
807  SS << "](";
808  self()->printSExpr(E->expr(), SS, Prec_Unary);
809  SS << ")";
810  return;
811  }
812  self()->printSExpr(E->expr(), SS, Prec_Unary);
813  }
814 
815  void printSCFG(const SCFG *E, StreamType &SS) {
816  SS << "CFG {\n";
817  for (const auto *BBI : *E)
818  printBasicBlock(BBI, SS);
819  SS << "}";
820  newline(SS);
821  }
822 
823  void printBBInstr(const SExpr *E, StreamType &SS) {
824  bool Sub = false;
825  if (E->opcode() == COP_Variable) {
826  const auto *V = cast<Variable>(E);
827  SS << "let " << V->name() << V->id() << " = ";
828  E = V->definition();
829  Sub = true;
830  }
831  else if (E->opcode() != COP_Store) {
832  SS << "let _x" << E->id() << " = ";
833  }
834  self()->printSExpr(E, SS, Prec_MAX, Sub);
835  SS << ";";
836  newline(SS);
837  }
838 
839  void printBasicBlock(const BasicBlock *E, StreamType &SS) {
840  SS << "BB_" << E->blockID() << ":";
841  if (E->parent())
842  SS << " BB_" << E->parent()->blockID();
843  newline(SS);
844 
845  for (const auto *A : E->arguments())
846  printBBInstr(A, SS);
847 
848  for (const auto *I : E->instructions())
849  printBBInstr(I, SS);
850 
851  const SExpr *T = E->terminator();
852  if (T) {
853  self()->printSExpr(T, SS, Prec_MAX, false);
854  SS << ";";
855  newline(SS);
856  }
857  newline(SS);
858  }
859 
860  void printPhi(const Phi *E, StreamType &SS) {
861  SS << "phi(";
862  if (E->status() == Phi::PH_SingleVal)
863  self()->printSExpr(E->values()[0], SS, Prec_MAX);
864  else {
865  unsigned i = 0;
866  for (const auto *V : E->values()) {
867  if (i++ > 0)
868  SS << ", ";
869  self()->printSExpr(V, SS, Prec_MAX);
870  }
871  }
872  SS << ")";
873  }
874 
875  void printGoto(const Goto *E, StreamType &SS) {
876  SS << "goto ";
877  printBlockLabel(SS, E->targetBlock(), E->index());
878  }
879 
880  void printBranch(const Branch *E, StreamType &SS) {
881  SS << "branch (";
882  self()->printSExpr(E->condition(), SS, Prec_MAX);
883  SS << ") ";
884  printBlockLabel(SS, E->thenBlock(), -1);
885  SS << " ";
886  printBlockLabel(SS, E->elseBlock(), -1);
887  }
888 
889  void printReturn(const Return *E, StreamType &SS) {
890  SS << "return ";
891  self()->printSExpr(E->returnValue(), SS, Prec_Other);
892  }
893 
894  void printIdentifier(const Identifier *E, StreamType &SS) {
895  SS << E->name();
896  }
897 
898  void printIfThenElse(const IfThenElse *E, StreamType &SS) {
899  if (CStyle) {
900  printSExpr(E->condition(), SS, Prec_Unary);
901  SS << " ? ";
902  printSExpr(E->thenExpr(), SS, Prec_Unary);
903  SS << " : ";
904  printSExpr(E->elseExpr(), SS, Prec_Unary);
905  return;
906  }
907  SS << "if (";
908  printSExpr(E->condition(), SS, Prec_MAX);
909  SS << ") then ";
910  printSExpr(E->thenExpr(), SS, Prec_Other);
911  SS << " else ";
912  printSExpr(E->elseExpr(), SS, Prec_Other);
913  }
914 
915  void printLet(const Let *E, StreamType &SS) {
916  SS << "let ";
917  printVariable(E->variableDecl(), SS, true);
918  SS << " = ";
920  SS << "; ";
921  printSExpr(E->body(), SS, Prec_Decl-1);
922  }
923 };
924 
925 class StdPrinter : public PrettyPrinter<StdPrinter, std::ostream> {};
926 
927 } // namespace til
928 } // namespace threadSafety
929 } // namespace clang
930 
931 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYTRAVERSE_H
clang::threadSafety::til::PrettyPrinter::printArrayAdd
void printArrayAdd(const ArrayAdd *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:767
clang::threadSafety::til::BasicBlock::terminator
const Terminator * terminator() const
Definition: ThreadSafetyTIL.h:1569
clang::threadSafety::til::ArrayIndex::array
SExpr * array()
Definition: ThreadSafetyTIL.h:1101
clang::threadSafety::til::Apply
Apply an argument to a function.
Definition: ThreadSafetyTIL.h:839
clang::threadSafety::til::VisitReducer::exitScope
void exitScope(const Variable &Orig)
Definition: ThreadSafetyTraverse.h:284
clang::threadSafety::til::VisitReducerBase::R_SExpr
bool R_SExpr
Definition: ThreadSafetyTraverse.h:168
clang::threadSafety::til::BinaryOp::expr0
SExpr * expr0()
Definition: ThreadSafetyTIL.h:1222
clang::threadSafety::til::VisitReducerBase::Container::push_back
void push_back(bool E)
Definition: ThreadSafetyTraverse.h:178
clang::threadSafety::til::Goto
Jump to another basic block.
Definition: ThreadSafetyTIL.h:1369
clang::threadSafety::til::PrettyPrinter::printStore
void printStore(const Store *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:754
ThreadSafetyUtil.h
clang::threadSafety::til::CopyReducerBase::CopyReducerBase
CopyReducerBase(MemRegionRef A)
Definition: ThreadSafetyTraverse.h:158
clang::ast_matchers::GtestCmp::Eq
@ Eq
clang::threadSafety::til::Future
Placeholder for an expression that has not yet been created.
Definition: ThreadSafetyTIL.h:435
clang::threadSafety::til::VisitReducerBase::Container::Success
bool Success
Definition: ThreadSafetyTraverse.h:174
clang::threadSafety::til::IfThenElse::condition
SExpr * condition()
Definition: ThreadSafetyTIL.h:1821
clang::threadSafety::til::Call::target
SExpr * target()
Definition: ThreadSafetyTIL.h:973
clang::threadSafety::til::SimpleReducerBase::lazyCtx
R_Ctx lazyCtx(R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:131
clang::threadSafety::til::VisitReducerBase::R_BasicBlock
bool R_BasicBlock
Definition: ThreadSafetyTraverse.h:169
clang::threadSafety::til::SApply::sfun
SExpr * sfun()
Definition: ThreadSafetyTIL.h:882
clang::threadSafety::til::Traversal::traverse
R::R_SExpr traverse(T *&E, typename R::R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:68
clang::threadSafety::til::Branch
A conditional branch to two other blocks.
Definition: ThreadSafetyTIL.h:1407
clang::threadSafety::til::VisitReducer::reduceBasicBlock
R_BasicBlock reduceBasicBlock(BasicBlock &Orig, Container< R_SExpr > &As, Container< R_SExpr > &Is, R_SExpr T)
Definition: ThreadSafetyTraverse.h:250
clang::threadSafety::til::Load
Load a value from memory.
Definition: ThreadSafetyTIL.h:1031
clang::threadSafety::til::EqualsComparator::enterScope
void enterScope(const Variable *V1, const Variable *V2)
Definition: ThreadSafetyTraverse.h:348
clang::threadSafety::til::Project::clangDecl
const ValueDecl * clangDecl() const
Definition: ThreadSafetyTIL.h:924
clang::threadSafety::til::PrettyPrinter::Prec_Atom
static const unsigned Prec_Atom
Definition: ThreadSafetyTraverse.h:433
clang::threadSafety::til::Traversal::traverseByCase
R::R_SExpr traverseByCase(SExpr *E, typename R::R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:79
clang::threadSafety::til::SExpr::block
BasicBlock * block() const
Returns the block, if this is an instruction in a basic block, otherwise returns null.
Definition: ThreadSafetyTIL.h:315
clang::threadSafety::til::Code::returnType
SExpr * returnType()
Definition: ThreadSafetyTIL.h:773
clang::threadSafety::til::VisitReducer::reduceSFunction
R_SExpr reduceSFunction(SFunction &Orig, Variable *Nvd, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:204
clang::threadSafety::til::Identifier
An identifier, e.g.
Definition: ThreadSafetyTIL.h:1787
clang::threadSafety::til::UnaryOp
Simple arithmetic unary operations, e.g.
Definition: ThreadSafetyTIL.h:1166
clang::threadSafety::til::Cast
Cast expressions.
Definition: ThreadSafetyTIL.h:1255
clang::threadSafety::til::PrettyPrinter::Prec_Unary
static const unsigned Prec_Unary
Definition: ThreadSafetyTraverse.h:435
clang::threadSafety::til::Return::returnValue
SExpr * returnValue()
Definition: ThreadSafetyTIL.h:1468
ThreadSafetyTIL.h
clang::threadSafety::til::VisitReducer::reduceSCFG
R_SExpr reduceSCFG(SCFG &Orig, Container< BasicBlock * > Bbs)
Definition: ThreadSafetyTraverse.h:246
clang::threadSafety::til::Branch::elseBlock
const BasicBlock * elseBlock() const
Definition: ThreadSafetyTIL.h:1429
clang::threadSafety::til::PrettyPrinter::PrettyPrinter
PrettyPrinter(bool V=false, bool C=true, bool CS=true)
Definition: ThreadSafetyTraverse.h:417
clang::threadSafety::til::PrettyPrinter::printSExpr
void printSExpr(const SExpr *E, StreamType &SS, unsigned P, bool Sub=true)
Definition: ThreadSafetyTraverse.h:498
clang::threadSafety::til::VisitReducer::reduceBranch
R_SExpr reduceBranch(Branch &O, R_SExpr C, BasicBlock *B0, BasicBlock *B1)
Definition: ThreadSafetyTraverse.h:263
clang::threadSafety::til::PrettyPrinter::printLoad
void printLoad(const Load *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:748
clang::threadSafety::til::MatchComparator::compareExprs
static bool compareExprs(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:393
clang::threadSafety::til::PrettyPrinter::printLiteral
void printLiteral(const Literal *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:550
clang::threadSafety::til::BasicBlock::arguments
const InstrArray & arguments() const
Definition: ThreadSafetyTIL.h:1554
clang::threadSafety::til::VisitReducer::VisitReducer
VisitReducer()=default
clang::threadSafety::til::Wildcard
Placeholder for a wildcard that matches any other expression.
Definition: ThreadSafetyTIL.h:509
clang::threadSafety::til::ValueType::Signed
bool Signed
Definition: ThreadSafetyTIL.h:184
clang::threadSafety::til::VisitReducer::enterBasicBlock
void enterBasicBlock(BasicBlock &BB)
Definition: ThreadSafetyTraverse.h:287
clang::threadSafety::til::LiteralPtr::clangDecl
const ValueDecl * clangDecl() const
Definition: ThreadSafetyTIL.h:645
clang::threadSafety::til::CopyReducerBase::Container::Elems
SimpleArray< T > Elems
Definition: ThreadSafetyTraverse.h:155
clang::threadSafety::til::VisitReducer::reduceFunction
R_SExpr reduceFunction(Function &Orig, Variable *Nvd, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:200
clang::threadSafety::til::Traversal::traverseSExpr
R::R_SExpr traverseSExpr(SExpr *E, typename R::R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:74
clang::threadSafety::til::VisitReducer::reduceLet
R_SExpr reduceLet(Let &Orig, Variable *Nvd, R_SExpr B)
Definition: ThreadSafetyTraverse.h:279
clang::threadSafety::til::ValueType::BT_Bool
@ BT_Bool
Definition: ThreadSafetyTIL.h:156
clang::threadSafety::til::VisitReducer::reduceGoto
R_SExpr reduceGoto(Goto &Orig, BasicBlock *B)
Definition: ThreadSafetyTraverse.h:259
clang::threadSafety::til::MatchComparator::compareVariableRefs
bool compareVariableRefs(const Variable *V1, const Variable *V2)
Definition: ThreadSafetyTraverse.h:389
clang::threadSafety::til::StdPrinter
Definition: ThreadSafetyTraverse.h:925
clang::threadSafety::til::VisitReducerBase::Container
Definition: ThreadSafetyTraverse.h:172
clang::threadSafety::til::PrettyPrinter::printSFunction
void printSFunction(const SFunction *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:661
clang::threadSafety::til::VisitReducer::reduceCall
R_SExpr reduceCall(Call &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:225
clang::threadSafety::til::CAST_none
@ CAST_none
Definition: ThreadSafetyTIL.h:114
clang::threadSafety::til::Future::maybeGetResult
SExpr * maybeGetResult() const
Definition: ThreadSafetyTIL.h:452
clang::threadSafety::til::PrettyPrinter::precedence
unsigned precedence(const SExpr *E)
Definition: ThreadSafetyTraverse.h:442
clang::threadSafety::til::SExpr::opcode
TIL_Opcode opcode() const
Definition: ThreadSafetyTIL.h:281
clang::threadSafety::til::UnaryOp::expr
SExpr * expr()
Definition: ThreadSafetyTIL.h:1180
clang::threadSafety::til::Branch::thenBlock
const BasicBlock * thenBlock() const
Definition: ThreadSafetyTIL.h:1426
clang::threadSafety::til::Apply::fun
SExpr * fun()
Definition: ThreadSafetyTIL.h:847
clang::threadSafety::til::Variable::definition
SExpr * definition()
Return the definition of the variable.
Definition: ThreadSafetyTIL.h:398
clang::threadSafety::til::Field
A typed, writable location in memory.
Definition: ThreadSafetyTIL.h:800
clang::threadSafety::til::CopyReducerBase::Container
Definition: ThreadSafetyTraverse.h:147
clang::threadSafety::til::BasicBlock::blockID
int blockID() const
Returns the block ID. Every block has a unique ID in the CFG.
Definition: ThreadSafetyTIL.h:1542
clang::threadSafety::til::PrettyPrinter::printIdentifier
void printIdentifier(const Identifier *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:894
clang::threadSafety::til::PrettyPrinter::printLiteralT
void printLiteralT(const LiteralT< T > *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:542
clang::threadSafety::til::Project
Project a named slot from a C++ struct or class.
Definition: ThreadSafetyTIL.h:912
clang::threadSafety::til::CopyReducerBase::Container::Container
Container(CopyReducerBase &S, unsigned N)
Definition: ThreadSafetyTraverse.h:150
clang::threadSafety::til::Project::isArrow
bool isArrow() const
Definition: ThreadSafetyTIL.h:926
clang::threadSafety::til::VisitReducer::reducePhi
R_SExpr reducePhi(Phi &Orig, Container< R_SExpr > &As)
Definition: ThreadSafetyTraverse.h:255
clang::threadSafety::til::VisitReducer::exitCFG
void exitCFG(SCFG &Cfg)
Definition: ThreadSafetyTraverse.h:286
clang::threadSafety::til::CopyReducerBase::Container::push_back
void push_back(T E)
Definition: ThreadSafetyTraverse.h:153
Decl.h
clang::threadSafety::til::VisitReducer::reduceStore
R_SExpr reduceStore(Store &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:228
clang::threadSafety::til::BasicBlock::parent
const BasicBlock * parent() const
Definition: ThreadSafetyTIL.h:1551
clang::threadSafety::til::ValueType::BT_String
@ BT_String
Definition: ThreadSafetyTIL.h:159
clang::threadSafety::til::EqualsComparator::trueResult
CType trueResult()
Definition: ThreadSafetyTraverse.h:334
clang::threadSafety::til::PrettyPrinter::printWildcard
void printWildcard(const Wildcard *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:537
clang::threadSafety::til::Code::body
SExpr * body()
Definition: ThreadSafetyTIL.h:776
clang::threadSafety::til::PrettyPrinter::printSCFG
void printSCFG(const SCFG *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:815
clang::threadSafety::til::ArrayIndex::index
SExpr * index()
Definition: ThreadSafetyTIL.h:1104
clang::threadSafety::til::UnaryOp::unaryOpcode
TIL_UnaryOpcode unaryOpcode() const
Definition: ThreadSafetyTIL.h:1176
clang::threadSafety::til::VisitReducer::reduceWildcard
R_SExpr reduceWildcard(Wildcard &Orig)
Definition: ThreadSafetyTraverse.h:193
clang::threadSafety::til::Call
Call a function (after all arguments have been applied).
Definition: ThreadSafetyTIL.h:965
clang::threadSafety::til::BasicBlock::instructions
InstrArray & instructions()
Definition: ThreadSafetyTIL.h:1557
clang::threadSafety::til::Let::body
SExpr * body()
Definition: ThreadSafetyTIL.h:1872
clang::threadSafety::til::PrettyPrinter::Prec_Postfix
static const unsigned Prec_Postfix
Definition: ThreadSafetyTraverse.h:434
clang::threadSafety::til::VisitReducer::reduceArrayAdd
R_SExpr reduceArrayAdd(Store &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:234
clang::threadSafety::til::CopyReducerBase::Arena
MemRegionRef Arena
Definition: ThreadSafetyTraverse.h:161
V
#define V(N, I)
Definition: ASTContext.h:3121
clang::threadSafety::til::VisitReducer
Definition: ThreadSafetyTraverse.h:185
clang::threadSafety::til::ValueType::BT_Pointer
@ BT_Pointer
Definition: ThreadSafetyTIL.h:160
clang::threadSafety::til::VisitReducer::reduceVariableRef
Variable * reduceVariableRef(Variable *Ovd)
Definition: ThreadSafetyTraverse.h:290
clang::threadSafety::til::VisitReducer::reduceReturn
R_SExpr reduceReturn(Return &O, R_SExpr E)
Definition: ThreadSafetyTraverse.h:267
clang::threadSafety::til::PrettyPrinter::printLiteralPtr
void printLiteralPtr(const LiteralPtr *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:625
clang::threadSafety::til::VisitReducer::reduceSApply
R_SExpr reduceSApply(SApply &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:220
clang::threadSafety::til::MatchComparator::enterScope
void enterScope(const Variable *V1, const Variable *V2)
Definition: ThreadSafetyTraverse.h:386
clang::threadSafety::til::PrettyPrinter::printBBInstr
void printBBInstr(const SExpr *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:823
clang::threadSafety::til::ValueType::BT_Void
@ BT_Void
Definition: ThreadSafetyTIL.h:155
clang::threadSafety::til::ValueType::Size
SizeType Size
Definition: ThreadSafetyTIL.h:183
clang::threadSafety::til::Alloc
Allocate memory for a new value on the heap or stack.
Definition: ThreadSafetyTIL.h:995
clang::threadSafety::til::PrettyPrinter::Prec_Decl
static const unsigned Prec_Decl
Definition: ThreadSafetyTraverse.h:438
clang::threadSafety::til::Apply::arg
SExpr * arg()
Definition: ThreadSafetyTIL.h:850
clang::threadSafety::til::PrettyPrinter::printNull
void printNull(StreamType &SS)
Definition: ThreadSafetyTraverse.h:525
clang::threadSafety::til::PrettyPrinter::printBranch
void printBranch(const Branch *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:880
clang::threadSafety::til::CAST_toFloat
@ CAST_toFloat
Definition: ThreadSafetyTIL.h:123
clang::threadSafety::til::MatchComparator::compareStrings
bool compareStrings(StringRef s, StringRef r)
Definition: ThreadSafetyTraverse.h:372
clang::threadSafety::til::VisitReducer::enterCFG
void enterCFG(SCFG &Cfg)
Definition: ThreadSafetyTraverse.h:285
clang::threadSafety::til::ValueType::BT_Float
@ BT_Float
Definition: ThreadSafetyTIL.h:158
clang::threadSafety::til::VisitReducer::traverse
bool traverse(SExpr *E, TraversalKind K=TRV_Normal)
Definition: ThreadSafetyTraverse.h:294
clang::threadSafety::til::VisitReducerBase
Definition: ThreadSafetyTraverse.h:165
clang::threadSafety::til::PrettyPrinter::printUndefined
void printUndefined(const Undefined *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:533
clang::threadSafety::til::PrettyPrinter::printSApply
void printSApply(const SApply *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:696
clang::threadSafety::til::VisitReducer::reduceLoad
R_SExpr reduceLoad(Load &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:227
clang::threadSafety::til::EqualsComparator::leaveScope
void leaveScope()
Definition: ThreadSafetyTraverse.h:349
clang::threadSafety::til::LiteralT
Definition: ThreadSafetyTIL.h:526
bool
#define bool
Definition: stdbool.h:15
clang::threadSafety::til::Cast::castOpcode
TIL_CastOpcode castOpcode() const
Definition: ThreadSafetyTIL.h:1262
clang::threadSafety::til::PrettyPrinter::printAlloc
void printAlloc(const Alloc *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:743
clang::threadSafety::til::Code
A block of code – e.g. the body of a function.
Definition: ThreadSafetyTIL.h:765
clang::threadSafety::til::IfThenElse::elseExpr
SExpr * elseExpr()
Definition: ThreadSafetyTIL.h:1827
clang::threadSafety::til::SimpleReducerBase::subExprCtx
R_Ctx subExprCtx(R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:123
clang::threadSafety::til::Let
A let-expression, e.g.
Definition: ThreadSafetyTIL.h:1857
clang::threadSafety::til::SimpleReducerBase::TRV_Normal
@ TRV_Normal
Definition: ThreadSafetyTraverse.h:105
clang::threadSafety::til::MatchComparator::leaveScope
void leaveScope()
Definition: ThreadSafetyTraverse.h:387
clang::threadSafety::til::Phi
Phi Node, for code in SSA form.
Definition: ThreadSafetyTIL.h:1293
clang::threadSafety::til::CAST_truncNum
@ CAST_truncNum
Definition: ThreadSafetyTIL.h:120
clang::threadSafety::til::getBinaryOpcodeString
StringRef getBinaryOpcodeString(TIL_BinaryOpcode Op)
Return the name of a binary opcode.
Definition: ThreadSafetyTIL.cpp:28
clang::threadSafety::til::PrettyPrinter::printField
void printField(const Field *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:675
clang::threadSafety::til::SimpleReducerBase
Definition: ThreadSafetyTraverse.h:101
clang::threadSafety::til::Undefined
Placeholder for expressions that cannot be represented in the TIL.
Definition: ThreadSafetyTIL.h:487
clang::threadSafety::til::Phi::values
const ValArray & values() const
Definition: ThreadSafetyTIL.h:1312
clang::threadSafety::til::VisitReducer::reduceProject
R_SExpr reduceProject(Project &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:224
clang::threadSafety::til::Store::source
SExpr * source()
Definition: ThreadSafetyTIL.h:1068
clang::threadSafety::til::VisitReducer::reduceCode
R_SExpr reduceCode(Code &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:208
clang::threadSafety::til::EqualsComparator::compareStrings
bool compareStrings(StringRef s, StringRef r)
Definition: ThreadSafetyTraverse.h:338
clang::threadSafety::til::PrettyPrinter::printReturn
void printReturn(const Return *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:889
clang::threadSafety::til::PrettyPrinter::Prec_Binary
static const unsigned Prec_Binary
Definition: ThreadSafetyTraverse.h:436
clang::threadSafety::til::PrettyPrinter::printBlockLabel
void printBlockLabel(StreamType &SS, const BasicBlock *BB, int index)
Definition: ThreadSafetyTraverse.h:485
clang::threadSafety::til::Literal::clangExpr
const Expr * clangExpr() const
Definition: ThreadSafetyTIL.h:539
clang::threadSafety::til::PrettyPrinter::print
static void print(const SExpr *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:420
clang::threadSafety::til::Literal::valueType
ValueType valueType() const
Definition: ThreadSafetyTIL.h:541
clang::threadSafety::til::ValueType::BT_ValueRef
@ BT_ValueRef
Definition: ThreadSafetyTIL.h:161
clang::threadSafety::til::ArrayIndex
If p is a reference to an array, then p[i] is a reference to the i'th element of the array.
Definition: ThreadSafetyTIL.h:1093
clang::threadSafety::til::Store::destination
SExpr * destination()
Definition: ThreadSafetyTIL.h:1065
clang::threadSafety::til::Literal
Definition: ThreadSafetyTIL.h:529
clang::threadSafety::til::Load::pointer
SExpr * pointer()
Definition: ThreadSafetyTIL.h:1038
clang::threadSafety::til::MatchComparator::notTrue
bool notTrue(CType ct)
Definition: ThreadSafetyTraverse.h:369
clang::threadSafety::til::SimpleArray
Definition: ThreadSafetyUtil.h:84
clang::threadSafety::til::Project::slotName
StringRef slotName() const
Definition: ThreadSafetyTIL.h:933
clang::threadSafety::til::VisitReducer::visit
static bool visit(SExpr *E)
Definition: ThreadSafetyTraverse.h:299
clang::threadSafety::til::SApply
Apply a self-argument to a self-applicable function.
Definition: ThreadSafetyTIL.h:874
clang::threadSafety::til::PrettyPrinter::printLet
void printLet(const Let *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:915
clang::threadSafety::til::MatchComparator
Definition: ThreadSafetyTraverse.h:361
clang::threadSafety::til::ValueType::Base
BaseType Base
Definition: ThreadSafetyTIL.h:182
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::threadSafety::til::VisitReducer::reduceLiteralPtr
R_SExpr reduceLiteralPtr(Literal &Orig)
Definition: ThreadSafetyTraverse.h:198
clang::threadSafety::til::SFunction::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:733
clang::threadSafety::til::ValueType::BT_Int
@ BT_Int
Definition: ThreadSafetyTIL.h:157
clang::threadSafety::til::VisitReducerBase::Container::Container
Container(VisitReducerBase &S, unsigned N)
Definition: ThreadSafetyTraverse.h:176
clang::threadSafety::til::Function::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:678
clang::threadSafety::til::CopyReducerBase
Definition: ThreadSafetyTraverse.h:138
clang::threadSafety::til::SimpleReducerBase::TRV_Lazy
@ TRV_Lazy
Definition: ThreadSafetyTraverse.h:111
clang::threadSafety::til::VisitReducer::reduceAlloc
R_SExpr reduceAlloc(Alloc &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:226
clang::threadSafety::til::Branch::condition
const SExpr * condition() const
Definition: ThreadSafetyTIL.h:1423
clang::threadSafety::til::BinaryOp
Simple arithmetic binary operations, e.g.
Definition: ThreadSafetyTIL.h:1204
clang::threadSafety::til::VisitReducer::exitBasicBlock
void exitBasicBlock(BasicBlock &BB)
Definition: ThreadSafetyTraverse.h:288
clang::threadSafety::til::SimpleReducerBase::TraversalKind
TraversalKind
Definition: ThreadSafetyTraverse.h:103
clang::threadSafety::til::ArrayAdd
Pointer arithmetic, restricted to arrays only.
Definition: ThreadSafetyTIL.h:1130
clang::threadSafety::til::PrettyPrinter::printArrayIndex
void printArrayIndex(const ArrayIndex *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:760
clang::threadSafety::til::PrettyPrinter::printCode
void printCode(const Code *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:668
clang::threadSafety::til::IfThenElse::thenExpr
SExpr * thenExpr()
Definition: ThreadSafetyTIL.h:1824
clang::threadSafety::til::Phi::status
Status status() const
Definition: ThreadSafetyTIL.h:1315
clang::threadSafety::til::SimpleReducerBase::TRV_Type
@ TRV_Type
Definition: ThreadSafetyTraverse.h:114
clang::threadSafety::til::SimpleReducerBase::declCtx
R_Ctx declCtx(R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:127
clang::threadSafety::til::ValueType
ValueTypes are data types that can actually be held in registers.
Definition: ThreadSafetyTIL.h:153
LLVM.h
clang::threadSafety::til::MatchComparator::CType
bool CType
Definition: ThreadSafetyTraverse.h:366
clang::threadSafety::til::PrettyPrinter::printGoto
void printGoto(const Goto *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:875
clang::threadSafety::til::SApply::isDelegation
bool isDelegation() const
Definition: ThreadSafetyTIL.h:888
clang::threadSafety::til::SimpleReducerBase::TRV_Decl
@ TRV_Decl
Definition: ThreadSafetyTraverse.h:108
clang::threadSafety::til::Variable
A named variable, e.g.
Definition: ThreadSafetyTIL.h:355
clang::threadSafety::til::Goto::index
unsigned index() const
Returns the index into the.
Definition: ThreadSafetyTIL.h:1382
clang::threadSafety::til::VisitReducer::reduceBasicBlockRef
BasicBlock * reduceBasicBlockRef(BasicBlock *Obb)
Definition: ThreadSafetyTraverse.h:291
clang::threadSafety::til::VisitReducer::reduceIfThenElse
R_SExpr reduceIfThenElse(IfThenElse &Orig, R_SExpr C, R_SExpr T, R_SExpr E)
Definition: ThreadSafetyTraverse.h:275
clang::threadSafety::til::MatchComparator::compareIntegers
bool compareIntegers(unsigned i, unsigned j)
Definition: ThreadSafetyTraverse.h:371
clang::NamedDecl::getQualifiedNameAsString
std::string getQualifiedNameAsString() const
Definition: Decl.cpp:1582
clang::threadSafety::til::Phi::PH_SingleVal
@ PH_SingleVal
Definition: ThreadSafetyTIL.h:1302
clang::threadSafety::til::Field::range
SExpr * range()
Definition: ThreadSafetyTIL.h:808
clang::threadSafety::til::CAST_objToPtr
@ CAST_objToPtr
Definition: ThreadSafetyTIL.h:129
clang::threadSafety::getSourceLiteralString
std::string getSourceLiteralString(const Expr *CE)
Definition: ThreadSafetyCommon.cpp:41
clang::threadSafety::til::ValueType::ST_16
@ ST_16
Definition: ThreadSafetyTIL.h:168
clang::threadSafety::til::Comparator::compareByCase
bool compareByCase(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:315
clang::threadSafety::til::ArrayAdd::index
SExpr * index()
Definition: ThreadSafetyTIL.h:1141
clang::NamedDecl::getNameAsString
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition: Decl.h:292
clang::threadSafety::til::VisitReducer::reduceField
R_SExpr reduceField(Field &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:212
clang::threadSafety::til::PrettyPrinter::printLiteralT
void printLiteralT(const LiteralT< uint8_t > *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:546
clang::threadSafety::til::Variable::VK_SFun
@ VK_SFun
SFunction (self) parameter.
Definition: ThreadSafetyTIL.h:365
clang::threadSafety::til::VisitReducer::reduceLiteral
R_SExpr reduceLiteral(Literal &Orig)
Definition: ThreadSafetyTraverse.h:195
clang::threadSafety::til::ArrayAdd::array
SExpr * array()
Definition: ThreadSafetyTIL.h:1138
clang::threadSafety::til::LiteralT::value
T value() const
Definition: ThreadSafetyTIL.h:570
clang::threadSafety::til::PrettyPrinter::printFunction
void printFunction(const Function *E, StreamType &SS, unsigned sugared=0)
Definition: ThreadSafetyTraverse.h:636
clang::threadSafety::til::PrettyPrinter::printUnaryOp
void printUnaryOp(const UnaryOp *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:773
clang::threadSafety::til::ValueType::ST_32
@ ST_32
Definition: ThreadSafetyTIL.h:169
clang::threadSafety::til::MemRegionRef
Definition: ThreadSafetyUtil.h:38
clang::threadSafety::til::PrettyPrinter::newline
void newline(StreamType &SS)
Definition: ThreadSafetyTraverse.h:428
clang::threadSafety::til::VisitReducer::reduceCast
R_SExpr reduceCast(Cast &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:244
clang::threadSafety::til::SimpleReducerBase::typeCtx
R_Ctx typeCtx(R_Ctx Ctx)
Definition: ThreadSafetyTraverse.h:134
clang::threadSafety::til::PrettyPrinter::Prec_Other
static const unsigned Prec_Other
Definition: ThreadSafetyTraverse.h:437
clang::threadSafety::til::BasicBlock
A basic block is part of an SCFG.
Definition: ThreadSafetyTIL.h:1501
clang::threadSafety::til::SApply::arg
SExpr * arg()
Definition: ThreadSafetyTIL.h:885
clang
Definition: CalledOnceCheck.h:17
clang::threadSafety::til::VisitReducer::reduceLiteralT
R_SExpr reduceLiteralT(LiteralT< T > &Orig)
Definition: ThreadSafetyTraverse.h:197
clang::threadSafety::til::EqualsComparator
Definition: ThreadSafetyTraverse.h:327
clang::threadSafety::til::PrettyPrinter::printCall
void printCall(const Call *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:731
clang::threadSafety::til::Function
A function – a.k.a.
Definition: ThreadSafetyTIL.h:664
clang::threadSafety::til::getUnaryOpcodeString
StringRef getUnaryOpcodeString(TIL_UnaryOpcode Op)
Return the name of a unary opcode.
Definition: ThreadSafetyTIL.cpp:19
clang::threadSafety::til::Alloc::dataType
SExpr * dataType()
Definition: ThreadSafetyTIL.h:1009
clang::threadSafety::til::PrettyPrinter::printPhi
void printPhi(const Phi *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:860
clang::threadSafety::til::ValueType::ST_64
@ ST_64
Definition: ThreadSafetyTIL.h:170
clang::threadSafety::til::Goto::targetBlock
const BasicBlock * targetBlock() const
Definition: ThreadSafetyTIL.h:1378
clang::threadSafety::til::VisitReducer::reduceUndefined
R_SExpr reduceUndefined(Undefined &Orig)
Definition: ThreadSafetyTraverse.h:192
clang::threadSafety::til::Let::variableDecl
Variable * variableDecl()
Definition: ThreadSafetyTIL.h:1869
s
__device__ __2f16 float bool s
Definition: __clang_hip_libdevice_declares.h:315
clang::threadSafety::til::VisitReducer::reduceBinaryOp
R_SExpr reduceBinaryOp(BinaryOp &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:240
clang::threadSafety::til::Store
Store a value to memory.
Definition: ThreadSafetyTIL.h:1058
clang::threadSafety::til::ValueType::ST_8
@ ST_8
Definition: ThreadSafetyTIL.h:167
clang::threadSafety::til::SExpr::id
unsigned id() const
Returns the instruction ID for this expression.
Definition: ThreadSafetyTIL.h:311
clang::threadSafety::til::PrettyPrinter::printVariable
void printVariable(const Variable *V, StreamType &SS, bool IsVarDecl=false)
Definition: ThreadSafetyTraverse.h:629
clang::threadSafety::til::SFunction::body
SExpr * body()
Definition: ThreadSafetyTIL.h:736
clang::threadSafety::til::VisitReducer::enterScope
Variable * enterScope(Variable &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:283
clang::threadSafety::til::EqualsComparator::compareIntegers
bool compareIntegers(unsigned i, unsigned j)
Definition: ThreadSafetyTraverse.h:337
clang::threadSafety::til::MatchComparator::trueResult
CType trueResult()
Definition: ThreadSafetyTraverse.h:368
clang::threadSafety::til::Field::body
SExpr * body()
Definition: ThreadSafetyTIL.h:811
clang::threadSafety::til::PrettyPrinter
Definition: ThreadSafetyTraverse.h:405
clang::threadSafety::til::PrettyPrinter::printProject
void printProject(const Project *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:705
clang::threadSafety::til::Return
Return from the enclosing function, passing the return value to the caller.
Definition: ThreadSafetyTIL.h:1458
clang::threadSafety::til::PrettyPrinter::printIfThenElse
void printIfThenElse(const IfThenElse *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:898
clang::threadSafety::til::PrettyPrinter::printBinaryOp
void printBinaryOp(const BinaryOp *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:778
clang::threadSafety::til::MatchComparator::comparePointers
bool comparePointers(const void *P, const void *Q)
Definition: ThreadSafetyTraverse.h:373
clang::threadSafety::til::PrettyPrinter::printApply
void printApply(const Apply *E, StreamType &SS, bool sugared=false)
Definition: ThreadSafetyTraverse.h:682
clang::threadSafety::til::VisitReducer::reduceIdentifier
R_SExpr reduceIdentifier(Identifier &Orig)
Definition: ThreadSafetyTraverse.h:271
clang::threadSafety::til::BinaryOp::binaryOpcode
TIL_BinaryOpcode binaryOpcode() const
Definition: ThreadSafetyTIL.h:1218
clang::threadSafety::til::PrettyPrinter::printCast
void printCast(const Cast *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:784
clang::threadSafety::til::EqualsComparator::compareExprs
static bool compareExprs(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:355
clang::threadSafety::til::PrettyPrinter::printBasicBlock
void printBasicBlock(const BasicBlock *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:839
clang::threadSafety::til::SCFG
An SCFG is a control-flow graph.
Definition: ThreadSafetyTIL.h:1688
clang::threadSafety::til::Literal::as
const LiteralT< T > & as() const
Definition: ThreadSafetyTIL.h:543
clang::threadSafety::til::SFunction
A self-applicable function.
Definition: ThreadSafetyTIL.h:715
clang::threadSafety::til::CAST_extendNum
@ CAST_extendNum
Definition: ThreadSafetyTIL.h:117
clang::threadSafety::til::PrettyPrinter::Prec_MAX
static const unsigned Prec_MAX
Definition: ThreadSafetyTraverse.h:439
clang::threadSafety::til::Identifier::name
StringRef name() const
Definition: ThreadSafetyTIL.h:1794
clang::threadSafety::til::Comparator
Definition: ThreadSafetyTraverse.h:310
clang::threadSafety::til::EqualsComparator::notTrue
bool notTrue(CType ct)
Definition: ThreadSafetyTraverse.h:335
clang::threadSafety::til::MatchComparator::compare
bool compare(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:375
clang::threadSafety::til::Function::body
SExpr * body()
Definition: ThreadSafetyTIL.h:681
clang::threadSafety::til::LiteralPtr
A Literal pointer to an object allocated in memory.
Definition: ThreadSafetyTIL.h:635
clang::threadSafety::til::VisitReducer::reduceUnaryOp
R_SExpr reduceUnaryOp(UnaryOp &Orig, R_SExpr E0)
Definition: ThreadSafetyTraverse.h:238
clang::threadSafety::til::BinaryOp::expr1
SExpr * expr1()
Definition: ThreadSafetyTIL.h:1225
clang::threadSafety::til::VisitReducer::reduceNull
R_SExpr reduceNull()
Definition: ThreadSafetyTraverse.h:191
clang::threadSafety::til::EqualsComparator::comparePointers
bool comparePointers(const void *P, const void *Q)
Definition: ThreadSafetyTraverse.h:339
clang::threadSafety::til::VisitReducer::reduceApply
R_SExpr reduceApply(Apply &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:216
clang::threadSafety::til::IfThenElse
An if-then-else expression.
Definition: ThreadSafetyTIL.h:1812
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:142
clang::threadSafety::til::Traversal
Definition: ThreadSafetyTraverse.h:58
clang::threadSafety::til::EqualsComparator::compareVariableRefs
bool compareVariableRefs(const Variable *V1, const Variable *V2)
Definition: ThreadSafetyTraverse.h:351
clang::threadSafety::til::EqualsComparator::CType
bool CType
Definition: ThreadSafetyTraverse.h:332
clang::threadSafety::til::Project::record
SExpr * record()
Definition: ThreadSafetyTIL.h:921
clang::threadSafety::til::VisitReducer::reduceArrayIndex
R_SExpr reduceArrayIndex(Store &Orig, R_SExpr E0, R_SExpr E1)
Definition: ThreadSafetyTraverse.h:230
clang::threadSafety::til::CAST_toInt
@ CAST_toInt
Definition: ThreadSafetyTIL.h:126
clang::threadSafety::til::EqualsComparator::compare
bool compare(const SExpr *E1, const SExpr *E2)
Definition: ThreadSafetyTraverse.h:341
clang::threadSafety::til::PrettyPrinter::printFuture
void printFuture(const Future *E, StreamType &SS)
Definition: ThreadSafetyTraverse.h:529
clang::threadSafety::til::Cast::expr
SExpr * expr()
Definition: ThreadSafetyTIL.h:1266
clang::threadSafety::til::SExpr
Base class for AST nodes in the typed intermediate language.
Definition: ThreadSafetyTIL.h:277