Coverage Report

Created: 2022-01-18 06:27

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