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