ScopeInfo.h revision 0d8e9646bc000bab521ce52ed294209a92298cef
1781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===--- ScopeInfo.h - Information about a semantic context -----*- C++ -*-===//
2781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
3781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//                     The LLVM Compiler Infrastructure
4781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
5781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// This file is distributed under the University of Illinois Open Source
6781472fe99a120098c631b0cbe33c89f8cef5e70John McCall// License. See LICENSE.TXT for details.
7781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
8781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===----------------------------------------------------------------------===//
9781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
10a55d32d1b8f799bf58c02540983976368c42d895Jordan Rose// This file defines FunctionScopeInfo and its subclasses, which contain
11a55d32d1b8f799bf58c02540983976368c42d895Jordan Rose// information about a single function, block, lambda, or method body.
12781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//
13781472fe99a120098c631b0cbe33c89f8cef5e70John McCall//===----------------------------------------------------------------------===//
14781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
15781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#ifndef LLVM_CLANG_SEMA_SCOPE_INFO_H
16781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#define LLVM_CLANG_SEMA_SCOPE_INFO_H
17781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
18781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/AST/Type.h"
193a2f91280a49f4747063f983dc6a3296bd9359d2Ben Langmuir#include "clang/Basic/CapturedStmt.h"
20351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek#include "clang/Basic/PartialDiagnostic.h"
21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/DenseMap.h"
22781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "llvm/ADT/SmallVector.h"
23781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
24781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace clang {
25781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
2658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseclass Decl;
27781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass BlockDecl;
286afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajclass CapturedDecl;
29f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregorclass CXXMethodDecl;
300d8e9646bc000bab521ce52ed294209a92298cefRichard Smithclass FieldDecl;
317fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Roseclass ObjCPropertyDecl;
32781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass IdentifierInfo;
338c045ace381972f41d385b0a661ccf172834f459Ben Langmuirclass ImplicitParamDecl;
34ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattnerclass LabelDecl;
35781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass ReturnStmt;
36781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass Scope;
37781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass SwitchStmt;
38f8af98286022f72157d84951b48fde5fb369ab29Douglas Gregorclass VarDecl;
397a2704800943fbb69207e125d28186278712af36Jordan Roseclass DeclRefExpr;
407a2704800943fbb69207e125d28186278712af36Jordan Roseclass ObjCIvarRefExpr;
4158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseclass ObjCPropertyRefExpr;
427fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Roseclass ObjCMessageExpr;
43781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
44781472fe99a120098c631b0cbe33c89f8cef5e70John McCallnamespace sema {
45781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
46625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko/// \brief Contains information about the compound statement currently being
47625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko/// parsed.
48625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenkoclass CompoundScopeInfo {
49625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenkopublic:
50625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  CompoundScopeInfo()
51625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko    : HasEmptyLoopBodies(false) { }
52625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
53625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  /// \brief Whether this compound stamement contains `for' or `while' loops
54625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  /// with empty bodies.
55625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  bool HasEmptyLoopBodies;
56625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
57625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  void setHasEmptyLoopBodies() {
58625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko    HasEmptyLoopBodies = true;
59625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  }
60625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko};
61625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
62351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekclass PossiblyUnreachableDiag {
63351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenekpublic:
64351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  PartialDiagnostic PD;
65351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  SourceLocation Loc;
66351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  const Stmt *stmt;
67351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek
68351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc,
69351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek                          const Stmt *stmt)
70351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek    : PD(PD), Loc(Loc), stmt(stmt) {}
71351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek};
72351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek
73781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a function, method, or block that is
74781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// currently being parsed.
75781472fe99a120098c631b0cbe33c89f8cef5e70John McCallclass FunctionScopeInfo {
76ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanprotected:
77ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  enum ScopeKind {
78ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    SK_Function,
79ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    SK_Block,
806afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    SK_Lambda,
816afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    SK_CapturedRegion
82ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  };
83ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
84781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic:
85ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief What kind of scope we are describing.
86ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  ///
87ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  ScopeKind Kind;
88781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
89809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett  /// \brief Whether this function contains a VLA, \@try, try, C++
90781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// initializer, or anything else that can't be jumped past.
91781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasBranchProtectedScope;
92781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
93781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Whether this function contains any switches or direct gotos.
94781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasBranchIntoScope;
95781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
96781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Whether this function contains any indirect gotos.
97781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool HasIndirectGoto;
98781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
99820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis  /// \brief Whether a statement was dropped because it was invalid.
100820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis  bool HasDroppedStmt;
101820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis
102535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose  /// A flag that is set when parsing a method that must call super's
103535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose  /// implementation, such as \c -dealloc, \c -finalize, or any method marked
104535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose  /// with \c __attribute__((objc_requires_super)).
105535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose  bool ObjCShouldCallSuper;
10695aac15936e8362aeb4813f95bc255dee6473592Eli Friedman
1078fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  /// \brief Used to determine if errors occurred in this function or block.
1088fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  DiagnosticErrorTrap ErrorTrap;
109781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
110781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// SwitchStack - This is the current set of active switch statements in the
111781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// block.
112686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<SwitchStmt*, 8> SwitchStack;
113781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
114781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief The list of return statements that occur within the function or
115781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// block, if there is any chance of applying the named return value
1167dd900ed308506f9cf1cb72c70db1652f94cab37Jordan Rose  /// optimization, or if we need to infer a return type.
117686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<ReturnStmt*, 4> Returns;
118625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
119625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  /// \brief The stack of currently active compound stamement scopes in the
120625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  /// function.
121625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko  SmallVector<CompoundScopeInfo, 4> CompoundScopes;
122625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko
123351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// \brief A list of PartialDiagnostics created but delayed within the
124351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// current function scope.  These diagnostics are vetted for reachability
125351ba91eaa6d30e523587b2d7ed676a5172c6e56Ted Kremenek  /// prior to being emitted.
126686775deca8b8685eb90801495880e3abdd844c2Chris Lattner  SmallVector<PossiblyUnreachableDiag, 4> PossiblyUnreachableDiags;
127781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
12858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rosepublic:
12958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Represents a simple identification of a weak object.
13058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
13158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
13258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
13358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// This is used to determine if two weak accesses refer to the same object.
13458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Here are some examples of how various accesses are "profiled":
13558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
13658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Access Expression |     "Base" Decl     |          "Property" Decl
13758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// :---------------: | :-----------------: | :------------------------------:
13858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// self.property     | self (VarDecl)      | property (ObjCPropertyDecl)
13958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// self.implicitProp | self (VarDecl)      | -implicitProp (ObjCMethodDecl)
14058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// self->ivar.prop   | ivar (ObjCIvarDecl) | prop (ObjCPropertyDecl)
14158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// cxxObj.obj.prop   | obj (FieldDecl)     | prop (ObjCPropertyDecl)
14258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// [self foo].prop   | 0 (unknown)         | prop (ObjCPropertyDecl)
14358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// self.prop1.prop2  | prop1 (ObjCPropertyDecl)    | prop2 (ObjCPropertyDecl)
14458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// MyClass.prop      | MyClass (ObjCInterfaceDecl) | -prop (ObjCMethodDecl)
1457a2704800943fbb69207e125d28186278712af36Jordan Rose  /// weakVar           | 0 (known)           | weakVar (VarDecl)
1467a2704800943fbb69207e125d28186278712af36Jordan Rose  /// self->weakIvar    | self (VarDecl)      | weakIvar (ObjCIvarDecl)
14758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
14858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Objects are identified with only two Decls to make it reasonably fast to
14958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// compare them.
15058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  class WeakObjectProfileTy {
15158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// The base object decl, as described in the class documentation.
15258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    ///
15358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// The extra flag is "true" if the Base and Property are enough to uniquely
15458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// identify the object in memory.
15558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    ///
15658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// \sa isExactProfile()
15758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    typedef llvm::PointerIntPair<const NamedDecl *, 1, bool> BaseInfoTy;
15858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    BaseInfoTy Base;
15958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
16058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// The "property" decl, as described in the class documentation.
16158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    ///
16258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// Note that this may not actually be an ObjCPropertyDecl, e.g. in the
16358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// case of "implicit" properties (regular methods accessed via dot syntax).
16458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    const NamedDecl *Property;
16558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
1667a2704800943fbb69207e125d28186278712af36Jordan Rose    /// Used to find the proper base profile for a given base expression.
1677a2704800943fbb69207e125d28186278712af36Jordan Rose    static BaseInfoTy getBaseInfo(const Expr *BaseE);
1687a2704800943fbb69207e125d28186278712af36Jordan Rose
16958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    // For use in DenseMap.
170b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    friend class DenseMapInfo;
17158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    inline WeakObjectProfileTy();
17258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    static inline WeakObjectProfileTy getSentinel();
17358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
17458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  public:
17558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    WeakObjectProfileTy(const ObjCPropertyRefExpr *RE);
1767fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose    WeakObjectProfileTy(const Expr *Base, const ObjCPropertyDecl *Property);
1777a2704800943fbb69207e125d28186278712af36Jordan Rose    WeakObjectProfileTy(const DeclRefExpr *RE);
1787a2704800943fbb69207e125d28186278712af36Jordan Rose    WeakObjectProfileTy(const ObjCIvarRefExpr *RE);
17958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
180c0e44454bd78b8b4f3d70f08cf1edd5466b0c798Jordan Rose    const NamedDecl *getBase() const { return Base.getPointer(); }
18158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    const NamedDecl *getProperty() const { return Property; }
18258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
18358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// Returns true if the object base specifies a known object in memory,
18458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// rather than, say, an instance variable or property of another object.
18558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    ///
18658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// Note that this ignores the effects of aliasing; that is, \c foo.bar is
18758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// considered an exact profile if \c foo is a local variable, even if
18858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// another variable \c foo2 refers to the same object as \c foo.
18958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    ///
19058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// For increased precision, accesses with base variables that are
19158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// properties or ivars of 'self' (e.g. self.prop1.prop2) are considered to
19258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// be exact, though this is not true for arbitrary variables
19358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    /// (foo.prop1.prop2).
19458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    bool isExactProfile() const {
19558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose      return Base.getInt();
19658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    }
19758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
19858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    bool operator==(const WeakObjectProfileTy &Other) const {
19958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose      return Base == Other.Base && Property == Other.Property;
20058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    }
201b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose
202b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    // For use in DenseMap.
203b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    // We can't specialize the usual llvm::DenseMapInfo at the end of the file
204b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    // because by that point the DenseMap in FunctionScopeInfo has already been
205b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    // instantiated.
206b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    class DenseMapInfo {
207b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    public:
208b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      static inline WeakObjectProfileTy getEmptyKey() {
209b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose        return WeakObjectProfileTy();
210b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      }
211b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      static inline WeakObjectProfileTy getTombstoneKey() {
212b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose        return WeakObjectProfileTy::getSentinel();
213b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      }
214b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose
215b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      static unsigned getHashValue(const WeakObjectProfileTy &Val) {
216b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose        typedef std::pair<BaseInfoTy, const NamedDecl *> Pair;
217b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose        return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base,
218b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose                                                           Val.Property));
219b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      }
220b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose
221b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      static bool isEqual(const WeakObjectProfileTy &LHS,
222b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose                          const WeakObjectProfileTy &RHS) {
223b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose        return LHS == RHS;
224b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose      }
225b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose    };
22658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  };
22758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
22858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Represents a single use of a weak object.
22958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
23058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Stores both the expression and whether the access is potentially unsafe
23158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// (i.e. it could potentially be warned about).
23258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
23358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
23458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  class WeakUseTy {
23558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    llvm::PointerIntPair<const Expr *, 1, bool> Rep;
23658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  public:
23758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    WeakUseTy(const Expr *Use, bool IsRead) : Rep(Use, IsRead) {}
23858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
23958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    const Expr *getUseExpr() const { return Rep.getPointer(); }
24058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    bool isUnsafe() const { return Rep.getInt(); }
24158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    void markSafe() { Rep.setInt(false); }
24258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
24358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    bool operator==(const WeakUseTy &Other) const {
24458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose      return Rep == Other.Rep;
24558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    }
24658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  };
24758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
24858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Used to collect uses of a particular weak object in a function body.
24958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
25058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
25158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  typedef SmallVector<WeakUseTy, 4> WeakUseVector;
25258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
25358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Used to collect all uses of weak objects in a function body.
25458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
25558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
256b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose  typedef llvm::SmallDenseMap<WeakObjectProfileTy, WeakUseVector, 8,
257b6d80fe68d30ebd14b20c96643c252c36041df8dJordan Rose                              WeakObjectProfileTy::DenseMapInfo>
25858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose          WeakObjectUseMap;
25958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
26058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Roseprivate:
26158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Used to collect all uses of weak objects in this function body.
26258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
26358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
26458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  WeakObjectUseMap WeakObjectUses;
26558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
26658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rosepublic:
2677a2704800943fbb69207e125d28186278712af36Jordan Rose  /// Record that a weak object was accessed.
26858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
26958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
2707a2704800943fbb69207e125d28186278712af36Jordan Rose  template <typename ExprT>
2717a2704800943fbb69207e125d28186278712af36Jordan Rose  inline void recordUseOfWeak(const ExprT *E, bool IsRead = true);
27258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
2737fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose  void recordUseOfWeak(const ObjCMessageExpr *Msg,
2747fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose                       const ObjCPropertyDecl *Prop);
2757fffce781e6ecbf4058b24df7e5ae3037569aa56Jordan Rose
27658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Record that a given expression is a "safe" access of a weak object (e.g.
27758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// assigning it to a strong variable.)
27858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  ///
27958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  /// Part of the implementation of -Wrepeated-use-of-weak.
28058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  void markSafeWeakUse(const Expr *E);
28158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
28258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  const WeakObjectUseMap &getWeakObjectUses() const {
28358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose    return WeakObjectUses;
28458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  }
28558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
286781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasBranchIntoScope() {
287781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasBranchIntoScope = true;
288781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
289781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
290781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasBranchProtectedScope() {
291781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasBranchProtectedScope = true;
292781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
293781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
294781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  void setHasIndirectGoto() {
295781472fe99a120098c631b0cbe33c89f8cef5e70John McCall    HasIndirectGoto = true;
296781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
297781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
298820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis  void setHasDroppedStmt() {
299820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis    HasDroppedStmt = true;
300820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis  }
301820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis
302781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  bool NeedsScopeChecking() const {
303820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis    return !HasDroppedStmt &&
304820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis        (HasIndirectGoto ||
305820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis          (HasBranchProtectedScope && HasBranchIntoScope));
306781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
307781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
308d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  FunctionScopeInfo(DiagnosticsEngine &Diag)
309ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    : Kind(SK_Function),
310781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasBranchProtectedScope(false),
311781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasBranchIntoScope(false),
312781472fe99a120098c631b0cbe33c89f8cef5e70John McCall      HasIndirectGoto(false),
313820b23dc924a4ae7af07d5a75d6b1d781c267d57Argyrios Kyrtzidis      HasDroppedStmt(false),
314535a5d001b2035a7aa68ee368fbe44ec90e33740Jordan Rose      ObjCShouldCallSuper(false),
3158fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis      ErrorTrap(Diag) { }
316781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
317781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  virtual ~FunctionScopeInfo();
318781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
319781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// \brief Clear out the information in this function scope, making it
320781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// suitable for reuse.
3218fc32d272bd57b0a59f61c874cb7b56d9005e89eArgyrios Kyrtzidis  void Clear();
322781472fe99a120098c631b0cbe33c89f8cef5e70John McCall};
323781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
324b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass CapturingScopeInfo : public FunctionScopeInfo {
325b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanpublic:
326b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  enum ImplicitCaptureStyle {
3276afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block,
3286afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    ImpCap_CapturedRegion
329b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  };
330b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
331b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  ImplicitCaptureStyle ImpCaptureStyle;
332b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
333b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  class Capture {
3340d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // There are three categories of capture: capturing 'this', capturing
3350d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // local variables, and C++1y initialized captures (which can have an
3360d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // arbitrary initializer, and don't really capture in the traditional
3370d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // sense at all).
3380d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    //
3390d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // There are three ways to capture a local variable:
3400d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    //  - capture by copy in the C++11 sense,
3410d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    //  - capture by reference in the C++11 sense, and
3420d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    //  - __block capture.
3430d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // Lambdas explicitly specify capture by copy or capture by reference.
3440d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // For blocks, __block capture applies to variables with that annotation,
3450d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // variables of reference type are captured by reference, and other
3460d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // variables are captured by copy.
347b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    enum CaptureKind {
3480d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_ThisOrInit
349b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    };
350b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
3510d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // The variable being captured (if we are not capturing 'this', and whether
3520d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // this is a nested capture; the expression is only required if we are
3530d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // capturing ByVal and the variable's type has a non-trivial copy
3540d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // constructor, or for an initialized capture.
3550d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    typedef llvm::PointerIntPair<VarDecl*, 1, bool> VarAndNested;
356b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
3570d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // The variable being captured, or the implicitly-generated field for
3580d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // an init-capture.
3590d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    llvm::PointerUnion<VarAndNested, FieldDecl*> VarOrField;
360b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
3610d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // Expression to initialize a field of the given type, and the kind of
3620d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    // capture (if this is a capture and not an init-capture).
3630d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    llvm::PointerIntPair<Expr*, 2, CaptureKind> InitExprAndCaptureKind;
3640d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
3650d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    /// \brief The source location at which the first capture occurred.
36693962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    SourceLocation Loc;
3670d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
368a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    /// \brief The location of the ellipsis that expands a parameter pack.
369a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    SourceLocation EllipsisLoc;
3700d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
371999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    /// \brief The type as it was captured, which is in effect the type of the
372999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    /// non-static data member that would hold the capture.
373999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    QualType CaptureType;
3740d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
375b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  public:
3760d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested,
3770d8e9646bc000bab521ce52ed294209a92298cefRichard Smith            SourceLocation Loc, SourceLocation EllipsisLoc,
378999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor            QualType CaptureType, Expr *Cpy)
3790d8e9646bc000bab521ce52ed294209a92298cefRichard Smith        : VarOrField(VarAndNested(Var, IsNested)),
3800d8e9646bc000bab521ce52ed294209a92298cefRichard Smith          InitExprAndCaptureKind(Cpy, Block ? Cap_Block :
3810d8e9646bc000bab521ce52ed294209a92298cefRichard Smith                                      ByRef ? Cap_ByRef : Cap_ByCopy),
3820d8e9646bc000bab521ce52ed294209a92298cefRichard Smith          Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {}
383b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
384b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    enum IsThisCapture { ThisCapture };
3850d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Capture(IsThisCapture, bool IsNested, SourceLocation Loc,
386999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor            QualType CaptureType, Expr *Cpy)
3870d8e9646bc000bab521ce52ed294209a92298cefRichard Smith        : VarOrField(VarAndNested(0, IsNested)),
3880d8e9646bc000bab521ce52ed294209a92298cefRichard Smith          InitExprAndCaptureKind(Cpy, Cap_ThisOrInit),
3890d8e9646bc000bab521ce52ed294209a92298cefRichard Smith          Loc(Loc), EllipsisLoc(), CaptureType(CaptureType) {}
390b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
3910d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Capture(FieldDecl *Field, Expr *Init)
3920d8e9646bc000bab521ce52ed294209a92298cefRichard Smith        : VarOrField(Field), InitExprAndCaptureKind(Init, Cap_ThisOrInit),
3930d8e9646bc000bab521ce52ed294209a92298cefRichard Smith          Loc(), EllipsisLoc(), CaptureType() {}
3940d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
3950d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isThisCapture() const {
3960d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getInt() == Cap_ThisOrInit &&
3970d8e9646bc000bab521ce52ed294209a92298cefRichard Smith             VarOrField.is<VarAndNested>();
3980d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
3990d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isVariableCapture() const {
4000d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getInt() != Cap_ThisOrInit;
4010d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4020d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isInitCapture() const {
4030d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return VarOrField.is<FieldDecl*>();
4040d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4050d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isCopyCapture() const {
4060d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getInt() == Cap_ByCopy;
4070d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4080d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isReferenceCapture() const {
4090d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getInt() == Cap_ByRef;
4100d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4110d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isBlockCapture() const {
4120d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getInt() == Cap_Block;
4130d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4140d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    bool isNested() { return VarOrField.dyn_cast<VarAndNested>().getInt(); }
415b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
416b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    VarDecl *getVariable() const {
4170d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return VarOrField.dyn_cast<VarAndNested>().getPointer();
4180d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    }
4190d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    FieldDecl *getInitCaptureField() const {
4200d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return VarOrField.dyn_cast<FieldDecl*>();
421b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    }
42293962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor
42393962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    /// \brief Retrieve the location at which this variable was captured.
42493962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor    SourceLocation getLocation() const { return Loc; }
42593962e5360a43200faa70939571afc4fb9326cf7Douglas Gregor
426a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    /// \brief Retrieve the source location of the ellipsis, whose presence
427a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    /// indicates that the capture is a pack expansion.
428a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
429a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor
430999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    /// \brief Retrieve the capture type for this capture, which is effectively
431999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    /// the type of the non-static data member in the lambda/block structure
432999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    /// that would store this capture.
433999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor    QualType getCaptureType() const { return CaptureType; }
434999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor
4350d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Expr *getInitExpr() const {
4360d8e9646bc000bab521ce52ed294209a92298cefRichard Smith      return InitExprAndCaptureKind.getPointer();
437b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    }
438b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  };
439b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
440b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
44184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman    : FunctionScopeInfo(Diag), ImpCaptureStyle(Style), CXXThisCaptureIndex(0),
44284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman      HasImplicitReturnType(false)
443b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman     {}
444b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
445b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// CaptureMap - A map of captured variables to (index+1) into Captures.
446b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  llvm::DenseMap<VarDecl*, unsigned> CaptureMap;
447b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
448b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// CXXThisCaptureIndex - The (index+1) of the capture of 'this';
449b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// zero if 'this' is not captured.
450b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  unsigned CXXThisCaptureIndex;
451b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
452b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  /// Captures - The captures.
453b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  SmallVector<Capture, 4> Captures;
454b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
45584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// \brief - Whether the target type of return statements in this context
45684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// is deduced (e.g. a lambda or block with omitted return type).
45784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  bool HasImplicitReturnType;
45884b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman
45984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// ReturnType - The target type of return statements in this context,
46084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  /// or null if unknown.
46184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman  QualType ReturnType;
46284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman
463999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor  void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested,
464999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor                  SourceLocation Loc, SourceLocation EllipsisLoc,
465999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor                  QualType CaptureType, Expr *Cpy) {
466a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor    Captures.push_back(Capture(Var, isBlock, isByref, isNested, Loc,
467999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor                               EllipsisLoc, CaptureType, Cpy));
468b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    CaptureMap[Var] = Captures.size();
469b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  }
470b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
471999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor  void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType,
472c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor                      Expr *Cpy);
473b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
4740d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  void addInitCapture(FieldDecl *Field, Expr *Init) {
4750d8e9646bc000bab521ce52ed294209a92298cefRichard Smith    Captures.push_back(Capture(Field, Init));
4760d8e9646bc000bab521ce52ed294209a92298cefRichard Smith  }
4770d8e9646bc000bab521ce52ed294209a92298cefRichard Smith
478a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// \brief Determine whether the C++ 'this' is captured.
479a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  bool isCXXThisCaptured() const { return CXXThisCaptureIndex != 0; }
480a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor
481a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// \brief Retrieve the capture of C++ 'this', if it has been captured.
482a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  Capture &getCXXThisCapture() {
483a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    assert(isCXXThisCaptured() && "this has not been captured");
484a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    return Captures[CXXThisCaptureIndex - 1];
485a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  }
486a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor
487a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// \brief Determine whether the given variable has been captured.
488a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  bool isCaptured(VarDecl *Var) const {
489b11a7fd2f2204c7aadd74f870c98667d461997f5Aaron Ballman    return CaptureMap.count(Var);
490a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  }
491a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor
492a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// \brief Retrieve the capture of the given variable, if it has been
493a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// captured already.
494a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  Capture &getCapture(VarDecl *Var) {
495a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    assert(isCaptured(Var) && "Variable has not been captured");
496a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    return Captures[CaptureMap[Var] - 1];
497a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  }
498a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor
499a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  const Capture &getCapture(VarDecl *Var) const {
500a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
501a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor      = CaptureMap.find(Var);
502a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    assert(Known != CaptureMap.end() && "Variable has not been captured");
503a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    return Captures[Known->second - 1];
504a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  }
505a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor
506b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  static bool classof(const FunctionScopeInfo *FSI) {
5076afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    return FSI->Kind == SK_Block || FSI->Kind == SK_Lambda
5086afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj                                 || FSI->Kind == SK_CapturedRegion;
509b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman  }
510b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman};
511b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
512781472fe99a120098c631b0cbe33c89f8cef5e70John McCall/// \brief Retains information about a block that is currently being parsed.
513b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass BlockScopeInfo : public CapturingScopeInfo {
514781472fe99a120098c631b0cbe33c89f8cef5e70John McCallpublic:
515781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  BlockDecl *TheDecl;
516781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
517781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// TheScope - This is the scope for the block itself, which contains
518781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// arguments etc.
519781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  Scope *TheScope;
520781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
521781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// BlockType - The function type of the block, if one was given.
522781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  /// Its return type may be BuiltinType::Dependent.
523781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  QualType FunctionType;
524781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
525d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikie  BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
526b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    : CapturingScopeInfo(Diag, ImpCap_Block), TheDecl(Block),
527b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman      TheScope(BlockScope)
528781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  {
529ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    Kind = SK_Block;
530781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  }
531781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
532781472fe99a120098c631b0cbe33c89f8cef5e70John McCall  virtual ~BlockScopeInfo();
533781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
534ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  static bool classof(const FunctionScopeInfo *FSI) {
535ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    return FSI->Kind == SK_Block;
536ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
537781472fe99a120098c631b0cbe33c89f8cef5e70John McCall};
538781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
5396afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj/// \brief Retains information about a captured region.
5406afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajclass CapturedRegionScopeInfo: public CapturingScopeInfo {
5416afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Sirajpublic:
5426afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  /// \brief The CapturedDecl for this statement.
5436afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  CapturedDecl *TheCapturedDecl;
5446afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  /// \brief The captured record type.
5456afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  RecordDecl *TheRecordDecl;
5466afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  /// \brief This is the enclosing scope of the captured region.
5476afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  Scope *TheScope;
5488c045ace381972f41d385b0a661ccf172834f459Ben Langmuir  /// \brief The implicit parameter for the captured variables.
5498c045ace381972f41d385b0a661ccf172834f459Ben Langmuir  ImplicitParamDecl *ContextParam;
5506afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  /// \brief The kind of captured region.
5516afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  CapturedRegionKind CapRegionKind;
5526afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj
5536afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD,
5548c045ace381972f41d385b0a661ccf172834f459Ben Langmuir                          RecordDecl *RD, ImplicitParamDecl *Context,
5558c045ace381972f41d385b0a661ccf172834f459Ben Langmuir                          CapturedRegionKind K)
5566afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    : CapturingScopeInfo(Diag, ImpCap_CapturedRegion),
5578c045ace381972f41d385b0a661ccf172834f459Ben Langmuir      TheCapturedDecl(CD), TheRecordDecl(RD), TheScope(S),
5588c045ace381972f41d385b0a661ccf172834f459Ben Langmuir      ContextParam(Context), CapRegionKind(K)
5596afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  {
5606afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    Kind = SK_CapturedRegion;
5616afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  }
5626afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj
5636afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  virtual ~CapturedRegionScopeInfo();
5646afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj
5656afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  /// \brief A descriptive name for the kind of captured region this is.
5666afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  StringRef getRegionName() const {
5676afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    switch (CapRegionKind) {
5686afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    case CR_Default:
5696afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj      return "default captured statement";
5706afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    }
5710579c165aa54840898956703ebd63bdd1f4dd907Benjamin Kramer    llvm_unreachable("Invalid captured region kind!");
5726afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  }
5736afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj
5746afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  static bool classof(const FunctionScopeInfo *FSI) {
5756afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj    return FSI->Kind == SK_CapturedRegion;
5766afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj  }
5776afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj};
5786afcf8875d4e447645cd7bf3733dd8e2eb8455dcTareq A. Siraj
579b69b42c55d56815bab62991bf839cdb41634d3afEli Friedmanclass LambdaScopeInfo : public CapturingScopeInfo {
580ec9ea7200718478e8a976529defbe21942a11c9cEli Friedmanpublic:
581ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief The class that describes the lambda.
582ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  CXXRecordDecl *Lambda;
58301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
58476e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  /// \brief The class that describes the lambda.
58576e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  CXXMethodDecl *CallOperator;
58676e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor
58701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Source range covering the lambda introducer [...].
58801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  SourceRange IntroducerRange;
58901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
590ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// \brief The number of captures in the \c Captures list that are
591ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  /// explicit captures.
592ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  unsigned NumExplicitCaptures;
59372899c34e3d1abfffa241ad0ce5c4bf175e5ea51Eli Friedman
594503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor  /// \brief Whether this is a mutable lambda.
595d67d0cc40f31956b40b44b6ee3619d17a0f73294Eli Friedman  bool Mutable;
59601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor
59701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  /// \brief Whether the (empty) parameter list is explicit.
59801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor  bool ExplicitParams;
599d67d0cc40f31956b40b44b6ee3619d17a0f73294Eli Friedman
600503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor  /// \brief Whether any of the capture expressions requires cleanups.
601503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor  bool ExprNeedsCleanups;
602503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor
603612409ece080e814f79e06772c690d603f45fbd6Richard Smith  /// \brief Whether the lambda contains an unexpanded parameter pack.
604612409ece080e814f79e06772c690d603f45fbd6Richard Smith  bool ContainsUnexpandedParameterPack;
605612409ece080e814f79e06772c690d603f45fbd6Richard Smith
6069daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Variables used to index into by-copy array captures.
607cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  SmallVector<VarDecl *, 4> ArrayIndexVars;
6089daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
6099daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// \brief Offsets into the ArrayIndexVars array at which each capture starts
6109daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor  /// its list of array index variables.
611cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  SmallVector<unsigned, 4> ArrayIndexStarts;
6129daa7bfdff7256cef693d7bf10084881bcb9253cDouglas Gregor
61376e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor  LambdaScopeInfo(DiagnosticsEngine &Diag, CXXRecordDecl *Lambda,
61476e3da57b0e8cf72d221f44d54566ef206341668Douglas Gregor                  CXXMethodDecl *CallOperator)
615b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman    : CapturingScopeInfo(Diag, ImpCap_None), Lambda(Lambda),
616503384f731b5abcbf870b0a5224eb920e631db0aDouglas Gregor      CallOperator(CallOperator), NumExplicitCaptures(0), Mutable(false),
617612409ece080e814f79e06772c690d603f45fbd6Richard Smith      ExprNeedsCleanups(false), ContainsUnexpandedParameterPack(false)
618ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  {
619ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    Kind = SK_Lambda;
620ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
621b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
622ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  virtual ~LambdaScopeInfo();
623b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman
624a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  /// \brief Note when
625a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  void finishedExplicitCaptures() {
626a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor    NumExplicitCaptures = Captures.size();
627a1f2114d9e81923c750f6b439302ac03552c37dbDouglas Gregor  }
628c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor
629c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor  static bool classof(const FunctionScopeInfo *FSI) {
630ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman    return FSI->Kind == SK_Lambda;
631ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman  }
632ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman};
633ec9ea7200718478e8a976529defbe21942a11c9cEli Friedman
634c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor
63558b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
63658b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  : Base(0, false), Property(0) {}
63758b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
63858b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy
63958b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan RoseFunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
64058b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  FunctionScopeInfo::WeakObjectProfileTy Result;
64158b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  Result.Base.setInt(true);
64258b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose  return Result;
64358b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose}
64458b6bdcdeb683a3504f2248a409e1f4e85876ceeJordan Rose
6457a2704800943fbb69207e125d28186278712af36Jordan Rosetemplate <typename ExprT>
6467a2704800943fbb69207e125d28186278712af36Jordan Rosevoid FunctionScopeInfo::recordUseOfWeak(const ExprT *E, bool IsRead) {
6477a2704800943fbb69207e125d28186278712af36Jordan Rose  assert(E);
6487a2704800943fbb69207e125d28186278712af36Jordan Rose  WeakUseVector &Uses = WeakObjectUses[WeakObjectProfileTy(E)];
6497a2704800943fbb69207e125d28186278712af36Jordan Rose  Uses.push_back(WeakUseTy(E, IsRead));
650781472fe99a120098c631b0cbe33c89f8cef5e70John McCall}
6517a2704800943fbb69207e125d28186278712af36Jordan Rose
652c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregorinline void
653c3f1742bdd1ae0091d51168e111cd63861587b13Douglas GregorCapturingScopeInfo::addThisCapture(bool isNested, SourceLocation Loc,
654c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor                                   QualType CaptureType, Expr *Cpy) {
655c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor  Captures.push_back(Capture(Capture::ThisCapture, isNested, Loc, CaptureType,
656c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor                             Cpy));
657c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor  CXXThisCaptureIndex = Captures.size();
658c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor
659c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor  if (LambdaScopeInfo *LSI = dyn_cast<LambdaScopeInfo>(this))
660c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor    LSI->ArrayIndexStarts.push_back(LSI->ArrayIndexVars.size());
661c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor}
662c3f1742bdd1ae0091d51168e111cd63861587b13Douglas Gregor
6637a2704800943fbb69207e125d28186278712af36Jordan Rose} // end namespace sema
6647a2704800943fbb69207e125d28186278712af36Jordan Rose} // end namespace clang
665781472fe99a120098c631b0cbe33c89f8cef5e70John McCall
666781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#endif
667