Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===//
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 implements the ASTReader::readDeclRecord method, which is the
10
// entrypoint for loading a decl.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "ASTCommon.h"
15
#include "ASTReaderInternals.h"
16
#include "clang/AST/ASTConcept.h"
17
#include "clang/AST/ASTContext.h"
18
#include "clang/AST/ASTStructuralEquivalence.h"
19
#include "clang/AST/Attr.h"
20
#include "clang/AST/AttrIterator.h"
21
#include "clang/AST/Decl.h"
22
#include "clang/AST/DeclBase.h"
23
#include "clang/AST/DeclCXX.h"
24
#include "clang/AST/DeclFriend.h"
25
#include "clang/AST/DeclObjC.h"
26
#include "clang/AST/DeclOpenMP.h"
27
#include "clang/AST/DeclTemplate.h"
28
#include "clang/AST/DeclVisitor.h"
29
#include "clang/AST/DeclarationName.h"
30
#include "clang/AST/Expr.h"
31
#include "clang/AST/ExternalASTSource.h"
32
#include "clang/AST/LambdaCapture.h"
33
#include "clang/AST/NestedNameSpecifier.h"
34
#include "clang/AST/OpenMPClause.h"
35
#include "clang/AST/Redeclarable.h"
36
#include "clang/AST/Stmt.h"
37
#include "clang/AST/TemplateBase.h"
38
#include "clang/AST/Type.h"
39
#include "clang/AST/UnresolvedSet.h"
40
#include "clang/Basic/AttrKinds.h"
41
#include "clang/Basic/DiagnosticSema.h"
42
#include "clang/Basic/ExceptionSpecificationType.h"
43
#include "clang/Basic/IdentifierTable.h"
44
#include "clang/Basic/LLVM.h"
45
#include "clang/Basic/Lambda.h"
46
#include "clang/Basic/LangOptions.h"
47
#include "clang/Basic/Linkage.h"
48
#include "clang/Basic/Module.h"
49
#include "clang/Basic/PragmaKinds.h"
50
#include "clang/Basic/SourceLocation.h"
51
#include "clang/Basic/Specifiers.h"
52
#include "clang/Sema/IdentifierResolver.h"
53
#include "clang/Serialization/ASTBitCodes.h"
54
#include "clang/Serialization/ASTRecordReader.h"
55
#include "clang/Serialization/ContinuousRangeMap.h"
56
#include "clang/Serialization/ModuleFile.h"
57
#include "llvm/ADT/DenseMap.h"
58
#include "llvm/ADT/FoldingSet.h"
59
#include "llvm/ADT/STLExtras.h"
60
#include "llvm/ADT/SmallPtrSet.h"
61
#include "llvm/ADT/SmallVector.h"
62
#include "llvm/ADT/iterator_range.h"
63
#include "llvm/Bitstream/BitstreamReader.h"
64
#include "llvm/Support/Casting.h"
65
#include "llvm/Support/ErrorHandling.h"
66
#include "llvm/Support/SaveAndRestore.h"
67
#include <algorithm>
68
#include <cassert>
69
#include <cstdint>
70
#include <cstring>
71
#include <string>
72
#include <utility>
73
74
using namespace clang;
75
using namespace serialization;
76
77
//===----------------------------------------------------------------------===//
78
// Declaration deserialization
79
//===----------------------------------------------------------------------===//
80
81
namespace clang {
82
83
  class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
84
    ASTReader &Reader;
85
    ASTRecordReader &Record;
86
    ASTReader::RecordLocation Loc;
87
    const DeclID ThisDeclID;
88
    const SourceLocation ThisDeclLoc;
89
90
    using RecordData = ASTReader::RecordData;
91
92
    TypeID DeferredTypeID = 0;
93
    unsigned AnonymousDeclNumber = 0;
94
    GlobalDeclID NamedDeclForTagDecl = 0;
95
    IdentifierInfo *TypedefNameForLinkage = nullptr;
96
97
    bool HasPendingBody = false;
98
99
    ///A flag to carry the information for a decl from the entity is
100
    /// used. We use it to delay the marking of the canonical decl as used until
101
    /// the entire declaration is deserialized and merged.
102
    bool IsDeclMarkedUsed = false;
103
104
    uint64_t GetCurrentCursorOffset();
105
106
5.00M
    uint64_t ReadLocalOffset() {
107
5.00M
      uint64_t LocalOffset = Record.readInt();
108
5.00M
      assert(LocalOffset < Loc.Offset && "offset point after current record");
109
5.00M
      return LocalOffset ? 
Loc.Offset - LocalOffset2.38M
:
02.62M
;
110
5.00M
    }
111
112
149k
    uint64_t ReadGlobalOffset() {
113
149k
      uint64_t Local = ReadLocalOffset();
114
149k
      return Local ? Record.getGlobalBitOffset(Local) : 
00
;
115
149k
    }
116
117
5.40M
    SourceLocation readSourceLocation() {
118
5.40M
      return Record.readSourceLocation();
119
5.40M
    }
120
121
433k
    SourceRange readSourceRange() {
122
433k
      return Record.readSourceRange();
123
433k
    }
124
125
370k
    TypeSourceInfo *readTypeSourceInfo() {
126
370k
      return Record.readTypeSourceInfo();
127
370k
    }
128
129
5.86M
    serialization::DeclID readDeclID() {
130
5.86M
      return Record.readDeclID();
131
5.86M
    }
132
133
12
    std::string readString() {
134
12
      return Record.readString();
135
12
    }
136
137
125k
    void readDeclIDList(SmallVectorImpl<DeclID> &IDs) {
138
245k
      for (unsigned I = 0, Size = Record.readInt(); I != Size; 
++I119k
)
139
119k
        IDs.push_back(readDeclID());
140
125k
    }
141
142
85.8M
    Decl *readDecl() {
143
85.8M
      return Record.readDecl();
144
85.8M
    }
145
146
    template<typename T>
147
6.59M
    T *readDeclAs() {
148
6.59M
      return Record.readDeclAs<T>();
149
6.59M
    }
clang::DeclContext* clang::ASTDeclReader::readDeclAs<clang::DeclContext>()
Line
Count
Source
147
5.19M
    T *readDeclAs() {
148
5.19M
      return Record.readDeclAs<T>();
149
5.19M
    }
clang::TypeAliasTemplateDecl* clang::ASTDeclReader::readDeclAs<clang::TypeAliasTemplateDecl>()
Line
Count
Source
147
24.7k
    T *readDeclAs() {
148
24.7k
      return Record.readDeclAs<T>();
149
24.7k
    }
clang::EnumDecl* clang::ASTDeclReader::readDeclAs<clang::EnumDecl>()
Line
Count
Source
147
1.73k
    T *readDeclAs() {
148
1.73k
      return Record.readDeclAs<T>();
149
1.73k
    }
clang::FunctionDecl* clang::ASTDeclReader::readDeclAs<clang::FunctionDecl>()
Line
Count
Source
147
38.6k
    T *readDeclAs() {
148
38.6k
      return Record.readDeclAs<T>();
149
38.6k
    }
clang::FunctionTemplateDecl* clang::ASTDeclReader::readDeclAs<clang::FunctionTemplateDecl>()
Line
Count
Source
147
145k
    T *readDeclAs() {
148
145k
      return Record.readDeclAs<T>();
149
145k
    }
clang::NamedDecl* clang::ASTDeclReader::readDeclAs<clang::NamedDecl>()
Line
Count
Source
147
186k
    T *readDeclAs() {
148
186k
      return Record.readDeclAs<T>();
149
186k
    }
clang::ParmVarDecl* clang::ASTDeclReader::readDeclAs<clang::ParmVarDecl>()
Line
Count
Source
147
346k
    T *readDeclAs() {
148
346k
      return Record.readDeclAs<T>();
149
346k
    }
clang::ImplicitParamDecl* clang::ASTDeclReader::readDeclAs<clang::ImplicitParamDecl>()
Line
Count
Source
147
145k
    T *readDeclAs() {
148
145k
      return Record.readDeclAs<T>();
149
145k
    }
clang::ObjCMethodDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCMethodDecl>()
Line
Count
Source
147
1.01k
    T *readDeclAs() {
148
1.01k
      return Record.readDeclAs<T>();
149
1.01k
    }
clang::ObjCTypeParamDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCTypeParamDecl>()
Line
Count
Source
147
3.82k
    T *readDeclAs() {
148
3.82k
      return Record.readDeclAs<T>();
149
3.82k
    }
clang::ObjCProtocolDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCProtocolDecl>()
Line
Count
Source
147
2.91k
    T *readDeclAs() {
148
2.91k
      return Record.readDeclAs<T>();
149
2.91k
    }
clang::ObjCInterfaceDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCInterfaceDecl>()
Line
Count
Source
147
3.02k
    T *readDeclAs() {
148
3.02k
      return Record.readDeclAs<T>();
149
3.02k
    }
clang::ObjCIvarDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCIvarDecl>()
Line
Count
Source
147
505
    T *readDeclAs() {
148
505
      return Record.readDeclAs<T>();
149
505
    }
clang::ObjCPropertyDecl* clang::ASTDeclReader::readDeclAs<clang::ObjCPropertyDecl>()
Line
Count
Source
147
16
    T *readDeclAs() {
148
16
      return Record.readDeclAs<T>();
149
16
    }
clang::FieldDecl* clang::ASTDeclReader::readDeclAs<clang::FieldDecl>()
Line
Count
Source
147
13.2k
    T *readDeclAs() {
148
13.2k
      return Record.readDeclAs<T>();
149
13.2k
    }
clang::VarTemplateDecl* clang::ASTDeclReader::readDeclAs<clang::VarTemplateDecl>()
Line
Count
Source
147
516
    T *readDeclAs() {
148
516
      return Record.readDeclAs<T>();
149
516
    }
clang::VarDecl* clang::ASTDeclReader::readDeclAs<clang::VarDecl>()
Line
Count
Source
147
18.5k
    T *readDeclAs() {
148
18.5k
      return Record.readDeclAs<T>();
149
18.5k
    }
clang::BindingDecl* clang::ASTDeclReader::readDeclAs<clang::BindingDecl>()
Line
Count
Source
147
12
    T *readDeclAs() {
148
12
      return Record.readDeclAs<T>();
149
12
    }
clang::UsingShadowDecl* clang::ASTDeclReader::readDeclAs<clang::UsingShadowDecl>()
Line
Count
Source
147
9.55k
    T *readDeclAs() {
148
9.55k
      return Record.readDeclAs<T>();
149
9.55k
    }
clang::UsingEnumDecl* clang::ASTDeclReader::readDeclAs<clang::UsingEnumDecl>()
Line
Count
Source
147
1
    T *readDeclAs() {
148
1
      return Record.readDeclAs<T>();
149
1
    }
clang::ConstructorUsingShadowDecl* clang::ASTDeclReader::readDeclAs<clang::ConstructorUsingShadowDecl>()
Line
Count
Source
147
188
    T *readDeclAs() {
148
188
      return Record.readDeclAs<T>();
149
188
    }
clang::ClassTemplateDecl* clang::ASTDeclReader::readDeclAs<clang::ClassTemplateDecl>()
Line
Count
Source
147
310k
    T *readDeclAs() {
148
310k
      return Record.readDeclAs<T>();
149
310k
    }
clang::CXXRecordDecl* clang::ASTDeclReader::readDeclAs<clang::CXXRecordDecl>()
Line
Count
Source
147
6.96k
    T *readDeclAs() {
148
6.96k
      return Record.readDeclAs<T>();
149
6.96k
    }
clang::CXXConstructorDecl* clang::ASTDeclReader::readDeclAs<clang::CXXConstructorDecl>()
Line
Count
Source
147
77
    T *readDeclAs() {
148
77
      return Record.readDeclAs<T>();
149
77
    }
clang::CXXMethodDecl* clang::ASTDeclReader::readDeclAs<clang::CXXMethodDecl>()
Line
Count
Source
147
212
    T *readDeclAs() {
148
212
      return Record.readDeclAs<T>();
149
212
    }
clang::RedeclarableTemplateDecl* clang::ASTDeclReader::readDeclAs<clang::RedeclarableTemplateDecl>()
Line
Count
Source
147
132k
    T *readDeclAs() {
148
132k
      return Record.readDeclAs<T>();
149
132k
    }
clang::ClassTemplatePartialSpecializationDecl* clang::ASTDeclReader::readDeclAs<clang::ClassTemplatePartialSpecializationDecl>()
Line
Count
Source
147
8.60k
    T *readDeclAs() {
148
8.60k
      return Record.readDeclAs<T>();
149
8.60k
    }
clang::VarTemplatePartialSpecializationDecl* clang::ASTDeclReader::readDeclAs<clang::VarTemplatePartialSpecializationDecl>()
Line
Count
Source
147
42
    T *readDeclAs() {
148
42
      return Record.readDeclAs<T>();
149
42
    }
clang::ValueDecl* clang::ASTDeclReader::readDeclAs<clang::ValueDecl>()
Line
Count
Source
147
21
    T *readDeclAs() {
148
21
      return Record.readDeclAs<T>();
149
21
    }
clang::NamespaceDecl* clang::ASTDeclReader::readDeclAs<clang::NamespaceDecl>()
Line
Count
Source
147
546
    T *readDeclAs() {
148
546
      return Record.readDeclAs<T>();
149
546
    }
150
151
3.35M
    serialization::SubmoduleID readSubmoduleID() {
152
3.35M
      if (Record.getIdx() == Record.size())
153
0
        return 0;
154
155
3.35M
      return Record.getGlobalSubmoduleID(Record.readInt());
156
3.35M
    }
157
158
205
    Module *readModule() {
159
205
      return Record.getSubmodule(readSubmoduleID());
160
205
    }
161
162
    void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
163
                                 Decl *LambdaContext = nullptr,
164
                                 unsigned IndexInLambdaContext = 0);
165
    void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
166
                               const CXXRecordDecl *D, Decl *LambdaContext,
167
                               unsigned IndexInLambdaContext);
168
    void MergeDefinitionData(CXXRecordDecl *D,
169
                             struct CXXRecordDecl::DefinitionData &&NewDD);
170
    void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data);
171
    void MergeDefinitionData(ObjCInterfaceDecl *D,
172
                             struct ObjCInterfaceDecl::DefinitionData &&NewDD);
173
    void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data);
174
    void MergeDefinitionData(ObjCProtocolDecl *D,
175
                             struct ObjCProtocolDecl::DefinitionData &&NewDD);
176
177
    static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC);
178
179
    static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader,
180
                                                 DeclContext *DC,
181
                                                 unsigned Index);
182
    static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC,
183
                                           unsigned Index, NamedDecl *D);
184
185
    /// Commit to a primary definition of the class RD, which is known to be
186
    /// a definition of the class. We might not have read the definition data
187
    /// for it yet. If we haven't then allocate placeholder definition data
188
    /// now too.
189
    static CXXRecordDecl *getOrFakePrimaryClassDefinition(ASTReader &Reader,
190
                                                          CXXRecordDecl *RD);
191
192
    /// Results from loading a RedeclarableDecl.
193
    class RedeclarableResult {
194
      Decl *MergeWith;
195
      GlobalDeclID FirstID;
196
      bool IsKeyDecl;
197
198
    public:
199
      RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl)
200
2.97M
          : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
201
202
      /// Retrieve the first ID.
203
1.82M
      GlobalDeclID getFirstID() const { return FirstID; }
204
205
      /// Is this declaration a key declaration?
206
650k
      bool isKeyDecl() const { return IsKeyDecl; }
207
208
      /// Get a known declaration that this should be merged with, if
209
      /// any.
210
1.02M
      Decl *getKnownMergeTarget() const { return MergeWith; }
211
    };
212
213
    /// Class used to capture the result of searching for an existing
214
    /// declaration of a specific kind and name, along with the ability
215
    /// to update the place where this result was found (the declaration
216
    /// chain hanging off an identifier or the DeclContext we searched in)
217
    /// if requested.
218
    class FindExistingResult {
219
      ASTReader &Reader;
220
      NamedDecl *New = nullptr;
221
      NamedDecl *Existing = nullptr;
222
      bool AddResult = false;
223
      unsigned AnonymousDeclNumber = 0;
224
      IdentifierInfo *TypedefNameForLinkage = nullptr;
225
226
    public:
227
19.4k
      FindExistingResult(ASTReader &Reader) : Reader(Reader) {}
228
229
      FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing,
230
                         unsigned AnonymousDeclNumber,
231
                         IdentifierInfo *TypedefNameForLinkage)
232
515k
          : Reader(Reader), New(New), Existing(Existing), AddResult(true),
233
515k
            AnonymousDeclNumber(AnonymousDeclNumber),
234
515k
            TypedefNameForLinkage(TypedefNameForLinkage) {}
235
236
      FindExistingResult(FindExistingResult &&Other)
237
          : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
238
            AddResult(Other.AddResult),
239
            AnonymousDeclNumber(Other.AnonymousDeclNumber),
240
0
            TypedefNameForLinkage(Other.TypedefNameForLinkage) {
241
0
        Other.AddResult = false;
242
0
      }
243
244
      FindExistingResult &operator=(FindExistingResult &&) = delete;
245
      ~FindExistingResult();
246
247
      /// Suppress the addition of this result into the known set of
248
      /// names.
249
692
      void suppress() { AddResult = false; }
250
251
535k
      operator NamedDecl*() const { return Existing; }
252
253
      template<typename T>
254
159k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::TypedefNameDecl*<clang::TypedefNameDecl>() const
Line
Count
Source
254
10.2k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::TagDecl*<clang::TagDecl>() const
Line
Count
Source
254
5.02k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::EnumConstantDecl*<clang::EnumConstantDecl>() const
Line
Count
Source
254
67
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::FunctionDecl*<clang::FunctionDecl>() const
Line
Count
Source
254
25.3k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::ObjCInterfaceDecl*<clang::ObjCInterfaceDecl>() const
Line
Count
Source
254
107
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::ObjCProtocolDecl*<clang::ObjCProtocolDecl>() const
Line
Count
Source
254
46
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::FieldDecl*<clang::FieldDecl>() const
Line
Count
Source
254
326
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::IndirectFieldDecl*<clang::IndirectFieldDecl>() const
Line
Count
Source
254
46
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::VarDecl*<clang::VarDecl>() const
Line
Count
Source
254
10.4k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::NamespaceDecl*<clang::NamespaceDecl>() const
Line
Count
Source
254
79.3k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::NamespaceAliasDecl*<clang::NamespaceAliasDecl>() const
Line
Count
Source
254
3
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::UsingDecl*<clang::UsingDecl>() const
Line
Count
Source
254
1.87k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
Unexecuted instantiation: clang::ASTDeclReader::FindExistingResult::operator clang::UsingEnumDecl*<clang::UsingEnumDecl>() const
clang::ASTDeclReader::FindExistingResult::operator clang::UsingPackDecl*<clang::UsingPackDecl>() const
Line
Count
Source
254
4
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::UsingShadowDecl*<clang::UsingShadowDecl>() const
Line
Count
Source
254
809
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::UnresolvedUsingValueDecl*<clang::UnresolvedUsingValueDecl>() const
Line
Count
Source
254
12
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::UnresolvedUsingTypenameDecl*<clang::UnresolvedUsingTypenameDecl>() const
Line
Count
Source
254
10
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::ConceptDecl*<clang::ConceptDecl>() const
Line
Count
Source
254
25
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
clang::ASTDeclReader::FindExistingResult::operator clang::RedeclarableTemplateDecl*<clang::RedeclarableTemplateDecl>() const
Line
Count
Source
254
26.0k
      operator T*() const { return dyn_cast_or_null<T>(Existing); }
255
    };
256
257
    static DeclContext *getPrimaryContextForMerging(ASTReader &Reader,
258
                                                    DeclContext *DC);
259
    FindExistingResult findExisting(NamedDecl *D);
260
261
  public:
262
    ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record,
263
                  ASTReader::RecordLocation Loc,
264
                  DeclID thisDeclID, SourceLocation ThisDeclLoc)
265
3.53M
        : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID),
266
3.53M
          ThisDeclLoc(ThisDeclLoc) {}
267
268
    template <typename T> static
269
    void AddLazySpecializations(T *D,
270
284k
                                SmallVectorImpl<serialization::DeclID>& IDs) {
271
284k
      if (IDs.empty())
272
231k
        return;
273
274
      // FIXME: We should avoid this pattern of getting the ASTContext.
275
52.8k
      ASTContext &C = D->getASTContext();
276
277
52.8k
      auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
278
279
52.8k
      if (auto &Old = LazySpecializations) {
280
11.1k
        IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
281
11.1k
        llvm::sort(IDs);
282
11.1k
        IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
283
11.1k
      }
284
285
52.8k
      auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
286
52.8k
      *Result = IDs.size();
287
52.8k
      std::copy(IDs.begin(), IDs.end(), Result + 1);
288
289
52.8k
      LazySpecializations = Result;
290
52.8k
    }
void clang::ASTDeclReader::AddLazySpecializations<clang::ClassTemplateDecl>(clang::ClassTemplateDecl*, llvm::SmallVectorImpl<unsigned int>&)
Line
Count
Source
270
113k
                                SmallVectorImpl<serialization::DeclID>& IDs) {
271
113k
      if (IDs.empty())
272
68.7k
        return;
273
274
      // FIXME: We should avoid this pattern of getting the ASTContext.
275
44.7k
      ASTContext &C = D->getASTContext();
276
277
44.7k
      auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
278
279
44.7k
      if (auto &Old = LazySpecializations) {
280
10.4k
        IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
281
10.4k
        llvm::sort(IDs);
282
10.4k
        IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
283
10.4k
      }
284
285
44.7k
      auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
286
44.7k
      *Result = IDs.size();
287
44.7k
      std::copy(IDs.begin(), IDs.end(), Result + 1);
288
289
44.7k
      LazySpecializations = Result;
290
44.7k
    }
void clang::ASTDeclReader::AddLazySpecializations<clang::VarTemplateDecl>(clang::VarTemplateDecl*, llvm::SmallVectorImpl<unsigned int>&)
Line
Count
Source
270
554
                                SmallVectorImpl<serialization::DeclID>& IDs) {
271
554
      if (IDs.empty())
272
400
        return;
273
274
      // FIXME: We should avoid this pattern of getting the ASTContext.
275
154
      ASTContext &C = D->getASTContext();
276
277
154
      auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
278
279
154
      if (auto &Old = LazySpecializations) {
280
6
        IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
281
6
        llvm::sort(IDs);
282
6
        IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
283
6
      }
284
285
154
      auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
286
154
      *Result = IDs.size();
287
154
      std::copy(IDs.begin(), IDs.end(), Result + 1);
288
289
154
      LazySpecializations = Result;
290
154
    }
void clang::ASTDeclReader::AddLazySpecializations<clang::FunctionTemplateDecl>(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<unsigned int>&)
Line
Count
Source
270
170k
                                SmallVectorImpl<serialization::DeclID>& IDs) {
271
170k
      if (IDs.empty())
272
162k
        return;
273
274
      // FIXME: We should avoid this pattern of getting the ASTContext.
275
7.95k
      ASTContext &C = D->getASTContext();
276
277
7.95k
      auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
278
279
7.95k
      if (auto &Old = LazySpecializations) {
280
681
        IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
281
681
        llvm::sort(IDs);
282
681
        IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
283
681
      }
284
285
7.95k
      auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
286
7.95k
      *Result = IDs.size();
287
7.95k
      std::copy(IDs.begin(), IDs.end(), Result + 1);
288
289
7.95k
      LazySpecializations = Result;
290
7.95k
    }
291
292
    template <typename DeclT>
293
    static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D);
294
    static Decl *getMostRecentDeclImpl(...);
295
    static Decl *getMostRecentDecl(Decl *D);
296
297
    static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
298
                                           Decl *Previous);
299
300
    template <typename DeclT>
301
    static void attachPreviousDeclImpl(ASTReader &Reader,
302
                                       Redeclarable<DeclT> *D, Decl *Previous,
303
                                       Decl *Canon);
304
    static void attachPreviousDeclImpl(ASTReader &Reader, ...);
305
    static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous,
306
                                   Decl *Canon);
307
308
    template <typename DeclT>
309
    static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest);
310
    static void attachLatestDeclImpl(...);
311
    static void attachLatestDecl(Decl *D, Decl *latest);
312
313
    template <typename DeclT>
314
    static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D);
315
    static void markIncompleteDeclChainImpl(...);
316
317
    /// Determine whether this declaration has a pending body.
318
3.35M
    bool hasPendingBody() const { return HasPendingBody; }
319
320
    void ReadFunctionDefinition(FunctionDecl *FD);
321
    void Visit(Decl *D);
322
323
    void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &);
324
325
    static void setNextObjCCategory(ObjCCategoryDecl *Cat,
326
2.19k
                                    ObjCCategoryDecl *Next) {
327
2.19k
      Cat->NextClassCategory = Next;
328
2.19k
    }
329
330
    void VisitDecl(Decl *D);
331
    void VisitPragmaCommentDecl(PragmaCommentDecl *D);
332
    void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
333
    void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
334
    void VisitNamedDecl(NamedDecl *ND);
335
    void VisitLabelDecl(LabelDecl *LD);
336
    void VisitNamespaceDecl(NamespaceDecl *D);
337
    void VisitHLSLBufferDecl(HLSLBufferDecl *D);
338
    void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
339
    void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
340
    void VisitTypeDecl(TypeDecl *TD);
341
    RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD);
342
    void VisitTypedefDecl(TypedefDecl *TD);
343
    void VisitTypeAliasDecl(TypeAliasDecl *TD);
344
    void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
345
    void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D);
346
    RedeclarableResult VisitTagDecl(TagDecl *TD);
347
    void VisitEnumDecl(EnumDecl *ED);
348
    RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
349
    void VisitRecordDecl(RecordDecl *RD);
350
    RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
351
160k
    void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); }
352
    RedeclarableResult VisitClassTemplateSpecializationDeclImpl(
353
                                            ClassTemplateSpecializationDecl *D);
