Coverage Report

Created: 2019-07-24 05:18

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