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