354
355
    void VisitClassTemplateSpecializationDecl(
356
224k
        ClassTemplateSpecializationDecl *D) {
357
224k
      VisitClassTemplateSpecializationDeclImpl(D);
358
224k
    }
359
360
    void VisitClassTemplatePartialSpecializationDecl(
361
                                     ClassTemplatePartialSpecializationDecl *D);
362
    void VisitClassScopeFunctionSpecializationDecl(
363
                                       ClassScopeFunctionSpecializationDecl *D);
364
    RedeclarableResult
365
    VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D);
366
367
206
    void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
368
206
      VisitVarTemplateSpecializationDeclImpl(D);
369
206
    }
370
371
    void VisitVarTemplatePartialSpecializationDecl(
372
        VarTemplatePartialSpecializationDecl *D);
373
    void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
374
    void VisitValueDecl(ValueDecl *VD);
375
    void VisitEnumConstantDecl(EnumConstantDecl *ECD);
376
    void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
377
    void VisitDeclaratorDecl(DeclaratorDecl *DD);
378
    void VisitFunctionDecl(FunctionDecl *FD);
379
    void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD);
380
    void VisitCXXMethodDecl(CXXMethodDecl *D);
381
    void VisitCXXConstructorDecl(CXXConstructorDecl *D);
382
    void VisitCXXDestructorDecl(CXXDestructorDecl *D);
383
    void VisitCXXConversionDecl(CXXConversionDecl *D);
384
    void VisitFieldDecl(FieldDecl *FD);
385
    void VisitMSPropertyDecl(MSPropertyDecl *FD);
386
    void VisitMSGuidDecl(MSGuidDecl *D);
387
    void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D);
388
    void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D);
389
    void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
390
    RedeclarableResult VisitVarDeclImpl(VarDecl *D);
391
    void ReadVarDeclInit(VarDecl *VD);
392
646k
    void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
393
    void VisitImplicitParamDecl(ImplicitParamDecl *PD);
394
    void VisitParmVarDecl(ParmVarDecl *PD);
395
    void VisitDecompositionDecl(DecompositionDecl *DD);
396
    void VisitBindingDecl(BindingDecl *BD);
397
    void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
398
    void VisitTemplateDecl(TemplateDecl *D);
399
    void VisitConceptDecl(ConceptDecl *D);
400
    void VisitImplicitConceptSpecializationDecl(
401
        ImplicitConceptSpecializationDecl *D);
402
    void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D);
403
    RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
404
    void VisitClassTemplateDecl(ClassTemplateDecl *D);
405
    void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
406
    void VisitVarTemplateDecl(VarTemplateDecl *D);
407
    void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
408
    void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
409
    void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
410
    void VisitUsingDecl(UsingDecl *D);
411
    void VisitUsingEnumDecl(UsingEnumDecl *D);
412
    void VisitUsingPackDecl(UsingPackDecl *D);
413
    void VisitUsingShadowDecl(UsingShadowDecl *D);
414
    void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
415
    void VisitLinkageSpecDecl(LinkageSpecDecl *D);
416
    void VisitExportDecl(ExportDecl *D);
417
    void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
418
    void VisitTopLevelStmtDecl(TopLevelStmtDecl *D);
419
    void VisitImportDecl(ImportDecl *D);
420
    void VisitAccessSpecDecl(AccessSpecDecl *D);
421
    void VisitFriendDecl(FriendDecl *D);
422
    void VisitFriendTemplateDecl(FriendTemplateDecl *D);
423
    void VisitStaticAssertDecl(StaticAssertDecl *D);
424
    void VisitBlockDecl(BlockDecl *BD);
425
    void VisitCapturedDecl(CapturedDecl *CD);
426
    void VisitEmptyDecl(EmptyDecl *D);
427
    void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
428
429
    std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
430
431
    template<typename T>
432
    RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
433
434
    template <typename T>
435
    void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl);
436
437
    void mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl,
438
                     Decl *Context, unsigned Number);
439
440
    void mergeRedeclarableTemplate(RedeclarableTemplateDecl *D,
441
                                   RedeclarableResult &Redecl);
442
443
    template <typename T>
444
    void mergeRedeclarable(Redeclarable<T> *D, T *Existing,
445
                           RedeclarableResult &Redecl);
446
447
    template<typename T>
448
    void mergeMergeable(Mergeable<T> *D);
449
450
    void mergeMergeable(LifetimeExtendedTemporaryDecl *D);
451
452
    void mergeTemplatePattern(RedeclarableTemplateDecl *D,
453
                              RedeclarableTemplateDecl *Existing,
454
                              bool IsKeyDecl);
455
456
    ObjCTypeParamList *ReadObjCTypeParamList();
457
458
    // FIXME: Reorder according to DeclNodes.td?
459
    void VisitObjCMethodDecl(ObjCMethodDecl *D);
460
    void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
461
    void VisitObjCContainerDecl(ObjCContainerDecl *D);
462
    void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
463
    void VisitObjCIvarDecl(ObjCIvarDecl *D);
464
    void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
465
    void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
466
    void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
467
    void VisitObjCImplDecl(ObjCImplDecl *D);
468
    void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
469
    void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
470
    void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
471
    void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
472
    void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
473
    void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
474
    void VisitOMPAllocateDecl(OMPAllocateDecl *D);
475
    void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
476
    void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
477
    void VisitOMPRequiresDecl(OMPRequiresDecl *D);
478
    void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
479
  };
480
481
} // namespace clang
482
483
namespace {
484
485
/// Iterator over the redeclarations of a declaration that have already
486
/// been merged into the same redeclaration chain.
487
template <typename DeclT> class MergedRedeclIterator {
488
  DeclT *Start = nullptr;
489
  DeclT *Canonical = nullptr;
490
  DeclT *Current = nullptr;
491
492
public:
493
2.42k
  MergedRedeclIterator() = default;
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::EnumDecl>::MergedRedeclIterator()
Line
Count
Source
493
1.13k
  MergedRedeclIterator() = default;
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::RecordDecl>::MergedRedeclIterator()
Line
Count
Source
493
1.19k
  MergedRedeclIterator() = default;
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::Decl>::MergedRedeclIterator()
Line
Count
Source
493
89
  MergedRedeclIterator() = default;
494
2.42k
  MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::EnumDecl>::MergedRedeclIterator(clang::EnumDecl*)
Line
Count
Source
494
1.13k
  MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::RecordDecl>::MergedRedeclIterator(clang::RecordDecl*)
Line
Count
Source
494
1.19k
  MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::Decl>::MergedRedeclIterator(clang::Decl*)
Line
Count
Source
494
89
  MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
495
496
2.43k
  DeclT *operator*() { return Current; }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::EnumDecl>::operator*()
Line
Count
Source
496
1.13k
  DeclT *operator*() { return Current; }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::RecordDecl>::operator*()
Line
Count
Source
496
1.20k
  DeclT *operator*() { return Current; }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::Decl>::operator*()
Line
Count
Source
496
99
  DeclT *operator*() { return Current; }
497
498
2.34k
  MergedRedeclIterator &operator++() {
499
2.34k
    if (Current->isFirstDecl()) {
500
2.33k
      Canonical = Current;
501
2.33k
      Current = Current->getMostRecentDecl();
502
2.33k
    } else
503
10
      Current = Current->getPreviousDecl();
504
505
    // If we started in the merged portion, we'll reach our start position
506
    // eventually. Otherwise, we'll never reach it, but the second declaration
507
    // we reached was the canonical declaration, so stop when we see that one
508
    // again.
509
2.34k
    if (Current == Start || 
Current == Canonical13
)
510
2.33k
      Current = nullptr;
511
2.34k
    return *this;
512
2.34k
  }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::EnumDecl>::operator++()
Line
Count
Source
498
1.12k
  MergedRedeclIterator &operator++() {
499
1.12k
    if (Current->isFirstDecl()) {
500
1.12k
      Canonical = Current;
501
1.12k
      Current = Current->getMostRecentDecl();
502
1.12k
    } else
503
0
      Current = Current->getPreviousDecl();
504
505
    // If we started in the merged portion, we'll reach our start position
506
    // eventually. Otherwise, we'll never reach it, but the second declaration
507
    // we reached was the canonical declaration, so stop when we see that one
508
    // again.
509
1.12k
    if (Current == Start || 
Current == Canonical0
)
510
1.12k
      Current = nullptr;
511
1.12k
    return *this;
512
1.12k
  }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::RecordDecl>::operator++()
Line
Count
Source
498
1.19k
  MergedRedeclIterator &operator++() {
499
1.19k
    if (Current->isFirstDecl()) {
500
1.19k
      Canonical = Current;
501
1.19k
      Current = Current->getMostRecentDecl();
502
1.19k
    } else
503
0
      Current = Current->getPreviousDecl();
504
505
    // If we started in the merged portion, we'll reach our start position
506
    // eventually. Otherwise, we'll never reach it, but the second declaration
507
    // we reached was the canonical declaration, so stop when we see that one
508
    // again.
509
1.19k
    if (Current == Start || 
Current == Canonical3
)
510
1.19k
      Current = nullptr;
511
1.19k
    return *this;
512
1.19k
  }
ASTReaderDecl.cpp:(anonymous namespace)::MergedRedeclIterator<clang::Decl>::operator++()
Line
Count
Source
498
23
  MergedRedeclIterator &operator++() {
499
23
    if (Current->isFirstDecl()) {
500
13
      Canonical = Current;
501
13
      Current = Current->getMostRecentDecl();
502
13
    } else
503
10
      Current = Current->getPreviousDecl();
504
505
    // If we started in the merged portion, we'll reach our start position
506
    // eventually. Otherwise, we'll never reach it, but the second declaration
507
    // we reached was the canonical declaration, so stop when we see that one
508
    // again.
509
23
    if (Current == Start || 
Current == Canonical10
)
510
13
      Current = nullptr;
511
23
    return *this;
512
23
  }
513
514
  friend bool operator!=(const MergedRedeclIterator &A,
515
4.77k
                         const MergedRedeclIterator &B) {
516
4.77k
    return A.Current != B.Current;
517
4.77k
  }
ASTReaderDecl.cpp:(anonymous namespace)::operator!=((anonymous namespace)::MergedRedeclIterator<clang::EnumDecl> const&, (anonymous namespace)::MergedRedeclIterator<clang::EnumDecl> const&)
Line
Count
Source
515
2.26k
                         const MergedRedeclIterator &B) {
516
2.26k
    return A.Current != B.Current;
517
2.26k
  }
ASTReaderDecl.cpp:(anonymous namespace)::operator!=((anonymous namespace)::MergedRedeclIterator<clang::RecordDecl> const&, (anonymous namespace)::MergedRedeclIterator<clang::RecordDecl> const&)
Line
Count
Source
515
2.39k
                         const MergedRedeclIterator &B) {
516
2.39k
    return A.Current != B.Current;
517
2.39k
  }
ASTReaderDecl.cpp:(anonymous namespace)::operator!=((anonymous namespace)::MergedRedeclIterator<clang::Decl> const&, (anonymous namespace)::MergedRedeclIterator<clang::Decl> const&)
Line
Count
Source
515
112
                         const MergedRedeclIterator &B) {
516
112
    return A.Current != B.Current;
517
112
  }
518
};
519
520
} // namespace
521
522
template <typename DeclT>
523
static llvm::iterator_range<MergedRedeclIterator<DeclT>>
524
2.42k
merged_redecls(DeclT *D) {
525
2.42k
  return llvm::make_range(MergedRedeclIterator<DeclT>(D),
526
2.42k
                          MergedRedeclIterator<DeclT>());
527
2.42k
}
ASTReaderDecl.cpp:llvm::iterator_range<(anonymous namespace)::MergedRedeclIterator<clang::EnumDecl> > merged_redecls<clang::EnumDecl>(clang::EnumDecl*)
Line
Count
Source
524
1.13k
merged_redecls(DeclT *D) {
525
1.13k
  return llvm::make_range(MergedRedeclIterator<DeclT>(D),
526
1.13k
                          MergedRedeclIterator<DeclT>());
527
1.13k
}
ASTReaderDecl.cpp:llvm::iterator_range<(anonymous namespace)::MergedRedeclIterator<clang::RecordDecl> > merged_redecls<clang::RecordDecl>(clang::RecordDecl*)
Line
Count
Source
524
1.19k
merged_redecls(DeclT *D) {
525
1.19k
  return llvm::make_range(MergedRedeclIterator<DeclT>(D),
526
1.19k
                          MergedRedeclIterator<DeclT>());
527
1.19k
}
ASTReaderDecl.cpp:llvm::iterator_range<(anonymous namespace)::MergedRedeclIterator<clang::Decl> > merged_redecls<clang::Decl>(clang::Decl*)
Line
Count
Source
524
89
merged_redecls(DeclT *D) {
525
89
  return llvm::make_range(MergedRedeclIterator<DeclT>(D),
526
89
                          MergedRedeclIterator<DeclT>());
527
89
}
528
529
257k
uint64_t ASTDeclReader::GetCurrentCursorOffset() {
530
257k
  return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
531
257k
}
532
533
158k
void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) {
534
158k
  if (Record.readInt()) {
535
183
    Reader.DefinitionSource[FD] =
536
183
        Loc.F->Kind == ModuleKind::MK_MainFile ||
537
183
        
Reader.getContext().getLangOpts().BuildingPCHWithObjectFile135
;
538
183
  }
539
158k
  if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
540
26.2k
    CD->setNumCtorInitializers(Record.readInt());
541
26.2k
    if (CD->getNumCtorInitializers())
542
19.3k
      CD->CtorInitializers = ReadGlobalOffset();
543
26.2k
  }
544
  // Store the offset of the body so we can lazily load it later.
545
158k
  Reader.PendingBodies[FD] = GetCurrentCursorOffset();
546
158k
  HasPendingBody = true;
547
158k
}
548
549
3.35M
void ASTDeclReader::Visit(Decl *D) {
550
3.35M
  DeclVisitor<ASTDeclReader, void>::Visit(D);
551
552
  // At this point we have deserialized and merged the decl and it is safe to
553
  // update its canonical decl to signal that the entire entity is used.
554
3.35M
  D->getCanonicalDecl()->Used |= IsDeclMarkedUsed;
555
3.35M
  IsDeclMarkedUsed = false;
556
557
3.35M
  if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
558
1.02M
    if (auto *TInfo = DD->getTypeSourceInfo())
559
779k
      Record.readTypeLoc(TInfo->getTypeLoc());
560
1.02M
  }
561
562
3.35M
  if (auto *TD = dyn_cast<TypeDecl>(D)) {
563
    // We have a fully initialized TypeDecl. Read its type now.
564
825k
    TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull());
565
566
    // If this is a tag declaration with a typedef name for linkage, it's safe
567
    // to load that typedef now.
568
825k
    if (NamedDeclForTagDecl)
569
314
      cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
570
314
          cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl));
571
2.52M
  } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
572
    // if we have a fully initialized TypeDecl, we can safely read its type now.
573
12.6k
    ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull();
574
2.51M
  } else if (auto *FD = dyn_cast<FunctionDecl>(D)) {
575
    // FunctionDecl's body was written last after all other Stmts/Exprs.
576
290k
    if (Record.readInt())
577
155k
      ReadFunctionDefinition(FD);
578
2.22M
  } else if (auto *VD = dyn_cast<VarDecl>(D)) {
579
647k
    ReadVarDeclInit(VD);
580
1.57M
  } else if (auto *FD = dyn_cast<FieldDecl>(D)) {
581
30.2k
    if (FD->hasInClassInitializer() && 
Record.readInt()373
) {
582
309
      FD->setLazyInClassInitializer(LazyDeclStmtPtr(GetCurrentCursorOffset()));
583
309
    }
584
30.2k
  }
585
3.35M
}
586
587
3.35M
void ASTDeclReader::VisitDecl(Decl *D) {
588
3.35M
  if (D->isTemplateParameter() || 
D->isTemplateParameterPack()2.96M
||
589
3.35M
      
isa<ParmVarDecl, ObjCTypeParamDecl>(D)2.96M
) {
590
    // We don't want to deserialize the DeclContext of a template
591
    // parameter or of a parameter of a function template immediately.   These
592
    // entities might be used in the formulation of its DeclContext (for
593
    // example, a function parameter can be used in decltype() in trailing
594
    // return type of the function).  Use the translation unit DeclContext as a
595
    // placeholder.
596
753k
    GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
597
753k
    GlobalDeclID LexicalDCIDForTemplateParmDecl = readDeclID();
598
753k
    if (!LexicalDCIDForTemplateParmDecl)
599
753k
      LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
600
753k
    Reader.addPendingDeclContextInfo(D,
601
753k
                                     SemaDCIDForTemplateParmDecl,
602
753k
                                     LexicalDCIDForTemplateParmDecl);
603
753k
    D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
604
2.59M
  } else {
605
2.59M
    auto *SemaDC = readDeclAs<DeclContext>();
606
2.59M
    auto *LexicalDC = readDeclAs<DeclContext>();
607
2.59M
    if (!LexicalDC)
608
2.53M
      LexicalDC = SemaDC;
609
    // If the context is a class, we might not have actually merged it yet, in
610
    // the case where the definition comes from an update record.
611
2.59M
    DeclContext *MergedSemaDC;
612
2.59M
    if (auto *RD = dyn_cast<CXXRecordDecl>(SemaDC))
613
346k
      MergedSemaDC = getOrFakePrimaryClassDefinition(Reader, RD);
614
2.25M
    else
615
2.25M
      MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
616
    // Avoid calling setLexicalDeclContext() directly because it uses
617
    // Decl::getASTContext() internally which is unsafe during derialization.
618
2.59M
    D->setDeclContextsImpl(MergedSemaDC ? 
MergedSemaDC346k
:
SemaDC2.25M
, LexicalDC,
619
2.59M
                           Reader.getContext());
620
2.59M
  }
621
3.35M
  D->setLocation(ThisDeclLoc);
622
3.35M
  D->InvalidDecl = Record.readInt();
623
3.35M
  if (Record.readInt()) { // hasAttrs
624
899k
    AttrVec Attrs;
625
899k
    Record.readAttributes(Attrs);
626
    // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
627
    // internally which is unsafe during derialization.
628
899k
    D->setAttrsImpl(Attrs, Reader.getContext());
629
899k
  }
630
3.35M
  D->setImplicit(Record.readInt());
631
3.35M
  D->Used = Record.readInt();
632
3.35M
  IsDeclMarkedUsed |= D->Used;
633
3.35M
  D->setReferenced(Record.readInt());
634
3.35M
  D->setTopLevelDeclInObjCContainer(Record.readInt());
635
3.35M
  D->setAccess((AccessSpecifier)Record.readInt());
636
3.35M
  D->FromASTFile = true;
637
3.35M
  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
638
3.35M
  bool ModulePrivate =
639
3.35M
      (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
640
641
  // Determine whether this declaration is part of a (sub)module. If so, it
642
  // may not yet be visible.
643
3.35M
  if (unsigned SubmoduleID = readSubmoduleID()) {
644
645
2.92M
    switch (ModuleOwnership) {
646
2.91M
    case Decl::ModuleOwnershipKind::Visible:
647
2.91M
      ModuleOwnership = Decl::ModuleOwnershipKind::VisibleWhenImported;
648
2.91M
      break;
649
0
    case Decl::ModuleOwnershipKind::Unowned:
650
9.21k
    case Decl::ModuleOwnershipKind::VisibleWhenImported:
651
11.6k
    case Decl::ModuleOwnershipKind::ReachableWhenImported:
652
11.6k
    case Decl::ModuleOwnershipKind::ModulePrivate:
653
11.6k
      break;
654
2.92M
    }
655
656
2.92M
    D->setModuleOwnershipKind(ModuleOwnership);
657
    // Store the owning submodule ID in the declaration.
658
2.92M
    D->setOwningModuleID(SubmoduleID);
659
660
2.92M
    if (ModulePrivate) {
661
      // Module-private declarations are never visible, so there is no work to
662
      // do.
663
2.92M
    } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
664
      // If local visibility is being tracked, this declaration will become
665
      // hidden and visible as the owning module does.
666
2.92M
    } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
667
      // Mark the declaration as visible when its owning module becomes visible.
668
2.92M
      if (Owner->NameVisibility == Module::AllVisible)
669
2.56M
        D->setVisibleDespiteOwningModule();
670
358k
      else
671
358k
        Reader.HiddenNamesMap[Owner].push_back(D);
672
2.92M
    }
673
2.92M
  } else 
if (422k
ModulePrivate422k
) {
674
0
    D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate);
675
0
  }
676
3.35M
}
677
678
4
void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
679
4
  VisitDecl(D);
680
4
  D->setLocation(readSourceLocation());
681
4
  D->CommentKind = (PragmaMSCommentKind)Record.readInt();
682
4
  std::string Arg = readString();
683
4
  memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size());
684
4
  D->getTrailingObjects<char>()[Arg.size()] = '\0';
685
4
}
686
687
4
void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) {
688
4
  VisitDecl(D);
689
4
  D->setLocation(readSourceLocation());
690
4
  std::string Name = readString();
691
4
  memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size());
692
4
  D->getTrailingObjects<char>()[Name.size()] = '\0';
693
694
4
  D->ValueStart = Name.size() + 1;
695
4
  std::string Value = readString();
696
4
  memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(),
697
4
         Value.size());
698
4
  D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0';
699
4
}
700
701
0
void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
702
0
  llvm_unreachable("Translation units are not serialized");
703
0
}
704
705
3.28M
void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
706
3.28M
  VisitDecl(ND);
707
3.28M
  ND->setDeclName(Record.readDeclarationName());
708
3.28M
  AnonymousDeclNumber = Record.readInt();
709
3.28M
}
710
711
825k
void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
712
825k
  VisitNamedDecl(TD);
713
825k
  TD->setLocStart(readSourceLocation());
714
  // Delay type reading until after we have fully initialized the decl.
715
825k
  DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
716
825k
}
717
718
ASTDeclReader::RedeclarableResult
719
97.6k
ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
720
97.6k
  RedeclarableResult Redecl = VisitRedeclarable(TD);
721
97.6k
  VisitTypeDecl(TD);
722
97.6k
  TypeSourceInfo *TInfo = readTypeSourceInfo();
723
97.6k
  if (Record.readInt()) { // isModed
724
0
    QualType modedT = Record.readType();
725
0
    TD->setModedTypeSourceInfo(TInfo, modedT);
726
0
  } else
727
97.6k
    TD->setTypeSourceInfo(TInfo);
728
  // Read and discard the declaration for which this is a typedef name for
729
  // linkage, if it exists. We cannot rely on our type to pull in this decl,
730
  // because it might have been merged with a type from another module and
731
  // thus might not refer to our version of the declaration.
732
97.6k
  readDecl();
733
97.6k
  return Redecl;
734
97.6k
}
735
736
69.0k
void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
737
69.0k
  RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
738
69.0k
  mergeRedeclarable(TD, Redecl);
739
69.0k
}
740
741
24.7k
void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
742
24.7k
  RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
743
24.7k
  if (auto *Template = readDeclAs<TypeAliasTemplateDecl>())
744
    // Merged when we merge the template.
745
6.93k
    TD->setDescribedAliasTemplate(Template);
746
17.8k
  else
747
17.8k
    mergeRedeclarable(TD, Redecl);
748
24.7k
}
749
750
396k
ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) {
751
396k
  RedeclarableResult Redecl = VisitRedeclarable(TD);
752
396k
  VisitTypeDecl(TD);
753
754
396k
  TD->IdentifierNamespace = Record.readInt();
755
396k
  TD->setTagKind((TagDecl::TagKind)Record.readInt());
756
396k
  if (!isa<CXXRecordDecl>(TD))
757
3.78k
    TD->setCompleteDefinition(Record.readInt());
758
396k
  TD->setEmbeddedInDeclarator(Record.readInt());
759
396k
  TD->setFreeStanding(Record.readInt());
760
396k
  TD->setCompleteDefinitionRequired(Record.readInt());
761
396k
  TD->setBraceRange(readSourceRange());
762
763
396k
  switch (Record.readInt()) {
764
391k
  case 0:
765
391k
    break;
766
5.22k
  case 1: { // ExtInfo
767
5.22k
    auto *Info = new (Reader.getContext()) TagDecl::ExtInfo();
768
5.22k
    Record.readQualifierInfo(*Info);
769
5.22k
    TD->TypedefNameDeclOrQualifier = Info;
770
5.22k
    break;
771
0
  }
772
314
  case 2: // TypedefNameForAnonDecl
773
314
    NamedDeclForTagDecl = readDeclID();
774
314
    TypedefNameForLinkage = Record.readIdentifier();
775
314
    break;
776
0
  default:
777
0
    llvm_unreachable("unexpected tag info kind");
778
396k
  }
779
780
396k
  if (!isa<CXXRecordDecl>(TD))
781
3.78k
    mergeRedeclarable(TD, Redecl);
782
396k
  return Redecl;
783
396k
}
784
785
1.73k
void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
786
1.73k
  VisitTagDecl(ED);
787
1.73k
  if (TypeSourceInfo *TI = readTypeSourceInfo())
788
810
    ED->setIntegerTypeSourceInfo(TI);
789
929
  else
790
929
    ED->setIntegerType(Record.readType());
791
1.73k
  ED->setPromotionType(Record.readType());
792
1.73k
  ED->setNumPositiveBits(Record.readInt());
793
1.73k
  ED->setNumNegativeBits(Record.readInt());
794
1.73k
  ED->setScoped(Record.readInt());
795
1.73k
  ED->setScopedUsingClassTag(Record.readInt());
796
1.73k
  ED->setFixed(Record.readInt());
797
798
1.73k
  ED->setHasODRHash(true);
799
1.73k
  ED->ODRHash = Record.readInt();
800
801
  // If this is a definition subject to the ODR, and we already have a
802
  // definition, merge this one into it.
