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