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