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