clang  9.0.0svn
ScopeInfo.h
Go to the documentation of this file.
1 //===- ScopeInfo.h - Information about a semantic context -------*- 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 FunctionScopeInfo and its subclasses, which contain
10 // information about a single function, block, lambda, or method body.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SEMA_SCOPEINFO_H
15 #define LLVM_CLANG_SEMA_SCOPEINFO_H
16 
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/Type.h"
20 #include "clang/Basic/LLVM.h"
23 #include "clang/Sema/CleanupInfo.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/DenseMapInfo.h"
26 #include "llvm/ADT/MapVector.h"
27 #include "llvm/ADT/PointerIntPair.h"
28 #include "llvm/ADT/SmallPtrSet.h"
29 #include "llvm/ADT/SmallSet.h"
30 #include "llvm/ADT/SmallVector.h"
31 #include "llvm/ADT/StringRef.h"
32 #include "llvm/ADT/StringSwitch.h"
33 #include "llvm/ADT/TinyPtrVector.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include <algorithm>
37 #include <cassert>
38 #include <utility>
39 
40 namespace clang {
41 
42 class BlockDecl;
43 class CapturedDecl;
44 class CXXMethodDecl;
45 class CXXRecordDecl;
46 class ImplicitParamDecl;
47 class NamedDecl;
48 class ObjCIvarRefExpr;
49 class ObjCMessageExpr;
50 class ObjCPropertyDecl;
51 class ObjCPropertyRefExpr;
52 class ParmVarDecl;
53 class RecordDecl;
54 class ReturnStmt;
55 class Scope;
56 class Stmt;
57 class SwitchStmt;
58 class TemplateParameterList;
59 class TemplateTypeParmDecl;
60 class VarDecl;
61 
62 namespace sema {
63 
64 /// Contains information about the compound statement currently being
65 /// parsed.
67 public:
68  /// Whether this compound stamement contains `for' or `while' loops
69  /// with empty bodies.
70  bool HasEmptyLoopBodies = false;
71 
72  /// Whether this compound statement corresponds to a GNU statement
73  /// expression.
74  bool IsStmtExpr;
75 
76  CompoundScopeInfo(bool IsStmtExpr) : IsStmtExpr(IsStmtExpr) {}
77 
79  HasEmptyLoopBodies = true;
80  }
81 };
82 
84 public:
87  llvm::TinyPtrVector<const Stmt*> Stmts;
88 
91  : PD(PD), Loc(Loc), Stmts(Stmts) {}
92 };
93 
94 /// Retains information about a function, method, or block that is
95 /// currently being parsed.
97 protected:
98  enum ScopeKind {
102  SK_CapturedRegion
103  };
104 
105 public:
106  /// What kind of scope we are describing.
108 
109  /// Whether this function contains a VLA, \@try, try, C++
110  /// initializer, or anything else that can't be jumped past.
112 
113  /// Whether this function contains any switches or direct gotos.
115 
116  /// Whether this function contains any indirect gotos.
117  bool HasIndirectGoto : 1;
118 
119  /// Whether a statement was dropped because it was invalid.
120  bool HasDroppedStmt : 1;
121 
122  /// True if current scope is for OpenMP declare reduction combiner.
124 
125  /// Whether there is a fallthrough statement in this function.
127 
128  /// Whether we make reference to a declaration that could be
129  /// unavailable.
131 
132  /// A flag that is set when parsing a method that must call super's
133  /// implementation, such as \c -dealloc, \c -finalize, or any method marked
134  /// with \c __attribute__((objc_requires_super)).
136 
137  /// True when this is a method marked as a designated initializer.
139 
140  /// This starts true for a method marked as designated initializer and will
141  /// be set to false if there is an invocation to a designated initializer of
142  /// the super class.
144 
145  /// True when this is an initializer method not marked as a designated
146  /// initializer within a class that has at least one initializer marked as a
147  /// designated initializer.
149 
150  /// This starts true for a secondary initializer method and will be set to
151  /// false if there is an invocation of an initializer on 'self'.
153 
154  /// True only when this function has not already built, or attempted
155  /// to build, the initial and final coroutine suspend points
157 
158  /// An enumeration represeting the kind of the first coroutine statement
159  /// in the function. One of co_return, co_await, or co_yield.
160  unsigned char FirstCoroutineStmtKind : 2;
161 
162  /// First coroutine statement in the current function.
163  /// (ex co_return, co_await, co_yield)
165 
166  /// First 'return' statement in the current function.
168 
169  /// First C++ 'try' statement in the current function.
171 
172  /// First SEH '__try' statement in the current function.
174 
175  /// Used to determine if errors occurred in this function or block.
177 
178  /// A SwitchStmt, along with a flag indicating if its list of case statements
179  /// is incomplete (because we dropped an invalid one while parsing).
180  using SwitchInfo = llvm::PointerIntPair<SwitchStmt*, 1, bool>;
181 
182  /// SwitchStack - This is the current set of active switch statements in the
183  /// block.
185 
186  /// The list of return statements that occur within the function or
187  /// block, if there is any chance of applying the named return value
188  /// optimization, or if we need to infer a return type.
190 
191  /// The promise object for this coroutine, if any.
192  VarDecl *CoroutinePromise = nullptr;
193 
194  /// A mapping between the coroutine function parameters that were moved
195  /// to the coroutine frame, and their move statements.
196  llvm::SmallMapVector<ParmVarDecl *, Stmt *, 4> CoroutineParameterMoves;
197 
198  /// The initial and final coroutine suspend points.
199  std::pair<Stmt *, Stmt *> CoroutineSuspends;
200 
201  /// The stack of currently active compound stamement scopes in the
202  /// function.
204 
205  /// The set of blocks that are introduced in this function.
206  llvm::SmallPtrSet<const BlockDecl *, 1> Blocks;
207 
208  /// The set of __block variables that are introduced in this function.
209  llvm::TinyPtrVector<VarDecl *> ByrefBlockVars;
210 
211  /// A list of PartialDiagnostics created but delayed within the
212  /// current function scope. These diagnostics are vetted for reachability
213  /// prior to being emitted.
215 
216  /// A list of parameters which have the nonnull attribute and are
217  /// modified in the function.
218  llvm::SmallPtrSet<const ParmVarDecl *, 8> ModifiedNonNullParams;
219 
220 public:
221  /// Represents a simple identification of a weak object.
222  ///
223  /// Part of the implementation of -Wrepeated-use-of-weak.
224  ///
225  /// This is used to determine if two weak accesses refer to the same object.
226  /// Here are some examples of how various accesses are "profiled":
227  ///
228  /// Access Expression | "Base" Decl | "Property" Decl
229  /// :---------------: | :-----------------: | :------------------------------:
230  /// self.property | self (VarDecl) | property (ObjCPropertyDecl)
231  /// self.implicitProp | self (VarDecl) | -implicitProp (ObjCMethodDecl)
232  /// self->ivar.prop | ivar (ObjCIvarDecl) | prop (ObjCPropertyDecl)
233  /// cxxObj.obj.prop | obj (FieldDecl) | prop (ObjCPropertyDecl)
234  /// [self foo].prop | 0 (unknown) | prop (ObjCPropertyDecl)
235  /// self.prop1.prop2 | prop1 (ObjCPropertyDecl) | prop2 (ObjCPropertyDecl)
236  /// MyClass.prop | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl)
237  /// MyClass.foo.prop | +foo (ObjCMethodDecl) | -prop (ObjCPropertyDecl)
238  /// weakVar | 0 (known) | weakVar (VarDecl)
239  /// self->weakIvar | self (VarDecl) | weakIvar (ObjCIvarDecl)
240  ///
241  /// Objects are identified with only two Decls to make it reasonably fast to
242  /// compare them.
244  /// The base object decl, as described in the class documentation.
245  ///
246  /// The extra flag is "true" if the Base and Property are enough to uniquely
247  /// identify the object in memory.
248  ///
249  /// \sa isExactProfile()
250  using BaseInfoTy = llvm::PointerIntPair<const NamedDecl *, 1, bool>;
251  BaseInfoTy Base;
252 
253  /// The "property" decl, as described in the class documentation.
254  ///
255  /// Note that this may not actually be an ObjCPropertyDecl, e.g. in the
256  /// case of "implicit" properties (regular methods accessed via dot syntax).
257  const NamedDecl *Property = nullptr;
258 
259  /// Used to find the proper base profile for a given base expression.
260  static BaseInfoTy getBaseInfo(const Expr *BaseE);
261 
262  inline WeakObjectProfileTy();
263  static inline WeakObjectProfileTy getSentinel();
264 
265  public:
267  WeakObjectProfileTy(const Expr *Base, const ObjCPropertyDecl *Property);
268  WeakObjectProfileTy(const DeclRefExpr *RE);
270 
271  const NamedDecl *getBase() const { return Base.getPointer(); }
272  const NamedDecl *getProperty() const { return Property; }
273 
274  /// Returns true if the object base specifies a known object in memory,
275  /// rather than, say, an instance variable or property of another object.
276  ///
277  /// Note that this ignores the effects of aliasing; that is, \c foo.bar is
278  /// considered an exact profile if \c foo is a local variable, even if
279  /// another variable \c foo2 refers to the same object as \c foo.
280  ///
281  /// For increased precision, accesses with base variables that are
282  /// properties or ivars of 'self' (e.g. self.prop1.prop2) are considered to
283  /// be exact, though this is not true for arbitrary variables
284  /// (foo.prop1.prop2).
285  bool isExactProfile() const {
286  return Base.getInt();
287  }
288 
289  bool operator==(const WeakObjectProfileTy &Other) const {
290  return Base == Other.Base && Property == Other.Property;
291  }
292 
293  // For use in DenseMap.
294  // We can't specialize the usual llvm::DenseMapInfo at the end of the file
295  // because by that point the DenseMap in FunctionScopeInfo has already been
296  // instantiated.
297  class DenseMapInfo {
298  public:
300  return WeakObjectProfileTy();
301  }
302 
304  return WeakObjectProfileTy::getSentinel();
305  }
306 
307  static unsigned getHashValue(const WeakObjectProfileTy &Val) {
308  using Pair = std::pair<BaseInfoTy, const NamedDecl *>;
309 
310  return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base,
311  Val.Property));
312  }
313 
314  static bool isEqual(const WeakObjectProfileTy &LHS,
315  const WeakObjectProfileTy &RHS) {
316  return LHS == RHS;
317  }
318  };
319  };
320 
321  /// Represents a single use of a weak object.
322  ///
323  /// Stores both the expression and whether the access is potentially unsafe
324  /// (i.e. it could potentially be warned about).
325  ///
326  /// Part of the implementation of -Wrepeated-use-of-weak.
327  class WeakUseTy {
328  llvm::PointerIntPair<const Expr *, 1, bool> Rep;
329 
330  public:
331  WeakUseTy(const Expr *Use, bool IsRead) : Rep(Use, IsRead) {}
332 
333  const Expr *getUseExpr() const { return Rep.getPointer(); }
334  bool isUnsafe() const { return Rep.getInt(); }
335  void markSafe() { Rep.setInt(false); }
336 
337  bool operator==(const WeakUseTy &Other) const {
338  return Rep == Other.Rep;
339  }
340  };
341 
342  /// Used to collect uses of a particular weak object in a function body.
343  ///
344  /// Part of the implementation of -Wrepeated-use-of-weak.
346 
347  /// Used to collect all uses of weak objects in a function body.
348  ///
349  /// Part of the implementation of -Wrepeated-use-of-weak.
350  using WeakObjectUseMap =
351  llvm::SmallDenseMap<WeakObjectProfileTy, WeakUseVector, 8,
353 
354 private:
355  /// Used to collect all uses of weak objects in this function body.
356  ///
357  /// Part of the implementation of -Wrepeated-use-of-weak.
358  WeakObjectUseMap WeakObjectUses;
359 
360 protected:
361  FunctionScopeInfo(const FunctionScopeInfo&) = default;
362 
363 public:
365  : Kind(SK_Function), HasBranchProtectedScope(false),
366  HasBranchIntoScope(false), HasIndirectGoto(false),
367  HasDroppedStmt(false), HasOMPDeclareReductionCombiner(false),
368  HasFallthroughStmt(false), HasPotentialAvailabilityViolations(false),
369  ObjCShouldCallSuper(false), ObjCIsDesignatedInit(false),
370  ObjCWarnForNoDesignatedInitChain(false), ObjCIsSecondaryInit(false),
371  ObjCWarnForNoInitDelegation(false), NeedsCoroutineSuspends(true),
372  ErrorTrap(Diag) {}
373 
374  virtual ~FunctionScopeInfo();
375 
376  /// Record that a weak object was accessed.
377  ///
378  /// Part of the implementation of -Wrepeated-use-of-weak.
379  template <typename ExprT>
380  inline void recordUseOfWeak(const ExprT *E, bool IsRead = true);
381 
382  void recordUseOfWeak(const ObjCMessageExpr *Msg,
383  const ObjCPropertyDecl *Prop);
384 
385  /// Record that a given expression is a "safe" access of a weak object (e.g.
386  /// assigning it to a strong variable.)
387  ///
388  /// Part of the implementation of -Wrepeated-use-of-weak.
389  void markSafeWeakUse(const Expr *E);
390 
392  return WeakObjectUses;
393  }
394 
396  HasBranchIntoScope = true;
397  }
398 
400  HasBranchProtectedScope = true;
401  }
402 
404  HasIndirectGoto = true;
405  }
406 
408  HasDroppedStmt = true;
409  }
410 
412  HasOMPDeclareReductionCombiner = true;
413  }
414 
416  HasFallthroughStmt = true;
417  }
418 
420  setHasBranchProtectedScope();
421  FirstCXXTryLoc = TryLoc;
422  }
423 
425  setHasBranchProtectedScope();
426  FirstSEHTryLoc = TryLoc;
427  }
428 
429  bool NeedsScopeChecking() const {
430  return !HasDroppedStmt &&
431  (HasIndirectGoto ||
432  (HasBranchProtectedScope && HasBranchIntoScope));
433  }
434 
435  // Add a block introduced in this function.
436  void addBlock(const BlockDecl *BD) {
437  Blocks.insert(BD);
438  }
439 
440  // Add a __block variable introduced in this function.
442  ByrefBlockVars.push_back(VD);
443  }
444 
445  bool isCoroutine() const { return !FirstCoroutineStmtLoc.isInvalid(); }
446 
447  void setFirstCoroutineStmt(SourceLocation Loc, StringRef Keyword) {
448  assert(FirstCoroutineStmtLoc.isInvalid() &&
449  "first coroutine statement location already set");
450  FirstCoroutineStmtLoc = Loc;
451  FirstCoroutineStmtKind = llvm::StringSwitch<unsigned char>(Keyword)
452  .Case("co_return", 0)
453  .Case("co_await", 1)
454  .Case("co_yield", 2);
455  }
456 
457  StringRef getFirstCoroutineStmtKeyword() const {
458  assert(FirstCoroutineStmtLoc.isValid()
459  && "no coroutine statement available");
460  switch (FirstCoroutineStmtKind) {
461  case 0: return "co_return";
462  case 1: return "co_await";
463  case 2: return "co_yield";
464  default:
465  llvm_unreachable("FirstCoroutineStmtKind has an invalid value");
466  };
467  }
468 
469  void setNeedsCoroutineSuspends(bool value = true) {
470  assert((!value || CoroutineSuspends.first == nullptr) &&
471  "we already have valid suspend points");
472  NeedsCoroutineSuspends = value;
473  }
474 
476  return !NeedsCoroutineSuspends && CoroutineSuspends.first == nullptr;
477  }
478 
479  void setCoroutineSuspends(Stmt *Initial, Stmt *Final) {
480  assert(Initial && Final && "suspend points cannot be null");
481  assert(CoroutineSuspends.first == nullptr && "suspend points already set");
482  NeedsCoroutineSuspends = false;
483  CoroutineSuspends.first = Initial;
484  CoroutineSuspends.second = Final;
485  }
486 
487  /// Clear out the information in this function scope, making it
488  /// suitable for reuse.
489  void Clear();
490 };
491 
492 class Capture {
493  // There are three categories of capture: capturing 'this', capturing
494  // local variables, and C++1y initialized captures (which can have an
495  // arbitrary initializer, and don't really capture in the traditional
496  // sense at all).
497  //
498  // There are three ways to capture a local variable:
499  // - capture by copy in the C++11 sense,
500  // - capture by reference in the C++11 sense, and
501  // - __block capture.
502  // Lambdas explicitly specify capture by copy or capture by reference.
503  // For blocks, __block capture applies to variables with that annotation,
504  // variables of reference type are captured by reference, and other
505  // variables are captured by copy.
506  enum CaptureKind {
507  Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
508  };
509  enum {
510  IsNestedCapture = 0x1,
511  IsThisCaptured = 0x2
512  };
513 
514  /// The variable being captured (if we are not capturing 'this') and whether
515  /// this is a nested capture, and whether we are capturing 'this'
516  llvm::PointerIntPair<VarDecl*, 2> VarAndNestedAndThis;
517 
518  /// Expression to initialize a field of the given type, and the kind of
519  /// capture (if this is a capture and not an init-capture). The expression
520  /// is only required if we are capturing ByVal and the variable's type has
521  /// a non-trivial copy constructor.
522  llvm::PointerIntPair<void *, 2, CaptureKind> InitExprAndCaptureKind;
523 
524  /// The source location at which the first capture occurred.
525  SourceLocation Loc;
526 
527  /// The location of the ellipsis that expands a parameter pack.
528  SourceLocation EllipsisLoc;
529 
530  /// The type as it was captured, which is in effect the type of the
531  /// non-static data member that would hold the capture.
532  QualType CaptureType;
533 
534  /// Whether an explicit capture has been odr-used in the body of the
535  /// lambda.
536  bool ODRUsed = false;
537 
538  /// Whether an explicit capture has been non-odr-used in the body of
539  /// the lambda.
540  bool NonODRUsed = false;
541 
542 public:
543  Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested,
544  SourceLocation Loc, SourceLocation EllipsisLoc,
545  QualType CaptureType, Expr *Cpy)
546  : VarAndNestedAndThis(Var, IsNested ? IsNestedCapture : 0),
547  InitExprAndCaptureKind(
548  Cpy, !Var ? Cap_VLA : Block ? Cap_Block : ByRef ? Cap_ByRef
549  : Cap_ByCopy),
550  Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {}
551 
552  enum IsThisCapture { ThisCapture };
553  Capture(IsThisCapture, bool IsNested, SourceLocation Loc,
554  QualType CaptureType, Expr *Cpy, const bool ByCopy)
555  : VarAndNestedAndThis(
556  nullptr, (IsThisCaptured | (IsNested ? IsNestedCapture : 0))),
557  InitExprAndCaptureKind(Cpy, ByCopy ? Cap_ByCopy : Cap_ByRef),
558  Loc(Loc), CaptureType(CaptureType) {}
559 
560  bool isThisCapture() const {
561  return VarAndNestedAndThis.getInt() & IsThisCaptured;
562  }
563 
564  bool isVariableCapture() const {
565  return !isThisCapture() && !isVLATypeCapture();
566  }
567 
568  bool isCopyCapture() const {
569  return InitExprAndCaptureKind.getInt() == Cap_ByCopy;
570  }
571 
572  bool isReferenceCapture() const {
573  return InitExprAndCaptureKind.getInt() == Cap_ByRef;
574  }
575 
576  bool isBlockCapture() const {
577  return InitExprAndCaptureKind.getInt() == Cap_Block;
578  }
579 
580  bool isVLATypeCapture() const {
581  return InitExprAndCaptureKind.getInt() == Cap_VLA;
582  }
583 
584  bool isNested() const {
585  return VarAndNestedAndThis.getInt() & IsNestedCapture;
586  }
587 
588  bool isODRUsed() const { return ODRUsed; }
589  bool isNonODRUsed() const { return NonODRUsed; }
590  void markUsed(bool IsODRUse) { (IsODRUse ? ODRUsed : NonODRUsed) = true; }
591 
592  VarDecl *getVariable() const {
593  assert(isVariableCapture());
594  return VarAndNestedAndThis.getPointer();
595  }
596 
597  /// Retrieve the location at which this variable was captured.
598  SourceLocation getLocation() const { return Loc; }
599 
600  /// Retrieve the source location of the ellipsis, whose presence
601  /// indicates that the capture is a pack expansion.
602  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
603 
604  /// Retrieve the capture type for this capture, which is effectively
605  /// the type of the non-static data member in the lambda/block structure
606  /// that would store this capture.
608  assert(!isThisCapture());
609  return CaptureType;
610  }
611 
612  Expr *getInitExpr() const {
613  assert(!isVLATypeCapture() && "no init expression for type capture");
614  return static_cast<Expr *>(InitExprAndCaptureKind.getPointer());
615  }
616 };
617 
619 protected:
620  CapturingScopeInfo(const CapturingScopeInfo&) = default;
621 
622 public:
624  ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block,
625  ImpCap_CapturedRegion
626  };
627 
629 
631  : FunctionScopeInfo(Diag), ImpCaptureStyle(Style) {}
632 
633  /// CaptureMap - A map of captured variables to (index+1) into Captures.
634  llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
635 
636  /// CXXThisCaptureIndex - The (index+1) of the capture of 'this';
637  /// zero if 'this' is not captured.
638  unsigned CXXThisCaptureIndex = 0;
639 
640  /// Captures - The captures.
642 
643  /// - Whether the target type of return statements in this context
644  /// is deduced (e.g. a lambda or block with omitted return type).
645  bool HasImplicitReturnType = false;
646 
647  /// ReturnType - The target type of return statements in this context,
648  /// or null if unknown.
650 
651  void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested,
652  SourceLocation Loc, SourceLocation EllipsisLoc,
653  QualType CaptureType, Expr *Cpy) {
654  Captures.push_back(Capture(Var, isBlock, isByref, isNested, Loc,
655  EllipsisLoc, CaptureType, Cpy));
656  CaptureMap[Var] = Captures.size();
657  }
658 
659  void addVLATypeCapture(SourceLocation Loc, QualType CaptureType) {
660  Captures.push_back(Capture(/*Var*/ nullptr, /*isBlock*/ false,
661  /*isByref*/ false, /*isNested*/ false, Loc,
662  /*EllipsisLoc*/ SourceLocation(), CaptureType,
663  /*Cpy*/ nullptr));
664  }
665 
666  // Note, we do not need to add the type of 'this' since that is always
667  // retrievable from Sema::getCurrentThisType - and is also encoded within the
668  // type of the corresponding FieldDecl.
669  void addThisCapture(bool isNested, SourceLocation Loc,
670  Expr *Cpy, bool ByCopy);
671 
672  /// Determine whether the C++ 'this' is captured.
673  bool isCXXThisCaptured() const { return CXXThisCaptureIndex != 0; }
674 
675  /// Retrieve the capture of C++ 'this', if it has been captured.
677  assert(isCXXThisCaptured() && "this has not been captured");
678  return Captures[CXXThisCaptureIndex - 1];
679  }
680 
681  /// Determine whether the given variable has been captured.
682  bool isCaptured(VarDecl *Var) const {
683  return CaptureMap.count(Var);
684  }
685 
686  /// Determine whether the given variable-array type has been captured.
687  bool isVLATypeCaptured(const VariableArrayType *VAT) const;
688 
689  /// Retrieve the capture of the given variable, if it has been
690  /// captured already.
692  assert(isCaptured(Var) && "Variable has not been captured");
693  return Captures[CaptureMap[Var] - 1];
694  }
695 
696  const Capture &getCapture(VarDecl *Var) const {
697  llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
698  = CaptureMap.find(Var);
699  assert(Known != CaptureMap.end() && "Variable has not been captured");
700  return Captures[Known->second - 1];
701  }
702 
703  static bool classof(const FunctionScopeInfo *FSI) {
704  return FSI->Kind == SK_Block || FSI->Kind == SK_Lambda
705  || FSI->Kind == SK_CapturedRegion;
706  }
707 };
708 
709 /// Retains information about a block that is currently being parsed.
710 class BlockScopeInfo final : public CapturingScopeInfo {
711 public:
713 
714  /// TheScope - This is the scope for the block itself, which contains
715  /// arguments etc.
717 
718  /// BlockType - The function type of the block, if one was given.
719  /// Its return type may be BuiltinType::Dependent.
721 
723  : CapturingScopeInfo(Diag, ImpCap_Block), TheDecl(Block),
724  TheScope(BlockScope) {
725  Kind = SK_Block;
726  }
727 
728  ~BlockScopeInfo() override;
729 
730  static bool classof(const FunctionScopeInfo *FSI) {
731  return FSI->Kind == SK_Block;
732  }
733 };
734 
735 /// Retains information about a captured region.
737 public:
738  /// The CapturedDecl for this statement.
740 
741  /// The captured record type.
743 
744  /// This is the enclosing scope of the captured region.
746 
747  /// The implicit parameter for the captured variables.
749 
750  /// The kind of captured region.
751  unsigned short CapRegionKind;
752 
753  unsigned short OpenMPLevel;
754 
756  RecordDecl *RD, ImplicitParamDecl *Context,
757  CapturedRegionKind K, unsigned OpenMPLevel)
758  : CapturingScopeInfo(Diag, ImpCap_CapturedRegion),
759  TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S),
760  ContextParam(Context), CapRegionKind(K), OpenMPLevel(OpenMPLevel) {
761  Kind = SK_CapturedRegion;
762  }
763 
764  ~CapturedRegionScopeInfo() override;
765 
766  /// A descriptive name for the kind of captured region this is.
767  StringRef getRegionName() const {
768  switch (CapRegionKind) {
769  case CR_Default:
770  return "default captured statement";
771  case CR_ObjCAtFinally:
772  return "Objective-C @finally statement";
773  case CR_OpenMP:
774  return "OpenMP region";
775  }
776  llvm_unreachable("Invalid captured region kind!");
777  }
778 
779  static bool classof(const FunctionScopeInfo *FSI) {
780  return FSI->Kind == SK_CapturedRegion;
781  }
782 };
783 
784 class LambdaScopeInfo final : public CapturingScopeInfo {
785 public:
786  /// The class that describes the lambda.
787  CXXRecordDecl *Lambda = nullptr;
788 
789  /// The lambda's compiler-generated \c operator().
790  CXXMethodDecl *CallOperator = nullptr;
791 
792  /// Source range covering the lambda introducer [...].
794 
795  /// Source location of the '&' or '=' specifying the default capture
796  /// type, if any.
798 
799  /// The number of captures in the \c Captures list that are
800  /// explicit captures.
801  unsigned NumExplicitCaptures = 0;
802 
803  /// Whether this is a mutable lambda.
804  bool Mutable = false;
805 
806  /// Whether the (empty) parameter list is explicit.
807  bool ExplicitParams = false;
808 
809  /// Whether any of the capture expressions requires cleanups.
811 
812  /// Whether the lambda contains an unexpanded parameter pack.
813  bool ContainsUnexpandedParameterPack = false;
814 
815  /// If this is a generic lambda, use this as the depth of
816  /// each 'auto' parameter, during initial AST construction.
817  unsigned AutoTemplateParameterDepth = 0;
818 
819  /// The number of parameters in the template parameter list that were
820  /// explicitly specified by the user, as opposed to being invented by use
821  /// of an auto parameter.
822  unsigned NumExplicitTemplateParams = 0;
823 
824  /// Source range covering the explicit template parameter list (if it exists).
826 
827  /// Store the list of the template parameters for a generic lambda.
828  /// If this is a generic lambda, this holds the explicit template parameters
829  /// followed by the auto parameters converted into TemplateTypeParmDecls.
830  /// It can be used to construct the generic lambda's template parameter list
831  /// during initial AST construction.
833 
834  /// If this is a generic lambda, and the template parameter
835  /// list has been created (from the TemplateParams) then store
836  /// a reference to it (cache it to avoid reconstructing it).
837  TemplateParameterList *GLTemplateParameterList = nullptr;
838 
839  /// Contains all variable-referring-expressions (i.e. DeclRefExprs
840  /// or MemberExprs) that refer to local variables in a generic lambda
841  /// or a lambda in a potentially-evaluated-if-used context.
842  ///
843  /// Potentially capturable variables of a nested lambda that might need
844  /// to be captured by the lambda are housed here.
845  /// This is specifically useful for generic lambdas or
846  /// lambdas within a potentially evaluated-if-used context.
847  /// If an enclosing variable is named in an expression of a lambda nested
848  /// within a generic lambda, we don't always know know whether the variable
849  /// will truly be odr-used (i.e. need to be captured) by that nested lambda,
850  /// until its instantiation. But we still need to capture it in the
851  /// enclosing lambda if all intervening lambdas can capture the variable.
853 
854  /// Contains all variable-referring-expressions that refer
855  /// to local variables that are usable as constant expressions and
856  /// do not involve an odr-use (they may still need to be captured
857  /// if the enclosing full-expression is instantiation dependent).
858  llvm::SmallSet<Expr *, 8> NonODRUsedCapturingExprs;
859 
860  /// A map of explicit capture indices to their introducer source ranges.
861  llvm::DenseMap<unsigned, SourceRange> ExplicitCaptureRanges;
862 
863  /// Contains all of the variables defined in this lambda that shadow variables
864  /// that were defined in parent contexts. Used to avoid warnings when the
865  /// shadowed variables are uncaptured by this lambda.
867  const VarDecl *VD;
869  };
871 
873 
875  : CapturingScopeInfo(Diag, ImpCap_None) {
876  Kind = SK_Lambda;
877  }
878 
879  /// Note when all explicit captures have been added.
881  NumExplicitCaptures = Captures.size();
882  }
883 
884  static bool classof(const FunctionScopeInfo *FSI) {
885  return FSI->Kind == SK_Lambda;
886  }
887 
888  /// Is this scope known to be for a generic lambda? (This will be false until
889  /// we parse a template parameter list or the first 'auto'-typed parameter).
890  bool isGenericLambda() const {
891  return !TemplateParams.empty() || GLTemplateParameterList;
892  }
893 
894  /// Add a variable that might potentially be captured by the
895  /// lambda and therefore the enclosing lambdas.
896  ///
897  /// This is also used by enclosing lambda's to speculatively capture
898  /// variables that nested lambda's - depending on their enclosing
899  /// specialization - might need to capture.
900  /// Consider:
901  /// void f(int, int); <-- don't capture
902  /// void f(const int&, double); <-- capture
903  /// void foo() {
904  /// const int x = 10;
905  /// auto L = [=](auto a) { // capture 'x'
906  /// return [=](auto b) {
907  /// f(x, a); // we may or may not need to capture 'x'
908  /// };
909  /// };
910  /// }
911  void addPotentialCapture(Expr *VarExpr) {
912  assert(isa<DeclRefExpr>(VarExpr) || isa<MemberExpr>(VarExpr));
913  PotentiallyCapturingExprs.push_back(VarExpr);
914  }
915 
917  PotentialThisCaptureLocation = Loc;
918  }
919 
920  bool hasPotentialThisCapture() const {
921  return PotentialThisCaptureLocation.isValid();
922  }
923 
924  /// Mark a variable's reference in a lambda as non-odr using.
925  ///
926  /// For generic lambdas, if a variable is named in a potentially evaluated
927  /// expression, where the enclosing full expression is dependent then we
928  /// must capture the variable (given a default capture).
929  /// This is accomplished by recording all references to variables
930  /// (DeclRefExprs or MemberExprs) within said nested lambda in its array of
931  /// PotentialCaptures. All such variables have to be captured by that lambda,
932  /// except for as described below.
933  /// If that variable is usable as a constant expression and is named in a
934  /// manner that does not involve its odr-use (e.g. undergoes
935  /// lvalue-to-rvalue conversion, or discarded) record that it is so. Upon the
936  /// act of analyzing the enclosing full expression (ActOnFinishFullExpr)
937  /// if we can determine that the full expression is not instantiation-
938  /// dependent, then we can entirely avoid its capture.
939  ///
940  /// const int n = 0;
941  /// [&] (auto x) {
942  /// (void)+n + x;
943  /// };
944  /// Interestingly, this strategy would involve a capture of n, even though
945  /// it's obviously not odr-used here, because the full-expression is
946  /// instantiation-dependent. It could be useful to avoid capturing such
947  /// variables, even when they are referred to in an instantiation-dependent
948  /// expression, if we can unambiguously determine that they shall never be
949  /// odr-used. This would involve removal of the variable-referring-expression
950  /// from the array of PotentialCaptures during the lvalue-to-rvalue
951  /// conversions. But per the working draft N3797, (post-chicago 2013) we must
952  /// capture such variables.
953  /// Before anyone is tempted to implement a strategy for not-capturing 'n',
954  /// consider the insightful warning in:
955  /// /cfe-commits/Week-of-Mon-20131104/092596.html
956  /// "The problem is that the set of captures for a lambda is part of the ABI
957  /// (since lambda layout can be made visible through inline functions and the
958  /// like), and there are no guarantees as to which cases we'll manage to build
959  /// an lvalue-to-rvalue conversion in, when parsing a template -- some
960  /// seemingly harmless change elsewhere in Sema could cause us to start or stop
961  /// building such a node. So we need a rule that anyone can implement and get
962  /// exactly the same result".
963  void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr) {
964  assert(isa<DeclRefExpr>(CapturingVarExpr)
965  || isa<MemberExpr>(CapturingVarExpr));
966  NonODRUsedCapturingExprs.insert(CapturingVarExpr);
967  }
968  bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const {
969  assert(isa<DeclRefExpr>(CapturingVarExpr)
970  || isa<MemberExpr>(CapturingVarExpr));
971  return NonODRUsedCapturingExprs.count(CapturingVarExpr);
972  }
974  PotentiallyCapturingExprs.erase(
975  std::remove(PotentiallyCapturingExprs.begin(),
976  PotentiallyCapturingExprs.end(), E),
977  PotentiallyCapturingExprs.end());
978  }
980  PotentiallyCapturingExprs.clear();
981  PotentialThisCaptureLocation = SourceLocation();
982  }
984  return PotentiallyCapturingExprs.size();
985  }
986 
987  bool hasPotentialCaptures() const {
988  return getNumPotentialVariableCaptures() ||
989  PotentialThisCaptureLocation.isValid();
990  }
991 
992  // When passed the index, returns the VarDecl and Expr associated
993  // with the index.
994  void getPotentialVariableCapture(unsigned Idx, VarDecl *&VD, Expr *&E) const;
995 };
996 
997 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
998  : Base(nullptr, false) {}
999 
1001 FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
1003  Result.Base.setInt(true);
1004  return Result;
1005 }
1006 
1007 template <typename ExprT>
1008 void FunctionScopeInfo::recordUseOfWeak(const ExprT *E, bool IsRead) {
1009  assert(E);
1010  WeakUseVector &Uses = WeakObjectUses[WeakObjectProfileTy(E)];
1011  Uses.push_back(WeakUseTy(E, IsRead));
1012 }
1013 
1014 inline void
1016  Expr *Cpy,
1017  const bool ByCopy) {
1018  Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, QualType(),
1019  Cpy, ByCopy));
1020  CXXThisCaptureIndex = Captures.size();
1021 }
1022 
1023 } // namespace sema
1024 
1025 } // namespace clang
1026 
1027 #endif // LLVM_CLANG_SEMA_SCOPEINFO_H
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:614
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
Definition: ScopeInfo.h:793
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
A (possibly-)qualified type.
Definition: Type.h:639
void addThisCapture(bool isNested, SourceLocation Loc, Expr *Cpy, bool ByCopy)
Definition: ScopeInfo.h:1015
bool HasFallthroughStmt
Whether there is a fallthrough statement in this function.
Definition: ScopeInfo.h:126
bool HasEmptyLoopBodies
Whether this compound stamement contains `for&#39; or `while&#39; loops with empty bodies.
Definition: ScopeInfo.h:70
void setNeedsCoroutineSuspends(bool value=true)
Definition: ScopeInfo.h:469
Stmt - This represents one statement.
Definition: Stmt.h:65
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
Definition: ScopeInfo.h:649
C Language Family Type Representation.
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
Definition: ScopeInfo.h:607
bool hasPotentialCaptures() const
Definition: ScopeInfo.h:987
bool operator==(const WeakUseTy &Other) const
Definition: ScopeInfo.h:337
bool isCopyCapture() const
Definition: ScopeInfo.h:568
const WeakObjectUseMap & getWeakObjectUses() const
Definition: ScopeInfo.h:391
StringRef getFirstCoroutineStmtKeyword() const
Definition: ScopeInfo.h:457
static unsigned getHashValue(const WeakObjectProfileTy &Val)
Definition: ScopeInfo.h:307
bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const
Definition: ScopeInfo.h:968
std::pair< Stmt *, Stmt * > CoroutineSuspends
The initial and final coroutine suspend points.
Definition: ScopeInfo.h:199
llvm::TinyPtrVector< const Stmt * > Stmts
Definition: ScopeInfo.h:87
static bool classof(const FunctionScopeInfo *FSI)
Definition: ScopeInfo.h:884
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:96
bool isODRUsed() const
Definition: ScopeInfo.h:588
Represents a variable declaration or definition.
Definition: Decl.h:812
static bool classof(const FunctionScopeInfo *FSI)
Definition: ScopeInfo.h:779
bool hasPotentialThisCapture() const
Definition: ScopeInfo.h:920
static bool classof(const FunctionScopeInfo *FSI)
Definition: ScopeInfo.h:703
RAII class that determines when any errors have occurred between the time the instance was created an...
Definition: Diagnostic.h:1000
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:67
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
Definition: ScopeInfo.h:870
llvm::PointerIntPair< SwitchStmt *, 1, bool > SwitchInfo
A SwitchStmt, along with a flag indicating if its list of case statements is incomplete (because we d...
Definition: ScopeInfo.h:180
bool NeedsCoroutineSuspends
True only when this function has not already built, or attempted to build, the initial and final coro...
Definition: ScopeInfo.h:156
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
Definition: ScopeInfo.h:739
bool HasDroppedStmt
Whether a statement was dropped because it was invalid.
Definition: ScopeInfo.h:120
llvm::SmallMapVector< ParmVarDecl *, Stmt *, 4 > CoroutineParameterMoves
A mapping between the coroutine function parameters that were moved to the coroutine frame...
Definition: ScopeInfo.h:196
Represents a struct/union/class.
Definition: Decl.h:3598
unsigned char FirstCoroutineStmtKind
An enumeration represeting the kind of the first coroutine statement in the function.
Definition: ScopeInfo.h:160
void addByrefBlockVar(VarDecl *VD)
Definition: ScopeInfo.h:441
ScopeKind Kind
What kind of scope we are describing.
Definition: ScopeInfo.h:107
Scope * TheScope
This is the enclosing scope of the captured region.
Definition: ScopeInfo.h:745
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
Definition: ScopeInfo.h:858
llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks
The set of blocks that are introduced in this function.
Definition: ScopeInfo.h:206
SourceLocation FirstSEHTryLoc
First SEH &#39;__try&#39; statement in the current function.
Definition: ScopeInfo.h:173
bool operator==(const WeakObjectProfileTy &Other) const
Definition: ScopeInfo.h:289
DiagnosticErrorTrap ErrorTrap
Used to determine if errors occurred in this function or block.
Definition: ScopeInfo.h:176
bool isThisCapture() const
Definition: ScopeInfo.h:560
Expr * getInitExpr() const
Definition: ScopeInfo.h:612
CompoundScopeInfo(bool IsStmtExpr)
Definition: ScopeInfo.h:76
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
WeakUseTy(const Expr *Use, bool IsRead)
Definition: ScopeInfo.h:331
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:148
QualType FunctionType
BlockType - The function type of the block, if one was given.
Definition: ScopeInfo.h:720
void finishedExplicitCaptures()
Note when all explicit captures have been added.
Definition: ScopeInfo.h:880
bool IsStmtExpr
Whether this compound statement corresponds to a GNU statement expression.
Definition: ScopeInfo.h:74
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
FunctionScopeInfo(DiagnosticsEngine &Diag)
Definition: ScopeInfo.h:364
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4056
Contains information about the compound statement currently being parsed.
Definition: ScopeInfo.h:66
SourceLocation FirstCXXTryLoc
First C++ &#39;try&#39; statement in the current function.
Definition: ScopeInfo.h:170
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
Definition: ScopeInfo.h:810
ImplicitCaptureStyle ImpCaptureStyle
Definition: ScopeInfo.h:628
void addPotentialCapture(Expr *VarExpr)
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas...
Definition: ScopeInfo.h:911
void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr)
Mark a variable&#39;s reference in a lambda as non-odr using.
Definition: ScopeInfo.h:963
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
Definition: ScopeInfo.h:189
Retains information about a captured region.
Definition: ScopeInfo.h:736
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
Definition: ScopeInfo.h:1008
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
Definition: ScopeInfo.h:602
SourceLocation PotentialThisCaptureLocation
Definition: ScopeInfo.h:872
CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, RecordDecl *RD, ImplicitParamDecl *Context, CapturedRegionKind K, unsigned OpenMPLevel)
Definition: ScopeInfo.h:755
bool isVariableCapture() const
Definition: ScopeInfo.h:564
Retains information about a block that is currently being parsed.
Definition: ScopeInfo.h:710
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:3863
This represents one expression.
Definition: Expr.h:108
void removePotentialCapture(Expr *E)
Definition: ScopeInfo.h:973
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
Definition: ScopeInfo.h:184
bool HasBranchProtectedScope
Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can&#39;t be jump...
Definition: ScopeInfo.h:111
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
Definition: ScopeInfo.h:861
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
Definition: ScopeInfo.h:682
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Definition: ScopeInfo.h:691
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:950
void setHasCXXTry(SourceLocation TryLoc)
Definition: ScopeInfo.h:419
unsigned short CapRegionKind
The kind of captured region.
Definition: ScopeInfo.h:751
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Definition: ScopeInfo.h:598
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda.
Definition: ScopeInfo.h:832
CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
Definition: ScopeInfo.h:630
#define false
Definition: stdbool.h:17
Kind
VarDecl * getVariable() const
Definition: ScopeInfo.h:592
void setHasSEHTry(SourceLocation TryLoc)
Definition: ScopeInfo.h:424
bool HasPotentialAvailabilityViolations
Whether we make reference to a declaration that could be unavailable.
Definition: ScopeInfo.h:130
Encodes a location in the source.
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
Definition: ScopeInfo.h:825
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
Definition: ScopeInfo.h:143
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2108
bool isVLATypeCapture() const
Definition: ScopeInfo.h:580
SmallVector< Capture, 4 > Captures
Captures - The captures.
Definition: ScopeInfo.h:641
SourceLocation FirstCoroutineStmtLoc
First coroutine statement in the current function.
Definition: ScopeInfo.h:164
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:728
void addPotentialThisCapture(SourceLocation Loc)
Definition: ScopeInfo.h:916
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
Definition: ScopeInfo.h:138
bool ObjCShouldCallSuper
A flag that is set when parsing a method that must call super&#39;s implementation, such as -dealloc...
Definition: ScopeInfo.h:135
SourceLocation CaptureDefaultLoc
Source location of the &#39;&&#39; or &#39;=&#39; specifying the default capture type, if any.
Definition: ScopeInfo.h:797
bool HasOMPDeclareReductionCombiner
True if current scope is for OpenMP declare reduction combiner.
Definition: ScopeInfo.h:123
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
Contains all variable-referring-expressions (i.e.
Definition: ScopeInfo.h:852
bool isGenericLambda() const
Is this scope known to be for a generic lambda? (This will be false until we parse a template paramet...
Definition: ScopeInfo.h:890
Dataflow Directional Tag Classes.
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, ArrayRef< const Stmt *> Stmts)
Definition: ScopeInfo.h:89
bool isValid() const
Return true if this is a valid SourceLocation object.
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
Definition: ScopeInfo.h:148
bool HasIndirectGoto
Whether this function contains any indirect gotos.
Definition: ScopeInfo.h:117
const Capture & getCapture(VarDecl *Var) const
Definition: ScopeInfo.h:696
StringRef getRegionName() const
A descriptive name for the kind of captured region this is.
Definition: ScopeInfo.h:767
Represents a simple identification of a weak object.
Definition: ScopeInfo.h:243
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
Definition: ScopeInfo.h:152
BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
Definition: ScopeInfo.h:722
LambdaScopeInfo(DiagnosticsEngine &Diag)
Definition: ScopeInfo.h:874
SourceLocation FirstReturnLoc
First &#39;return&#39; statement in the current function.
Definition: ScopeInfo.h:167
Contains all of the variables defined in this lambda that shadow variables that were defined in paren...
Definition: ScopeInfo.h:866
RecordDecl * TheRecordDecl
The captured record type.
Definition: ScopeInfo.h:742
bool isReferenceCapture() const
Definition: ScopeInfo.h:572
void setFirstCoroutineStmt(SourceLocation Loc, StringRef Keyword)
Definition: ScopeInfo.h:447
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
llvm::DenseMap< VarDecl *, unsigned > CaptureMap
CaptureMap - A map of captured variables to (index+1) into Captures.
Definition: ScopeInfo.h:634
unsigned getNumPotentialVariableCaptures() const
Definition: ScopeInfo.h:983
Capture & getCXXThisCapture()
Retrieve the capture of C++ &#39;this&#39;, if it has been captured.
Definition: ScopeInfo.h:676
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:546
static bool isEqual(const WeakObjectProfileTy &LHS, const WeakObjectProfileTy &RHS)
Definition: ScopeInfo.h:314
Defines the clang::SourceLocation class and associated facilities.
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
A list of PartialDiagnostics created but delayed within the current function scope.
Definition: ScopeInfo.h:214
Represents a C++ struct/union/class.
Definition: DeclCXX.h:299
void markUsed(bool IsODRUse)
Definition: ScopeInfo.h:590
bool isNested() const
Definition: ScopeInfo.h:584
Capture(IsThisCapture, bool IsNested, SourceLocation Loc, QualType CaptureType, Expr *Cpy, const bool ByCopy)
Definition: ScopeInfo.h:553
static bool classof(const FunctionScopeInfo *FSI)
Definition: ScopeInfo.h:730
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
A list of parameters which have the nonnull attribute and are modified in the function.
Definition: ScopeInfo.h:218
bool isCXXThisCaptured() const
Determine whether the C++ &#39;this&#39; is captured.
Definition: ScopeInfo.h:673
void addVLATypeCapture(SourceLocation Loc, QualType CaptureType)
Definition: ScopeInfo.h:659
Represents a single use of a weak object.
Definition: ScopeInfo.h:327
Scope * TheScope
TheScope - This is the scope for the block itself, which contains arguments etc.
Definition: ScopeInfo.h:716
void addBlock(const BlockDecl *BD)
Definition: ScopeInfo.h:436
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
Used to collect all uses of weak objects in a function body.
Definition: ScopeInfo.h:352
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1081
CapturedRegionKind
The different kinds of captured statement.
Definition: CapturedStmt.h:16
bool isNonODRUsed() const
Definition: ScopeInfo.h:589
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
Definition: ScopeInfo.h:651
bool hasInvalidCoroutineSuspends() const
Definition: ScopeInfo.h:475
ImplicitParamDecl * ContextParam
The implicit parameter for the captured variables.
Definition: ScopeInfo.h:748
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
Definition: ScopeInfo.h:203
bool isExactProfile() const
Returns true if the object base specifies a known object in memory, rather than, say, an instance variable or property of another object.
Definition: ScopeInfo.h:285
#define true
Definition: stdbool.h:16
A trivial tuple used to represent a source range.
llvm::TinyPtrVector< VarDecl * > ByrefBlockVars
The set of __block variables that are introduced in this function.
Definition: ScopeInfo.h:209
This represents a decl that may have a name.
Definition: Decl.h:248
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:2983
Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
Definition: ScopeInfo.h:543
bool HasBranchIntoScope
Whether this function contains any switches or direct gotos.
Definition: ScopeInfo.h:114
bool isBlockCapture() const
Definition: ScopeInfo.h:576
const FormatStyle & Style
void setCoroutineSuspends(Stmt *Initial, Stmt *Final)
Definition: ScopeInfo.h:479