803
1.73k
  if (ED->isCompleteDefinition() &&
804
1.73k
      
Reader.getContext().getLangOpts().Modules1.49k
&&
805
1.73k
      
Reader.getContext().getLangOpts().CPlusPlus1.32k
) {
806
1.18k
    EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
807
1.18k
    if (!OldDef) {
808
      // This is the first time we've seen an imported definition. Look for a
809
      // local definition before deciding that we are the first definition.
810
1.13k
      for (auto *D : merged_redecls(ED->getCanonicalDecl())) {
811
1.13k
        if (!D->isFromASTFile() && 
D->isCompleteDefinition()10
) {
812
10
          OldDef = D;
813
10
          break;
814
10
        }
815
1.13k
      }
816
1.13k
    }
817
1.18k
    if (OldDef) {
818
53
      Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
819
53
      ED->demoteThisDefinitionToDeclaration();
820
53
      Reader.mergeDefinitionVisibility(OldDef, ED);
821
53
      if (OldDef->getODRHash() != ED->getODRHash())
822
17
        Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
823
1.12k
    } else {
824
1.12k
      OldDef = ED;
825
1.12k
    }
826
1.18k
  }
827
828
1.73k
  if (auto *InstED = readDeclAs<EnumDecl>()) {
829
151
    auto TSK = (TemplateSpecializationKind)Record.readInt();
830
151
    SourceLocation POI = readSourceLocation();
831
151
    ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK);
832
151
    ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
833
151
  }
834
1.73k
}
835
836
ASTDeclReader::RedeclarableResult
837
395k
ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
838
395k
  RedeclarableResult Redecl = VisitTagDecl(RD);
839
395k
  RD->setHasFlexibleArrayMember(Record.readInt());
840
395k
  RD->setAnonymousStructOrUnion(Record.readInt());
841
395k
  RD->setHasObjectMember(Record.readInt());
842
395k
  RD->setHasVolatileMember(Record.readInt());
843
395k
  RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt());
844
395k
  RD->setNonTrivialToPrimitiveCopy(Record.readInt());
845
395k
  RD->setNonTrivialToPrimitiveDestroy(Record.readInt());
846
395k
  RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(Record.readInt());
847
395k
  RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt());
848
395k
  RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt());
849
395k
  RD->setParamDestroyedInCallee(Record.readInt());
850
395k
  RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt());
851
395k
  return Redecl;
852
395k
}
853
854
2.04k
void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
855
2.04k
  VisitRecordDeclImpl(RD);
856
2.04k
  RD->setODRHash(Record.readInt());
857
858
  // Maintain the invariant of a redeclaration chain containing only
859
  // a single definition.
860
2.04k
  if (RD->isCompleteDefinition()) {
861
1.24k
    RecordDecl *Canon = static_cast<RecordDecl *>(RD->getCanonicalDecl());
862
1.24k
    RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
863
1.24k
    if (!OldDef) {
864
      // This is the first time we've seen an imported definition. Look for a
865
      // local definition before deciding that we are the first definition.
866
1.20k
      for (auto *D : merged_redecls(Canon)) {
867
1.20k
        if (!D->isFromASTFile() && 
D->isCompleteDefinition()14
) {
868
9
          OldDef = D;
869
9
          break;
870
9
        }
871
1.20k
      }
872
1.19k
    }
873
1.24k
    if (OldDef) {
874
58
      Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
875
58
      RD->demoteThisDefinitionToDeclaration();
876
58
      Reader.mergeDefinitionVisibility(OldDef, RD);
877
58
      if (OldDef->getODRHash() != RD->getODRHash())
878
24
        Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
879
1.19k
    } else {
880
1.19k
      OldDef = RD;
881
1.19k
    }
882
1.24k
  }
883
2.04k
}
884
885
1.02M
void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
886
1.02M
  VisitNamedDecl(VD);
887
  // For function or variable declarations, defer reading the type in case the
888
  // declaration has a deduced type that references an entity declared within
889
  // the function definition or variable initializer.
890
1.02M
  if (isa<FunctionDecl, VarDecl>(VD))
891
938k
    DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
892
86.6k
  else
893
86.6k
    VD->setType(Record.readType());
894
1.02M
}
895
896
1.73k
void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
897
1.73k
  VisitValueDecl(ECD);
898
1.73k
  if (Record.readInt())
899
1.13k
    ECD->setInitExpr(Record.readExpr());
900
1.73k
  ECD->setInitVal(Record.readAPSInt());
901
1.73k
  mergeMergeable(ECD);
902
1.73k
}
903
904
1.02M
void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
905
1.02M
  VisitValueDecl(DD);
906
1.02M
  DD->setInnerLocStart(readSourceLocation());
907
1.02M
  if (Record.readInt()) { // hasExtInfo
908
23.3k
    auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
909
23.3k
    Record.readQualifierInfo(*Info);
910
23.3k
    Info->TrailingRequiresClause = Record.readExpr();
911
23.3k
    DD->DeclInfo = Info;
912
23.3k
  }
913
1.02M
  QualType TSIType = Record.readType();
914
1.02M
  DD->setTypeSourceInfo(
915
1.02M
      TSIType.isNull() ? 
nullptr242k
916
1.02M
                       : 
Reader.getContext().CreateTypeSourceInfo(TSIType)779k
);
917
1.02M
}
918
919
290k
void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
920
290k
  RedeclarableResult Redecl = VisitRedeclarable(FD);
921
922
290k
  FunctionDecl *Existing = nullptr;
923
924
290k
  switch ((FunctionDecl::TemplatedKind)Record.readInt()) {
925
151k
  case FunctionDecl::TK_NonTemplate:
926
151k
    break;
927
5
  case FunctionDecl::TK_DependentNonTemplate:
928
5
    FD->setInstantiatedFromDecl(readDeclAs<FunctionDecl>());
929
5
    break;
930
90.1k
  case FunctionDecl::TK_FunctionTemplate: {
931
90.1k
    auto *Template = readDeclAs<FunctionTemplateDecl>();
932
90.1k
    Template->init(FD);
933
90.1k
    FD->setDescribedFunctionTemplate(Template);
934
90.1k
    break;
935
0
  }
936
21.9k
  case FunctionDecl::TK_MemberSpecialization: {
937
21.9k
    auto *InstFD = readDeclAs<FunctionDecl>();
938
21.9k
    auto TSK = (TemplateSpecializationKind)Record.readInt();
939
21.9k
    SourceLocation POI = readSourceLocation();
940
21.9k
    FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
941
21.9k
    FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
942
21.9k
    break;
943
0
  }
944
27.7k
  case FunctionDecl::TK_FunctionTemplateSpecialization: {
945
27.7k
    auto *Template = readDeclAs<FunctionTemplateDecl>();
946
27.7k
    auto TSK = (TemplateSpecializationKind)Record.readInt();
947
948
    // Template arguments.
949
27.7k
    SmallVector<TemplateArgument, 8> TemplArgs;
950
27.7k
    Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
951
952
    // Template args as written.
953
27.7k
    SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
954
27.7k
    SourceLocation LAngleLoc, RAngleLoc;
955
27.7k
    bool HasTemplateArgumentsAsWritten = Record.readInt();
956
27.7k
    if (HasTemplateArgumentsAsWritten) {
957
212
      unsigned NumTemplateArgLocs = Record.readInt();
958
212
      TemplArgLocs.reserve(NumTemplateArgLocs);
959
344
      for (unsigned i = 0; i != NumTemplateArgLocs; 
++i132
)
960
132
        TemplArgLocs.push_back(Record.readTemplateArgumentLoc());
961
962
212
      LAngleLoc = readSourceLocation();
963
212
      RAngleLoc = readSourceLocation();
964
212
    }
965
966
27.7k
    SourceLocation POI = readSourceLocation();
967
968
27.7k
    ASTContext &C = Reader.getContext();
969
27.7k
    TemplateArgumentList *TemplArgList
970
27.7k
      = TemplateArgumentList::CreateCopy(C, TemplArgs);
971
27.7k
    TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
972
27.8k
    for (unsigned i = 0, e = TemplArgLocs.size(); i != e; 
++i132
)
973
132
      TemplArgsInfo.addArgument(TemplArgLocs[i]);
974
975
27.7k
    MemberSpecializationInfo *MSInfo = nullptr;
976
27.7k
    if (Record.readInt()) {
977
24
      auto *FD = readDeclAs<FunctionDecl>();
978
24
      auto TSK = (TemplateSpecializationKind)Record.readInt();
979
24
      SourceLocation POI = readSourceLocation();
980
981
24
      MSInfo = new (C) MemberSpecializationInfo(FD, TSK);
982
24
      MSInfo->setPointOfInstantiation(POI);
983
24
    }
984
985
27.7k
    FunctionTemplateSpecializationInfo *FTInfo =
986
27.7k
        FunctionTemplateSpecializationInfo::Create(
987
27.7k
            C, FD, Template, TSK, TemplArgList,
988
27.7k
            HasTemplateArgumentsAsWritten ? 
&TemplArgsInfo212
:
nullptr27.5k
, POI,
989
27.7k
            MSInfo);
990
27.7k
    FD->TemplateOrSpecialization = FTInfo;
991
992
27.7k
    if (FD->isCanonicalDecl()) { // if canonical add to template's set.
993
      // The template that contains the specializations set. It's not safe to
994
      // use getCanonicalDecl on Template since it may still be initializing.
995
27.4k
      auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>();
996
      // Get the InsertPos by FindNodeOrInsertPos() instead of calling
997
      // InsertNode(FTInfo) directly to avoid the getASTContext() call in
998
      // FunctionTemplateSpecializationInfo's Profile().
999
      // We avoid getASTContext because a decl in the parent hierarchy may
1000
      // be initializing.
1001
27.4k
      llvm::FoldingSetNodeID ID;
1002
27.4k
      FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C);
1003
27.4k
      void *InsertPos = nullptr;
1004
27.4k
      FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr();
1005
27.4k
      FunctionTemplateSpecializationInfo *ExistingInfo =
1006
27.4k
          CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos);
1007
27.4k
      if (InsertPos)
1008
26.4k
        CommonPtr->Specializations.InsertNode(FTInfo, InsertPos);
1009
1.08k
      else {
1010
1.08k
        assert(Reader.getContext().getLangOpts().Modules &&
1011
1.08k
               "already deserialized this template specialization");
1012
1.08k
        Existing = ExistingInfo->getFunction();
1013
1.08k
      }
1014
27.4k
    }
1015
27.7k
    break;
1016
27.7k
  }
1017
27.7k
  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
1018
    // Templates.
1019
59
    UnresolvedSet<8> TemplDecls;
1020
59
    unsigned NumTemplates = Record.readInt();
1021
468
    while (NumTemplates--)
1022
409
      TemplDecls.addDecl(readDeclAs<NamedDecl>());
1023
1024
    // Templates args.
1025
59
    TemplateArgumentListInfo TemplArgs;
1026
59
    unsigned NumArgs = Record.readInt();
1027
59
    while (NumArgs--)
1028
0
      TemplArgs.addArgument(Record.readTemplateArgumentLoc());
1029
59
    TemplArgs.setLAngleLoc(readSourceLocation());
1030
59
    TemplArgs.setRAngleLoc(readSourceLocation());
1031
1032
59
    FD->setDependentTemplateSpecialization(Reader.getContext(),
1033
59
                                           TemplDecls, TemplArgs);
1034
    // These are not merged; we don't need to merge redeclarations of dependent
1035
    // template friends.
1036
59
    break;
1037
27.7k
  }
1038
290k
  }
1039
1040
290k
  VisitDeclaratorDecl(FD);
1041
1042
  // Attach a type to this function. Use the real type if possible, but fall
1043
  // back to the type as written if it involves a deduced return type.
1044
290k
  if (FD->getTypeSourceInfo() && FD->getTypeSourceInfo()
1045
232k
                                     ->getType()
1046
232k
                                     ->castAs<FunctionType>()
1047
232k
                                     ->getReturnType()
1048
232k
                                     ->getContainedAutoType()) {
1049
    // We'll set up the real type in Visit, once we've finished loading the
1050
    // function.
1051
297
    FD->setType(FD->getTypeSourceInfo()->getType());
1052
297
    Reader.PendingDeducedFunctionTypes.push_back({FD, DeferredTypeID});
1053
290k
  } else {
1054
290k
    FD->setType(Reader.GetType(DeferredTypeID));
1055
290k
  }
1056
290k
  DeferredTypeID = 0;
1057
1058
290k
  FD->DNLoc = Record.readDeclarationNameLoc(FD->getDeclName());
1059
290k
  FD->IdentifierNamespace = Record.readInt();
1060
1061
  // FunctionDecl's body is handled last at ASTDeclReader::Visit,
1062
  // after everything else is read.
1063
1064
290k
  FD->setStorageClass(static_cast<StorageClass>(Record.readInt()));
1065
290k
  FD->setInlineSpecified(Record.readInt());
1066
290k
  FD->setImplicitlyInline(Record.readInt());
1067
290k
  FD->setVirtualAsWritten(Record.readInt());
1068
  // We defer calling `FunctionDecl::setPure()` here as for methods of
1069
  // `CXXTemplateSpecializationDecl`s, we may not have connected up the
1070
  // definition (which is required for `setPure`).
1071
290k
  const bool Pure = Record.readInt();
1072
290k
  FD->setHasInheritedPrototype(Record.readInt());
1073
290k
  FD->setHasWrittenPrototype(Record.readInt());
1074
290k
  FD->setDeletedAsWritten(Record.readInt());
1075
290k
  FD->setTrivial(Record.readInt());
1076
290k
  FD->setTrivialForCall(Record.readInt());
1077
290k
  FD->setDefaulted(Record.readInt());
1078
290k
  FD->setExplicitlyDefaulted(Record.readInt());
1079
290k
  FD->setIneligibleOrNotSelected(Record.readInt());
1080
290k
  FD->setHasImplicitReturnZero(Record.readInt());
1081
290k
  FD->setConstexprKind(static_cast<ConstexprSpecKind>(Record.readInt()));
1082
290k
  FD->setUsesSEHTry(Record.readInt());
1083
290k
  FD->setHasSkippedBody(Record.readInt());
1084
290k
  FD->setIsMultiVersion(Record.readInt());
1085
290k
  FD->setLateTemplateParsed(Record.readInt());
1086
290k
  FD->setFriendConstraintRefersToEnclosingTemplate(Record.readInt());
1087
1088
290k
  FD->setCachedLinkage(static_cast<Linkage>(Record.readInt()));
1089
290k
  FD->EndRangeLoc = readSourceLocation();
1090
290k
  FD->setDefaultLoc(readSourceLocation());
1091
1092
290k
  FD->ODRHash = Record.readInt();
1093
290k
  FD->setHasODRHash(true);
1094
1095
290k
  if (FD->isDefaulted()) {
1096
59.4k
    if (unsigned NumLookups = Record.readInt()) {
1097
4
      SmallVector<DeclAccessPair, 8> Lookups;
1098
10
      for (unsigned I = 0; I != NumLookups; 
++I6
) {
1099
6
        NamedDecl *ND = Record.readDeclAs<NamedDecl>();
1100
6
        AccessSpecifier AS = (AccessSpecifier)Record.readInt();
1101
6
        Lookups.push_back(DeclAccessPair::make(ND, AS));
1102
6
      }
1103
4
      FD->setDefaultedFunctionInfo(FunctionDecl::DefaultedFunctionInfo::Create(
1104
4
          Reader.getContext(), Lookups));
1105
4
    }
1106
59.4k
  }
1107
1108
290k
  if (Existing)
1109
1.08k
    mergeRedeclarable(FD, Existing, Redecl);
1110
289k
  else if (auto Kind = FD->getTemplatedKind();
1111
289k
           Kind == FunctionDecl::TK_FunctionTemplate ||
1112
289k
           
Kind == FunctionDecl::TK_FunctionTemplateSpecialization199k
) {
1113
    // Function Templates have their FunctionTemplateDecls merged instead of
1114
    // their FunctionDecls.
1115
116k
    auto merge = [this, &Redecl, FD](auto &&F) {
1116
116k
      auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1117
116k
      RedeclarableResult NewRedecl(Existing ? 
F(Existing)963
:
nullptr115k
,
1118
116k
                                   Redecl.getFirstID(), Redecl.isKeyDecl());
1119
116k
      mergeRedeclarableTemplate(F(FD), NewRedecl);
1120
116k
    };
ASTReaderDecl.cpp:auto clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_0::operator()<clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_1>(clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_1&&) const
Line
Count
Source
1115
90.1k
    auto merge = [this, &Redecl, FD](auto &&F) {
1116
90.1k
      auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1117
90.1k
      RedeclarableResult NewRedecl(Existing ? 
F(Existing)961
:
nullptr89.1k
,
1118
90.1k
                                   Redecl.getFirstID(), Redecl.isKeyDecl());
1119
90.1k
      mergeRedeclarableTemplate(F(FD), NewRedecl);
1120
90.1k
    };
ASTReaderDecl.cpp:auto clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_0::operator()<clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_2>(clang::ASTDeclReader::VisitFunctionDecl(clang::FunctionDecl*)::$_2&&) const
Line
Count
Source
1115
26.6k
    auto merge = [this, &Redecl, FD](auto &&F) {
1116
26.6k
      auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1117
26.6k
      RedeclarableResult NewRedecl(Existing ? 
F(Existing)2
:
nullptr26.6k
,
1118
26.6k
                                   Redecl.getFirstID(), Redecl.isKeyDecl());
1119
26.6k
      mergeRedeclarableTemplate(F(FD), NewRedecl);
1120
26.6k
    };
1121
116k
    if (Kind == FunctionDecl::TK_FunctionTemplate)
1122
90.1k
      merge(
1123
91.1k
          [](FunctionDecl *FD) { return FD->getDescribedFunctionTemplate(); });
1124
26.6k
    else
1125
26.6k
      
merge([](FunctionDecl *FD) 26.6k
{
1126
26.6k
        return FD->getTemplateSpecializationInfo()->getTemplate();
1127
26.6k
      });
1128
116k
  } else
1129
173k
    mergeRedeclarable(FD, Redecl);
1130
1131
  // Defer calling `setPure` until merging above has guaranteed we've set
1132
  // `DefinitionData` (as this will need to access it).
1133
290k
  FD->setPure(Pure);
1134
1135
  // Read in the parameters.
1136
290k
  unsigned NumParams = Record.readInt();
1137
290k
  SmallVector<ParmVarDecl *, 16> Params;
1138
290k
  Params.reserve(NumParams);
1139
633k
  for (unsigned I = 0; I != NumParams; 
++I342k
)
1140
342k
    Params.push_back(readDeclAs<ParmVarDecl>());
1141
290k
  FD->setParams(Reader.getContext(), Params);
1142
290k
}
1143
1144
7.99k
void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
1145
7.99k
  VisitNamedDecl(MD);
1146
7.99k
  if (Record.readInt()) {
1147
    // Load the body on-demand. Most clients won't care, because method
1148
    // definitions rarely show up in headers.
1149
18
    Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1150
18
    HasPendingBody = true;
1151
18
  }
1152
7.99k
  MD->setSelfDecl(readDeclAs<ImplicitParamDecl>());
1153
7.99k
  MD->setCmdDecl(readDeclAs<ImplicitParamDecl>());
1154
7.99k
  MD->setInstanceMethod(Record.readInt());
1155
7.99k
  MD->setVariadic(Record.readInt());
1156
7.99k
  MD->setPropertyAccessor(Record.readInt());
1157
7.99k
  MD->setSynthesizedAccessorStub(Record.readInt());
1158
7.99k
  MD->setDefined(Record.readInt());
1159
7.99k
  MD->setOverriding(Record.readInt());
1160
7.99k
  MD->setHasSkippedBody(Record.readInt());
1161
1162
7.99k
  MD->setIsRedeclaration(Record.readInt());
1163
7.99k
  MD->setHasRedeclaration(Record.readInt());
1164
7.99k
  if (MD->hasRedeclaration())
1165
2
    Reader.getContext().setObjCMethodRedeclaration(MD,
1166
2
                                       readDeclAs<ObjCMethodDecl>());
1167
1168
7.99k
  MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt());
1169
7.99k
  MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt());
1170
7.99k
  MD->setRelatedResultType(Record.readInt());
1171
7.99k
  MD->setReturnType(Record.readType());
1172
7.99k
  MD->setReturnTypeSourceInfo(readTypeSourceInfo());
1173
7.99k
  MD->DeclEndLoc = readSourceLocation();
1174
7.99k
  unsigned NumParams = Record.readInt();
1175
7.99k
  SmallVector<ParmVarDecl *, 16> Params;
1176
7.99k
  Params.reserve(NumParams);
1177
11.6k
  for (unsigned I = 0; I != NumParams; 
++I3.64k
)
1178
3.64k
    Params.push_back(readDeclAs<ParmVarDecl>());
1179
1180
7.99k
  MD->setSelLocsKind((SelectorLocationsKind)Record.readInt());
1181
7.99k
  unsigned NumStoredSelLocs = Record.readInt();
1182
7.99k
  SmallVector<SourceLocation, 16> SelLocs;
1183
7.99k
  SelLocs.reserve(NumStoredSelLocs);
1184
10.0k
  for (unsigned i = 0; i != NumStoredSelLocs; 
++i2.03k
)
1185
2.03k
    SelLocs.push_back(readSourceLocation());
1186
1187
7.99k
  MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
1188
7.99k
}
1189
1190
3.82k
void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
1191
3.82k
  VisitTypedefNameDecl(D);
1192
1193
3.82k
  D->Variance = Record.readInt();
1194
3.82k
  D->Index = Record.readInt();
1195
3.82k
  D->VarianceLoc = readSourceLocation();
1196
3.82k
  D->ColonLoc = readSourceLocation();
1197
3.82k
}
1198
1199
17.5k
void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
1200
17.5k
  VisitNamedDecl(CD);
1201
17.5k
  CD->setAtStartLoc(readSourceLocation());
1202
17.5k
  CD->setAtEndRange(readSourceRange());
1203
17.5k
}
1204
1205
15.6k
ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() {
1206
15.6k
  unsigned numParams = Record.readInt();
1207
15.6k
  if (numParams == 0)
1208
12.8k
    return nullptr;
1209
1210
2.79k
  SmallVector<ObjCTypeParamDecl *, 4> typeParams;
1211
2.79k
  typeParams.reserve(numParams);
1212
6.61k
  for (unsigned i = 0; i != numParams; 
++i3.82k
) {
1213
3.82k
    auto *typeParam = readDeclAs<ObjCTypeParamDecl>();
1214
3.82k
    if (!typeParam)
1215
0
      return nullptr;
1216
1217
3.82k
    typeParams.push_back(typeParam);
1218
3.82k
  }
1219
1220
2.79k
  SourceLocation lAngleLoc = readSourceLocation();
1221
2.79k
  SourceLocation rAngleLoc = readSourceLocation();
1222
1223
2.79k
  return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc,
1224
2.79k
                                   typeParams, rAngleLoc);
1225
2.79k
}
1226
1227
void ASTDeclReader::ReadObjCDefinitionData(
1228
2.92k
         struct ObjCInterfaceDecl::DefinitionData &Data) {
1229
  // Read the superclass.
1230
2.92k
  Data.SuperClassTInfo = readTypeSourceInfo();
1231
1232
2.92k
  Data.EndLoc = readSourceLocation();
1233
2.92k
  Data.HasDesignatedInitializers = Record.readInt();
1234
2.92k
  Data.ODRHash = Record.readInt();
1235
2.92k
  Data.HasODRHash = true;
1236
1237
  // Read the directly referenced protocols and their SourceLocations.
1238
2.92k
  unsigned NumProtocols = Record.readInt();
1239
2.92k
  SmallVector<ObjCProtocolDecl *, 16> Protocols;
1240
2.92k
  Protocols.reserve(NumProtocols);
1241
4.95k
  for (unsigned I = 0; I != NumProtocols; 
++I2.03k
)
1242
2.03k
    Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1243
2.92k
  SmallVector<SourceLocation, 16> ProtoLocs;
1244
2.92k
  ProtoLocs.reserve(NumProtocols);
1245
4.95k
  for (unsigned I = 0; I != NumProtocols; 
++I2.03k
)
1246
2.03k
    ProtoLocs.push_back(readSourceLocation());
1247
2.92k
  Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1248
2.92k
                               Reader.getContext());
1249
1250
  // Read the transitive closure of protocols referenced by this class.
1251
2.92k
  NumProtocols = Record.readInt();
1252
2.92k
  Protocols.clear();
1253
2.92k
  Protocols.reserve(NumProtocols);
1254
2.92k
  for (unsigned I = 0; I != NumProtocols; 
++I0
)
1255
0
    Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1256
2.92k
  Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1257
2.92k
                                  Reader.getContext());
1258
2.92k
}
1259
1260
void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
1261
1.89k
         struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1262
1.89k
  struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1263
1.89k
  if (DD.Definition == NewDD.Definition)
1264
1.82k
    return;
1265
1266
71
  Reader.MergedDeclContexts.insert(
1267
71
      std::make_pair(NewDD.Definition, DD.Definition));
1268
71
  Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
1269
1270
71
  if (D->getODRHash() != NewDD.ODRHash)
1271
32
    Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back(
1272
32
        {NewDD.Definition, &NewDD});
1273
71
}
1274
1275
12.6k
void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
1276
12.6k
  RedeclarableResult Redecl = VisitRedeclarable(ID);
1277
12.6k
  VisitObjCContainerDecl(ID);
1278
12.6k
  DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
1279
12.6k
  mergeRedeclarable(ID, Redecl);
1280
1281
12.6k
  ID->TypeParamList = ReadObjCTypeParamList();
1282
12.6k
  if (Record.readInt()) {
1283
    // Read the definition.
1284
2.92k
    ID->allocateDefinitionData();
1285
1286
2.92k
    ReadObjCDefinitionData(ID->data());
1287
2.92k
    ObjCInterfaceDecl *Canon = ID->getCanonicalDecl();
1288
2.92k
    if (Canon->Data.getPointer()) {
1289
      // If we already have a definition, keep the definition invariant and
1290
      // merge the data.
1291
1.89k
      MergeDefinitionData(Canon, std::move(ID->data()));
1292
1.89k
      ID->Data = Canon->Data;
1293
1.89k
    } else {
1294
      // Set the definition data of the canonical declaration, so other
1295
      // redeclarations will see it.
1296
1.02k
      ID->getCanonicalDecl()->Data = ID->Data;
1297
1298
      // We will rebuild this list lazily.
1299
1.02k
      ID->setIvarList(nullptr);
1300
1.02k
    }
1301
1302
    // Note that we have deserialized a definition.
1303
2.92k
    Reader.PendingDefinitions.insert(ID);
1304
1305
    // Note that we've loaded this Objective-C class.
1306
2.92k
    Reader.ObjCClassesLoaded.push_back(ID);
1307
9.75k
  } else {
1308
9.75k
    ID->Data = ID->getCanonicalDecl()->Data;
1309
9.75k
  }
1310
12.6k
}
1311
1312
200
void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
1313
200
  VisitFieldDecl(IVD);
1314
200
  IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt());
1315
  // This field will be built lazily.
1316
200
  IVD->setNextIvar(nullptr);
1317
200
  bool synth = Record.readInt();
1318
200
  IVD->setSynthesize(synth);
1319
1320
  // Check ivar redeclaration.
1321
200
  if (IVD->isInvalidDecl())
1322
0
    return;
1323
  // Don't check ObjCInterfaceDecl as interfaces are named and mismatches can be
1324
  // detected in VisitObjCInterfaceDecl. Here we are looking for redeclarations
1325
  // in extensions.
1326
200
  if (isa<ObjCInterfaceDecl>(IVD->getDeclContext()))
1327
161
    return;
1328
39
  ObjCInterfaceDecl *CanonIntf =
1329
39
      IVD->getContainingInterface()->getCanonicalDecl();
1330
39
  IdentifierInfo *II = IVD->getIdentifier();
1331
39
  ObjCIvarDecl *PrevIvar = CanonIntf->lookupInstanceVariable(II);
1332
39
  if (PrevIvar && 
PrevIvar != IVD31
) {
1333
11
    auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->getDeclContext());
1334
11
    auto *PrevParentExt =
1335
11
        dyn_cast<ObjCCategoryDecl>(PrevIvar->getDeclContext());
1336
11
    if (ParentExt && 
PrevParentExt9
) {
1337
      // Postpone diagnostic as we should merge identical extensions from
1338
      // different modules.
1339
8
      Reader
1340
8
          .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt,
1341
8
                                                                 PrevParentExt)]
1342
8
          .push_back(std::make_pair(IVD, PrevIvar));
1343
8
    } else 
if (3
ParentExt3
||
PrevParentExt2
) {
1344
      // Duplicate ivars in extension + implementation are never compatible.
1345
      // Compatibility of implementation + implementation should be handled in
1346
      // VisitObjCImplementationDecl.
1347
1
      Reader.Diag(IVD->getLocation(), diag::err_duplicate_ivar_declaration)
1348
1
          << II;
1349
1
      Reader.Diag(PrevIvar->getLocation(), diag::note_previous_definition);
1350
1
    }
1351
11
  }
1352
39
}
1353
1354
void ASTDeclReader::ReadObjCDefinitionData(
1355
1.11k
         struct ObjCProtocolDecl::DefinitionData &Data) {
1356
1.11k
    unsigned NumProtoRefs = Record.readInt();
1357
1.11k
    SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
1358
1.11k
    ProtoRefs.reserve(NumProtoRefs);
1359
1.83k
    for (unsigned I = 0; I != NumProtoRefs; 
++I721
)
1360
721
      ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1361
1.11k
    SmallVector<SourceLocation, 16> ProtoLocs;
1362
1.11k
    ProtoLocs.reserve(NumProtoRefs);
1363
1.83k
    for (unsigned I = 0; I != NumProtoRefs; 
++I721
)
1364
721
      ProtoLocs.push_back(readSourceLocation());
1365
1.11k
    Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1366
1.11k
                                 ProtoLocs.data(), Reader.getContext());
1367
1.11k
    Data.ODRHash = Record.readInt();
1368
1.11k
    Data.HasODRHash = true;
1369
1.11k
}
1370
1371
void ASTDeclReader::MergeDefinitionData(
1372
832
    ObjCProtocolDecl *D, struct ObjCProtocolDecl::DefinitionData &&NewDD) {
1373
832
  struct ObjCProtocolDecl::DefinitionData &DD = D->data();
1374
832
  if (DD.Definition == NewDD.Definition)
1375
798
    return;
1376
1377
34
  Reader.MergedDeclContexts.insert(
1378
34
      std::make_pair(NewDD.Definition, DD.Definition));
1379
34
  Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
1380
1381
34
  if (D->getODRHash() != NewDD.ODRHash)
1382
22
    Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back(
1383
22
        {NewDD.Definition, &NewDD});
1384
34
}
1385
1386
1.89k
void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
1387
1.89k
  RedeclarableResult Redecl = VisitRedeclarable(PD);
1388
1.89k
  VisitObjCContainerDecl(PD);
1389
1.89k
  mergeRedeclarable(PD, Redecl);
1390
1391
1.89k
  if (Record.readInt()) {
1392
    // Read the definition.
1393
1.11k
    PD->allocateDefinitionData();
1394
1395
1.11k
    ReadObjCDefinitionData(PD->data());
1396
1397
1.11k
    ObjCProtocolDecl *Canon = PD->getCanonicalDecl();
1398
1.11k
    if (Canon->Data.getPointer()) {
1399
      // If we already have a definition, keep the definition invariant and
1400
      // merge the data.
1401
832
      MergeDefinitionData(Canon, std::move(PD->data()));
1402
832
      PD->Data = Canon->Data;
1403
832
    } else {
1404
      // Set the definition data of the canonical declaration, so other
1405
      // redeclarations will see it.
1406
284
      PD->getCanonicalDecl()->Data = PD->Data;
1407
284
    }
1408
    // Note that we have deserialized a definition.
1409
1.11k
    Reader.PendingDefinitions.insert(PD);
1410
1.11k
  } else {
1411
780
    PD->Data = PD->getCanonicalDecl()->Data;
1412
780
  }
1413
1.89k
}
1414
1415
0
void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
1416
0
  VisitFieldDecl(FD);
1417
0
}
1418
1419
2.93k
void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
1420
2.93k
  VisitObjCContainerDecl(CD);
1421
2.93k
  CD->setCategoryNameLoc(readSourceLocation());
1422
2.93k
  CD->setIvarLBraceLoc(readSourceLocation());
1423
2.93k
  CD->setIvarRBraceLoc(readSourceLocation());
1424
1425
  // Note that this category has been deserialized. We do this before
1426
  // deserializing the interface declaration, so that it will consider this
1427
  /// category.
1428
2.93k
  Reader.CategoriesDeserialized.insert(CD);
1429
1430
2.93k
  CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>();
1431
2.93k
  CD->TypeParamList = ReadObjCTypeParamList();
1432
2.93k
  unsigned NumProtoRefs = Record.readInt();
1433
2.93k
  SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
1434
2.93k
  ProtoRefs.reserve(NumProtoRefs);
1435
3.10k
  for (unsigned I = 0; I != NumProtoRefs; 
++I164
)
1436
164
    ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1437
2.93k
  SmallVector<SourceLocation, 16> ProtoLocs;
1438
2.93k
  ProtoLocs.reserve(NumProtoRefs);
1439
3.10k
  for (unsigned I = 0; I != NumProtoRefs; 
++I164
)
1440
164
    ProtoLocs.push_back(readSourceLocation());
1441
2.93k
  CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
1442
2.93k
                      Reader.getContext());
1443
1444
  // Protocols in the class extension belong to the class.
1445
2.93k
  if (NumProtoRefs > 0 && 
CD->ClassInterface123
&&
CD->IsClassExtension()123
)
1446
2
    CD->ClassInterface->mergeClassExtensionProtocolList(
1447
2
        (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs,
1448
2
        Reader.getContext());
1449
2.93k
}
1450
1451
3
void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
1452
3
  VisitNamedDecl(CAD);
1453
3
  CAD->setClassInterface(readDeclAs<ObjCInterfaceDecl>());
1454
3
}
1455
1456
489
void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
1457
489
  VisitNamedDecl(D);
1458
489
  D->setAtLoc(readSourceLocation());
1459
489
  D->setLParenLoc(readSourceLocation());
1460
489
  QualType T = Record.readType();
1461
489
  TypeSourceInfo *TSI = readTypeSourceInfo();
1462
489
  D->setType(T, TSI);
1463
489
  D->setPropertyAttributes((ObjCPropertyAttribute::Kind)Record.readInt());
1464
489
  D->setPropertyAttributesAsWritten(
1465
489
      (ObjCPropertyAttribute::Kind)Record.readInt());
1466
489
  D->setPropertyImplementation(
1467
489
      (ObjCPropertyDecl::PropertyControl)Record.readInt());
1468
489
  DeclarationName GetterName = Record.readDeclarationName();
1469
489
  SourceLocation GetterLoc = readSourceLocation();
1470
489
  D->setGetterName(GetterName.getObjCSelector(), GetterLoc);
1471
489
  DeclarationName SetterName = Record.readDeclarationName();
1472
489
  SourceLocation SetterLoc = readSourceLocation();
1473
489
  D->setSetterName(SetterName.getObjCSelector(), SetterLoc);
1474
489
  D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1475
489
  D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1476
489
  D->setPropertyIvarDecl(readDeclAs<ObjCIvarDecl>());
1477
489
}
1478
1479
43
void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
1480
43
  VisitObjCContainerDecl(D);
1481
43
  D->setClassInterface(readDeclAs<ObjCInterfaceDecl>());
1482
43
}
1483
1484
7
void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
1485
7
  VisitObjCImplDecl(D);
1486
7
  D->CategoryNameLoc = readSourceLocation();
1487
7
}
1488
1489
36
void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
1490
36
  VisitObjCImplDecl(D);
1491
36
  D->setSuperClass(readDeclAs<ObjCInterfaceDecl>());
1492
36
  D->SuperLoc = readSourceLocation();
1493
36
  D->setIvarLBraceLoc(readSourceLocation());
1494
36
  D->setIvarRBraceLoc(readSourceLocation());
1495
36
  D->setHasNonZeroConstructors(Record.readInt());
1496
36
  D->setHasDestructors(Record.readInt());
1497
36
  D->NumIvarInitializers = Record.readInt();
1498
36
  if (D->NumIvarInitializers)
1499
4
    D->IvarInitializers = ReadGlobalOffset();
1500
36
}
1501
1502
16
void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
1503
16
  VisitDecl(D);
1504
16
  D->setAtLoc(readSourceLocation());
1505
16
  D->setPropertyDecl(readDeclAs<ObjCPropertyDecl>());
1506
16
  D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>();
1507
16
  D->IvarLoc = readSourceLocation();
1508
16
  D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1509
16
  D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1510
16
  D->setGetterCXXConstructor(Record.readExpr());
1511
16
  D->setSetterCXXAssignment(Record.readExpr());
1512
16
}
1513
1514
30.2k
void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
1515
30.2k
  VisitDeclaratorDecl(FD);
1516
30.2k
  FD->Mutable = Record.readInt();
1517
1518
30.2k
  unsigned Bits = Record.readInt();
1519
30.2k
  FD->StorageKind = Bits >> 1;
1520
30.2k
  if (FD->StorageKind == FieldDecl::ISK_CapturedVLAType)
1521
1.36k
    FD->CapturedVLAType =
1522
1.36k
        cast<VariableArrayType>(Record.readType().getTypePtr());
1523
28.8k
  else if (Bits & 1)
1524
423
    FD->setBitWidth(Record.readExpr());
1525
1526
30.2k
  if (!FD->getDeclName()) {
1527
13.2k
    if (auto *Tmpl = readDeclAs<FieldDecl>())
1528
110
      Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
1529
13.2k
  }
1530
30.2k
  mergeMergeable(FD);
1531
30.2k
}
1532
1533
21
void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) {
1534
21
  VisitDeclaratorDecl(PD);
1535
21
  PD->GetterId = Record.readIdentifier();
1536
21
  PD->SetterId = Record.readIdentifier();
1537
21
}
1538
1539
1
void ASTDeclReader::VisitMSGuidDecl(MSGuidDecl *D) {
1540
1
  VisitValueDecl(D);
1541
1
  D->PartVal.Part1 = Record.readInt();
1542
1
  D->PartVal.Part2 = Record.readInt();
1543
1
  D->PartVal.Part3 = Record.readInt();
1544
1
  for (auto &C : D->PartVal.Part4And5)
1545
8
    C = Record.readInt();
1546
1547
  // Add this GUID to the AST context's lookup structure, and merge if needed.
1548
1
  if (MSGuidDecl *Existing = Reader.getContext().MSGuidDecls.GetOrInsertNode(D))
1549
1
    Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1550
1
}
1551
1552
void ASTDeclReader::VisitUnnamedGlobalConstantDecl(
1553
0
    UnnamedGlobalConstantDecl *D) {
1554
0
  VisitValueDecl(D);
1555
0
  D->Value = Record.readAPValue();
1556
1557
  // Add this to the AST context's lookup structure, and merge if needed.
1558
0
  if (UnnamedGlobalConstantDecl *Existing =
1559
0
          Reader.getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D))
1560
0
    Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1561
0
}
1562
1563
2
void ASTDeclReader::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) {
1564
2
  VisitValueDecl(D);
1565
2
  D->Value = Record.readAPValue();
1566
1567
  // Add this template parameter object to the AST context's lookup structure,
1568
  // and merge if needed.
1569
2
  if (TemplateParamObjectDecl *Existing =
1570
2
          Reader.getContext().TemplateParamObjectDecls.GetOrInsertNode(D))
1571
2
    Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1572
2
}
1573
1574
389
void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
1575
389
  VisitValueDecl(FD);
1576
1577
389
  FD->ChainingSize = Record.readInt();
1578
389
  assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
1579
389
  FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
1580
1581
1.17k
  for (unsigned I = 0; I != FD->ChainingSize; 
++I784
)
1582
784
    FD->Chaining[I] = readDeclAs<NamedDecl>();
1583
1584
389
  mergeMergeable(FD);
1585
389
}
1586
1587
647k
ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
1588
647k
  RedeclarableResult Redecl = VisitRedeclarable(VD);
1589
647k
  VisitDeclaratorDecl(VD);
1590
1591
647k
  VD->VarDeclBits.SClass = (StorageClass)Record.readInt();
1592
647k
  VD->VarDeclBits.TSCSpec = Record.readInt();
1593
647k
  VD->VarDeclBits.InitStyle = Record.readInt();
1594
647k
  VD->VarDeclBits.ARCPseudoStrong = Record.readInt();
1595
647k
  bool HasDeducedType = false;
1596
647k
  if (!isa<ParmVarDecl>(VD)) {
1597
284k
    VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =
1598
284k
        Record.readInt();
1599
284k
    VD->NonParmVarDeclBits.ExceptionVar = Record.readInt();
1600
284k
    VD->NonParmVarDeclBits.NRVOVariable = Record.readInt();
1601
284k
    VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt();
1602
284k
    VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt();
1603
284k
    VD->NonParmVarDeclBits.IsInline = Record.readInt();
1604
284k
    VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
1605
284k
    VD->NonParmVarDeclBits.IsConstexpr = Record.readInt();
1606
284k
    VD->NonParmVarDeclBits.IsInitCapture = Record.readInt();
1607
284k
    VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt();
1608
284k
    VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt();
1609
284k
    VD->NonParmVarDeclBits.EscapingByref = Record.readInt();
1610
284k
    HasDeducedType = Record.readInt();
1611
284k
  }
1612
1613
  // If this variable has a deduced type, defer reading that type until we are
1614
  // done deserializing this variable, because the type might refer back to the
1615
  // variable.
1616
647k
  if (HasDeducedType)
1617
1.32k
    Reader.PendingDeducedVarTypes.push_back({VD, DeferredTypeID});
1618
645k
  else
1619
645k
    VD->setType(Reader.GetType(DeferredTypeID));
1620
647k
  DeferredTypeID = 0;
1621
1622
647k
  auto VarLinkage = Linkage(Record.readInt());
1623
647k
  VD->setCachedLinkage(VarLinkage);
1624
1625
  // Reconstruct the one piece of the IdentifierNamespace that we need.
1626
647k
  if (VD->getStorageClass() == SC_Extern && 
VarLinkage != NoLinkage2.03k
&&
1627
647k
      
VD->getLexicalDeclContext()->isFunctionOrMethod()2.03k
)
1628
23
    VD->setLocalExternDecl();
1629
1630
647k
  if (VD->hasAttr<BlocksAttr>()) {
1631
5
    Expr *CopyExpr = Record.readExpr();
1632
5
    if (CopyExpr)
1633
2
      Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt());
1634
5
  }
1635
1636
647k
  if (Record.readInt()) {
1637
136
    Reader.DefinitionSource[VD] =
1638
136
        Loc.F->Kind == ModuleKind::MK_MainFile ||
1639
136
        
Reader.getContext().getLangOpts().BuildingPCHWithObjectFile111
;
1640
136
  }
1641
1642
647k
  enum VarKind {
1643
647k
    VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1644
647k
  };
1645
647k
  switch ((VarKind)Record.readInt()) {
1646
629k
  case VarNotTemplate:
1647
    // Only true variables (not parameters or implicit parameters) can be
1648
    // merged; the other kinds are not really redeclarable at all.
1649
629k
    if (!isa<ParmVarDecl>(VD) && 
!isa<ImplicitParamDecl>(VD)266k
&&
1650
629k
        
!isa<VarTemplateSpecializationDecl>(VD)121k
)
1651
121k
      mergeRedeclarable(VD, Redecl);
1652
629k
    break;
1653
293
  case VarTemplate:
1654
    // Merged when we merge the template.
1655
293
    VD->setDescribedVarTemplate(readDeclAs<VarTemplateDecl>());
1656
293
    break;
1657
17.3k
  case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo.
1658
17.3k
    auto *Tmpl = readDeclAs<VarDecl>();
1659
17.3k
    auto TSK = (TemplateSpecializationKind)Record.readInt();
1660
17.3k
    SourceLocation POI = readSourceLocation();
1661
17.3k
    Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
1662
17.3k
    mergeRedeclarable(VD, Redecl);
1663
17.3k
    break;
1664
0
  }
1665
647k
  }
1666
1667
647k
  return Redecl;
1668
647k
}
1669
1670
647k
void ASTDeclReader::ReadVarDeclInit(VarDecl *VD) {
1671
647k
  if (uint64_t Val = Record.readInt()) {
1672
98.3k
    EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
1673
98.3k
    Eval->HasConstantInitialization = (Val & 2) != 0;
1674
98.3k
    Eval->HasConstantDestruction = (Val & 4) != 0;
1675
98.3k
    Eval->WasEvaluated = (Val & 8) != 0;
1676
98.3k
    if (Eval->WasEvaluated) {
1677
14.9k
      Eval->Evaluated = Record.readAPValue();
1678
14.9k
      if (Eval->Evaluated.needsCleanup())
1679
9
        Reader.getContext().addDestruction(&Eval->Evaluated);
1680
14.9k
    }
1681
1682
    // Store the offset of the initializer. Don't deserialize it yet: it might
1683
    // not be needed, and might refer back to the variable, for example if it
1684
    // contains a lambda.
1685
98.3k
    Eval->Value = GetCurrentCursorOffset();
1686
98.3k
  }
1687
647k
}
1688
1689
145k
void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
1690
145k
  VisitVarDecl(PD);
1691
145k
}
1692
1693
363k
void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
1694
363k
  VisitVarDecl(PD);
1695
363k
  unsigned isObjCMethodParam = Record.readInt();
1696
363k
  unsigned scopeDepth = Record.readInt();
1697
363k
  unsigned scopeIndex = Record.readInt();
1698
363k
  unsigned declQualifier = Record.readInt();
1699
363k
  if (isObjCMethodParam) {
1700
2.46k
    assert(scopeDepth == 0);
1701
2.46k
    PD->setObjCMethodScopeInfo(scopeIndex);
1702
2.46k
    PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
1703
360k
  } else {
1704
360k
    PD->setScopeInfo(scopeDepth, scopeIndex);
1705
360k
  }
1706
363k
  PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt();
1707
363k
  PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt();
1708
363k
  if (Record.readInt()) // hasUninstantiatedDefaultArg.
1709
906
    PD->setUninstantiatedDefaultArg(Record.readExpr());
1710
1711
  // FIXME: If this is a redeclaration of a function from another module, handle
1712
  // inheritance of default arguments.
1713
363k
}
1714
1715
7
void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) {
1716
7
  VisitVarDecl(DD);
1717
7
  auto **BDs = DD->getTrailingObjects<BindingDecl *>();
1718
19
  for (unsigned I = 0; I != DD->NumBindings; 
++I12
) {
1719
12
    BDs[I] = readDeclAs<BindingDecl>();
1720
12
    BDs[I]->setDecomposedDecl(DD);
1721
12
  }
1722
7
}
1723
1724
12
void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) {
1725
12
  VisitValueDecl(BD);
1726
12
  BD->Binding = Record.readExpr();
1727
12
}
1728
1729
116
void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
1730
116
  VisitDecl(AD);
1731
116
  AD->setAsmString(cast<StringLiteral>(Record.readExpr()));
1732
116
  AD->setRParenLoc(readSourceLocation());
1733
116
}
1734
1735
1
void ASTDeclReader::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
1736
1
  VisitDecl(D);
1737
1
  D->Statement = Record.readStmt();
1738
1
}
1739
1740
17
void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
1741
17
  VisitDecl(BD);
1742
17
  BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt()));
1743
17
  BD->setSignatureAsWritten(readTypeSourceInfo());
1744
17
  unsigned NumParams = Record.readInt();
1745
17
  SmallVector<ParmVarDecl *, 16> Params;
1746
17
  Params.reserve(NumParams);
1747
27
  for (unsigned I = 0; I != NumParams; 
++I10
)
1748
10
    Params.push_back(readDeclAs<ParmVarDecl>());
1749
17
  BD->setParams(Params);
1750
1751
17
  BD->setIsVariadic(Record.readInt());
1752
17
  BD->setBlockMissingReturnType(Record.readInt());
1753
17
  BD->setIsConversionFromLambda(Record.readInt());
1754
17
  BD->setDoesNotEscape(Record.readInt());
1755
17
  BD->setCanAvoidCopyToHeap(Record.readInt());
1756
1757
17
  bool capturesCXXThis = Record.readInt();
1758
17
  unsigned numCaptures = Record.readInt();
1759
17
  SmallVector<BlockDecl::Capture, 16> captures;
1760
17
  captures.reserve(numCaptures);
1761
26
  for (unsigned i = 0; i != numCaptures; 
++i9
) {
1762
9
    auto *decl = readDeclAs<VarDecl>();
1763
9
    unsigned flags = Record.readInt();
1764
9
    bool byRef = (flags & 1);
1765
9
    bool nested = (flags & 2);
1766
9
    Expr *copyExpr = ((flags & 4) ? 
Record.readExpr()0
: nullptr);
1767
1768
9
    captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1769
9
  }
1770
17
  BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
1771
17
}
1772
1773
36.6k
void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {
1774
36.6k
  VisitDecl(CD);
1775
36.6k
  unsigned ContextParamPos = Record.readInt();
1776
36.6k
  CD->setNothrow(Record.readInt() != 0);
1777
  // Body is set by VisitCapturedStmt.
1778
165k
  for (unsigned I = 0; I < CD->NumParams; 
++I129k
) {
1779
129k
    if (I != ContextParamPos)
1780
92.6k
      CD->setParam(I, readDeclAs<ImplicitParamDecl>());
1781
36.6k
    else
1782
36.6k
      CD->setContextParam(I, readDeclAs<ImplicitParamDecl>());
1783
129k
  }
1784
36.6k
}
1785
1786
12.1k
void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1787
12.1k
  VisitDecl(D);
1788
12.1k
  D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt());
1789
12.1k
  D->setExternLoc(readSourceLocation());
1790
12.1k
  D->setRBraceLoc(readSourceLocation());
1791
12.1k
}
1792
1793
404
void ASTDeclReader::VisitExportDecl(ExportDecl *D) {
1794
404
  VisitDecl(D);
1795
404
  D->RBraceLoc = readSourceLocation();
1796
404
}
1797
1798
17
void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
1799
17
  VisitNamedDecl(D);
1800
17
  D->setLocStart(readSourceLocation());
1801
17
}
1802
1803
1.23M
void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
1804
1.23M
  RedeclarableResult Redecl = VisitRedeclarable(D);
1805
1.23M
  VisitNamedDecl(D);
1806
1.23M
  D->setInline(Record.readInt());
1807
1.23M
  D->setNested(Record.readInt());
1808
1.23M
  D->LocStart = readSourceLocation();
1809
1.23M
  D->RBraceLoc = readSourceLocation();
1810
1811
  // Defer loading the anonymous namespace until we've finished merging
1812
  // this namespace; loading it might load a later declaration of the
1813
  // same namespace, and we have an invariant that older declarations
1814
  // get merged before newer ones try to merge.
1815
1.23M
  GlobalDeclID AnonNamespace = 0;
1816
1.23M
  if (Redecl.getFirstID() == ThisDeclID) {
1817
468k
    AnonNamespace = readDeclID();
1818
766k
  } else {
1819
    // Link this namespace back to the first declaration, which has already
1820
    // been deserialized.
1821
766k
    D->AnonOrFirstNamespaceAndFlags.setPointer(D->getFirstDecl());
1822
766k
  }
1823
1824
1.23M
  mergeRedeclarable(D, Redecl);
1825
1826
1.23M
  if (AnonNamespace) {
1827
    // Each module has its own anonymous namespace, which is disjoint from
1828
    // any other module's anonymous namespaces, so don't attach the anonymous
1829
    // namespace at all.
1830
11
    auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace));
1831
11
    if (!Record.isModule())
1832
6
      D->setAnonymousNamespace(Anon);
1833
11
  }
1834
1.23M
}
1835
1836
2
void ASTDeclReader::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
1837
2
  VisitNamedDecl(D);
1838
2
  VisitDeclContext(D);
1839
2
  D->IsCBuffer = Record.readBool();
1840
2
  D->KwLoc = readSourceLocation();
1841
2
  D->LBraceLoc = readSourceLocation();
1842
2
  D->RBraceLoc = readSourceLocation();
1843
2
}
1844
1845
18
void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1846
18
  RedeclarableResult Redecl = VisitRedeclarable(D);
1847
18
  VisitNamedDecl(D);
1848
18
  D->NamespaceLoc = readSourceLocation();
1849
18
  D->IdentLoc = readSourceLocation();
1850
18
  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1851
18
  D->Namespace = readDeclAs<NamedDecl>();
1852
18
  mergeRedeclarable(D, Redecl);
1853
18
}
1854
1855
4.21k
void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
1856
4.21k
  VisitNamedDecl(D);
1857
4.21k
  D->setUsingLoc(readSourceLocation());
1858
4.21k
  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1859
4.21k
  D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName());
1860
4.21k
  D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1861
4.21k
  D->setTypename(Record.readInt());
1862
4.21k
  if (auto *Pattern = readDeclAs<NamedDecl>())
1863
213
    Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
1864
4.21k
  mergeMergeable(D);
1865
4.21k
}
1866
1867
1
void ASTDeclReader::VisitUsingEnumDecl(UsingEnumDecl *D) {
1868
1
  VisitNamedDecl(D);
1869
1
  D->setUsingLoc(readSourceLocation());
1870
1
  D->setEnumLoc(readSourceLocation());
1871
1
  D->setEnumType(Record.readTypeSourceInfo());
1872
1
  D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1873
1
  if (auto *Pattern = readDeclAs<UsingEnumDecl>())
1874
0
    Reader.getContext().setInstantiatedFromUsingEnumDecl(D, Pattern);
1875
1
  mergeMergeable(D);
1876
1
}
1877
1878
10
void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) {
1879
10
  VisitNamedDecl(D);
1880
10
  D->InstantiatedFrom = readDeclAs<NamedDecl>();
1881
10
  auto **Expansions = D->getTrailingObjects<NamedDecl *>();
1882
32
  for (unsigned I = 0; I != D->NumExpansions; 
++I22
)
1883
22
    Expansions[I] = readDeclAs<NamedDecl>();
1884
10
  mergeMergeable(D);
1885
10
}
1886
1887
5.33k
void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
1888
5.33k
  RedeclarableResult Redecl = VisitRedeclarable(D);
1889
5.33k
  VisitNamedDecl(D);
1890
5.33k
  D->Underlying = readDeclAs<NamedDecl>();
1891
5.33k
  D->IdentifierNamespace = Record.readInt();
1892
5.33k
  D->UsingOrNextShadow = readDeclAs<NamedDecl>();
1893
5.33k
  auto *Pattern = readDeclAs<UsingShadowDecl>();
1894
5.33k
  if (Pattern)
1895
97
    Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
1896
5.33k
  mergeRedeclarable(D, Redecl);
1897
5.33k
}
1898
1899
void ASTDeclReader::VisitConstructorUsingShadowDecl(
1900
93
    ConstructorUsingShadowDecl *D) {
1901
93
  VisitUsingShadowDecl(D);
1902
93
  D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1903
93
  D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1904
93
  D->IsVirtual = Record.readInt();
1905
93
}
1906
1907
433
void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1908
433
  VisitNamedDecl(D);
1909
433
  D->UsingLoc = readSourceLocation();
1910
433
  D->NamespaceLoc = readSourceLocation();
1911
433
  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1912
433
  D->NominatedNamespace = readDeclAs<NamedDecl>();
1913
433
  D->CommonAncestor = readDeclAs<DeclContext>();
1914
433
}
1915
1916
88
void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1917
88
  VisitValueDecl(D);
1918
88
  D->setUsingLoc(readSourceLocation());
1919
88
  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1920
88
  D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName());
1921
88
  D->EllipsisLoc = readSourceLocation();
1922
88
  mergeMergeable(D);
1923
88
}
1924
1925
void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
1926
153
                                               UnresolvedUsingTypenameDecl *D) {
1927
153
  VisitTypeDecl(D);
1928
153
  D->TypenameLocation = readSourceLocation();
1929
153
  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1930
153
  D->EllipsisLoc = readSourceLocation();
1931
153
  mergeMergeable(D);
1932
153
}
1933
1934
void ASTDeclReader::VisitUnresolvedUsingIfExistsDecl(
1935
0
    UnresolvedUsingIfExistsDecl *D) {
1936
0
  VisitNamedDecl(D);
1937
0
}
1938
1939
void ASTDeclReader::ReadCXXDefinitionData(
1940
    struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D,
1941
321k
    Decl *LambdaContext, unsigned IndexInLambdaContext) {
1942
17.3M
#define FIELD(Name, Width, Merge) Data.Name = Record.readInt();
1943
321k
#include "clang/AST/CXXRecordDeclDefinitionBits.def"
1944
1945
  // Note: the caller has deserialized the IsLambda bit already.
1946
321k
  Data.ODRHash = Record.readInt();
1947
321k
  Data.HasODRHash = true;
1948
1949
321k
  if (Record.readInt()) {
1950
12
    Reader.DefinitionSource[D] =
1951
12
        Loc.F->Kind == ModuleKind::MK_MainFile ||
1952
12
        
Reader.getContext().getLangOpts().BuildingPCHWithObjectFile6
;
1953
12
  }
1954
1955
321k
  Record.readUnresolvedSet(Data.Conversions);
1956
321k
  Data.ComputedVisibleConversions = Record.readInt();
1957
321k
  if (Data.ComputedVisibleConversions)
1958
2.53k
    Record.readUnresolvedSet(Data.VisibleConversions);
1959
321k
  assert(Data.Definition && "Data.Definition should be already set!");
1960
1961
321k
  if (!Data.IsLambda) {
1962
320k
    assert(!LambdaContext && !IndexInLambdaContext &&
1963
320k
           "given lambda context for non-lambda");
1964
1965
320k
    Data.NumBases = Record.readInt();
1966
320k
    if (Data.NumBases)
1967
129k
      Data.Bases = ReadGlobalOffset();
1968
1969
320k
    Data.NumVBases = Record.readInt();
1970
320k
    if (Data.NumVBases)
1971
596
      Data.VBases = ReadGlobalOffset();
1972
1973
320k
    Data.FirstFriend = readDeclID();
1974
320k
  } else {
1975
753
    using Capture = LambdaCapture;
1976
1977
753
    auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data);
1978
753
    Lambda.DependencyKind = Record.readInt();
1979
753
    Lambda.IsGenericLambda = Record.readInt();
1980
753
    Lambda.CaptureDefault = Record.readInt();
1981
753
    Lambda.NumCaptures = Record.readInt();
1982
753
    Lambda.NumExplicitCaptures = Record.readInt();
1983
753
    Lambda.HasKnownInternalLinkage = Record.readInt();
1984
753
    Lambda.ManglingNumber = Record.readInt();
1985
753
    if (unsigned DeviceManglingNumber = Record.readInt())
1986
0
      Reader.getContext().DeviceLambdaManglingNumbers[D] = DeviceManglingNumber;
1987
753
    Lambda.IndexInContext = IndexInLambdaContext;
1988
753
    Lambda.ContextDecl = LambdaContext;
1989
753
    Capture *ToCapture = nullptr;
1990
753
    if (Lambda.NumCaptures) {
1991
499
      ToCapture = (Capture *)Reader.getContext().Allocate(sizeof(Capture) *
1992
499
                                                          Lambda.NumCaptures);
1993
499
      Lambda.AddCaptureList(Reader.getContext(), ToCapture);
1994
499
    }
1995
753
    Lambda.MethodTyInfo = readTypeSourceInfo();
1996
1.96k
    for (unsigned I = 0, N = Lambda.NumCaptures; I != N; 
++I1.21k
) {
1997
1.21k
      SourceLocation Loc = readSourceLocation();
1998
1.21k
      bool IsImplicit = Record.readInt();
1999
1.21k
      auto Kind = static_cast<LambdaCaptureKind>(Record.readInt());
2000
1.21k
      switch (Kind) {
2001
2
      case LCK_StarThis:
2002
28
      case LCK_This:
2003
29
      case LCK_VLAType:
2004
29
        *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation());
2005
29
        break;
2006
96
      case LCK_ByCopy:
2007
1.18k
      case LCK_ByRef:
2008
1.18k
        auto *Var = readDeclAs<VarDecl>();
2009
1.18k
        SourceLocation EllipsisLoc = readSourceLocation();
2010
1.18k
        *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
2011
1.18k
        break;
2012
1.21k
      }
2013
1.21k
    }
2014
753
  }
2015
321k
}
2016
2017
void ASTDeclReader::MergeDefinitionData(
2018
20.9k
    CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) {
2019
20.9k
  assert(D->DefinitionData &&
2020
20.9k
         "merging class definition into non-definition");
2021
20.9k
  auto &DD = *D->DefinitionData;
2022
2023
20.9k
  if (DD.Definition != MergeDD.Definition) {
2024
    // Track that we merged the definitions.
2025
7.10k
    Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
2026
7.10k
                                                    DD.Definition));
2027
7.10k
    Reader.PendingDefinitions.erase(MergeDD.Definition);
2028
7.10k
    MergeDD.Definition->setCompleteDefinition(false);
2029
7.10k
    Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
2030
7.10k
    assert(!Reader.Lookups.contains(MergeDD.Definition) &&
2031
7.10k
           "already loaded pending lookups for merged definition");
2032
7.10k
  }
2033
2034
20.9k
  auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
2035
20.9k
  if (PFDI != Reader.PendingFakeDefinitionData.end() &&
2036
20.9k
      
PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake476
) {
2037
    // We faked up this definition data because we found a class for which we'd
2038
    // not yet loaded the definition. Replace it with the real thing now.
2039
476
    assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
2040
476
    PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
2041
2042
    // Don't change which declaration is the definition; that is required
2043
    // to be invariant once we select it.
2044
476
    auto *Def = DD.Definition;
2045
476
    DD = std::move(MergeDD);
2046
476
    DD.Definition = Def;
2047
476
    return;
2048
476
  }
2049
2050
20.5k
  bool DetectedOdrViolation = false;
2051
2052
1.10M
  #define FIELD(Name, Width, Merge) Merge(Name)
2053
1.12M
  #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
2054
20.5k
  #define NO_MERGE(Field) \
2055
922k
    DetectedOdrViolation |= DD.Field != MergeDD.Field; \
2056
922k
    MERGE_OR(Field)
2057
20.5k
  #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2058
20.5k
  NO_MERGE(IsLambda)
2059
20.5k
  #undef NO_MERGE
2060
20.5k
  #undef MERGE_OR
2061
2062
20.5k
  if (DD.NumBases != MergeDD.NumBases || 
DD.NumVBases != MergeDD.NumVBases20.5k
)
2063
5
    DetectedOdrViolation = true;
2064
  // FIXME: Issue a diagnostic if the base classes don't match when we come
2065
  // to lazily load them.
2066
2067
  // FIXME: Issue a diagnostic if the list of conversion functions doesn't
2068
  // match when we come to lazily load them.
2069
20.5k
  if (MergeDD.ComputedVisibleConversions && 
!DD.ComputedVisibleConversions0
) {
2070
0
    DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
2071
0
    DD.ComputedVisibleConversions = true;
2072
0
  }
2073
2074
  // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
2075
  // lazily load it.
2076
2077
20.5k
  if (DD.IsLambda) {
2078
17
    auto &Lambda1 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(DD);
2079
17
    auto &Lambda2 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(MergeDD);
2080
17
    DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind;
2081
17
    DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda;
2082
17
    DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault;
2083
17
    DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures;
2084
17
    DetectedOdrViolation |=
2085
17
        Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures;
2086
17
    DetectedOdrViolation |=
2087
17
        Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage;
2088
17
    DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber;
2089
2090
17
    if (Lambda1.NumCaptures && 
Lambda1.NumCaptures == Lambda2.NumCaptures2
) {
2091
4
      for (unsigned I = 0, N = Lambda1.NumCaptures; I != N; 
++I2
) {
2092
2
        LambdaCapture &Cap1 = Lambda1.Captures.front()[I];
2093
2
        LambdaCapture &Cap2 = Lambda2.Captures.front()[I];
2094
2
        DetectedOdrViolation |= Cap1.getCaptureKind() != Cap2.getCaptureKind();
2095
2
      }
2096
2
      Lambda1.AddCaptureList(Reader.getContext(), Lambda2.Captures.front());
2097
2
    }
2098
17
  }
2099
2100
20.5k
  if (D->getODRHash() != MergeDD.ODRHash) {
2101
214
    DetectedOdrViolation = true;
2102
214
  }
2103
2104
20.5k
  if (DetectedOdrViolation)
2105
214
    Reader.PendingOdrMergeFailures[DD.Definition].push_back(
2106
214
        {MergeDD.Definition, &MergeDD});
2107
20.5k
}
2108
2109
void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
2110
                                            Decl *LambdaContext,
2111
321k
                                            unsigned IndexInLambdaContext) {
2112
321k
  struct CXXRecordDecl::DefinitionData *DD;
2113
321k
  ASTContext &C = Reader.getContext();
2114
2115
  // Determine whether this is a lambda closure type, so that we can
2116
  // allocate the appropriate DefinitionData structure.
2117
321k
  bool IsLambda = Record.readInt();
2118
321k
  assert(!(IsLambda && Update) &&
2119
321k
         "lambda definition should not be added by update record");
2120
321k
  if (IsLambda)
2121
753
    DD = new (C) CXXRecordDecl::LambdaDefinitionData(
2122
753
        D, nullptr, CXXRecordDecl::LDK_Unknown, false, LCD_None);
2123
320k
  else
2124
320k
    DD = new (C) struct CXXRecordDecl::DefinitionData(D);
2125
2126
321k
  CXXRecordDecl *Canon = D->getCanonicalDecl();
2127
  // Set decl definition data before reading it, so that during deserialization
2128
  // when we read CXXRecordDecl, it already has definition data and we don't
2129
  // set fake one.
2130
321k
  if (!Canon->DefinitionData)
2131
306k
    Canon->DefinitionData = DD;
2132
321k
  D->DefinitionData = Canon->DefinitionData;
2133
321k
  ReadCXXDefinitionData(*DD, D, LambdaContext, IndexInLambdaContext);
2134
2135
  // We might already have a different definition for this record. This can
2136
  // happen either because we're reading an update record, or because we've
2137
  // already done some merging. Either way, just merge into it.
2138
321k
  if (Canon->DefinitionData != DD) {
2139
14.9k
    MergeDefinitionData(Canon, std::move(*DD));
2140
14.9k
    return;
2141
14.9k
  }
2142
2143
  // Mark this declaration as being a definition.
2144
306k
  D->setCompleteDefinition(true);
2145
2146
  // If this is not the first declaration or is an update record, we can have
2147
  // other redeclarations already. Make a note that we need to propagate the
2148
  // DefinitionData pointer onto them.
2149
306k
  if (Update || 
Canon != D301k
)
2150
20.7k
    Reader.PendingDefinitions.insert(D);
2151
306k
}
2152
2153
ASTDeclReader::RedeclarableResult
2154
393k
ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) {
2155
393k
  RedeclarableResult Redecl = VisitRecordDeclImpl(D);
2156
2157
393k
  ASTContext &C = Reader.getContext();
2158
2159
393k
  enum CXXRecKind {
2160
393k
    CXXRecNotTemplate = 0,
2161
393k
    CXXRecTemplate,
2162
393k
    CXXRecMemberSpecialization,
2163
393k
    CXXLambda
2164
393k
  };
2165
2166
393k
  Decl *LambdaContext = nullptr;
2167
393k
  unsigned IndexInLambdaContext = 0;
2168
2169
393k
  switch ((CXXRecKind)Record.readInt()) {
2170
306k
  case CXXRecNotTemplate:
2171
    // Merged when we merge the folding set entry in the primary template.
2172
306k
    if (!isa<ClassTemplateSpecializationDecl>(D))
2173
73.3k
      mergeRedeclarable(D, Redecl);
2174
306k
    break;
2175
79.1k
  case CXXRecTemplate: {
2176
    // Merged when we merge the template.
2177
79.1k
    auto *Template = readDeclAs<ClassTemplateDecl>();
2178
79.1k
    D->TemplateOrInstantiation = Template;
2179
79.1k
    if (!Template->getTemplatedDecl()) {
2180
      // We've not actually loaded the ClassTemplateDecl yet, because we're
2181
      // currently being loaded as its pattern. Rely on it to set up our
2182
      // TypeForDecl (see VisitClassTemplateDecl).
2183
      //
2184
      // Beware: we do not yet know our canonical declaration, and may still
2185
      // get merged once the surrounding class template has got off the ground.
2186
65.9k
      DeferredTypeID = 0;
2187
65.9k
    }
2188
79.1k
    break;
2189
0
  }
2190
6.96k
  case CXXRecMemberSpecialization: {
2191
6.96k
    auto *RD = readDeclAs<CXXRecordDecl>();
2192
6.96k
    auto TSK = (TemplateSpecializationKind)Record.readInt();
2193
6.96k
    SourceLocation POI = readSourceLocation();
2194
6.96k
    MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
2195
6.96k
    MSI->setPointOfInstantiation(POI);
2196
6.96k
    D->TemplateOrInstantiation = MSI;
2197
6.96k
    mergeRedeclarable(D, Redecl);
2198
6.96k
    break;
2199
0
  }
2200
753
  case CXXLambda: {
2201
753
    LambdaContext = readDecl();
2202
753
    if (LambdaContext)
2203
43
      IndexInLambdaContext = Record.readInt();
2204
753
    mergeLambda(D, Redecl, LambdaContext, IndexInLambdaContext);
2205
753
    break;
2206
0
  }
2207
393k
  }
2208
2209
393k
  bool WasDefinition = Record.readInt();
2210
393k
  if (WasDefinition)
2211
302k
    ReadCXXRecordDefinition(D, /*Update=*/false, LambdaContext,
2212
302k
                            IndexInLambdaContext);
2213
90.9k
  else
2214
    // Propagate DefinitionData pointer from the canonical declaration.
2215
90.9k
    D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
2216
2217
  // Lazily load the key function to avoid deserializing every method so we can
2218
  // compute it.
2219
393k
  if (WasDefinition) {
2220
302k
    DeclID KeyFn = readDeclID();
2221
302k
    if (KeyFn && 
D->isCompleteDefinition()1.88k
)
2222
      // FIXME: This is wrong for the ARM ABI, where some other module may have
2223
      // made this function no longer be a key function. We need an update
2224
      // record or similar for that case.
2225
1.87k
      C.KeyFunctions[D] = KeyFn;
2226
302k
  }
2227
2228
393k
  return Redecl;
2229
393k
}
2230
2231
75
void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
2232
75
  D->setExplicitSpecifier(Record.readExplicitSpec());
2233
75
  D->Ctor = readDeclAs<CXXConstructorDecl>();
2234
75
  VisitFunctionDecl(D);
2235
75
  D->setDeductionCandidateKind(
2236
75
      static_cast<DeductionCandidate>(Record.readInt()));
2237
75
}
2238
2239
172k
void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
2240
172k
  VisitFunctionDecl(D);
2241
2242
172k
  unsigned NumOverridenMethods = Record.readInt();
2243
172k
  if (D->isCanonicalDecl()) {
2244
126k
    while (NumOverridenMethods--) {
2245
      // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
2246
      // MD may be initializing.
2247
200
      if (auto *MD = readDeclAs<CXXMethodDecl>())
2248
200
        Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl());
2249
200
    }
2250
126k
  } else {
2251
    // We don't care about which declarations this used to override; we get
2252
    // the relevant information from the canonical declaration.
2253
45.6k
    Record.skipInts(NumOverridenMethods);
2254
45.6k
  }
2255
172k
}
2256
2257
65.2k
void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
2258
  // We need the inherited constructor information to merge the declaration,
2259
  // so we have to read it before we call VisitCXXMethodDecl.
2260
65.2k
  D->setExplicitSpecifier(Record.readExplicitSpec());
2261
65.2k
  if (D->isInheritingConstructor()) {
2262
2
    auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>();
2263
2
    auto *Ctor = readDeclAs<CXXConstructorDecl>();
2264
2
    *D->getTrailingObjects<InheritedConstructor>() =
2265
2
        InheritedConstructor(Shadow, Ctor);
2266
2
  }
2267
2268
65.2k
  VisitCXXMethodDecl(D);
2269
65.2k
}
2270
2271
16.6k
void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
2272
16.6k
  VisitCXXMethodDecl(D);
2273
2274
16.6k
  if (auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
2275
28
    CXXDestructorDecl *Canon = D->getCanonicalDecl();
2276
28
    auto *ThisArg = Record.readExpr();
2277
    // FIXME: Check consistency if we have an old and new operator delete.
2278
28
    if (!Canon->OperatorDelete) {
2279
22
      Canon->OperatorDelete = OperatorDelete;
2280
22
      Canon->OperatorDeleteThisArg = ThisArg;
2281
22
    }
2282
28
  }
2283
16.6k
}
2284
2285
5.44k
void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
2286
5.44k
  D->setExplicitSpecifier(Record.readExplicitSpec());
2287
5.44k
  VisitCXXMethodDecl(D);
2288
5.44k
}
2289
2290
205
void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
2291
205
  VisitDecl(D);
2292
205
  D->ImportedModule = readModule();
2293
205
  D->setImportComplete(Record.readInt());
2294
205
  auto *StoredLocs = D->getTrailingObjects<SourceLocation>();
2295
418
  for (unsigned I = 0, N = Record.back(); I != N; 
++I213
)
2296
213
    StoredLocs[I] = readSourceLocation();
2297
205
  Record.skipInts(1); // The number of stored source locations.
2298
205
}
2299
2300
7.06k
void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
2301
7.06k
  VisitDecl(D);
2302
7.06k
  D->setColonLoc(readSourceLocation());
2303
7.06k
}
2304
2305
3.20k
void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
2306
3.20k
  VisitDecl(D);
2307
3.20k
  if (Record.readInt()) // hasFriendDecl
2308
3.05k
    D->Friend = readDeclAs<NamedDecl>();
2309
150
  else
2310
150
    D->Friend = readTypeSourceInfo();
2311
3.20k
  for (unsigned i = 0; i != D->NumTPLists; 
++i0
)
2312
0
    D->getTrailingObjects<TemplateParameterList *>()[i] =
2313
0
        Record.readTemplateParameterList();
2314
3.20k
  D->NextFriend = readDeclID();
2315
3.20k
  D->UnsupportedFriend = (Record.readInt() != 0);
2316
3.20k
  D->FriendLoc = readSourceLocation();
2317
3.20k
}
2318
2319
0
void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
2320
0
  VisitDecl(D);
2321
0
  unsigned NumParams = Record.readInt();
2322
0
  D->NumParams = NumParams;
2323
0
  D->Params = new (Reader.getContext()) TemplateParameterList *[NumParams];
2324
0
  for (unsigned i = 0; i != NumParams; ++i)
2325
0
    D->Params[i] = Record.readTemplateParameterList();
2326
0
  if (Record.readInt()) // HasFriendDecl
2327
0
    D->Friend = readDeclAs<NamedDecl>();
2328
0
  else
2329
0
    D->Friend = readTypeSourceInfo();
2330
0
  D->FriendLoc = readSourceLocation();
2331
0
}
2332
2333
166k
void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
2334
166k
  VisitNamedDecl(D);
2335
2336
166k
  assert(!D->TemplateParams && "TemplateParams already set!");
2337
166k
  D->TemplateParams = Record.readTemplateParameterList();
2338
166k
  D->init(readDeclAs<NamedDecl>());
2339
166k
}
2340
2341
80
void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) {
2342
80
  VisitTemplateDecl(D);
2343
80
  D->ConstraintExpr = Record.readExpr();
2344
80
  mergeMergeable(D);
2345
80
}
2346
2347
void ASTDeclReader::VisitImplicitConceptSpecializationDecl(
2348
76
    ImplicitConceptSpecializationDecl *D) {
2349
  // The size of the template list was read during creation of the Decl, so we
2350
  // don't have to re-read it here.
2351
76
  VisitDecl(D);
2352
76
  llvm::SmallVector<TemplateArgument, 4> Args;
2353
189
  for (unsigned I = 0; I < D->NumTemplateArgs; 
++I113
)
2354
113
    Args.push_back(Record.readTemplateArgument(/*Canonicalize=*/true));
2355
76
  D->setTemplateArguments(Args);
2356
76
}
2357
2358
29
void ASTDeclReader::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
2359
29
}
2360
2361
ASTDeclReader::RedeclarableResult
2362
164k
ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
2363
164k
  RedeclarableResult Redecl = VisitRedeclarable(D);
2364
2365
  // Make sure we've allocated the Common pointer first. We do this before
2366
  // VisitTemplateDecl so that getCommonPtr() can be used during initialization.
2367
164k
  RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl();
2368
164k
  if (!CanonD->Common) {
2369
132k
    CanonD->Common = CanonD->newCommon(Reader.getContext());
2370
132k
    Reader.PendingDefinitions.insert(CanonD);
2371
132k
  }
2372
164k
  D->Common = CanonD->Common;
2373
2374
  // If this is the first declaration of the template, fill in the information
2375
  // for the 'common' pointer.
2376
164k
  if (ThisDeclID == Redecl.getFirstID()) {
2377
132k
    if (auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) {
2378
3.48k
      assert(RTD->getKind() == D->getKind() &&
2379
3.48k
             "InstantiatedFromMemberTemplate kind mismatch");
2380
3.48k
      D->setInstantiatedFromMemberTemplate(RTD);
2381
3.48k
      if (Record.readInt())
2382
40
        D->setMemberSpecialization();
2383
3.48k
    }
2384
132k
  }
2385
2386
164k
  VisitTemplateDecl(D);
2387
164k
  D->IdentifierNamespace = Record.readInt();
2388
2389
164k
  return Redecl;
2390
164k
}
2391
2392
67.6k
void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
2393
67.6k
  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2394
67.6k
  mergeRedeclarableTemplate(D, Redecl);
2395
2396
67.6k
  if (ThisDeclID == Redecl.getFirstID()) {
2397
    // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
2398
    // the specializations.
2399
45.4k
    SmallVector<serialization::DeclID, 32> SpecIDs;
2400
45.4k
    readDeclIDList(SpecIDs);
2401
45.4k
    ASTDeclReader::AddLazySpecializations(D, SpecIDs);
2402
45.4k
  }
2403
2404
67.6k
  if (D->getTemplatedDecl()->TemplateOrInstantiation) {
2405
    // We were loaded before our templated declaration was. We've not set up
2406
    // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct
2407
    // it now.
2408
65.9k
    Reader.getContext().getInjectedClassNameType(
2409
65.9k
        D->getTemplatedDecl(), D->getInjectedClassNameSpecialization());
2410
65.9k
  }
2411
67.6k
}
2412
2413
0
void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
2414
0
  llvm_unreachable("BuiltinTemplates are not serialized");
2415
0
}
2416
2417
/// TODO: Unify with ClassTemplateDecl version?
2418
///       May require unifying ClassTemplateDecl and
2419
///        VarTemplateDecl beyond TemplateDecl...
2420
293
void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) {
2421
293
  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2422
293
  mergeRedeclarableTemplate(D, Redecl);
2423
2424
293
  if (ThisDeclID == Redecl.getFirstID()) {
2425
    // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of
2426
    // the specializations.
2427
257
    SmallVector<serialization::DeclID, 32> SpecIDs;
2428
257
    readDeclIDList(SpecIDs);
2429
257
    ASTDeclReader::AddLazySpecializations(D, SpecIDs);
2430
257
  }
2431
293
}
2432
2433
ASTDeclReader::RedeclarableResult
2434
ASTDeclReader::VisitClassTemplateSpecializationDeclImpl(
2435
232k
    ClassTemplateSpecializationDecl *D) {
2436
232k
  RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D);
2437
2438
232k
  ASTContext &C = Reader.getContext();
2439
232k
  if (Decl *InstD = readDecl()) {
2440
232k
    if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2441
176k
      D->SpecializedTemplate = CTD;
2442
176k
    } else {
2443
56.3k
      SmallVector<TemplateArgument, 8> TemplArgs;
2444
56.3k
      Record.readTemplateArgumentList(TemplArgs);
2445
56.3k
      TemplateArgumentList *ArgList
2446
56.3k
        = TemplateArgumentList::CreateCopy(C, TemplArgs);
2447
56.3k
      auto *PS =
2448
56.3k
          new (C) ClassTemplateSpecializationDecl::
2449
56.3k
                                             SpecializedPartialSpecialization();
2450
56.3k
      PS->PartialSpecialization
2451
56.3k
          = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2452
56.3k
      PS->TemplateArgs = ArgList;
2453
56.3k
      D->SpecializedTemplate = PS;
2454
56.3k
    }
2455
232k
  }
2456
2457
232k
  SmallVector<TemplateArgument, 8> TemplArgs;
2458
232k
  Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2459
232k
  D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2460
232k
  D->PointOfInstantiation = readSourceLocation();
2461
232k
  D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2462
2463
232k
  bool writtenAsCanonicalDecl = Record.readInt();
2464
232k
  if (writtenAsCanonicalDecl) {
2465
231k
    auto *CanonPattern = readDeclAs<ClassTemplateDecl>();
2466
231k
    if (D->isCanonicalDecl()) { // It's kept in the folding set.
2467
      // Set this as, or find, the canonical declaration for this specialization
2468
231k
      ClassTemplateSpecializationDecl *CanonSpec;
2469
231k
      if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
2470
8.58k
        CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2471
8.58k
            .GetOrInsertNode(Partial);
2472
223k
      } else {
2473
223k
        CanonSpec =
2474
223k
            CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2475
223k
      }
2476
      // If there was already a canonical specialization, merge into it.
2477
231k
      if (CanonSpec != D) {
2478
6.02k
        mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2479
2480
        // This declaration might be a definition. Merge with any existing
2481
        // definition.
2482
6.02k
        if (auto *DDD = D->DefinitionData) {
2483
5.78k
          if (CanonSpec->DefinitionData)
2484
5.78k
            MergeDefinitionData(CanonSpec, std::move(*DDD));
2485
8
          else
2486
8
            CanonSpec->DefinitionData = D->DefinitionData;
2487
5.78k
        }
2488
6.02k
        D->DefinitionData = CanonSpec->DefinitionData;
2489
6.02k
      }
2490
231k
    }
2491
231k
  }
2492
2493
  // Explicit info.
2494
232k
  if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) {
2495
13.9k
    auto *ExplicitInfo =
2496
13.9k
        new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2497
13.9k
    ExplicitInfo->TypeAsWritten = TyInfo;
2498
13.9k
    ExplicitInfo->ExternLoc = readSourceLocation();
2499
13.9k
    ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2500
13.9k
    D->ExplicitInfo = ExplicitInfo;
2501
13.9k
  }
2502
2503
232k
  return Redecl;
2504
232k
}
2505
2506
void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
2507
8.62k
                                    ClassTemplatePartialSpecializationDecl *D) {
2508
  // We need to read the template params first because redeclarable is going to
2509
  // need them for profiling
2510
8.62k
  TemplateParameterList *Params = Record.readTemplateParameterList();
2511
8.62k
  D->TemplateParams = Params;
2512
8.62k
  D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2513
2514
8.62k
  RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D);
2515
2516
  // These are read/set from/to the first declaration.
2517
8.62k
  if (ThisDeclID == Redecl.getFirstID()) {
2518
8.58k
    D->InstantiatedFromMember.setPointer(
2519
8.58k
      readDeclAs<ClassTemplatePartialSpecializationDecl>());
2520
8.58k
    D->InstantiatedFromMember.setInt(Record.readInt());
2521
8.58k
  }
2522
8.62k
}
2523
2524
void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
2525
12
                                    ClassScopeFunctionSpecializationDecl *D) {
2526
12
  VisitDecl(D);
2527
12
  D->Specialization = readDeclAs<CXXMethodDecl>();
2528
12
  if (Record.readInt())
2529
8
    D->TemplateArgs = Record.readASTTemplateArgumentListInfo();
2530
12
}
2531
2532
90.1k
void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
2533
90.1k
  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2534
2535
90.1k
  if (ThisDeclID == Redecl.getFirstID()) {
2536
    // This FunctionTemplateDecl owns a CommonPtr; read it.
2537
80.0k
    SmallVector<serialization::DeclID, 32> SpecIDs;
2538
80.0k
    readDeclIDList(SpecIDs);
2539
80.0k
    ASTDeclReader::AddLazySpecializations(D, SpecIDs);
2540
80.0k
  }
2541
90.1k
}
2542
2543
/// TODO: Unify with ClassTemplateSpecializationDecl version?
2544
///       May require unifying ClassTemplate(Partial)SpecializationDecl and
2545
///        VarTemplate(Partial)SpecializationDecl with a new data
2546
///        structure Template(Partial)SpecializationDecl, and
2547
///        using Template(Partial)SpecializationDecl as input type.
2548
ASTDeclReader::RedeclarableResult
2549
ASTDeclReader::VisitVarTemplateSpecializationDeclImpl(
2550
259
    VarTemplateSpecializationDecl *D) {
2551
259
  ASTContext &C = Reader.getContext();
2552
259
  if (Decl *InstD = readDecl()) {
2553
259
    if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2554
254
      D->SpecializedTemplate = VTD;
2555
254
    } else {
2556
5
      SmallVector<TemplateArgument, 8> TemplArgs;
2557
5
      Record.readTemplateArgumentList(TemplArgs);
2558
5
      TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy(
2559
5
          C, TemplArgs);
2560
5
      auto *PS =
2561
5
          new (C)
2562
5
          VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2563
5
      PS->PartialSpecialization =
2564
5
          cast<VarTemplatePartialSpecializationDecl>(InstD);
2565
5
      PS->TemplateArgs = ArgList;
2566
5
      D->SpecializedTemplate = PS;
2567
5
    }
2568
259
  }
2569
2570
  // Explicit info.
2571
259
  if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) {
2572
9
    auto *ExplicitInfo =
2573
9
        new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2574
9
    ExplicitInfo->TypeAsWritten = TyInfo;
2575
9
    ExplicitInfo->ExternLoc = readSourceLocation();
2576
9
    ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2577
9
    D->ExplicitInfo = ExplicitInfo;
2578
9
  }
2579
2580
259
  SmallVector<TemplateArgument, 8> TemplArgs;
2581
259
  Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2582
259
  D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2583
259
  D->PointOfInstantiation = readSourceLocation();
2584
259
  D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2585
259
  D->IsCompleteDefinition = Record.readInt();
2586
2587
259
  RedeclarableResult Redecl = VisitVarDeclImpl(D);
2588
2589
259
  bool writtenAsCanonicalDecl = Record.readInt();
2590
259
  if (writtenAsCanonicalDecl) {
2591
223
    auto *CanonPattern = readDeclAs<VarTemplateDecl>();
2592
223
    if (D->isCanonicalDecl()) { // It's kept in the folding set.
2593
223
      VarTemplateSpecializationDecl *CanonSpec;
2594
223
      if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
2595
42
        CanonSpec = CanonPattern->getCommonPtr()
2596
42
                        ->PartialSpecializations.GetOrInsertNode(Partial);
2597
181
      } else {
2598
181
        CanonSpec =
2599
181
            CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2600
181
      }
2601
      // If we already have a matching specialization, merge it.
2602
223
      if (CanonSpec != D)
2603
11
        mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl);
2604
223
    }
2605
223
  }
2606
2607
259
  return Redecl;
2608
259
}
2609
2610
/// TODO: Unify with ClassTemplatePartialSpecializationDecl version?
2611
///       May require unifying ClassTemplate(Partial)SpecializationDecl and
2612
///        VarTemplate(Partial)SpecializationDecl with a new data
2613
///        structure Template(Partial)SpecializationDecl, and
2614
///        using Template(Partial)SpecializationDecl as input type.
2615
void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl(
2616
53
    VarTemplatePartialSpecializationDecl *D) {
2617
53
  TemplateParameterList *Params = Record.readTemplateParameterList();
2618
53
  D->TemplateParams = Params;
2619
53
  D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2620
2621
53
  RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D);
2622
2623
  // These are read/set from/to the first declaration.
2624
53
  if (ThisDeclID == Redecl.getFirstID()) {
2625
42
    D->InstantiatedFromMember.setPointer(
2626
42
        readDeclAs<VarTemplatePartialSpecializationDecl>());
2627
42
    D->InstantiatedFromMember.setInt(Record.readInt());
2628
42
  }
2629
53
}
2630
2631
330k
void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
2632
330k
  VisitTypeDecl(D);
2633
2634
330k
  D->setDeclaredWithTypename(Record.readInt());
2635
2636
330k
  if (Record.readBool()) {
2637
45
    ConceptReference *CR = nullptr;
2638
45
    if (Record.readBool())
2639
45
      CR = Record.readConceptReference();
2640
45
    Expr *ImmediatelyDeclaredConstraint = Record.readExpr();
2641
2642
45
    D->setTypeConstraint(CR, ImmediatelyDeclaredConstraint);
2643
45
    if ((D->ExpandedParameterPack = Record.readInt()))
2644
0
      D->NumExpanded = Record.readInt();
2645
45
  }
2646
2647
330k
  if (Record.readInt())
2648
25.3k
    D->setDefaultArgument(readTypeSourceInfo());
2649
330k
}
2650
2651
53.9k
void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
2652
53.9k
  VisitDeclaratorDecl(D);
2653
  // TemplateParmPosition.
2654
53.9k
  D->setDepth(Record.readInt());
2655
53.9k
  D->setPosition(Record.readInt());
2656
53.9k
  if (D->hasPlaceholderTypeConstraint())
2657
0
    D->setPlaceholderTypeConstraint(Record.readExpr());
2658
53.9k
  if (D->isExpandedParameterPack()) {
2659
4
    auto TypesAndInfos =
2660
4
        D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2661
12
    for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; 
++I8
) {
2662
8
      new (&TypesAndInfos[I].first) QualType(Record.readType());
2663
8
      TypesAndInfos[I].second = readTypeSourceInfo();
2664
8
    }
2665
53.9k
  } else {
2666
    // Rest of NonTypeTemplateParmDecl.
2667
53.9k
    D->ParameterPack = Record.readInt();
2668
53.9k
    if (Record.readInt())
2669
16.6k
      D->setDefaultArgument(Record.readExpr());
2670
53.9k
  }
2671
53.9k
}
2672
2673
1.86k
void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
2674
1.86k
  VisitTemplateDecl(D);
2675
  // TemplateParmPosition.
2676
1.86k
  D->setDepth(Record.readInt());
2677
1.86k
  D->setPosition(Record.readInt());
2678
1.86k
  if (D->isExpandedParameterPack()) {
2679
4
    auto **Data = D->getTrailingObjects<TemplateParameterList *>();
2680
4
    for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2681
12
         I != N; 
++I8
)
2682
8
      Data[I] = Record.readTemplateParameterList();
2683
1.86k
  } else {
2684
    // Rest of TemplateTemplateParmDecl.
2685
1.86k
    D->ParameterPack = Record.readInt();
2686
1.86k
    if (Record.readInt())
2687
650
      D->setDefaultArgument(Reader.getContext(),
2688
650
                            Record.readTemplateArgumentLoc());
2689
1.86k
  }
2690
1.86k
}
2691
2692
6.93k
void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
2693
6.93k
  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2694
6.93k
  mergeRedeclarableTemplate(D, Redecl);
2695
6.93k
}
2696
2697
2.37k
void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
2698
2.37k
  VisitDecl(D);
2699
2.37k
  D->AssertExprAndFailed.setPointer(Record.readExpr());
2700
2.37k
  D->AssertExprAndFailed.setInt(Record.readInt());
2701
2.37k
  D->Message = cast_or_null<StringLiteral>(Record.readExpr());
2702
2.37k
  D->RParenLoc = readSourceLocation();
2703
2.37k
}
2704
2705
16
void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {
2706
16
  VisitDecl(D);
2707
16
}
2708
2709
void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
2710
21
    LifetimeExtendedTemporaryDecl *D) {
2711
21
  VisitDecl(D);
2712
21
  D->ExtendingDecl = readDeclAs<ValueDecl>();
2713
21
  D->ExprWithTemporary = Record.readStmt();
2714
21
  if (Record.readInt()) {
2715
9
    D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
2716
9
    D->getASTContext().addDestruction(D->Value);
2717
9
  }
2718
21
  D->ManglingNumber = Record.readInt();
2719
21
  mergeMergeable(D);
2720
21
}
2721
2722
std::pair<uint64_t, uint64_t>
2723
1.99M
ASTDeclReader::VisitDeclContext(DeclContext *DC) {
2724
1.99M
  uint64_t LexicalOffset = ReadLocalOffset();
2725
1.99M
  uint64_t VisibleOffset = ReadLocalOffset();
2726
1.99M
  return std::make_pair(LexicalOffset, VisibleOffset);
2727
1.99M
}
2728
2729
template <typename T>
2730
ASTDeclReader::RedeclarableResult
2731
2.85M
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
2.85M
  DeclID FirstDeclID = readDeclID();
2733
2.85M
  Decl *MergeWith = nullptr;
2734
2735
2.85M
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
2.85M
  bool IsFirstLocalDecl = false;
2737
2738
2.85M
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
2.85M
  if (FirstDeclID == 0) {
2743
1.46M
    FirstDeclID = ThisDeclID;
2744
1.46M
    IsKeyDecl = true;
2745
1.46M
    IsFirstLocalDecl = true;
2746
1.46M
  } else 
if (unsigned 1.39M
N1.39M
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
834k
    IsKeyDecl = N == 1;
2750
834k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
85.7M
    for (unsigned I = 0; I != N - 1; 
++I84.9M
)
2758
84.9M
      MergeWith = readDecl();
2759
2760
834k
    RedeclOffset = ReadLocalOffset();
2761
834k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
556k
    (void)readDecl();
2765
556k
  }
2766
2767
2.85M
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
2.85M
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
876k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
876k
    D->First = FirstDecl->getCanonicalDecl();
2775
876k
  }
2776
2777
2.85M
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
2.85M
  if (IsFirstLocalDecl)
2784
2.29M
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
2.85M
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
2.85M
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl>*)
Line
Count
Source
2731
97.6k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
97.6k
  DeclID FirstDeclID = readDeclID();
2733
97.6k
  Decl *MergeWith = nullptr;
2734
2735
97.6k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
97.6k
  bool IsFirstLocalDecl = false;
2737
2738
97.6k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
97.6k
  if (FirstDeclID == 0) {
2743
84.7k
    FirstDeclID = ThisDeclID;
2744
84.7k
    IsKeyDecl = true;
2745
84.7k
    IsFirstLocalDecl = true;
2746
84.7k
  } else 
if (unsigned 12.9k
N12.9k
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
3.68k
    IsKeyDecl = N == 1;
2750
3.68k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
8.39k
    for (unsigned I = 0; I != N - 1; 
++I4.71k
)
2758
4.71k
      MergeWith = readDecl();
2759
2760
3.68k
    RedeclOffset = ReadLocalOffset();
2761
9.24k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
9.24k
    (void)readDecl();
2765
9.24k
  }
2766
2767
97.6k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
97.6k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
9.34k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
9.34k
    D->First = FirstDecl->getCanonicalDecl();
2775
9.34k
  }
2776
2777
97.6k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
97.6k
  if (IsFirstLocalDecl)
2784
88.4k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
97.6k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
97.6k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*)
Line
Count
Source
2731
396k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
396k
  DeclID FirstDeclID = readDeclID();
2733
396k
  Decl *MergeWith = nullptr;
2734
2735
396k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
396k
  bool IsFirstLocalDecl = false;
2737
2738
396k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
396k
  if (FirstDeclID == 0) {
2743
358k
    FirstDeclID = ThisDeclID;
2744
358k
    IsKeyDecl = true;
2745
358k
    IsFirstLocalDecl = true;
2746
358k
  } else 
if (unsigned 38.4k
N38.4k
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
19.3k
    IsKeyDecl = N == 1;
2750
19.3k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
37.7k
    for (unsigned I = 0; I != N - 1; 
++I18.3k
)
2758
18.3k
      MergeWith = readDecl();
2759
2760
19.3k
    RedeclOffset = ReadLocalOffset();
2761
19.3k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
19.1k
    (void)readDecl();
2765
19.1k
  }
2766
2767
396k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
396k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
26.5k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
26.5k
    D->First = FirstDecl->getCanonicalDecl();
2775
26.5k
  }
2776
2777
396k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
396k
  if (IsFirstLocalDecl)
2784
377k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
396k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
396k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::FunctionDecl>(clang::Redeclarable<clang::FunctionDecl>*)
Line
Count
Source
2731
290k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
290k
  DeclID FirstDeclID = readDeclID();
2733
290k
  Decl *MergeWith = nullptr;
2734
2735
290k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
290k
  bool IsFirstLocalDecl = false;
2737
2738
290k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
290k
  if (FirstDeclID == 0) {
2743
240k
    FirstDeclID = ThisDeclID;
2744
240k
    IsKeyDecl = true;
2745
240k
    IsFirstLocalDecl = true;
2746
240k
  } else 
if (unsigned 50.2k
N50.2k
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
27.1k
    IsKeyDecl = N == 1;
2750
27.1k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
43.0k
    for (unsigned I = 0; I != N - 1; 
++I15.8k
)
2758
15.8k
      MergeWith = readDecl();
2759
2760
27.1k
    RedeclOffset = ReadLocalOffset();
2761
27.1k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
23.1k
    (void)readDecl();
2765
23.1k
  }
2766
2767
290k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
290k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
24.1k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
24.1k
    D->First = FirstDecl->getCanonicalDecl();
2775
24.1k
  }
2776
2777
290k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
290k
  if (IsFirstLocalDecl)
2784
267k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
290k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
290k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl>*)
Line
Count
Source
2731
12.6k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
12.6k
  DeclID FirstDeclID = readDeclID();
2733
12.6k
  Decl *MergeWith = nullptr;
2734
2735
12.6k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
12.6k
  bool IsFirstLocalDecl = false;
2737
2738
12.6k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
12.6k
  if (FirstDeclID == 0) {
2743
2.10k
    FirstDeclID = ThisDeclID;
2744
2.10k
    IsKeyDecl = true;
2745
2.10k
    IsFirstLocalDecl = true;
2746
10.5k
  } else if (unsigned N = Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
1.45k
    IsKeyDecl = N == 1;
2750
1.45k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
1.90k
    for (unsigned I = 0; I != N - 1; 
++I449
)
2758
449
      MergeWith = readDecl();
2759
2760
1.45k
    RedeclOffset = ReadLocalOffset();
2761
9.12k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
9.12k
    (void)readDecl();
2765
9.12k
  }
2766
2767
12.6k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
12.6k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
9.50k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
9.50k
    D->First = FirstDecl->getCanonicalDecl();
2775
9.50k
  }
2776
2777
12.6k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
12.6k
  if (IsFirstLocalDecl)
2784
3.55k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
12.6k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
12.6k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl>*)
Line
Count
Source
2731
1.89k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
1.89k
  DeclID FirstDeclID = readDeclID();
2733
1.89k
  Decl *MergeWith = nullptr;
2734
2735
1.89k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
1.89k
  bool IsFirstLocalDecl = false;
2737
2738
1.89k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
1.89k
  if (FirstDeclID == 0) {
2743
874
    FirstDeclID = ThisDeclID;
2744
874
    IsKeyDecl = true;
2745
874
    IsFirstLocalDecl = true;
2746
1.02k
  } else if (unsigned N = Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
344
    IsKeyDecl = N == 1;
2750
344
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
430
    for (unsigned I = 0; I != N - 1; 
++I86
)
2758
86
      MergeWith = readDecl();
2759
2760
344
    RedeclOffset = ReadLocalOffset();
2761
678
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
678
    (void)readDecl();
2765
678
  }
2766
2767
1.89k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
1.89k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
729
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
729
    D->First = FirstDecl->getCanonicalDecl();
2775
729
  }
2776
2777
1.89k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
1.89k
  if (IsFirstLocalDecl)
2784
1.21k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
1.89k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
1.89k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::VarDecl>(clang::Redeclarable<clang::VarDecl>*)
Line
Count
Source
2731
647k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
647k
  DeclID FirstDeclID = readDeclID();
2733
647k
  Decl *MergeWith = nullptr;
2734
2735
647k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
647k
  bool IsFirstLocalDecl = false;
2737
2738
647k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
647k
  if (FirstDeclID == 0) {
2743
637k
    FirstDeclID = ThisDeclID;
2744
637k
    IsKeyDecl = true;
2745
637k
    IsFirstLocalDecl = true;
2746
637k
  } else 
if (unsigned 9.67k
N9.67k
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
7.54k
    IsKeyDecl = N == 1;
2750
7.54k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
65.0k
    for (unsigned I = 0; I != N - 1; 
++I57.4k
)
2758
57.4k
      MergeWith = readDecl();
2759
2760
7.54k
    RedeclOffset = ReadLocalOffset();
2761
7.54k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
2.13k
    (void)readDecl();
2765
2.13k
  }
2766
2767
647k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
647k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
6.98k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
6.98k
    D->First = FirstDecl->getCanonicalDecl();
2775
6.98k
  }
2776
2777
647k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
647k
  if (IsFirstLocalDecl)
2784
644k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
647k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
647k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl>*)
Line
Count
Source
2731
1.23M
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
1.23M
  DeclID FirstDeclID = readDeclID();
2733
1.23M
  Decl *MergeWith = nullptr;
2734
2735
1.23M
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
1.23M
  bool IsFirstLocalDecl = false;
2737
2738
1.23M
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
1.23M
  if (FirstDeclID == 0) {
2743
16.5k
    FirstDeclID = ThisDeclID;
2744
16.5k
    IsKeyDecl = true;
2745
16.5k
    IsFirstLocalDecl = true;
2746
1.21M
  } else if (unsigned N = Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
751k
    IsKeyDecl = N == 1;
2750
751k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
85.5M
    for (unsigned I = 0; I != N - 1; 
++I84.8M
)
2758
84.8M
      MergeWith = readDecl();
2759
2760
751k
    RedeclOffset = ReadLocalOffset();
2761
751k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
467k
    (void)readDecl();
2765
467k
  }
2766
2767
1.23M
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
1.23M
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
766k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
766k
    D->First = FirstDecl->getCanonicalDecl();
2775
766k
  }
2776
2777
1.23M
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
1.23M
  if (IsFirstLocalDecl)
2784
768k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
1.23M
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
1.23M
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl>*)
Line
Count
Source
2731
18
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
18
  DeclID FirstDeclID = readDeclID();
2733
18
  Decl *MergeWith = nullptr;
2734
2735
18
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
18
  bool IsFirstLocalDecl = false;
2737
2738
18
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
18
  if (FirstDeclID == 0) {
2743
18
    FirstDeclID = ThisDeclID;
2744
18
    IsKeyDecl = true;
2745
18
    IsFirstLocalDecl = true;
2746
18
  } else 
if (unsigned 0
N0
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
0
    IsKeyDecl = N == 1;
2750
0
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
0
    for (unsigned I = 0; I != N - 1; ++I)
2758
0
      MergeWith = readDecl();
2759
2760
0
    RedeclOffset = ReadLocalOffset();
2761
0
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
0
    (void)readDecl();
2765
0
  }
2766
2767
18
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
18
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
0
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
0
    D->First = FirstDecl->getCanonicalDecl();
2775
0
  }
2776
2777
18
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
18
  if (IsFirstLocalDecl)
2784
18
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
18
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
18
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::UsingShadowDecl>(clang::Redeclarable<clang::UsingShadowDecl>*)
Line
Count
Source
2731
5.33k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
5.33k
  DeclID FirstDeclID = readDeclID();
2733
5.33k
  Decl *MergeWith = nullptr;
2734
2735
5.33k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
5.33k
  bool IsFirstLocalDecl = false;
2737
2738
5.33k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
5.33k
  if (FirstDeclID == 0) {
2743
4.93k
    FirstDeclID = ThisDeclID;
2744
4.93k
    IsKeyDecl = true;
2745
4.93k
    IsFirstLocalDecl = true;
2746
4.93k
  } else 
if (unsigned 403
N403
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
83
    IsKeyDecl = N == 1;
2750
83
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
90
    for (unsigned I = 0; I != N - 1; 
++I7
)
2758
7
      MergeWith = readDecl();
2759
2760
83
    RedeclOffset = ReadLocalOffset();
2761
320
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
320
    (void)readDecl();
2765
320
  }
2766
2767
5.33k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
5.33k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
327
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
327
    D->First = FirstDecl->getCanonicalDecl();
2775
327
  }
2776
2777
5.33k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
5.33k
  if (IsFirstLocalDecl)
2784
5.01k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
5.33k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
5.33k
}
clang::ASTDeclReader::RedeclarableResult clang::ASTDeclReader::VisitRedeclarable<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl>*)
Line
Count
Source
2731
164k
ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
2732
164k
  DeclID FirstDeclID = readDeclID();
2733
164k
  Decl *MergeWith = nullptr;
2734
2735
164k
  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736
164k
  bool IsFirstLocalDecl = false;
2737
2738
164k
  uint64_t RedeclOffset = 0;
2739
2740
  // 0 indicates that this declaration was the only declaration of its entity,
2741
  // and is used for space optimization.
2742
164k
  if (FirstDeclID == 0) {
2743
115k
    FirstDeclID = ThisDeclID;
2744
115k
    IsKeyDecl = true;
2745
115k
    IsFirstLocalDecl = true;
2746
115k
  } else 
if (unsigned 49.0k
N49.0k
= Record.readInt()) {
2747
    // This declaration was the first local declaration, but may have imported
2748
    // other declarations.
2749
23.3k
    IsKeyDecl = N == 1;
2750
23.3k
    IsFirstLocalDecl = true;
2751
2752
    // We have some declarations that must be before us in our redeclaration
2753
    // chain. Read them now, and remember that we ought to merge with one of
2754
    // them.
2755
    // FIXME: Provide a known merge target to the second and subsequent such
2756
    // declaration.
2757
38.8k
    for (unsigned I = 0; I != N - 1; 
++I15.5k
)
2758
15.5k
      MergeWith = readDecl();
2759
2760
23.3k
    RedeclOffset = ReadLocalOffset();
2761
25.6k
  } else {
2762
    // This declaration was not the first local declaration. Read the first
2763
    // local declaration now, to trigger the import of other redeclarations.
2764
25.6k
    (void)readDecl();
2765
25.6k
  }
2766
2767
164k
  auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2768
164k
  if (FirstDecl != D) {
2769
    // We delay loading of the redeclaration chain to avoid deeply nested calls.
2770
    // We temporarily set the first (canonical) declaration as the previous one
2771
    // which is the one that matters and mark the real previous DeclID to be
2772
    // loaded & attached later on.
2773
32.3k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
2774
32.3k
    D->First = FirstDecl->getCanonicalDecl();
2775
32.3k
  }
2776
2777
164k
  auto *DAsT = static_cast<T *>(D);
2778
2779
  // Note that we need to load local redeclarations of this decl and build a
2780
  // decl chain for them. This must happen *after* we perform the preloading
2781
  // above; this ensures that the redeclaration chain is built in the correct
2782
  // order.
2783
164k
  if (IsFirstLocalDecl)
2784
139k
    Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2785
2786
164k
  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2787
164k
}
2788
2789
/// Attempts to merge the given declaration (D) with another declaration
2790
/// of the same entity.
2791
template <typename T>
2792
void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase,
2793
1.93M
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
1.93M
  if (!Reader.getContext().getLangOpts().Modules)
2796
178k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
1.75M
  if (!DBase->isFirstDecl())
2800
842k
    return;
2801
2802
909k
  auto *D = static_cast<T *>(DBase);
2803
2804
909k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
391k
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
518k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
157k
    if (T *Existing = ExistingRes)
2809
157k
      mergeRedeclarable(D, Existing, Redecl);
2810
909k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
86.9k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
86.9k
  if (!Reader.getContext().getLangOpts().Modules)
2796
5.82k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
81.0k
  if (!DBase->isFirstDecl())
2800
9.34k
    return;
2801
2802
71.7k
  auto *D = static_cast<T *>(DBase);
2803
2804
71.7k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
764
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
70.9k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
10.2k
    if (T *Existing = ExistingRes)
2809
10.2k
      mergeRedeclarable(D, Existing, Redecl);
2810
71.7k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
84.8k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
84.8k
  if (!Reader.getContext().getLangOpts().Modules)
2796
42.9k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
41.8k
  if (!DBase->isFirstDecl())
2800
3.21k
    return;
2801
2802
38.6k
  auto *D = static_cast<T *>(DBase);
2803
2804
38.6k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
274
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
38.3k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
5.02k
    if (T *Existing = ExistingRes)
2809
5.02k
      mergeRedeclarable(D, Existing, Redecl);
2810
38.6k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::FunctionDecl>(clang::Redeclarable<clang::FunctionDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
173k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
173k
  if (!Reader.getContext().getLangOpts().Modules)
2796
26.7k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
146k
  if (!DBase->isFirstDecl())
2800
13.3k
    return;
2801
2802
133k
  auto *D = static_cast<T *>(DBase);
2803
2804
133k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
5.10k
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
128k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
25.3k
    if (T *Existing = ExistingRes)
2809
25.3k
      mergeRedeclarable(D, Existing, Redecl);
2810
133k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
12.6k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
12.6k
  if (!Reader.getContext().getLangOpts().Modules)
2796
203
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
12.4k
  if (!DBase->isFirstDecl())
2800
9.49k
    return;
2801
2802
2.98k
  auto *D = static_cast<T *>(DBase);
2803
2804
2.98k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
43
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
2.94k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
107
    if (T *Existing = ExistingRes)
2809
107
      mergeRedeclarable(D, Existing, Redecl);
2810
2.98k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
1.89k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
1.89k
  if (!Reader.getContext().getLangOpts().Modules)
2796
32
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
1.86k
  if (!DBase->isFirstDecl())
2800
729
    return;
2801
2802
1.13k
  auto *D = static_cast<T *>(DBase);
2803
2804
1.13k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
6
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
1.12k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
46
    if (T *Existing = ExistingRes)
2809
46
      mergeRedeclarable(D, Existing, Redecl);
2810
1.13k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::VarDecl>(clang::Redeclarable<clang::VarDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
138k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
138k
  if (!Reader.getContext().getLangOpts().Modules)
2796
97.0k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
41.3k
  if (!DBase->isFirstDecl())
2800
6.68k
    return;
2801
2802
34.6k
  auto *D = static_cast<T *>(DBase);
2803
2804
34.6k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
569
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
34.0k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
10.4k
    if (T *Existing = ExistingRes)
2809
10.4k
      mergeRedeclarable(D, Existing, Redecl);
2810
34.6k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
1.23M
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
1.23M
  if (!Reader.getContext().getLangOpts().Modules)
2796
365
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
1.23M
  if (!DBase->isFirstDecl())
2800
766k
    return;
2801
2802
468k
  auto *D = static_cast<T *>(DBase);
2803
2804
468k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
384k
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
83.7k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
79.3k
    if (T *Existing = ExistingRes)
2809
79.3k
      mergeRedeclarable(D, Existing, Redecl);
2810
468k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
18
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
18
  if (!Reader.getContext().getLangOpts().Modules)
2796
4
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
14
  if (!DBase->isFirstDecl())
2800
0
    return;
2801
2802
14
  auto *D = static_cast<T *>(DBase);
2803
2804
14
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
0
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
14
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
3
    if (T *Existing = ExistingRes)
2809
3
      mergeRedeclarable(D, Existing, Redecl);
2810
14
}
void clang::ASTDeclReader::mergeRedeclarable<clang::UsingShadowDecl>(clang::Redeclarable<clang::UsingShadowDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
5.33k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
5.33k
  if (!Reader.getContext().getLangOpts().Modules)
2796
35
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
5.30k
  if (!DBase->isFirstDecl())
2800
327
    return;
2801
2802
4.97k
  auto *D = static_cast<T *>(DBase);
2803
2804
4.97k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
0
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
4.97k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
809
    if (T *Existing = ExistingRes)
2809
809
      mergeRedeclarable(D, Existing, Redecl);
2810
4.97k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl>*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2793
191k
                                      RedeclarableResult &Redecl) {
2794
  // If modules are not available, there is no reason to perform this merge.
2795
191k
  if (!Reader.getContext().getLangOpts().Modules)
2796
5.09k
    return;
2797
2798
  // If we're not the canonical declaration, we don't need to merge.
2799
186k
  if (!DBase->isFirstDecl())
2800
32.3k
    return;
2801
2802
154k
  auto *D = static_cast<T *>(DBase);
2803
2804
154k
  if (auto *Existing = Redecl.getKnownMergeTarget())
2805
    // We already know of an existing declaration we should merge with.
2806
91
    mergeRedeclarable(D, cast<T>(Existing), Redecl);
2807
154k
  else if (FindExistingResult ExistingRes = findExisting(D))
2808
26.0k
    if (T *Existing = ExistingRes)
2809
26.0k
      mergeRedeclarable(D, Existing, Redecl);
2810
154k
}
2811
2812
/// Attempt to merge D with a previous declaration of the same lambda, which is
2813
/// found by its index within its context declaration, if it has one.
2814
///
2815
/// We can't look up lambdas in their enclosing lexical or semantic context in
2816
/// general, because for lambdas in variables, both of those might be a
2817
/// namespace or the translation unit.
2818
void ASTDeclReader::mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl,
2819
753
                                Decl *Context, unsigned IndexInContext) {
2820
  // If we don't have a mangling context, treat this like any other
2821
  // declaration.
2822
753
  if (!Context)
2823
710
    return mergeRedeclarable(D, Redecl);
2824
2825
  // If modules are not available, there is no reason to perform this merge.
2826
43
  if (!Reader.getContext().getLangOpts().Modules)
2827
1
    return;
2828
2829
  // If we're not the canonical declaration, we don't need to merge.
2830
42
  if (!D->isFirstDecl())
2831
0
    return;
2832
2833
42
  if (auto *Existing = Redecl.getKnownMergeTarget())
2834
    // We already know of an existing declaration we should merge with.
2835
0
    mergeRedeclarable(D, cast<TagDecl>(Existing), Redecl);
2836
2837
  // Look up this lambda to see if we've seen it before. If so, merge with the
2838
  // one we already loaded.
2839
42
  NamedDecl *&Slot = Reader.LambdaDeclarationsForMerging[{
2840
42
      Context->getCanonicalDecl(), IndexInContext}];
2841
42
  if (Slot)
2842
12
    mergeRedeclarable(D, cast<TagDecl>(Slot), Redecl);
2843
30
  else
2844
30
    Slot = D;
2845
42
}
2846
2847
void ASTDeclReader::mergeRedeclarableTemplate(RedeclarableTemplateDecl *D,
2848
191k
                                              RedeclarableResult &Redecl) {
2849
191k
  mergeRedeclarable(D, Redecl);
2850
  // If we merged the template with a prior declaration chain, merge the
2851
  // common pointer.
2852
  // FIXME: Actually merge here, don't just overwrite.
2853
191k
  D->Common = D->getCanonicalDecl()->Common;
2854
191k
}
2855
2856
/// "Cast" to type T, asserting if we don't have an implicit conversion.
2857
/// We use this to put code in a template that will only be valid for certain
2858
/// instantiations.
2859
465k
template<typename T> static T assert_cast(T t) { return t; }
ASTReaderDecl.cpp:clang::NamespaceDecl* assert_cast<clang::NamespaceDecl*>(clang::NamespaceDecl*)
Line
Count
Source
2859
464k
template<typename T> static T assert_cast(T t) { return t; }
ASTReaderDecl.cpp:clang::RedeclarableTemplateDecl* assert_cast<clang::RedeclarableTemplateDecl*>(clang::RedeclarableTemplateDecl*)
Line
Count
Source
2859
1.21k
template<typename T> static T assert_cast(T t) { return t; }
2860
0
template<typename T> static T assert_cast(...) {
2861
0
  llvm_unreachable("bad assert_cast");
2862
0
}
Unexecuted instantiation: ASTReaderDecl.cpp:clang::NamespaceDecl* assert_cast<clang::NamespaceDecl*>(...)
Unexecuted instantiation: ASTReaderDecl.cpp:clang::RedeclarableTemplateDecl* assert_cast<clang::RedeclarableTemplateDecl*>(...)
2863
2864
/// Merge together the pattern declarations from two template
2865
/// declarations.
2866
void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D,
2867
                                         RedeclarableTemplateDecl *Existing,
2868
1.21k
                                         bool IsKeyDecl) {
2869
1.21k
  auto *DPattern = D->getTemplatedDecl();
2870
1.21k
  auto *ExistingPattern = Existing->getTemplatedDecl();
2871
1.21k
  RedeclarableResult Result(/*MergeWith*/ ExistingPattern,
2872
1.21k
                            DPattern->getCanonicalDecl()->getGlobalID(),
2873
1.21k
                            IsKeyDecl);
2874
2875
1.21k
  if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2876
    // Merge with any existing definition.
2877
    // FIXME: This is duplicated in several places. Refactor.
2878
974
    auto *ExistingClass =
2879
974
        cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2880
974
    if (auto *DDD = DClass->DefinitionData) {
2881
299
      if (ExistingClass->DefinitionData) {
2882
295
        MergeDefinitionData(ExistingClass, std::move(*DDD));
2883
295
      } else {
2884
4
        ExistingClass->DefinitionData = DClass->DefinitionData;
2885
        // We may have skipped this before because we thought that DClass
2886
        // was the canonical declaration.
2887
4
        Reader.PendingDefinitions.insert(DClass);
2888
4
      }
2889
299
    }
2890
974
    DClass->DefinitionData = ExistingClass->DefinitionData;
2891
2892
974
    return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern),
2893
974
                             Result);
2894
974
  }
2895
239
  if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2896
209
    return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern),
2897
209
                             Result);
2898
30
  if (auto *DVar = dyn_cast<VarDecl>(DPattern))
2899
10
    return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result);
2900
20
  if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2901
20
    return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern),
2902
20
                             Result);
2903
0
  llvm_unreachable("merged an unknown kind of redeclarable template");
2904
0
}
2905
2906
/// Attempts to merge the given declaration (D) with another declaration
2907
/// of the same entity.
2908
template <typename T>
2909
void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing,
2910
557k
                                      RedeclarableResult &Redecl) {
2911
557k
  auto *D = static_cast<T *>(DBase);
2912
557k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
557k
  T *DCanon = D->getCanonicalDecl();
2914
557k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
532k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
532k
    D->First = ExistingCanon;
2920
532k
    ExistingCanon->Used |= D->Used;
2921
532k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
532k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
464k
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
464k
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
532k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
1.21k
      mergeTemplatePattern(
2933
1.21k
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
1.21k
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
532k
    if (Redecl.isKeyDecl())
2938
140k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
532k
  }
2940
557k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::FunctionDecl>(clang::Redeclarable<clang::FunctionDecl>*, clang::FunctionDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
31.7k
                                      RedeclarableResult &Redecl) {
2911
31.7k
  auto *D = static_cast<T *>(DBase);
2912
31.7k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
31.7k
  T *DCanon = D->getCanonicalDecl();
2914
31.7k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
31.7k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
31.7k
    D->First = ExistingCanon;
2920
31.7k
    ExistingCanon->Used |= D->Used;
2921
31.7k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
31.7k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
31.7k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
31.7k
    if (Redecl.isKeyDecl())
2938
26.5k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
31.7k
  }
2940
31.7k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl>*, clang::ObjCInterfaceDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
150
                                      RedeclarableResult &Redecl) {
2911
150
  auto *D = static_cast<T *>(DBase);
2912
150
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
150
  T *DCanon = D->getCanonicalDecl();
2914
150
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
150
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
150
    D->First = ExistingCanon;
2920
150
    ExistingCanon->Used |= D->Used;
2921
150
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
150
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
150
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
150
    if (Redecl.isKeyDecl())
2938
107
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
150
  }
2940
150
}
void clang::ASTDeclReader::mergeRedeclarable<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl>*, clang::ObjCProtocolDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
52
                                      RedeclarableResult &Redecl) {
2911
52
  auto *D = static_cast<T *>(DBase);
2912
52
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
52
  T *DCanon = D->getCanonicalDecl();
2914
52
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
52
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
52
    D->First = ExistingCanon;
2920
52
    ExistingCanon->Used |= D->Used;
2921
52
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
52
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
52
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
52
    if (Redecl.isKeyDecl())
2938
46
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
52
  }
2940
52
}
void clang::ASTDeclReader::mergeRedeclarable<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl>*, clang::NamespaceDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
464k
                                      RedeclarableResult &Redecl) {
2911
464k
  auto *D = static_cast<T *>(DBase);
2912
464k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
464k
  T *DCanon = D->getCanonicalDecl();
2914
464k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
464k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
464k
    D->First = ExistingCanon;
2920
464k
    ExistingCanon->Used |= D->Used;
2921
464k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
464k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
464k
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
464k
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
464k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
464k
    if (Redecl.isKeyDecl())
2938
79.3k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
464k
  }
2940
464k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl>*, clang::NamespaceAliasDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
3
                                      RedeclarableResult &Redecl) {
2911
3
  auto *D = static_cast<T *>(DBase);
2912
3
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
3
  T *DCanon = D->getCanonicalDecl();
2914
3
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
3
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
3
    D->First = ExistingCanon;
2920
3
    ExistingCanon->Used |= D->Used;
2921
3
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
3
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
3
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
3
    if (Redecl.isKeyDecl())
2938
3
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
3
  }
2940
3
}
void clang::ASTDeclReader::mergeRedeclarable<clang::UsingShadowDecl>(clang::Redeclarable<clang::UsingShadowDecl>*, clang::UsingShadowDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
809
                                      RedeclarableResult &Redecl) {
2911
809
  auto *D = static_cast<T *>(DBase);
2912
809
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
809
  T *DCanon = D->getCanonicalDecl();
2914
809
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
809
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
809
    D->First = ExistingCanon;
2920
809
    ExistingCanon->Used |= D->Used;
2921
809
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
809
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
809
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
809
    if (Redecl.isKeyDecl())
2938
809
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
809
  }
2940
809
}
void clang::ASTDeclReader::mergeRedeclarable<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*, clang::TagDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
12.3k
                                      RedeclarableResult &Redecl) {
2911
12.3k
  auto *D = static_cast<T *>(DBase);
2912
12.3k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
12.3k
  T *DCanon = D->getCanonicalDecl();
2914
12.3k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
12.3k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
12.3k
    D->First = ExistingCanon;
2920
12.3k
    ExistingCanon->Used |= D->Used;
2921
12.3k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
12.3k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
12.3k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
12.3k
    if (Redecl.isKeyDecl())
2938
11.7k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
12.3k
  }
2940
12.3k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::VarDecl>(clang::Redeclarable<clang::VarDecl>*, clang::VarDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
11.0k
                                      RedeclarableResult &Redecl) {
2911
11.0k
  auto *D = static_cast<T *>(DBase);
2912
11.0k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
11.0k
  T *DCanon = D->getCanonicalDecl();
2914
11.0k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
11.0k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
11.0k
    D->First = ExistingCanon;
2920
11.0k
    ExistingCanon->Used |= D->Used;
2921
11.0k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
11.0k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
11.0k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
11.0k
    if (Redecl.isKeyDecl())
2938
10.4k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
11.0k
  }
2940
11.0k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl>*, clang::RedeclarableTemplateDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
26.1k
                                      RedeclarableResult &Redecl) {
2911
26.1k
  auto *D = static_cast<T *>(DBase);
2912
26.1k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
26.1k
  T *DCanon = D->getCanonicalDecl();
2914
26.1k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
1.21k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
1.21k
    D->First = ExistingCanon;
2920
1.21k
    ExistingCanon->Used |= D->Used;
2921
1.21k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
1.21k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
1.21k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
1.21k
      mergeTemplatePattern(
2933
1.21k
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
1.21k
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
1.21k
    if (Redecl.isKeyDecl())
2938
1.12k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
1.21k
  }
2940
26.1k
}
void clang::ASTDeclReader::mergeRedeclarable<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl>*, clang::TypedefNameDecl*, clang::ASTDeclReader::RedeclarableResult&)
Line
Count
Source
2910
11.0k
                                      RedeclarableResult &Redecl) {
2911
11.0k
  auto *D = static_cast<T *>(DBase);
2912
11.0k
  T *ExistingCanon = Existing->getCanonicalDecl();
2913
11.0k
  T *DCanon = D->getCanonicalDecl();
2914
11.0k
  if (ExistingCanon != DCanon) {
2915
    // Have our redeclaration link point back at the canonical declaration
2916
    // of the existing declaration, so that this declaration has the
2917
    // appropriate canonical declaration.
2918
11.0k
    D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2919
11.0k
    D->First = ExistingCanon;
2920
11.0k
    ExistingCanon->Used |= D->Used;
2921
11.0k
    D->Used = false;
2922
2923
    // When we merge a namespace, update its pointer to the first namespace.
2924
    // We cannot have loaded any redeclarations of this declaration yet, so
2925
    // there's nothing else that needs to be updated.
2926
11.0k
    if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927
0
      Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928
0
          assert_cast<NamespaceDecl *>(ExistingCanon));
2929
2930
    // When we merge a template, merge its pattern.
2931
11.0k
    if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2932
0
      mergeTemplatePattern(
2933
0
          DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934
0
          Redecl.isKeyDecl());
2935
2936
    // If this declaration is a key declaration, make a note of that.
2937
11.0k
    if (Redecl.isKeyDecl())
2938
10.2k
      Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2939
11.0k
  }
2940
11.0k
}
2941
2942
/// ODR-like semantics for C/ObjC allow us to merge tag types and a structural
2943
/// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89
2944
/// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee
2945
/// that some types are mergeable during deserialization, otherwise name
2946
/// lookup fails. This is the case for EnumConstantDecl.
2947
4.67k
static bool allowODRLikeMergeInC(NamedDecl *ND) {
2948
4.67k
  if (!ND)
2949
0
    return false;
2950
  // TODO: implement merge for other necessary decls.
2951
4.67k
  if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
2952
4.67k
    return true;
2953
0
  return false;
2954
4.67k
}
2955
2956
/// Attempts to merge LifetimeExtendedTemporaryDecl with
2957
/// identical class definitions from two different modules.
2958
21
void ASTDeclReader::mergeMergeable(LifetimeExtendedTemporaryDecl *D) {
2959
  // If modules are not available, there is no reason to perform this merge.
2960
21
  if (!Reader.getContext().getLangOpts().Modules)
2961
11
    return;
2962
2963
10
  LifetimeExtendedTemporaryDecl *LETDecl = D;
2964
2965
10
  LifetimeExtendedTemporaryDecl *&LookupResult =
2966
10
      Reader.LETemporaryForMerging[std::make_pair(
2967
10
          LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())];
2968
10
  if (LookupResult)
2969
0
    Reader.getContext().setPrimaryMergedDecl(LETDecl,
2970
0
                                             LookupResult->getCanonicalDecl());
2971
10
  else
2972
10
    LookupResult = LETDecl;
2973
10
}
2974
2975
/// Attempts to merge the given declaration (D) with another declaration
2976
/// of the same entity, for the case where the entity is not actually
2977
/// redeclarable. This happens, for instance, when merging the fields of
2978
/// identical class definitions from two different modules.
2979
template<typename T>
2980
36.8k
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
36.8k
  if (!Reader.getContext().getLangOpts().Modules)
2983
19.8k
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
17.0k
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
17.0k
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))4.67k
)
2991
0
    return;
2992
2993
17.0k
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
2.36k
    if (T *Existing = ExistingRes)
2995
2.36k
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
2.36k
                                               Existing->getCanonicalDecl());
2997
17.0k
}
void clang::ASTDeclReader::mergeMergeable<clang::EnumConstantDecl>(clang::Mergeable<clang::EnumConstantDecl>*)
Line
Count
Source
2980
1.73k
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
1.73k
  if (!Reader.getContext().getLangOpts().Modules)
2983
323
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
1.41k
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
1.41k
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))142
)
2991
0
    return;
2992
2993
1.41k
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
67
    if (T *Existing = ExistingRes)
2995
67
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
67
                                               Existing->getCanonicalDecl());
2997
1.41k
}
void clang::ASTDeclReader::mergeMergeable<clang::FieldDecl>(clang::Mergeable<clang::FieldDecl>*)
Line
Count
Source
2980
30.2k
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
30.2k
  if (!Reader.getContext().getLangOpts().Modules)
2983
19.4k
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
10.7k
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
10.7k
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))4.51k
)
2991
0
    return;
2992
2993
10.7k
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
326
    if (T *Existing = ExistingRes)
2995
326
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
326
                                               Existing->getCanonicalDecl());
2997
10.7k
}
void clang::ASTDeclReader::mergeMergeable<clang::IndirectFieldDecl>(clang::Mergeable<clang::IndirectFieldDecl>*)
Line
Count
Source
2980
389
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
389
  if (!Reader.getContext().getLangOpts().Modules)
2983
41
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
348
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
348
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))17
)
2991
0
    return;
2992
2993
348
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
46
    if (T *Existing = ExistingRes)
2995
46
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
46
                                               Existing->getCanonicalDecl());
2997
348
}
void clang::ASTDeclReader::mergeMergeable<clang::UsingDecl>(clang::Mergeable<clang::UsingDecl>*)
Line
Count
Source
2980
4.21k
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
4.21k
  if (!Reader.getContext().getLangOpts().Modules)
2983
25
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
4.18k
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
4.18k
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
4.18k
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
1.87k
    if (T *Existing = ExistingRes)
2995
1.87k
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
1.87k
                                               Existing->getCanonicalDecl());
2997
4.18k
}
void clang::ASTDeclReader::mergeMergeable<clang::UsingEnumDecl>(clang::Mergeable<clang::UsingEnumDecl>*)
Line
Count
Source
2980
1
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
1
  if (!Reader.getContext().getLangOpts().Modules)
2983
0
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
1
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
1
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
1
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
0
    if (T *Existing = ExistingRes)
2995
0
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
0
                                               Existing->getCanonicalDecl());
2997
1
}
void clang::ASTDeclReader::mergeMergeable<clang::UsingPackDecl>(clang::Mergeable<clang::UsingPackDecl>*)
Line
Count
Source
2980
10
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
10
  if (!Reader.getContext().getLangOpts().Modules)
2983
2
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
8
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
8
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
8
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
4
    if (T *Existing = ExistingRes)
2995
4
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
4
                                               Existing->getCanonicalDecl());
2997
8
}
void clang::ASTDeclReader::mergeMergeable<clang::UnresolvedUsingValueDecl>(clang::Mergeable<clang::UnresolvedUsingValueDecl>*)
Line
Count
Source
2980
88
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
88
  if (!Reader.getContext().getLangOpts().Modules)
2983
4
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
84
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
84
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
84
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
12
    if (T *Existing = ExistingRes)
2995
12
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
12
                                               Existing->getCanonicalDecl());
2997
84
}
void clang::ASTDeclReader::mergeMergeable<clang::UnresolvedUsingTypenameDecl>(clang::Mergeable<clang::UnresolvedUsingTypenameDecl>*)
Line
Count
Source
2980
153
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
153
  if (!Reader.getContext().getLangOpts().Modules)
2983
1
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
152
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
152
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
152
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
10
    if (T *Existing = ExistingRes)
2995
10
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
10
                                               Existing->getCanonicalDecl());
2997
152
}
void clang::ASTDeclReader::mergeMergeable<clang::ConceptDecl>(clang::Mergeable<clang::ConceptDecl>*)
Line
Count
Source
2980
80
void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2981
  // If modules are not available, there is no reason to perform this merge.
2982
80
  if (!Reader.getContext().getLangOpts().Modules)
2983
0
    return;
2984
2985
  // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2986
  // Note that C identically-named things in different translation units are
2987
  // not redeclarations, but may still have compatible types, where ODR-like
2988
  // semantics may apply.
2989
80
  if (!Reader.getContext().getLangOpts().CPlusPlus &&
2990
80
      
!allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))0
)
2991
0
    return;
2992
2993
80
  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2994
25
    if (T *Existing = ExistingRes)
2995
25
      Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2996
25
                                               Existing->getCanonicalDecl());
2997
80
}
2998
2999
280
void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
3000
280
  Record.readOMPChildren(D->Data);
3001
280
  VisitDecl(D);
3002
280
}
3003
3004
173
void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
3005
173
  Record.readOMPChildren(D->Data);
3006
173
  VisitDecl(D);
3007
173
}
3008
3009
32
void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) {
3010
32
  Record.readOMPChildren(D->Data);
3011
32
  VisitDecl(D);
3012
32
}
3013
3014
140
void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
3015
140
  VisitValueDecl(D);
3016
140
  D->setLocation(readSourceLocation());
3017
140
  Expr *In = Record.readExpr();
3018
140
  Expr *Out = Record.readExpr();
3019
140
  D->setCombinerData(In, Out);
3020
140
  Expr *Combiner = Record.readExpr();
3021
140
  D->setCombiner(Combiner);
3022
140
  Expr *Orig = Record.readExpr();
3023
140
  Expr *Priv = Record.readExpr();
3024
140
  D->setInitializerData(Orig, Priv);
3025
140
  Expr *Init = Record.readExpr();
3026
140
  auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt());
3027
140
  D->setInitializer(Init, IK);
3028
140
  D->PrevDeclInScope = readDeclID();
3029
140
}
3030
3031
100
void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
3032
100
  Record.readOMPChildren(D->Data);
3033
100
  VisitValueDecl(D);
3034
100
  D->VarName = Record.readDeclarationName();
3035
100
  D->PrevDeclInScope = readDeclID();
3036
100
}
3037
3038
5.20k
void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
3039
5.20k
  VisitVarDecl(D);
3040
5.20k
}
3041
3042
//===----------------------------------------------------------------------===//
3043
// Attribute Reading
3044
//===----------------------------------------------------------------------===//
3045
3046
namespace {
3047
class AttrReader {
3048
  ASTRecordReader &Reader;
3049
3050
public:
3051
1.21M
  AttrReader(ASTRecordReader &Reader) : Reader(Reader) {}
3052
3053
9.28M
  uint64_t readInt() {
3054
9.28M
    return Reader.readInt();
3055
9.28M
  }
3056
3057
1.21M
  bool readBool() { return Reader.readBool(); }
3058
3059
1.21M
  SourceRange readSourceRange() {
3060
1.21M
    return Reader.readSourceRange();
3061
1.21M
  }
3062
3063
1.21M
  SourceLocation readSourceLocation() {
3064
1.21M
    return Reader.readSourceLocation();
3065
1.21M
  }
3066
3067
20.5k
  Expr *readExpr() { return Reader.readExpr(); }
3068
3069
175k
  std::string readString() {
3070
175k
    return Reader.readString();
3071
175k
  }
3072
3073
23.9k
  TypeSourceInfo *readTypeSourceInfo() {
3074
23.9k
    return Reader.readTypeSourceInfo();
3075
23.9k
  }
3076
3077
2.44M
  IdentifierInfo *readIdentifier() {
3078
2.44M
    return Reader.readIdentifier();
3079
2.44M
  }
3080
3081
52.7k
  VersionTuple readVersionTuple() {
3082
52.7k
    return Reader.readVersionTuple();
3083
52.7k
  }
3084
3085
659
  OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); }
3086
3087
23
  template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
3088
23
    return Reader.GetLocalDeclAs<T>(LocalID);
3089
23
  }
ASTReaderDecl.cpp:clang::FunctionDecl* (anonymous namespace)::AttrReader::GetLocalDeclAs<clang::FunctionDecl>(unsigned int)
Line
Count
Source
3087
1
  template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
3088
1
    return Reader.GetLocalDeclAs<T>(LocalID);
3089
1
  }
ASTReaderDecl.cpp:clang::NamedDecl* (anonymous namespace)::AttrReader::GetLocalDeclAs<clang::NamedDecl>(unsigned int)
Line
Count
Source
3087
22
  template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
3088
22
    return Reader.GetLocalDeclAs<T>(LocalID);
3089
22
  }
Unexecuted instantiation: ASTReaderDecl.cpp:clang::VarDecl* (anonymous namespace)::AttrReader::GetLocalDeclAs<clang::VarDecl>(unsigned int)
Unexecuted instantiation: ASTReaderDecl.cpp:clang::MSGuidDecl* (anonymous namespace)::AttrReader::GetLocalDeclAs<clang::MSGuidDecl>(unsigned int)
3090
};
3091
}
3092
3093
1.21M
Attr *ASTRecordReader::readAttr() {
3094
1.21M
  AttrReader Record(*this);
3095
1.21M
  auto V = Record.readInt();
3096
1.21M
  if (!V)
3097
11
    return nullptr;
3098
3099
1.21M
  Attr *New = nullptr;
3100
  // Kind is stored as a 1-based integer because 0 is used to indicate a null
3101
  // Attr pointer.
3102
1.21M
  auto Kind = static_cast<attr::Kind>(V - 1);
3103
1.21M
  ASTContext &Context = getContext();
3104
3105
1.21M
  IdentifierInfo *AttrName = Record.readIdentifier();
3106
1.21M
  IdentifierInfo *ScopeName = Record.readIdentifier();
3107
1.21M
  SourceRange AttrRange = Record.readSourceRange();
3108
1.21M
  SourceLocation ScopeLoc = Record.readSourceLocation();
3109
1.21M
  unsigned ParsedKind = Record.readInt();
3110
1.21M
  unsigned Syntax = Record.readInt();
3111
1.21M
  unsigned SpellingIndex = Record.readInt();
3112
1.21M
  bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned &&
3113
1.21M
                    
Syntax == AttributeCommonInfo::AS_Keyword297
&&
3114
1.21M
                    
SpellingIndex == AlignedAttr::Keyword_alignas31
);
3115
1.21M
  bool IsRegularKeywordAttribute = Record.readBool();
3116
3117
1.21M
  AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc,
3118
1.21M
                           AttributeCommonInfo::Kind(ParsedKind),
3119
1.21M
                           {AttributeCommonInfo::Syntax(Syntax), SpellingIndex,
3120
1.21M
                            IsAlignas, IsRegularKeywordAttribute});
3121
3122
1.21M
#include "clang/Serialization/AttrPCHRead.inc"
3123
3124
1.21M
  assert(New && "Unable to decode attribute?");
3125
1.21M
  return New;
3126
1.21M
}
3127
3128
/// Reads attributes from the current stream position.
3129
902k
void ASTRecordReader::readAttributes(AttrVec &Attrs) {
3130
2.11M
  for (unsigned I = 0, E = readInt(); I != E; 
++I1.20M
)
3131
1.20M
    if (auto *A = readAttr())
3132
1.20M
      Attrs.push_back(A);
3133
902k
}
3134
3135
//===----------------------------------------------------------------------===//
3136
// ASTReader Implementation
3137
//===----------------------------------------------------------------------===//
3138
3139
/// Note that we have loaded the declaration with the given
3140
/// Index.
3141
///
3142
/// This routine notes that this declaration has already been loaded,
3143
/// so that future GetDecl calls will return this declaration rather
3144
/// than trying to load a new declaration.
3145
3.35M
inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
3146
3.35M
  assert(!DeclsLoaded[Index] && "Decl loaded twice?");
3147
3.35M
  DeclsLoaded[Index] = D;
3148
3.35M
}
3149
3150
/// Determine whether the consumer will be interested in seeing
3151
/// this declaration (via HandleTopLevelDecl).
3152
///
3153
/// This routine should return true for anything that might affect
3154
/// code generation, e.g., inline function definitions, Objective-C
3155
/// declarations with metadata, etc.
3156
3.34M
static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
3157
  // An ObjCMethodDecl is never considered as "interesting" because its
3158
  // implementation container always is.
3159
3160
  // An ImportDecl or VarDecl imported from a module map module will get
3161
  // emitted when we import the relevant module.
3162
3.34M
  if (isPartOfPerModuleInitializer(D)) {
3163
626k
    auto *M = D->getImportedOwningModule();
3164
626k
    if (M && 
M->Kind == Module::ModuleMapModule368k
&&
3165
626k
        
Ctx.DeclMustBeEmitted(D)367k
)
3166
864
      return false;
3167
626k
  }
3168
3169
3.34M
  if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCProtocolDecl, ObjCImplDecl,
3170
3.34M
          ImportDecl, PragmaCommentDecl, PragmaDetectMismatchDecl>(D))
3171
2.06k
    return true;
3172
3.34M
  if (isa<OMPThreadPrivateDecl, OMPDeclareReductionDecl, OMPDeclareMapperDecl,
3173
3.34M
          OMPAllocateDecl, OMPRequiresDecl>(D))
3174
725
    return !D->getDeclContext()->isFunctionOrMethod();
3175
3.33M
  if (const auto *Var = dyn_cast<VarDecl>(D))
3176
642k
    return Var->isFileVarDecl() &&
3177
642k
           
(29.6k
Var->isThisDeclarationADefinition() == VarDecl::Definition29.6k
||
3178
29.6k
            
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)23.0k
);
3179
2.69M
  if (const auto *Func = dyn_cast<FunctionDecl>(D))
3180
289k
    return Func->doesThisDeclarationHaveABody() || 
HasBody132k
;
3181
3182
2.40M
  if (auto *ES = D->getASTContext().getExternalSource())
3183
2.40M
    if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
3184
6
      return true;
3185
3186
2.40M
  return false;
3187
2.40M
}
3188
3189
/// Get the correct cursor and offset for loading a declaration.
3190
ASTReader::RecordLocation
3191
3.35M
ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
3192
3.35M
  GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
3193
3.35M
  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
3194
3.35M
  ModuleFile *M = I->second;
3195
3.35M
  const DeclOffset &DOffs =
3196
3.35M
      M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
3197
3.35M
  Loc = TranslateSourceLocation(*M, DOffs.getLocation());
3198
3.35M
  return RecordLocation(M, DOffs.getBitOffset(M->DeclsBlockStartOffset));
3199
3.35M
}
3200
3201
133k
ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
3202
133k
  auto I = GlobalBitOffsetsMap.find(GlobalOffset);
3203
3204
133k
  assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
3205
133k
  return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
3206
133k
}
3207
3208
149k
uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset) {
3209
149k
  return LocalOffset + M.GlobalBitOffset;
3210
149k
}
3211
3212
CXXRecordDecl *
3213
ASTDeclReader::getOrFakePrimaryClassDefinition(ASTReader &Reader,
3214
742k
                                               CXXRecordDecl *RD) {
3215
  // Try to dig out the definition.
3216
742k
  auto *DD = RD->DefinitionData;
3217
742k
  if (!DD)
3218
476
    DD = RD->getCanonicalDecl()->DefinitionData;
3219
3220
  // If there's no definition yet, then DC's definition is added by an update
3221
  // record, but we've not yet loaded that update record. In this case, we
3222
  // commit to DC being the canonical definition now, and will fix this when
3223
  // we load the update record.
3224
742k
  if (!DD) {
3225
476
    DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD);
3226
476
    RD->setCompleteDefinition(true);
3227
476
    RD->DefinitionData = DD;
3228
476
    RD->getCanonicalDecl()->DefinitionData = DD;
3229
3230
    // Track that we did this horrible thing so that we can fix it later.
3231
476
    Reader.PendingFakeDefinitionData.insert(
3232
476
        std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
3233
476
  }
3234
3235
742k
  return DD->Definition;
3236
742k
}
3237
3238
/// Find the context in which we should search for previous declarations when
3239
/// looking for declarations to merge.
3240
DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
3241
856k
                                                        DeclContext *DC) {
3242
856k
  if (auto *ND = dyn_cast<NamespaceDecl>(DC))
3243
346k
    return ND->getOriginalNamespace();
3244
3245
509k
  if (auto *RD = dyn_cast<CXXRecordDecl>(DC))
3246
396k
    return getOrFakePrimaryClassDefinition(Reader, RD);
3247
3248
113k
  if (auto *RD = dyn_cast<RecordDecl>(DC))
3249
8.82k
    return RD->getDefinition();
3250
3251
104k
  if (auto *ED = dyn_cast<EnumDecl>(DC))
3252
278
    return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
3253
278
                                                      : 
nullptr0
;
3254
3255
103k
  if (auto *OID = dyn_cast<ObjCInterfaceDecl>(DC))
3256
222
    return OID->getDefinition();
3257
3258
  // We can see the TU here only if we have no Sema object. In that case,
3259
  // there's no TU scope to look in, so using the DC alone is sufficient.
3260
103k
  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3261
84.2k
    return TU;
3262
3263
19.4k
  return nullptr;
3264
103k
}
3265
3266
535k
ASTDeclReader::FindExistingResult::~FindExistingResult() {
3267
  // Record that we had a typedef name for linkage whether or not we merge
3268
  // with that declaration.
3269
535k
  if (TypedefNameForLinkage) {
3270
219
    DeclContext *DC = New->getDeclContext()->getRedeclContext();
3271
219
    Reader.ImportedTypedefNamesForLinkage.insert(
3272
219
        std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3273
219
    return;
3274
219
  }
3275
3276
535k
  if (!AddResult || 
Existing514k
)
3277
179k
    return;
3278
3279
355k
  DeclarationName Name = New->getDeclName();
3280
355k
  DeclContext *DC = New->getDeclContext()->getRedeclContext();
3281
355k
  if (needsAnonymousDeclarationNumber(New)) {
3282
5.23k
    setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3283
5.23k
                               AnonymousDeclNumber, New);
3284
349k
  } else if (DC->isTranslationUnit() &&
3285
349k
             
!Reader.getContext().getLangOpts().CPlusPlus32.7k
) {
3286
11.2k
    if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
3287
11.2k
      Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3288
11.2k
            .push_back(New);
3289
338k
  } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3290
    // Add the declaration to its redeclaration context so later merging
3291
    // lookups will find it.
3292
338k
    MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true);
3293
338k
  }
3294
355k
}
3295
3296
/// Find the declaration that should be merged into, given the declaration found
3297
/// by name lookup. If we're merging an anonymous declaration within a typedef,
3298
/// we need a matching typedef, and we merge with the type inside it.
3299
static NamedDecl *getDeclForMerging(NamedDecl *Found,
3300
3.85M
                                    bool IsTypedefNameForLinkage) {
3301
3.85M
  if (!IsTypedefNameForLinkage)
3302
3.85M
    return Found;
3303
3304
  // If we found a typedef declaration that gives a name to some other
3305
  // declaration, then we want that inner declaration. Declarations from
3306
  // AST files are handled via ImportedTypedefNamesForLinkage.
3307
4
  if (Found->isFromASTFile())
3308
0
    return nullptr;
3309
3310
4
  if (auto *TND = dyn_cast<TypedefNameDecl>(Found))
3311
4
    return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
3312
3313
0
  return nullptr;
3314
4
}
3315
3316
/// Find the declaration to use to populate the anonymous declaration table
3317
/// for the given lexical DeclContext. We only care about finding local
3318
/// definitions of the context; we'll merge imported ones as we go.
3319
DeclContext *
3320
5.23k
ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) {
3321
  // For classes, we track the definition as we merge.
3322
5.23k
  if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3323
5.14k
    auto *DD = RD->getCanonicalDecl()->DefinitionData;
3324
5.14k
    return DD ? DD->Definition : 
nullptr0
;
3325
5.14k
  } else 
if (auto *93
OID93
= dyn_cast<ObjCInterfaceDecl>(LexicalDC)) {
3326
4
    return OID->getCanonicalDecl()->getDefinition();
3327
4
  }
3328
3329
  // For anything else, walk its merged redeclarations looking for a definition.
3330
  // Note that we can't just call getDefinition here because the redeclaration
3331
  // chain isn't wired up.
3332
99
  
for (auto *D : merged_redecls(cast<Decl>(LexicalDC)))89
{
3333
99
    if (auto *FD = dyn_cast<FunctionDecl>(D))
3334
70
      if (FD->isThisDeclarationADefinition())
3335
54
        return FD;
3336
45
    if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
3337
0
      if (MD->isThisDeclarationADefinition())
3338
0
        return MD;
3339
45
    if (auto *RD = dyn_cast<RecordDecl>(D))
3340
29
      if (RD->isThisDeclarationADefinition())
3341
22
        return RD;
3342
45
  }
3343
3344
  // No merged definition yet.
3345
13
  return nullptr;
3346
89
}
3347
3348
NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
3349
                                                     DeclContext *DC,
3350
5.35k
                                                     unsigned Index) {
3351
  // If the lexical context has been merged, look into the now-canonical
3352
  // definition.
3353
5.35k
  auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3354
3355
  // If we've seen this before, return the canonical declaration.
3356
5.35k
  auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3357
5.35k
  if (Index < Previous.size() && 
Previous[Index]966
)
3358
116
    return Previous[Index];
3359
3360
  // If this is the first time, but we have parsed a declaration of the context,
3361
  // build the anonymous declaration list from the parsed declaration.
3362
5.23k
  auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3363
5.23k
  if (PrimaryDC && 
!cast<Decl>(PrimaryDC)->isFromASTFile()5.22k
) {
3364
30
    numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) {
3365
30
      if (Previous.size() == Number)
3366
30
        Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));
3367
0
      else
3368
0
        Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl());
3369
30
    });
3370
11
  }
3371
3372
5.23k
  return Index < Previous.size() ? 
Previous[Index]861
:
nullptr4.37k
;
3373
5.35k
}
3374
3375
void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader,
3376
                                               DeclContext *DC, unsigned Index,
3377
5.23k
                                               NamedDecl *D) {
3378
5.23k
  auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3379
3380
5.23k
  auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3381
5.23k
  if (Index >= Previous.size())
3382
4.37k
    Previous.resize(Index + 1);
3383
5.23k
  if (!Previous[Index])
3384
5.22k
    Previous[Index] = D;
3385
5.23k
}
3386
3387
535k
ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
3388
535k
  DeclarationName Name = TypedefNameForLinkage ? 
TypedefNameForLinkage219
3389
535k
                                               : 
D->getDeclName()535k
;
3390
3391
535k
  if (!Name && 
!needsAnonymousDeclarationNumber(D)1.41k
) {
3392
    // Don't bother trying to find unnamed declarations that are in
3393
    // unmergeable contexts.
3394
692
    FindExistingResult Result(Reader, D, /*Existing=*/nullptr,
3395
692
                              AnonymousDeclNumber, TypedefNameForLinkage);
3396
692
    Result.suppress();
3397
692
    return Result;
3398
692
  }
3399
3400
534k
  ASTContext &C = Reader.getContext();
3401
534k
  DeclContext *DC = D->getDeclContext()->getRedeclContext();
3402
534k
  if (TypedefNameForLinkage) {
3403
219
    auto It = Reader.ImportedTypedefNamesForLinkage.find(
3404
219
        std::make_pair(DC, TypedefNameForLinkage));
3405
219
    if (It != Reader.ImportedTypedefNamesForLinkage.end())
3406
7
      if (C.isSameEntity(It->second, D))
3407
7
        return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3408
7
                                  TypedefNameForLinkage);
3409
    // Go on to check in other places in case an existing typedef name
3410
    // was not imported.
3411
219
  }
3412
3413
534k
  if (needsAnonymousDeclarationNumber(D)) {
3414
    // This is an anonymous declaration that we may need to merge. Look it up
3415
    // in its context by number.
3416
5.35k
    if (auto *Existing = getAnonymousDeclForMerging(
3417
5.35k
            Reader, D->getLexicalDeclContext(), AnonymousDeclNumber))
3418
127
      if (C.isSameEntity(Existing, D))
3419
114
        return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3420
114
                                  TypedefNameForLinkage);
3421
529k
  } else if (DC->isTranslationUnit() &&
3422
529k
             
!Reader.getContext().getLangOpts().CPlusPlus74.2k
) {
3423
11.5k
    IdentifierResolver &IdResolver = Reader.getIdResolver();
3424
3425
    // Temporarily consider the identifier to be up-to-date. We don't want to
3426
    // cause additional lookups here.
3427
11.5k
    class UpToDateIdentifierRAII {
3428
11.5k
      IdentifierInfo *II;
3429
11.5k
      bool WasOutToDate = false;
3430
3431
11.5k
    public:
3432
11.5k
      explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) {
3433
11.5k
        if (II) {
3434
11.5k
          WasOutToDate = II->isOutOfDate();
3435
11.5k
          if (WasOutToDate)
3436
408
            II->setOutOfDate(false);
3437
11.5k
        }
3438
11.5k
      }
3439
3440
11.5k
      ~UpToDateIdentifierRAII() {
3441
11.5k
        if (WasOutToDate)
3442
408
          II->setOutOfDate(true);
3443
11.5k
      }
3444
11.5k
    } UpToDate(Name.getAsIdentifierInfo());
3445
3446
11.5k
    for (IdentifierResolver::iterator I = IdResolver.begin(Name),
3447
11.5k
                                   IEnd = IdResolver.end();
3448
18.8k
         I != IEnd; 
++I7.27k
) {
3449
7.50k
      if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3450
7.50k
        if (C.isSameEntity(Existing, D))
3451
234
          return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3452
234
                                    TypedefNameForLinkage);
3453
7.50k
    }
3454
517k
  } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3455
498k
    DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
3456
4.18M
    for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; 
++I3.69M
) {
3457
3.84M
      if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3458
3.84M
        if (C.isSameEntity(Existing, D))
3459
159k
          return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3460
159k
                                    TypedefNameForLinkage);
3461
3.84M
    }
3462
498k
  } else {
3463
    // Not in a mergeable context.
3464
19.4k
    return FindExistingResult(Reader);
3465
19.4k
  }
3466
3467
  // If this declaration is from a merged context, make a note that we need to
3468
  // check that the canonical definition of that context contains the decl.
3469
  //
3470
  // FIXME: We should do something similar if we merge two definitions of the
3471
  // same template specialization into the same CXXRecordDecl.
3472
355k
  auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
3473
355k
  if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3474
355k
      
MergedDCIt->second == D->getDeclContext()425
)
3475
414
    Reader.PendingOdrMergeChecks.push_back(D);
3476
3477
355k
  return FindExistingResult(Reader, D, /*Existing=*/nullptr,
3478
355k
                            AnonymousDeclNumber, TypedefNameForLinkage);
3479
534k
}
3480
3481
template<typename DeclT>
3482
1.00M
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
1.00M
  return D->RedeclLink.getLatestNotUpdated();
3484
1.00M
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl>*)
Line
Count
Source
3482
763k
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
763k
  return D->RedeclLink.getLatestNotUpdated();
3484
763k
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl>*)
Line
Count
Source
3482
3
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
3
  return D->RedeclLink.getLatestNotUpdated();
3484
3
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl>*)
Line
Count
Source
3482
3.45k
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
3.45k
  return D->RedeclLink.getLatestNotUpdated();
3484
3.45k
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl>*)
Line
Count
Source
3482
1.21k
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
1.21k
  return D->RedeclLink.getLatestNotUpdated();
3484
1.21k
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl>*)
Line
Count
Source
3482
140k
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
140k
  return D->RedeclLink.getLatestNotUpdated();
3484
140k
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*)
Line
Count
Source
3482
40.4k
Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3483
40.4k
  return D->RedeclLink.getLatestNotUpdated();
3484
40.4k
}
clang::Decl* clang::ASTDeclReader::getMostRecentDeclImpl<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl>*)
Line
Count
Source
3482
11.1k
D