Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Serialization/ASTWriterDecl.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
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 serialization for Declarations.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "ASTCommon.h"
14
#include "clang/AST/Attr.h"
15
#include "clang/AST/DeclCXX.h"
16
#include "clang/AST/DeclTemplate.h"
17
#include "clang/AST/DeclVisitor.h"
18
#include "clang/AST/Expr.h"
19
#include "clang/AST/OpenMPClause.h"
20
#include "clang/AST/PrettyDeclStackTrace.h"
21
#include "clang/Basic/SourceManager.h"
22
#include "clang/Serialization/ASTReader.h"
23
#include "clang/Serialization/ASTRecordWriter.h"
24
#include "llvm/Bitstream/BitstreamWriter.h"
25
#include "llvm/Support/ErrorHandling.h"
26
#include <optional>
27
using namespace clang;
28
using namespace serialization;
29
30
//===----------------------------------------------------------------------===//
31
// Declaration serialization
32
//===----------------------------------------------------------------------===//
33
34
namespace clang {
35
  class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
36
    ASTWriter &Writer;
37
    ASTContext &Context;
38
    ASTRecordWriter Record;
39
40
    serialization::DeclCode Code;
41
    unsigned AbbrevToUse;
42
43
  public:
44
    ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
45
                  ASTWriter::RecordDataImpl &Record)
46
1.80M
        : Writer(Writer), Context(Context), Record(Writer, Record),
47
1.80M
          Code((serialization::DeclCode)0), AbbrevToUse(0) {}
48
49
1.80M
    uint64_t Emit(Decl *D) {
50
1.80M
      if (!Code)
51
0
        llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
52
0
            D->getDeclKindName() + "'");
53
1.80M
      return Record.Emit(Code, AbbrevToUse);
54
1.80M
    }
55
56
    void Visit(Decl *D);
57
58
    void VisitDecl(Decl *D);
59
    void VisitPragmaCommentDecl(PragmaCommentDecl *D);
60
    void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
61
    void VisitTranslationUnitDecl(TranslationUnitDecl *D);
62
    void VisitNamedDecl(NamedDecl *D);
63
    void VisitLabelDecl(LabelDecl *LD);
64
    void VisitNamespaceDecl(NamespaceDecl *D);
65
    void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
66
    void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
67
    void VisitTypeDecl(TypeDecl *D);
68
    void VisitTypedefNameDecl(TypedefNameDecl *D);
69
    void VisitTypedefDecl(TypedefDecl *D);
70
    void VisitTypeAliasDecl(TypeAliasDecl *D);
71
    void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
72
    void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D);
73
    void VisitTagDecl(TagDecl *D);
74
    void VisitEnumDecl(EnumDecl *D);
75
    void VisitRecordDecl(RecordDecl *D);
76
    void VisitCXXRecordDecl(CXXRecordDecl *D);
77
    void VisitClassTemplateSpecializationDecl(
78
                                            ClassTemplateSpecializationDecl *D);
79
    void VisitClassTemplatePartialSpecializationDecl(
80
                                     ClassTemplatePartialSpecializationDecl *D);
81
    void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
82
    void VisitVarTemplatePartialSpecializationDecl(
83
        VarTemplatePartialSpecializationDecl *D);
84
    void VisitClassScopeFunctionSpecializationDecl(
85
                                       ClassScopeFunctionSpecializationDecl *D);
86
    void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
87
    void VisitValueDecl(ValueDecl *D);
88
    void VisitEnumConstantDecl(EnumConstantDecl *D);
89
    void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
90
    void VisitDeclaratorDecl(DeclaratorDecl *D);
91
    void VisitFunctionDecl(FunctionDecl *D);
92
    void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
93
    void VisitCXXMethodDecl(CXXMethodDecl *D);
94
    void VisitCXXConstructorDecl(CXXConstructorDecl *D);
95
    void VisitCXXDestructorDecl(CXXDestructorDecl *D);
96
    void VisitCXXConversionDecl(CXXConversionDecl *D);
97
    void VisitFieldDecl(FieldDecl *D);
98
    void VisitMSPropertyDecl(MSPropertyDecl *D);
99
    void VisitMSGuidDecl(MSGuidDecl *D);
100
    void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D);
101
    void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D);
102
    void VisitIndirectFieldDecl(IndirectFieldDecl *D);
103
    void VisitVarDecl(VarDecl *D);
104
    void VisitImplicitParamDecl(ImplicitParamDecl *D);
105
    void VisitParmVarDecl(ParmVarDecl *D);
106
    void VisitDecompositionDecl(DecompositionDecl *D);
107
    void VisitBindingDecl(BindingDecl *D);
108
    void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
109
    void VisitTemplateDecl(TemplateDecl *D);
110
    void VisitConceptDecl(ConceptDecl *D);
111
    void VisitImplicitConceptSpecializationDecl(
112
        ImplicitConceptSpecializationDecl *D);
113
    void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D);
114
    void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
115
    void VisitClassTemplateDecl(ClassTemplateDecl *D);
116
    void VisitVarTemplateDecl(VarTemplateDecl *D);
117
    void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
118
    void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
119
    void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
120
    void VisitUsingDecl(UsingDecl *D);
121
    void VisitUsingEnumDecl(UsingEnumDecl *D);
122
    void VisitUsingPackDecl(UsingPackDecl *D);
123
    void VisitUsingShadowDecl(UsingShadowDecl *D);
124
    void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
125
    void VisitLinkageSpecDecl(LinkageSpecDecl *D);
126
    void VisitExportDecl(ExportDecl *D);
127
    void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
128
    void VisitTopLevelStmtDecl(TopLevelStmtDecl *D);
129
    void VisitImportDecl(ImportDecl *D);
130
    void VisitAccessSpecDecl(AccessSpecDecl *D);
131
    void VisitFriendDecl(FriendDecl *D);
132
    void VisitFriendTemplateDecl(FriendTemplateDecl *D);
133
    void VisitStaticAssertDecl(StaticAssertDecl *D);
134
    void VisitBlockDecl(BlockDecl *D);
135
    void VisitCapturedDecl(CapturedDecl *D);
136
    void VisitEmptyDecl(EmptyDecl *D);
137
    void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
138
    void VisitDeclContext(DeclContext *DC);
139
    template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
140
    void VisitHLSLBufferDecl(HLSLBufferDecl *D);
141
142
    // FIXME: Put in the same order is DeclNodes.td?
143
    void VisitObjCMethodDecl(ObjCMethodDecl *D);
144
    void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
145
    void VisitObjCContainerDecl(ObjCContainerDecl *D);
146
    void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
147
    void VisitObjCIvarDecl(ObjCIvarDecl *D);
148
    void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
149
    void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
150
    void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
151
    void VisitObjCImplDecl(ObjCImplDecl *D);
152
    void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
153
    void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
154
    void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
155
    void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
156
    void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
157
    void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
158
    void VisitOMPAllocateDecl(OMPAllocateDecl *D);
159
    void VisitOMPRequiresDecl(OMPRequiresDecl *D);
160
    void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
161
    void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
162
    void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
163
164
    /// Add an Objective-C type parameter list to the given record.
165
7.40k
    void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
166
      // Empty type parameter list.
167
7.40k
      if (!typeParams) {
168
6.88k
        Record.push_back(0);
169
6.88k
        return;
170
6.88k
      }
171
172
527
      Record.push_back(typeParams->size());
173
696
      for (auto *typeParam : *typeParams) {
174
696
        Record.AddDeclRef(typeParam);
175
696
      }
176
527
      Record.AddSourceLocation(typeParams->getLAngleLoc());
177
527
      Record.AddSourceLocation(typeParams->getRAngleLoc());
178
527
    }
179
180
    /// Add to the record the first declaration from each module file that
181
    /// provides a declaration of D. The intent is to provide a sufficient
182
    /// set such that reloading this set will load all current redeclarations.
183
38.4k
    void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
184
38.4k
      llvm::MapVector<ModuleFile*, const Decl*> Firsts;
185
      // FIXME: We can skip entries that we know are implied by others.
186
514k
      for (const Decl *R = D->getMostRecentDecl(); R; 
R = R->getPreviousDecl()476k
) {
187
476k
        if (R->isFromASTFile())
188
414k
          Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
189
62.2k
        else if (IncludeLocal)
190
18.2k
          Firsts[nullptr] = R;
191
476k
      }
192
38.4k
      for (const auto &F : Firsts)
193
261k
        Record.AddDeclRef(F.second);
194
38.4k
    }
195
196
    /// Get the specialization decl from an entry in the specialization list.
197
    template <typename EntryType>
198
    typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
199
18.0k
    getSpecializationDecl(EntryType &T) {
200
18.0k
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
18.0k
    }
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplateSpecializationDecl>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::ClassTemplateSpecializationDecl>(clang::ClassTemplateSpecializationDecl&)
Line
Count
Source
199
12.3k
    getSpecializationDecl(EntryType &T) {
200
12.3k
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
12.3k
    }
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::ClassTemplatePartialSpecializationDecl>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::ClassTemplatePartialSpecializationDecl>(clang::ClassTemplatePartialSpecializationDecl&)
Line
Count
Source
199
1.63k
    getSpecializationDecl(EntryType &T) {
200
1.63k
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
1.63k
    }
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplateSpecializationDecl>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::VarTemplateSpecializationDecl>(clang::VarTemplateSpecializationDecl&)
Line
Count
Source
199
121
    getSpecializationDecl(EntryType &T) {
200
121
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
121
    }
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::VarTemplatePartialSpecializationDecl>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::VarTemplatePartialSpecializationDecl>(clang::VarTemplatePartialSpecializationDecl&)
Line
Count
Source
199
37
    getSpecializationDecl(EntryType &T) {
200
37
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
37
    }
clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::FunctionTemplateSpecializationInfo>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::FunctionTemplateSpecializationInfo>(clang::FunctionTemplateSpecializationInfo&)
Line
Count
Source
199
3.87k
    getSpecializationDecl(EntryType &T) {
200
3.87k
      return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
201
3.87k
    }
Unexecuted instantiation: clang::RedeclarableTemplateDecl::SpecEntryTraits<clang::Decl const>::DeclType* clang::ASTDeclWriter::getSpecializationDecl<clang::Decl const>(clang::Decl const&)
202
203
    /// Get the list of partial specializations from a template's common ptr.
204
    template<typename T>
205
5.77k
    decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
206
5.77k
      return Common->PartialSpecializations;
207
5.77k
    }
decltype(clang::ClassTemplateDecl::Common::PartialSpecializations)& clang::ASTDeclWriter::getPartialSpecializations<clang::ClassTemplateDecl::Common>(clang::ClassTemplateDecl::Common*)
Line
Count
Source
205
5.47k
    decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
206
5.47k
      return Common->PartialSpecializations;
207
5.47k
    }
decltype(clang::VarTemplateDecl::Common::PartialSpecializations)& clang::ASTDeclWriter::getPartialSpecializations<clang::VarTemplateDecl::Common>(clang::VarTemplateDecl::Common*)
Line
Count
Source
205
306
    decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
206
306
      return Common->PartialSpecializations;
207
306
    }
208
14.5k
    ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
209
14.5k
      return std::nullopt;
210
14.5k
    }
211
212
    template<typename DeclTy>
213
20.3k
    void AddTemplateSpecializations(DeclTy *D) {
214
20.3k
      auto *Common = D->getCommonPtr();
215
216
      // If we have any lazy specializations, and the external AST source is
217
      // our chained AST reader, we can just write out the DeclIDs. Otherwise,
218
      // we need to resolve them to actual declarations.
219
20.3k
      if (Writer.Chain != Writer.Context->getExternalSource() &&
220
20.3k
          
Common->LazySpecializations3
) {
221
0
        D->LoadLazySpecializations();
222
0
        assert(!Common->LazySpecializations);
223
0
      }
224
225
20.3k
      ArrayRef<DeclID> LazySpecializations;
226
20.3k
      if (auto *LS = Common->LazySpecializations)
227
21
        LazySpecializations = llvm::ArrayRef(LS + 1, LS[0]);
228
229
      // Add a slot to the record for the number of specializations.
230
20.3k
      unsigned I = Record.size();
231
20.3k
      Record.push_back(0);
232
233
      // AddFirstDeclFromEachModule might trigger deserialization, invalidating
234
      // *Specializations iterators.
235
20.3k
      llvm::SmallVector<const Decl*, 16> Specs;
236
20.3k
      for (auto &Entry : Common->Specializations)
237
16.3k
        Specs.push_back(getSpecializationDecl(Entry));
238
20.3k
      for (auto &Entry : getPartialSpecializations(Common))
239
1.67k
        Specs.push_back(getSpecializationDecl(Entry));
240
241
20.3k
      for (auto *D : Specs) {
242
18.0k
        assert(D->isCanonicalDecl() && "non-canonical decl in set");
243
18.0k
        AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
244
18.0k
      }
245
20.3k
      Record.append(LazySpecializations.begin(), LazySpecializations.end());
246
247
      // Update the size entry we added earlier.
248
20.3k
      Record[I] = Record.size() - I - 1;
249
20.3k
    }
void clang::ASTDeclWriter::AddTemplateSpecializations<clang::ClassTemplateDecl>(clang::ClassTemplateDecl*)
Line
Count
Source
213
5.47k
    void AddTemplateSpecializations(DeclTy *D) {
214
5.47k
      auto *Common = D->getCommonPtr();
215
216
      // If we have any lazy specializations, and the external AST source is
217
      // our chained AST reader, we can just write out the DeclIDs. Otherwise,
218
      // we need to resolve them to actual declarations.
219
5.47k
      if (Writer.Chain != Writer.Context->getExternalSource() &&
220
5.47k
          
Common->LazySpecializations3
) {
221
0
        D->LoadLazySpecializations();
222
0
        assert(!Common->LazySpecializations);
223
0
      }
224
225
5.47k
      ArrayRef<DeclID> LazySpecializations;
226
5.47k
      if (auto *LS = Common->LazySpecializations)
227
19
        LazySpecializations = llvm::ArrayRef(LS + 1, LS[0]);
228
229
      // Add a slot to the record for the number of specializations.
230
5.47k
      unsigned I = Record.size();
231
5.47k
      Record.push_back(0);
232
233
      // AddFirstDeclFromEachModule might trigger deserialization, invalidating
234
      // *Specializations iterators.
235
5.47k
      llvm::SmallVector<const Decl*, 16> Specs;
236
5.47k
      for (auto &Entry : Common->Specializations)
237
12.3k
        Specs.push_back(getSpecializationDecl(Entry));
238
5.47k
      for (auto &Entry : getPartialSpecializations(Common))
239
1.63k
        Specs.push_back(getSpecializationDecl(Entry));
240
241
13.9k
      for (auto *D : Specs) {
242
13.9k
        assert(D->isCanonicalDecl() && "non-canonical decl in set");
243
13.9k
        AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
244
13.9k
      }
245
5.47k
      Record.append(LazySpecializations.begin(), LazySpecializations.end());
246
247
      // Update the size entry we added earlier.
248
5.47k
      Record[I] = Record.size() - I - 1;
249
5.47k
    }
void clang::ASTDeclWriter::AddTemplateSpecializations<clang::VarTemplateDecl>(clang::VarTemplateDecl*)
Line
Count
Source
213
306
    void AddTemplateSpecializations(DeclTy *D) {
214
306
      auto *Common = D->getCommonPtr();
215
216
      // If we have any lazy specializations, and the external AST source is
217
      // our chained AST reader, we can just write out the DeclIDs. Otherwise,
218
      // we need to resolve them to actual declarations.
219
306
      if (Writer.Chain != Writer.Context->getExternalSource() &&
220
306
          
Common->LazySpecializations0
) {
221
0
        D->LoadLazySpecializations();
222
0
        assert(!Common->LazySpecializations);
223
0
      }
224
225
306
      ArrayRef<DeclID> LazySpecializations;
226
306
      if (auto *LS = Common->LazySpecializations)
227
0
        LazySpecializations = llvm::ArrayRef(LS + 1, LS[0]);
228
229
      // Add a slot to the record for the number of specializations.
230
306
      unsigned I = Record.size();
231
306
      Record.push_back(0);
232
233
      // AddFirstDeclFromEachModule might trigger deserialization, invalidating
234
      // *Specializations iterators.
235
306
      llvm::SmallVector<const Decl*, 16> Specs;
236
306
      for (auto &Entry : Common->Specializations)
237
121
        Specs.push_back(getSpecializationDecl(Entry));
238
306
      for (auto &Entry : getPartialSpecializations(Common))
239
37
        Specs.push_back(getSpecializationDecl(Entry));
240
241
306
      for (auto *D : Specs) {
242
158
        assert(D->isCanonicalDecl() && "non-canonical decl in set");
243
158
        AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
244
158
      }
245
306
      Record.append(LazySpecializations.begin(), LazySpecializations.end());
246
247
      // Update the size entry we added earlier.
248
306
      Record[I] = Record.size() - I - 1;
249
306
    }
void clang::ASTDeclWriter::AddTemplateSpecializations<clang::FunctionTemplateDecl>(clang::FunctionTemplateDecl*)
Line
Count
Source
213
14.5k
    void AddTemplateSpecializations(DeclTy *D) {
214
14.5k
      auto *Common = D->getCommonPtr();
215
216
      // If we have any lazy specializations, and the external AST source is
217
      // our chained AST reader, we can just write out the DeclIDs. Otherwise,
218
      // we need to resolve them to actual declarations.
219
14.5k
      if (Writer.Chain != Writer.Context->getExternalSource() &&
220
14.5k
          
Common->LazySpecializations0
) {
221
0
        D->LoadLazySpecializations();
222
0
        assert(!Common->LazySpecializations);
223
0
      }
224
225
14.5k
      ArrayRef<DeclID> LazySpecializations;
226
14.5k
      if (auto *LS = Common->LazySpecializations)
227
2
        LazySpecializations = llvm::ArrayRef(LS + 1, LS[0]);
228
229
      // Add a slot to the record for the number of specializations.
230
14.5k
      unsigned I = Record.size();
231
14.5k
      Record.push_back(0);
232
233
      // AddFirstDeclFromEachModule might trigger deserialization, invalidating
234
      // *Specializations iterators.
235
14.5k
      llvm::SmallVector<const Decl*, 16> Specs;
236
14.5k
      for (auto &Entry : Common->Specializations)
237
3.87k
        Specs.push_back(getSpecializationDecl(Entry));
238
14.5k
      for (auto &Entry : getPartialSpecializations(Common))
239
0
        Specs.push_back(getSpecializationDecl(Entry));
240
241
14.5k
      for (auto *D : Specs) {
242
3.87k
        assert(D->isCanonicalDecl() && "non-canonical decl in set");
243
3.87k
        AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
244
3.87k
      }
245
14.5k
      Record.append(LazySpecializations.begin(), LazySpecializations.end());
246
247
      // Update the size entry we added earlier.
248
14.5k
      Record[I] = Record.size() - I - 1;
249
14.5k
    }
250
251
    /// Ensure that this template specialization is associated with the specified
252
    /// template on reload.
253
    void RegisterTemplateSpecialization(const Decl *Template,
254
21.0k
                                        const Decl *Specialization) {
255
21.0k
      Template = Template->getCanonicalDecl();
256
257
      // If the canonical template is local, we'll write out this specialization
258
      // when we emit it.
259
      // FIXME: We can do the same thing if there is any local declaration of
260
      // the template, to avoid emitting an update record.
261
21.0k
      if (!Template->isFromASTFile())
262
18.2k
        return;
263
264
      // We only need to associate the first local declaration of the
265
      // specialization. The other declarations will get pulled in by it.
266
2.76k
      if (Writer.getFirstLocalDecl(Specialization) != Specialization)
267
27
        return;
268
269
2.73k
      Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
270
2.73k
          UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
271
2.73k
    }
272
  };
273
}
274
275
1.80M
void ASTDeclWriter::Visit(Decl *D) {
276
1.80M
  DeclVisitor<ASTDeclWriter>::Visit(D);
277
278
  // Source locations require array (variable-length) abbreviations.  The
279
  // abbreviation infrastructure requires that arrays are encoded last, so
280
  // we handle it here in the case of those classes derived from DeclaratorDecl
281
1.80M
  if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
282
1.28M
    if (auto *TInfo = DD->getTypeSourceInfo())
283
986k
      Record.AddTypeLoc(TInfo->getTypeLoc());
284
1.28M
  }
285
286
  // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
287
  // have been written. We want it last because we will not read it back when
288
  // retrieving it from the AST, we'll just lazily set the offset.
289
1.80M
  if (auto *FD = dyn_cast<FunctionDecl>(D)) {
290
261k
    Record.push_back(FD->doesThisDeclarationHaveABody());
291
261k
    if (FD->doesThisDeclarationHaveABody())
292
94.0k
      Record.AddFunctionDefinition(FD);
293
261k
  }
294
295
  // Similar to FunctionDecls, handle VarDecl's initializer here and write it
296
  // after all other Stmts/Exprs. We will not read the initializer until after
297
  // we have finished recursive deserialization, because it can recursively
298
  // refer back to the variable.
299
1.80M
  if (auto *VD = dyn_cast<VarDecl>(D)) {
300
875k
    Record.AddVarDeclInit(VD);
301
875k
  }
302
303
  // And similarly for FieldDecls. We already serialized whether there is a
304
  // default member initializer.
305
1.80M
  if (auto *FD = dyn_cast<FieldDecl>(D)) {
306
141k
    if (FD->hasInClassInitializer()) {
307
283
      if (Expr *Init = FD->getInClassInitializer()) {
308
271
        Record.push_back(1);
309
271
        Record.AddStmt(Init);
310
271
      } else {
311
12
        Record.push_back(0);
312
        // Initializer has not been instantiated yet.
313
12
      }
314
283
    }
315
141k
  }
316
317
  // If this declaration is also a DeclContext, write blocks for the
318
  // declarations that lexically stored inside its context and those
319
  // declarations that are visible from its context.
320
1.80M
  if (auto *DC = dyn_cast<DeclContext>(D))
321
495k
    VisitDeclContext(DC);
322
1.80M
}
323
324
1.80M
void ASTDeclWriter::VisitDecl(Decl *D) {
325
1.80M
  Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
326
1.80M
  if (D->getDeclContext() != D->getLexicalDeclContext())
327
14.1k
    Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
328
1.79M
  else
329
1.79M
    Record.push_back(0);
330
1.80M
  Record.push_back(D->isInvalidDecl());
331
1.80M
  Record.push_back(D->hasAttrs());
332
1.80M
  if (D->hasAttrs())
333
386k
    Record.AddAttributes(D->getAttrs());
334
1.80M
  Record.push_back(D->isImplicit());
335
1.80M
  Record.push_back(D->isUsed(false));
336
1.80M
  Record.push_back(D->isReferenced());
337
1.80M
  Record.push_back(D->isTopLevelDeclInObjCContainer());
338
1.80M
  Record.push_back(D->getAccess());
339
1.80M
  Record.push_back((uint64_t)D->getModuleOwnershipKind());
340
1.80M
  Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
341
342
  // If this declaration injected a name into a context different from its
343
  // lexical context, and that context is an imported namespace, we need to
344
  // update its visible declarations to include this name.
345
  //
346
  // This happens when we instantiate a class with a friend declaration or a
347
  // function with a local extern declaration, for instance.
348
  //
349
  // FIXME: Can we handle this in AddedVisibleDecl instead?
350
1.80M
  if (D->isOutOfLine()) {
351
17.6k
    auto *DC = D->getDeclContext();
352
17.9k
    while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
353
4.08k
      if (!NS->isFromASTFile())
354
3.53k
        break;
355
550
      Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
356
550
      if (!NS->isInlineNamespace())
357
285
        break;
358
265
      DC = NS->getParent();
359
265
    }
360
17.6k
  }
361
1.80M
}
362
363
3
void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
364
3
  StringRef Arg = D->getArg();
365
3
  Record.push_back(Arg.size());
366
3
  VisitDecl(D);
367
3
  Record.AddSourceLocation(D->getBeginLoc());
368
3
  Record.push_back(D->getCommentKind());
369
3
  Record.AddString(Arg);
370
3
  Code = serialization::DECL_PRAGMA_COMMENT;
371
3
}
372
373
void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
374
3
    PragmaDetectMismatchDecl *D) {
375
3
  StringRef Name = D->getName();
376
3
  StringRef Value = D->getValue();
377
3
  Record.push_back(Name.size() + 1 + Value.size());
378
3
  VisitDecl(D);
379
3
  Record.AddSourceLocation(D->getBeginLoc());
380
3
  Record.AddString(Name);
381
3
  Record.AddString(Value);
382
3
  Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
383
3
}
384
385
0
void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
386
0
  llvm_unreachable("Translation units aren't directly serialized");
387
0
}
388
389
1.69M
void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
390
1.69M
  VisitDecl(D);
391
1.69M
  Record.AddDeclarationName(D->getDeclName());
392
1.69M
  Record.push_back(needsAnonymousDeclarationNumber(D)
393
1.69M
                       ? 
Writer.getAnonymousDeclarationNumber(D)88.8k
394
1.69M
                       : 
01.60M
);
395
1.69M
}
396
397
231k
void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
398
231k
  VisitNamedDecl(D);
399
231k
  Record.AddSourceLocation(D->getBeginLoc());
400
231k
  Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
401
231k
}
402
403
61.5k
void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
404
61.5k
  VisitRedeclarable(D);
405
61.5k
  VisitTypeDecl(D);
406
61.5k
  Record.AddTypeSourceInfo(D->getTypeSourceInfo());
407
61.5k
  Record.push_back(D->isModed());
408
61.5k
  if (D->isModed())
409
0
    Record.AddTypeRef(D->getUnderlyingType());
410
61.5k
  Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
411
61.5k
}
412
413
57.5k
void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
414
57.5k
  VisitTypedefNameDecl(D);
415
57.5k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
416
57.5k
      !D->hasAttrs() &&
417
57.5k
      
!D->isImplicit()48.0k
&&
418
57.5k
      
D->getFirstDecl() == D->getMostRecentDecl()42.7k
&&
419
57.5k
      
!D->isInvalidDecl()38.2k
&&
420
57.5k
      
!D->isTopLevelDeclInObjCContainer()38.2k
&&
421
57.5k
      
!D->isModulePrivate()38.1k
&&
422
57.5k
      
!needsAnonymousDeclarationNumber(D)38.1k
&&
423
57.5k
      
D->getDeclName().getNameKind() == DeclarationName::Identifier38.1k
)
424
38.1k
    AbbrevToUse = Writer.getDeclTypedefAbbrev();
425
426
57.5k
  Code = serialization::DECL_TYPEDEF;
427
57.5k
}
428
429
3.27k
void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
430
3.27k
  VisitTypedefNameDecl(D);
431
3.27k
  Record.AddDeclRef(D->getDescribedAliasTemplate());
432
3.27k
  Code = serialization::DECL_TYPEALIAS;
433
3.27k
}
434
435
123k
void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
436
123k
  static_assert(DeclContext::NumTagDeclBits == 10,
437
123k
                "You need to update the serializer after you change the "
438
123k
                "TagDeclBits");
439
440
123k
  VisitRedeclarable(D);
441
123k
  VisitTypeDecl(D);
442
123k
  Record.push_back(D->getIdentifierNamespace());
443
123k
  Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
444
123k
  if (!isa<CXXRecordDecl>(D))
445
18.5k
    Record.push_back(D->isCompleteDefinition());
446
123k
  Record.push_back(D->isEmbeddedInDeclarator());
447
123k
  Record.push_back(D->isFreeStanding());
448
123k
  Record.push_back(D->isCompleteDefinitionRequired());
449
123k
  Record.AddSourceRange(D->getBraceRange());
450
451
123k
  if (D->hasExtInfo()) {
452
1.27k
    Record.push_back(1);
453
1.27k
    Record.AddQualifierInfo(*D->getExtInfo());
454
122k
  } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
455
6.03k
    Record.push_back(2);
456
6.03k
    Record.AddDeclRef(TD);
457
6.03k
    Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
458
116k
  } else {
459
116k
    Record.push_back(0);
460
116k
  }
461
123k
}
462
463
10.3k
void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
464
10.3k
  static_assert(DeclContext::NumEnumDeclBits == 20,
465
10.3k
                "You need to update the serializer after you change the "
466
10.3k
                "EnumDeclBits");
467
468
10.3k
  VisitTagDecl(D);
469
10.3k
  Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
470
10.3k
  if (!D->getIntegerTypeSourceInfo())
471
6.66k
    Record.AddTypeRef(D->getIntegerType());
472
10.3k
  Record.AddTypeRef(D->getPromotionType());
473
10.3k
  Record.push_back(D->getNumPositiveBits());
474
10.3k
  Record.push_back(D->getNumNegativeBits());
475
10.3k
  Record.push_back(D->isScoped());
476
10.3k
  Record.push_back(D->isScopedUsingClassTag());
477
10.3k
  Record.push_back(D->isFixed());
478
10.3k
  Record.push_back(D->getODRHash());
479
480
10.3k
  if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
481
92
    Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
482
92
    Record.push_back(MemberInfo->getTemplateSpecializationKind());
483
92
    Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
484
10.3k
  } else {
485
10.3k
    Record.AddDeclRef(nullptr);
486
10.3k
  }
487
488
10.3k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
489
10.3k
      
!D->hasAttrs()9.65k
&&
490
10.3k
      
!D->isImplicit()6.69k
&&
491
10.3k
      
!D->isUsed(false)6.67k
&&
492
10.3k
      
!D->hasExtInfo()6.67k
&&
493
10.3k
      
!D->getTypedefNameForAnonDecl()6.67k
&&
494
10.3k
      
D->getFirstDecl() == D->getMostRecentDecl()6.32k
&&
495
10.3k
      
!D->isInvalidDecl()6.27k
&&
496
10.3k
      
!D->isReferenced()6.27k
&&
497
10.3k
      
!D->isTopLevelDeclInObjCContainer()6.11k
&&
498
10.3k
      
D->getAccess() == AS_none6.10k
&&
499
10.3k
      
!D->isModulePrivate()5.91k
&&
500
10.3k
      
!CXXRecordDecl::classofKind(D->getKind())5.91k
&&
501
10.3k
      
!D->getIntegerTypeSourceInfo()5.91k
&&
502
10.3k
      
!D->getMemberSpecializationInfo()5.90k
&&
503
10.3k
      
!needsAnonymousDeclarationNumber(D)5.90k
&&
504
10.3k
      
D->getDeclName().getNameKind() == DeclarationName::Identifier5.88k
)
505
5.88k
    AbbrevToUse = Writer.getDeclEnumAbbrev();
506
507
10.3k
  Code = serialization::DECL_ENUM;
508
10.3k
}
509
510
113k
void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
511
113k
  static_assert(DeclContext::NumRecordDeclBits == 41,
512
113k
                "You need to update the serializer after you change the "
513
113k
                "RecordDeclBits");
514
515
113k
  VisitTagDecl(D);
516
113k
  Record.push_back(D->hasFlexibleArrayMember());
517
113k
  Record.push_back(D->isAnonymousStructOrUnion());
518
113k
  Record.push_back(D->hasObjectMember());
519
113k
  Record.push_back(D->hasVolatileMember());
520
113k
  Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
521
113k
  Record.push_back(D->isNonTrivialToPrimitiveCopy());
522
113k
  Record.push_back(D->isNonTrivialToPrimitiveDestroy());
523
113k
  Record.push_back(D->hasNonTrivialToPrimitiveDefaultInitializeCUnion());
524
113k
  Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion());
525
113k
  Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion());
526
113k
  Record.push_back(D->isParamDestroyedInCallee());
527
113k
  Record.push_back(D->getArgPassingRestrictions());
528
  // Only compute this for C/Objective-C, in C++ this is computed as part
529
  // of CXXRecordDecl.
530
113k
  if (!isa<CXXRecordDecl>(D))
531
8.17k
    Record.push_back(D->getODRHash());
532
533
113k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
534
113k
      
!D->hasAttrs()110k
&&
535
113k
      
!D->isImplicit()62.4k
&&
536
113k
      
!D->isUsed(false)33.9k
&&
537
113k
      
!D->hasExtInfo()33.9k
&&
538
113k
      
!D->getTypedefNameForAnonDecl()33.0k
&&
539
113k
      
D->getFirstDecl() == D->getMostRecentDecl()31.7k
&&
540
113k
      
!D->isInvalidDecl()29.3k
&&
541
113k
      
!D->isReferenced()29.3k
&&
542
113k
      
!D->isTopLevelDeclInObjCContainer()26.6k
&&
543
113k
      
D->getAccess() == AS_none26.6k
&&
544
113k
      
!D->isModulePrivate()25.9k
&&
545
113k
      
!CXXRecordDecl::classofKind(D->getKind())25.9k
&&
546
113k
      
!needsAnonymousDeclarationNumber(D)2.94k
&&
547
113k
      
D->getDeclName().getNameKind() == DeclarationName::Identifier2.59k
)
548
2.59k
    AbbrevToUse = Writer.getDeclRecordAbbrev();
549
550
113k
  Code = serialization::DECL_RECORD;
551
113k
}
552
553
1.36M
void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
554
1.36M
  VisitNamedDecl(D);
555
1.36M
  Record.AddTypeRef(D->getType());
556
1.36M
}
557
558
75.7k
void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
559
75.7k
  VisitValueDecl(D);
560
75.7k
  Record.push_back(D->getInitExpr()? 
171.5k
:
04.22k
);
561
75.7k
  if (D->getInitExpr())
562
71.5k
    Record.AddStmt(D->getInitExpr());
563
75.7k
  Record.AddAPSInt(D->getInitVal());
564
565
75.7k
  Code = serialization::DECL_ENUM_CONSTANT;
566
75.7k
}
567
568
1.28M
void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
569
1.28M
  VisitValueDecl(D);
570
1.28M
  Record.AddSourceLocation(D->getInnerLocStart());
571
1.28M
  Record.push_back(D->hasExtInfo());
572
1.28M
  if (D->hasExtInfo()) {
573
6.13k
    DeclaratorDecl::ExtInfo *Info = D->getExtInfo();
574
6.13k
    Record.AddQualifierInfo(*Info);
575
6.13k
    Record.AddStmt(Info->TrailingRequiresClause);
576
6.13k
  }
577
  // The location information is deferred until the end of the record.
578
1.28M
  Record.AddTypeRef(D->getTypeSourceInfo() ? 
D->getTypeSourceInfo()->getType()986k
579
1.28M
                                           : 
QualType()300k
);
580
1.28M
}
581
582
261k
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
583
261k
  static_assert(DeclContext::NumFunctionDeclBits == 31,
584
261k
                "You need to update the serializer after you change the "
585
261k
                "FunctionDeclBits");
586
587
261k
  VisitRedeclarable(D);
588
589
261k
  Record.push_back(D->getTemplatedKind());
590
261k
  switch (D->getTemplatedKind()) {
591
224k
  case FunctionDecl::TK_NonTemplate:
592
224k
    break;
593
2
  case FunctionDecl::TK_DependentNonTemplate:
594
2
    Record.AddDeclRef(D->getInstantiatedFromDecl());
595
2
    break;
596
16.4k
  case FunctionDecl::TK_FunctionTemplate:
597
16.4k
    Record.AddDeclRef(D->getDescribedFunctionTemplate());
598
16.4k
    break;
599
16.0k
  case FunctionDecl::TK_MemberSpecialization: {
600
16.0k
    MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
601
16.0k
    Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
602
16.0k
    Record.push_back(MemberInfo->getTemplateSpecializationKind());
603
16.0k
    Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
604
16.0k
    break;
605
0
  }
606
4.63k
  case FunctionDecl::TK_FunctionTemplateSpecialization: {
607
4.63k
    FunctionTemplateSpecializationInfo *
608
4.63k
      FTSInfo = D->getTemplateSpecializationInfo();
609
610
4.63k
    RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
611
612
4.63k
    Record.AddDeclRef(FTSInfo->getTemplate());
613
4.63k
    Record.push_back(FTSInfo->getTemplateSpecializationKind());
614
615
    // Template arguments.
616
4.63k
    Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
617
618
    // Template args as written.
619
4.63k
    Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
620
4.63k
    if (FTSInfo->TemplateArgumentsAsWritten) {
621
193
      Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
622
193
      for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
623
310
             i!=e; 
++i117
)
624
117
        Record.AddTemplateArgumentLoc(
625
117
            (*FTSInfo->TemplateArgumentsAsWritten)[i]);
626
193
      Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
627
193
      Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
628
193
    }
629
630
4.63k
    Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
631
632
4.63k
    if (MemberSpecializationInfo *MemberInfo =
633
4.63k
        FTSInfo->getMemberSpecializationInfo()) {
634
12
      Record.push_back(1);
635
12
      Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
636
12
      Record.push_back(MemberInfo->getTemplateSpecializationKind());
637
12
      Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
638
4.61k
    } else {
639
4.61k
      Record.push_back(0);
640
4.61k
    }
641
642
4.63k
    if (D->isCanonicalDecl()) {
643
      // Write the template that contains the specializations set. We will
644
      // add a FunctionTemplateSpecializationInfo to it when reading.
645
4.42k
      Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
646
4.42k
    }
647
4.63k
    break;
648
0
  }
649
20
  case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
650
20
    DependentFunctionTemplateSpecializationInfo *
651
20
      DFTSInfo = D->getDependentSpecializationInfo();
652
653
    // Templates.
654
20
    Record.push_back(DFTSInfo->getNumTemplates());
655
145
    for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; 
++i125
)
656
125
      Record.AddDeclRef(DFTSInfo->getTemplate(i));
657
658
    // Templates args.
659
20
    Record.push_back(DFTSInfo->getNumTemplateArgs());
660
20
    for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; 
++i0
)
661
0
      Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
662
20
    Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
663
20
    Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
664
20
    break;
665
0
  }
666
261k
  }
667
668
261k
  VisitDeclaratorDecl(D);
669
261k
  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
670
261k
  Record.push_back(D->getIdentifierNamespace());
671
672
  // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
673
  // after everything else is written.
674
261k
  Record.push_back(
675
261k
      static_cast<int>(D->getStorageClass())); // FIXME: stable encoding
676
261k
  Record.push_back(D->isInlineSpecified());
677
261k
  Record.push_back(D->isInlined());
678
261k
  Record.push_back(D->isVirtualAsWritten());
679
261k
  Record.push_back(D->isPure());
680
261k
  Record.push_back(D->hasInheritedPrototype());
681
261k
  Record.push_back(D->hasWrittenPrototype());
682
261k
  Record.push_back(D->isDeletedBit());
683
261k
  Record.push_back(D->isTrivial());
684
261k
  Record.push_back(D->isTrivialForCall());
685
261k
  Record.push_back(D->isDefaulted());
686
261k
  Record.push_back(D->isExplicitlyDefaulted());
687
261k
  Record.push_back(D->isIneligibleOrNotSelected());
688
261k
  Record.push_back(D->hasImplicitReturnZero());
689
261k
  Record.push_back(static_cast<uint64_t>(D->getConstexprKind()));
690
261k
  Record.push_back(D->usesSEHTry());
691
261k
  Record.push_back(D->hasSkippedBody());
692
261k
  Record.push_back(D->isMultiVersion());
693
261k
  Record.push_back(D->isLateTemplateParsed());
694
261k
  Record.push_back(D->FriendConstraintRefersToEnclosingTemplate());
695
261k
  Record.push_back(D->getLinkageInternal());
696
261k
  Record.AddSourceLocation(D->getEndLoc());
697
261k
  Record.AddSourceLocation(D->getDefaultLoc());
698
699
261k
  Record.push_back(D->getODRHash());
700
701
261k
  if (D->isDefaulted()) {
702
14.1k
    if (auto *FDI = D->getDefaultedFunctionInfo()) {
703
6
      Record.push_back(FDI->getUnqualifiedLookups().size());
704
6
      for (DeclAccessPair P : FDI->getUnqualifiedLookups()) {
705
6
        Record.AddDeclRef(P.getDecl());
706
6
        Record.push_back(P.getAccess());
707
6
      }
708
14.1k
    } else {
709
14.1k
      Record.push_back(0);
710
14.1k
    }
711
14.1k
  }
712
713
261k
  Record.push_back(D->param_size());
714
261k
  for (auto *P : D->parameters())
715
439k
    Record.AddDeclRef(P);
716
261k
  Code = serialization::DECL_FUNCTION;
717
261k
}
718
719
static void addExplicitSpecifier(ExplicitSpecifier ES,
720
25.2k
                                 ASTRecordWriter &Record) {
721
25.2k
  uint64_t Kind = static_cast<uint64_t>(ES.getKind());
722
25.2k
  Kind = Kind << 1 | static_cast<bool>(ES.getExpr());
723
25.2k
  Record.push_back(Kind);
724
25.2k
  if (ES.getExpr()) {
725
24
    Record.AddStmt(ES.getExpr());
726
24
  }
727
25.2k
}
728
729
522
void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
730
522
  addExplicitSpecifier(D->getExplicitSpecifier(), Record);
731
522
  Record.AddDeclRef(D->Ctor);
732
522
  VisitFunctionDecl(D);
733
522
  Record.push_back(static_cast<unsigned char>(D->getDeductionCandidateKind()));
734
522
  Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
735
522
}
736
737
42.5k
void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
738
42.5k
  static_assert(DeclContext::NumObjCMethodDeclBits == 24,
739
42.5k
                "You need to update the serializer after you change the "
740
42.5k
                "ObjCMethodDeclBits");
741
742
42.5k
  VisitNamedDecl(D);
743
  // FIXME: convert to LazyStmtPtr?
744
  // Unlike C/C++, method bodies will never be in header files.
745
42.5k
  bool HasBodyStuff = D->getBody() != nullptr;
746
42.5k
  Record.push_back(HasBodyStuff);
747
42.5k
  if (HasBodyStuff) {
748
20
    Record.AddStmt(D->getBody());
749
20
  }
750
42.5k
  Record.AddDeclRef(D->getSelfDecl());
751
42.5k
  Record.AddDeclRef(D->getCmdDecl());
752
42.5k
  Record.push_back(D->isInstanceMethod());
753
42.5k
  Record.push_back(D->isVariadic());
754
42.5k
  Record.push_back(D->isPropertyAccessor());
755
42.5k
  Record.push_back(D->isSynthesizedAccessorStub());
756
42.5k
  Record.push_back(D->isDefined());
757
42.5k
  Record.push_back(D->isOverriding());
758
42.5k
  Record.push_back(D->hasSkippedBody());
759
760
42.5k
  Record.push_back(D->isRedeclaration());
761
42.5k
  Record.push_back(D->hasRedeclaration());
762
42.5k
  if (D->hasRedeclaration()) {
763
6
    assert(Context.getObjCMethodRedeclaration(D));
764
6
    Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
765
6
  }
766
767
  // FIXME: stable encoding for @required/@optional
768
42.5k
  Record.push_back(D->getImplementationControl());
769
  // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
770
42.5k
  Record.push_back(D->getObjCDeclQualifier());
771
42.5k
  Record.push_back(D->hasRelatedResultType());
772
42.5k
  Record.AddTypeRef(D->getReturnType());
773
42.5k
  Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
774
42.5k
  Record.AddSourceLocation(D->getEndLoc());
775
42.5k
  Record.push_back(D->param_size());
776
42.5k
  for (const auto *P : D->parameters())
777
37.2k
    Record.AddDeclRef(P);
778
779
42.5k
  Record.push_back(D->getSelLocsKind());
780
42.5k
  unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
781
42.5k
  SourceLocation *SelLocs = D->getStoredSelLocs();
782
42.5k
  Record.push_back(NumStoredSelLocs);
783
53.4k
  for (unsigned i = 0; i != NumStoredSelLocs; 
++i10.9k
)
784
10.9k
    Record.AddSourceLocation(SelLocs[i]);
785
786
42.5k
  Code = serialization::DECL_OBJC_METHOD;
787
42.5k
}
788
789
696
void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
790
696
  VisitTypedefNameDecl(D);
791
696
  Record.push_back(D->Variance);
792
696
  Record.push_back(D->Index);
793
696
  Record.AddSourceLocation(D->VarianceLoc);
794
696
  Record.AddSourceLocation(D->ColonLoc);
795
796
696
  Code = serialization::DECL_OBJC_TYPE_PARAM;
797
696
}
798
799
9.10k
void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
800
9.10k
  static_assert(DeclContext::NumObjCContainerDeclBits == 51,
801
9.10k
                "You need to update the serializer after you change the "
802
9.10k
                "ObjCContainerDeclBits");
803
804
9.10k
  VisitNamedDecl(D);
805
9.10k
  Record.AddSourceLocation(D->getAtStartLoc());
806
9.10k
  Record.AddSourceRange(D->getAtEndRange());
807
  // Abstract class (no need to define a stable serialization::DECL code).
808
9.10k
}
809
810
6.13k
void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
811
6.13k
  VisitRedeclarable(D);
812
6.13k
  VisitObjCContainerDecl(D);
813
6.13k
  Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
814
6.13k
  AddObjCTypeParamList(D->TypeParamList);
815
816
6.13k
  Record.push_back(D->isThisDeclarationADefinition());
817
6.13k
  if (D->isThisDeclarationADefinition()) {
818
    // Write the DefinitionData
819
2.40k
    ObjCInterfaceDecl::DefinitionData &Data = D->data();
820
821
2.40k
    Record.AddTypeSourceInfo(D->getSuperClassTInfo());
822
2.40k
    Record.AddSourceLocation(D->getEndOfDefinitionLoc());
823
2.40k
    Record.push_back(Data.HasDesignatedInitializers);
824
2.40k
    Record.push_back(D->getODRHash());
825
826
    // Write out the protocols that are directly referenced by the @interface.
827
2.40k
    Record.push_back(Data.ReferencedProtocols.size());
828
2.40k
    for (const auto *P : D->protocols())
829
1.36k
      Record.AddDeclRef(P);
830
2.40k
    for (const auto &PL : D->protocol_locs())
831
1.36k
      Record.AddSourceLocation(PL);
832
833
    // Write out the protocols that are transitively referenced.
834
2.40k
    Record.push_back(Data.AllReferencedProtocols.size());
835
2.40k
    for (ObjCList<ObjCProtocolDecl>::iterator
836
2.40k
              P = Data.AllReferencedProtocols.begin(),
837
2.40k
           PEnd = Data.AllReferencedProtocols.end();
838
2.42k
         P != PEnd; 
++P22
)
839
22
      Record.AddDeclRef(*P);
840
841
842
2.40k
    if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
843
      // Ensure that we write out the set of categories for this class.
844
435
      Writer.ObjCClassesWithCategories.insert(D);
845
846
      // Make sure that the categories get serialized.
847
1.43k
      for (; Cat; 
Cat = Cat->getNextClassCategoryRaw()1.00k
)
848
1.00k
        (void)Writer.GetDeclRef(Cat);
849
435
    }
850
2.40k
  }
851
852
6.13k
  Code = serialization::DECL_OBJC_INTERFACE;
853
6.13k
}
854
855
1.93k
void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
856
1.93k
  VisitFieldDecl(D);
857
  // FIXME: stable encoding for @public/@private/@protected/@package
858
1.93k
  Record.push_back(D->getAccessControl());
859
1.93k
  Record.push_back(D->getSynthesize());
860
861
1.93k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
862
1.93k
      !D->hasAttrs() &&
863
1.93k
      
!D->isImplicit()1.92k
&&
864
1.93k
      
!D->isUsed(false)1.92k
&&
865
1.93k
      
!D->isInvalidDecl()1.92k
&&
866
1.93k
      
!D->isReferenced()1.92k
&&
867
1.93k
      
!D->isModulePrivate()1.92k
&&
868
1.93k
      
!D->getBitWidth()1.92k
&&
869
1.93k
      
!D->hasExtInfo()1.84k
&&
870
1.93k
      
D->getDeclName()1.84k
)
871
1.84k
    AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
872
873
1.93k
  Code = serialization::DECL_OBJC_IVAR;
874
1.93k
}
875
876
1.65k
void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
877
1.65k
  VisitRedeclarable(D);
878
1.65k
  VisitObjCContainerDecl(D);
879
880
1.65k
  Record.push_back(D->isThisDeclarationADefinition());
881
1.65k
  if (D->isThisDeclarationADefinition()) {
882
1.12k
    Record.push_back(D->protocol_size());
883
1.12k
    for (const auto *I : D->protocols())
884
882
      Record.AddDeclRef(I);
885
1.12k
    for (const auto &PL : D->protocol_locs())
886
882
      Record.AddSourceLocation(PL);
887
1.12k
    Record.push_back(D->getODRHash());
888
1.12k
  }
889
890
1.65k
  Code = serialization::DECL_OBJC_PROTOCOL;
891
1.65k
}
892
893
0
void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
894
0
  VisitFieldDecl(D);
895
0
  Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
896
0
}
897
898
1.27k
void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
899
1.27k
  VisitObjCContainerDecl(D);
900
1.27k
  Record.AddSourceLocation(D->getCategoryNameLoc());
901
1.27k
  Record.AddSourceLocation(D->getIvarLBraceLoc());
902
1.27k
  Record.AddSourceLocation(D->getIvarRBraceLoc());
903
1.27k
  Record.AddDeclRef(D->getClassInterface());
904
1.27k
  AddObjCTypeParamList(D->TypeParamList);
905
1.27k
  Record.push_back(D->protocol_size());
906
1.27k
  for (const auto *I : D->protocols())
907
113
    Record.AddDeclRef(I);
908
1.27k
  for (const auto &PL : D->protocol_locs())
909
113
    Record.AddSourceLocation(PL);
910
1.27k
  Code = serialization::DECL_OBJC_CATEGORY;
911
1.27k
}
912
913
3
void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
914
3
  VisitNamedDecl(D);
915
3
  Record.AddDeclRef(D->getClassInterface());
916
3
  Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
917
3
}
918
919
14.4k
void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
920
14.4k
  VisitNamedDecl(D);
921
14.4k
  Record.AddSourceLocation(D->getAtLoc());
922
14.4k
  Record.AddSourceLocation(D->getLParenLoc());
923
14.4k
  Record.AddTypeRef(D->getType());
924
14.4k
  Record.AddTypeSourceInfo(D->getTypeSourceInfo());
925
  // FIXME: stable encoding
926
14.4k
  Record.push_back((unsigned)D->getPropertyAttributes());
927
14.4k
  Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
928
  // FIXME: stable encoding
929
14.4k
  Record.push_back((unsigned)D->getPropertyImplementation());
930
14.4k
  Record.AddDeclarationName(D->getGetterName());
931
14.4k
  Record.AddSourceLocation(D->getGetterNameLoc());
932
14.4k
  Record.AddDeclarationName(D->getSetterName());
933
14.4k
  Record.AddSourceLocation(D->getSetterNameLoc());
934
14.4k
  Record.AddDeclRef(D->getGetterMethodDecl());
935
14.4k
  Record.AddDeclRef(D->getSetterMethodDecl());
936
14.4k
  Record.AddDeclRef(D->getPropertyIvarDecl());
937
14.4k
  Code = serialization::DECL_OBJC_PROPERTY;
938
14.4k
}
939
940
42
void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
941
42
  VisitObjCContainerDecl(D);
942
42
  Record.AddDeclRef(D->getClassInterface());
943
  // Abstract class (no need to define a stable serialization::DECL code).
944
42
}
945
946
7
void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
947
7
  VisitObjCImplDecl(D);
948
7
  Record.AddSourceLocation(D->getCategoryNameLoc());
949
7
  Code = serialization::DECL_OBJC_CATEGORY_IMPL;
950
7
}
951
952
35
void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
953
35
  VisitObjCImplDecl(D);
954
35
  Record.AddDeclRef(D->getSuperClass());
955
35
  Record.AddSourceLocation(D->getSuperClassLoc());
956
35
  Record.AddSourceLocation(D->getIvarLBraceLoc());
957
35
  Record.AddSourceLocation(D->getIvarRBraceLoc());
958
35
  Record.push_back(D->hasNonZeroConstructors());
959
35
  Record.push_back(D->hasDestructors());
960
35
  Record.push_back(D->NumIvarInitializers);
961
35
  if (D->NumIvarInitializers)
962
3
    Record.AddCXXCtorInitializers(
963
3
        llvm::ArrayRef(D->init_begin(), D->init_end()));
964
35
  Code = serialization::DECL_OBJC_IMPLEMENTATION;
965
35
}
966
967
16
void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
968
16
  VisitDecl(D);
969
16
  Record.AddSourceLocation(D->getBeginLoc());
970
16
  Record.AddDeclRef(D->getPropertyDecl());
971
16
  Record.AddDeclRef(D->getPropertyIvarDecl());
972
16
  Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
973
16
  Record.AddDeclRef(D->getGetterMethodDecl());
974
16
  Record.AddDeclRef(D->getSetterMethodDecl());
975
16
  Record.AddStmt(D->getGetterCXXConstructor());
976
16
  Record.AddStmt(D->getSetterCXXAssignment());
977
16
  Code = serialization::DECL_OBJC_PROPERTY_IMPL;
978
16
}
979
980
141k
void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
981
141k
  VisitDeclaratorDecl(D);
982
141k
  Record.push_back(D->isMutable());
983
984
141k
  Record.push_back((D->StorageKind << 1) | D->BitField);
985
141k
  if (D->StorageKind == FieldDecl::ISK_CapturedVLAType)
986
3.83k
    Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
987
138k
  else if (D->BitField)
988
1.73k
    Record.AddStmt(D->getBitWidth());
989
990
141k
  if (!D->getDeclName())
991
46.0k
    Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
992
993
141k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
994
141k
      !D->hasAttrs() &&
995
141k
      
!D->isImplicit()111k
&&
996
141k
      
!D->isUsed(false)95.8k
&&
997
141k
      
!D->isInvalidDecl()95.8k
&&
998
141k
      
!D->isReferenced()95.8k
&&
999
141k
      
!D->isTopLevelDeclInObjCContainer()89.0k
&&
1000
141k
      
!D->isModulePrivate()89.0k
&&
1001
141k
      
!D->getBitWidth()89.0k
&&
1002
141k
      
!D->hasInClassInitializer()87.4k
&&
1003
141k
      
!D->hasCapturedVLAType()87.3k
&&
1004
141k
      
!D->hasExtInfo()87.3k
&&
1005
141k
      
!ObjCIvarDecl::classofKind(D->getKind())87.3k
&&
1006
141k
      
!ObjCAtDefsFieldDecl::classofKind(D->getKind())85.4k
&&
1007
141k
      
D->getDeclName()85.4k
)
1008
85.4k
    AbbrevToUse = Writer.getDeclFieldAbbrev();
1009
1010
141k
  Code = serialization::DECL_FIELD;
1011
141k
}
1012
1013
21
void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
1014
21
  VisitDeclaratorDecl(D);
1015
21
  Record.AddIdentifierRef(D->getGetterId());
1016
21
  Record.AddIdentifierRef(D->getSetterId());
1017
21
  Code = serialization::DECL_MS_PROPERTY;
1018
21
}
1019
1020
1
void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) {
1021
1
  VisitValueDecl(D);
1022
1
  MSGuidDecl::Parts Parts = D->getParts();
1023
1
  Record.push_back(Parts.Part1);
1024
1
  Record.push_back(Parts.Part2);
1025
1
  Record.push_back(Parts.Part3);
1026
1
  Record.append(std::begin(Parts.Part4And5), std::end(Parts.Part4And5));
1027
1
  Code = serialization::DECL_MS_GUID;
1028
1
}
1029
1030
void ASTDeclWriter::VisitUnnamedGlobalConstantDecl(
1031
0
    UnnamedGlobalConstantDecl *D) {
1032
0
  VisitValueDecl(D);
1033
0
  Record.AddAPValue(D->getValue());
1034
0
  Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT;
1035
0
}
1036
1037
2
void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) {
1038
2
  VisitValueDecl(D);
1039
2
  Record.AddAPValue(D->getValue());
1040
2
  Code = serialization::DECL_TEMPLATE_PARAM_OBJECT;
1041
2
}
1042
1043
337
void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
1044
337
  VisitValueDecl(D);
1045
337
  Record.push_back(D->getChainingSize());
1046
1047
337
  for (const auto *P : D->chain())
1048
714
    Record.AddDeclRef(P);
1049
337
  Code = serialization::DECL_INDIRECTFIELD;
1050
337
}
1051
1052
875k
void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
1053
875k
  VisitRedeclarable(D);
1054
875k
  VisitDeclaratorDecl(D);
1055
875k
  Record.push_back(D->getStorageClass());
1056
875k
  Record.push_back(D->getTSCSpec());
1057
875k
  Record.push_back(D->getInitStyle());
1058
875k
  Record.push_back(D->isARCPseudoStrong());
1059
875k
  bool HasDeducedType = false;
1060
875k
  if (!isa<ParmVarDecl>(D)) {
1061
356k
    Record.push_back(D->isThisDeclarationADemotedDefinition());
1062
356k
    Record.push_back(D->isExceptionVariable());
1063
356k
    Record.push_back(D->isNRVOVariable());
1064
356k
    Record.push_back(D->isCXXForRangeDecl());
1065
356k
    Record.push_back(D->isObjCForDecl());
1066
356k
    Record.push_back(D->isInline());
1067
356k
    Record.push_back(D->isInlineSpecified());
1068
356k
    Record.push_back(D->isConstexpr());
1069
356k
    Record.push_back(D->isInitCapture());
1070
356k
    Record.push_back(D->isPreviousDeclInSameBlockScope());
1071
356k
    if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
1072
217k
      Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
1073
139k
    else
1074
139k
      Record.push_back(0);
1075
356k
    Record.push_back(D->isEscapingByref());
1076
356k
    HasDeducedType = D->getType()->getContainedDeducedType();
1077
356k
    Record.push_back(HasDeducedType);
1078
356k
  }
1079
875k
  Record.push_back(D->getLinkageInternal());
1080
1081
875k
  if (D->hasAttr<BlocksAttr>()) {
1082
5
    BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
1083
5
    Record.AddStmt(Init.getCopyExpr());
1084
5
    if (Init.getCopyExpr())
1085
2
      Record.push_back(Init.canThrow());
1086
5
  }
1087
1088
875k
  bool ModulesCodegen = false;
1089
875k
  if (Writer.WritingModule && 
D->getStorageDuration() == SD_Static606k
&&
1090
875k
      
!D->getDescribedVarTemplate()25.1k
) {
1091
    // When building a C++20 module interface unit or a partition unit, a
1092
    // strong definition in the module interface is provided by the
1093
    // compilation of that unit, not by its users. (Inline variables are still
1094
    // emitted in module users.)
1095
24.9k
    ModulesCodegen =
1096
24.9k
        (Writer.WritingModule->isInterfaceOrPartition() ||
1097
24.9k
         
(24.7k
D->hasAttr<DLLExportAttr>()24.7k
&&
1098
24.7k
          
Writer.Context->getLangOpts().BuildingPCHWithObjectFile0
)) &&
1099
24.9k
         
Writer.Context->GetGVALinkageForVariable(D) >= GVA_StrongExternal200
;
1100
24.9k
  }
1101
875k
  Record.push_back(ModulesCodegen);
1102
875k
  if (ModulesCodegen)
1103
116
    Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
1104
1105
875k
  enum {
1106
875k
    VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1107
875k
  };
1108
875k
  if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
1109
339
    Record.push_back(VarTemplate);
1110
339
    Record.AddDeclRef(TemplD);
1111
874k
  } else if (MemberSpecializationInfo *SpecInfo
1112
874k
               = D->getMemberSpecializationInfo()) {
1113
2.99k
    Record.push_back(StaticDataMemberSpecialization);
1114
2.99k
    Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
1115
2.99k
    Record.push_back(SpecInfo->getTemplateSpecializationKind());
1116
2.99k
    Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
1117
871k
  } else {
1118
871k
    Record.push_back(VarNotTemplate);
1119
871k
  }
1120
1121
875k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
1122
875k
      
!D->hasAttrs()874k
&&
1123
875k
      
!D->isImplicit()825k
&&
1124
875k
      
!D->isUsed(false)563k
&&
1125
875k
      
!D->isInvalidDecl()404k
&&
1126
875k
      
!D->isReferenced()404k
&&
1127
875k
      
!D->isTopLevelDeclInObjCContainer()358k
&&
1128
875k
      
D->getAccess() == AS_none358k
&&
1129
875k
      
!D->isModulePrivate()355k
&&
1130
875k
      
!needsAnonymousDeclarationNumber(D)355k
&&
1131
875k
      
D->getDeclName().getNameKind() == DeclarationName::Identifier355k
&&
1132
875k
      
!D->hasExtInfo()355k
&&
1133
875k
      
D->getFirstDecl() == D->getMostRecentDecl()355k
&&
1134
875k
      
D->getKind() == Decl::Var355k
&&
1135
875k
      
!D->isInline()7.22k
&&
1136
875k
      
!D->isConstexpr()7.05k
&&
1137
875k
      
!D->isInitCapture()6.94k
&&
1138
875k
      
!D->isPreviousDeclInSameBlockScope()6.94k
&&
1139
875k
      
!D->isEscapingByref()6.94k
&&
1140
875k
      
!HasDeducedType6.94k
&&
1141
875k
      
D->getStorageDuration() != SD_Static6.84k
&&
1142
875k
      
!D->getDescribedVarTemplate()1.99k
&&
1143
875k
      
!D->getMemberSpecializationInfo()1.98k
)
1144
1.98k
    AbbrevToUse = Writer.getDeclVarAbbrev();
1145
1146
875k
  Code = serialization::DECL_VAR;
1147
875k
}
1148
1149
217k
void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
1150
217k
  VisitVarDecl(D);
1151
217k
  Code = serialization::DECL_IMPLICIT_PARAM;
1152
217k
}
1153
1154
518k
void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
1155
518k
  VisitVarDecl(D);
1156
518k
  Record.push_back(D->isObjCMethodParameter());
1157
518k
  Record.push_back(D->getFunctionScopeDepth());
1158
518k
  Record.push_back(D->getFunctionScopeIndex());
1159
518k
  Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
1160
518k
  Record.push_back(D->isKNRPromoted());
1161
518k
  Record.push_back(D->hasInheritedDefaultArg());
1162
518k
  Record.push_back(D->hasUninstantiatedDefaultArg());
1163
518k
  if (D->hasUninstantiatedDefaultArg())
1164
1.76k
    Record.AddStmt(D->getUninstantiatedDefaultArg());
1165
518k
  Code = serialization::DECL_PARM_VAR;
1166
1167
  // If the assumptions about the DECL_PARM_VAR abbrev are true, use it.  Here
1168
  // we dynamically check for the properties that we optimize for, but don't
1169
  // know are true of all PARM_VAR_DECLs.
1170
518k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
1171
518k
      !D->hasAttrs() &&
1172
518k
      
!D->hasExtInfo()504k
&&
1173
518k
      
!D->isImplicit()504k
&&
1174
518k
      
!D->isUsed(false)504k
&&
1175
518k
      
!D->isInvalidDecl()376k
&&
1176
518k
      
!D->isReferenced()376k
&&
1177
518k
      
D->getAccess() == AS_none348k
&&
1178
518k
      
!D->isModulePrivate()348k
&&
1179
518k
      
D->getStorageClass() == 0348k
&&
1180
518k
      
D->getInitStyle() == VarDecl::CInit348k
&& // Can params have anything else?
1181
518k
      
D->getFunctionScopeDepth() == 0348k
&&
1182
518k
      
D->getObjCDeclQualifier() == 0345k
&&
1183
518k
      
!D->isKNRPromoted()333k
&&
1184
518k
      
!D->hasInheritedDefaultArg()333k
&&
1185
518k
      
D->getInit() == nullptr333k
&&
1186
518k
      
!D->hasUninstantiatedDefaultArg()332k
) // No default expr.
1187
330k
    AbbrevToUse = Writer.getDeclParmVarAbbrev();
1188
1189
  // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1190
  // just us assuming it.
1191
518k
  assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
1192
518k
  assert(!D->isThisDeclarationADemotedDefinition()
1193
518k
         && "PARM_VAR_DECL can't be demoted definition.");
1194
518k
  assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
1195
518k
  assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
1196
518k
  assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
1197
518k
  assert(!D->isStaticDataMember() &&
1198
518k
         "PARM_VAR_DECL can't be static data member");
1199
518k
}
1200
1201
9
void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
1202
  // Record the number of bindings first to simplify deserialization.
1203
9
  Record.push_back(D->bindings().size());
1204
1205
9
  VisitVarDecl(D);
1206
9
  for (auto *B : D->bindings())
1207
16
    Record.AddDeclRef(B);
1208
9
  Code = serialization::DECL_DECOMPOSITION;
1209
9
}
1210
1211
16
void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
1212
16
  VisitValueDecl(D);
1213
16
  Record.AddStmt(D->getBinding());
1214
16
  Code = serialization::DECL_BINDING;
1215
16
}
1216
1217
61
void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
1218
61
  VisitDecl(D);
1219
61
  Record.AddStmt(D->getAsmString());
1220
61
  Record.AddSourceLocation(D->getRParenLoc());
1221
61
  Code = serialization::DECL_FILE_SCOPE_ASM;
1222
61
}
1223
1224
1
void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
1225
1
  VisitDecl(D);
1226
1
  Record.AddStmt(D->getStmt());
1227
1
  Code = serialization::DECL_TOP_LEVEL_STMT_DECL;
1228
1
}
1229
1230
197
void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1231
197
  VisitDecl(D);
1232
197
  Code = serialization::DECL_EMPTY;
1233
197
}
1234
1235
void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(
1236
19
    LifetimeExtendedTemporaryDecl *D) {
1237
19
  VisitDecl(D);
1238
19
  Record.AddDeclRef(D->getExtendingDecl());
1239
19
  Record.AddStmt(D->getTemporaryExpr());
1240
19
  Record.push_back(static_cast<bool>(D->getValue()));
1241
19
  if (D->getValue())
1242
6
    Record.AddAPValue(*D->getValue());
1243
19
  Record.push_back(D->getManglingNumber());
1244
19
  Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY;
1245
19
}
1246
22
void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
1247
22
  VisitDecl(D);
1248
22
  Record.AddStmt(D->getBody());
1249
22
  Record.AddTypeSourceInfo(D->getSignatureAsWritten());
1250
22
  Record.push_back(D->param_size());
1251
22
  for (ParmVarDecl *P : D->parameters())
1252
15
    Record.AddDeclRef(P);
1253
22
  Record.push_back(D->isVariadic());
1254
22
  Record.push_back(D->blockMissingReturnType());
1255
22
  Record.push_back(D->isConversionFromLambda());
1256
22
  Record.push_back(D->doesNotEscape());
1257
22
  Record.push_back(D->canAvoidCopyToHeap());
1258
22
  Record.push_back(D->capturesCXXThis());
1259
22
  Record.push_back(D->getNumCaptures());
1260
22
  for (const auto &capture : D->captures()) {
1261
11
    Record.AddDeclRef(capture.getVariable());
1262
1263
11
    unsigned flags = 0;
1264
11
    if (capture.isByRef()) 
flags |= 14
;
1265
11
    if (capture.isNested()) 
flags |= 20
;
1266
11
    if (capture.hasCopyExpr()) 
flags |= 42
;
1267
11
    Record.push_back(flags);
1268
1269
11
    if (capture.hasCopyExpr()) 
Record.AddStmt(capture.getCopyExpr())2
;
1270
11
  }
1271
1272
22
  Code = serialization::DECL_BLOCK;
1273
22
}
1274
1275
37.4k
void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1276
37.4k
  Record.push_back(CD->getNumParams());
1277
37.4k
  VisitDecl(CD);
1278
37.4k
  Record.push_back(CD->getContextParamPosition());
1279
37.4k
  Record.push_back(CD->isNothrow() ? 
135.6k
:
01.80k
);
1280
  // Body is stored by VisitCapturedStmt.
1281
169k
  for (unsigned I = 0; I < CD->getNumParams(); 
++I132k
)
1282
132k
    Record.AddDeclRef(CD->getParam(I));
1283
37.4k
  Code = serialization::DECL_CAPTURED;
1284
37.4k
}
1285
1286
15.5k
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1287
15.5k
  static_assert(DeclContext::NumLinkageSpecDeclBits == 4,
1288
15.5k
                "You need to update the serializer after you change the"
1289
15.5k
                "LinkageSpecDeclBits");
1290
1291
15.5k
  VisitDecl(D);
1292
15.5k
  Record.push_back(D->getLanguage());
1293
15.5k
  Record.AddSourceLocation(D->getExternLoc());
1294
15.5k
  Record.AddSourceLocation(D->getRBraceLoc());
1295
15.5k
  Code = serialization::DECL_LINKAGE_SPEC;
1296
15.5k
}
1297
1298
293
void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
1299
293
  VisitDecl(D);
1300
293
  Record.AddSourceLocation(D->getRBraceLoc());
1301
293
  Code = serialization::DECL_EXPORT;
1302
293
}
1303
1304
44
void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1305
44
  VisitNamedDecl(D);
1306
44
  Record.AddSourceLocation(D->getBeginLoc());
1307
44
  Code = serialization::DECL_LABEL;
1308
44
}
1309
1310
1311
4.83k
void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
1312
4.83k
  VisitRedeclarable(D);
1313
4.83k
  VisitNamedDecl(D);
1314
4.83k
  Record.push_back(D->isInline());
1315
4.83k
  Record.push_back(D->isNested());
1316
4.83k
  Record.AddSourceLocation(D->getBeginLoc());
1317
4.83k
  Record.AddSourceLocation(D->getRBraceLoc());
1318
1319
4.83k
  if (D->isOriginalNamespace())
1320
2.15k
    Record.AddDeclRef(D->getAnonymousNamespace());
1321
4.83k
  Code = serialization::DECL_NAMESPACE;
1322
1323
4.83k
  if (Writer.hasChain() && 
D->isAnonymousNamespace()4.59k
&&
1324
4.83k
      
D == D->getMostRecentDecl()23
) {
1325
    // This is a most recent reopening of the anonymous namespace. If its parent
1326
    // is in a previous PCH (or is the TU), mark that parent for update, because
1327
    // the original namespace always points to the latest re-opening of its
1328
    // anonymous namespace.
1329
21
    Decl *Parent = cast<Decl>(
1330
21
        D->getParent()->getRedeclContext()->getPrimaryContext());
1331
21
    if (Parent->isFromASTFile() || 
isa<TranslationUnitDecl>(Parent)12
) {
1332
15
      Writer.DeclUpdates[Parent].push_back(
1333
15
          ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
1334
15
    }
1335
21
  }
1336
4.83k
}
1337
1338
12
void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1339
12
  VisitRedeclarable(D);
1340
12
  VisitNamedDecl(D);
1341
12
  Record.AddSourceLocation(D->getNamespaceLoc());
1342
12
  Record.AddSourceLocation(D->getTargetNameLoc());
1343
12
  Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1344
12
  Record.AddDeclRef(D->getNamespace());
1345
12
  Code = serialization::DECL_NAMESPACE_ALIAS;
1346
12
}
1347
1348
2.26k
void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
1349
2.26k
  VisitNamedDecl(D);
1350
2.26k
  Record.AddSourceLocation(D->getUsingLoc());
1351
2.26k
  Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1352
2.26k
  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1353
2.26k
  Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1354
2.26k
  Record.push_back(D->hasTypename());
1355
2.26k
  Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
1356
2.26k
  Code = serialization::DECL_USING;
1357
2.26k
}
1358
1359
1
void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) {
1360
1
  VisitNamedDecl(D);
1361
1
  Record.AddSourceLocation(D->getUsingLoc());
1362
1
  Record.AddSourceLocation(D->getEnumLoc());
1363
1
  Record.AddTypeSourceInfo(D->getEnumType());
1364
1
  Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1365
1
  Record.AddDeclRef(Context.getInstantiatedFromUsingEnumDecl(D));
1366
1
  Code = serialization::DECL_USING_ENUM;
1367
1
}
1368
1369
10
void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1370
10
  Record.push_back(D->NumExpansions);
1371
10
  VisitNamedDecl(D);
1372
10
  Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1373
10
  for (auto *E : D->expansions())
1374
22
    Record.AddDeclRef(E);
1375
10
  Code = serialization::DECL_USING_PACK;
1376
10
}
1377
1378
4.81k
void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1379
4.81k
  VisitRedeclarable(D);
1380
4.81k
  VisitNamedDecl(D);
1381
4.81k
  Record.AddDeclRef(D->getTargetDecl());
1382
4.81k
  Record.push_back(D->getIdentifierNamespace());
1383
4.81k
  Record.AddDeclRef(D->UsingOrNextShadow);
1384
4.81k
  Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
1385
4.81k
  Code = serialization::DECL_USING_SHADOW;
1386
4.81k
}
1387
1388
void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1389
54
    ConstructorUsingShadowDecl *D) {
1390
54
  VisitUsingShadowDecl(D);
1391
54
  Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1392
54
  Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1393
54
  Record.push_back(D->IsVirtual);
1394
54
  Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
1395
54
}
1396
1397
82
void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1398
82
  VisitNamedDecl(D);
1399
82
  Record.AddSourceLocation(D->getUsingLoc());
1400
82
  Record.AddSourceLocation(D->getNamespaceKeyLocation());
1401
82
  Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1402
82
  Record.AddDeclRef(D->getNominatedNamespace());
1403
82
  Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
1404
82
  Code = serialization::DECL_USING_DIRECTIVE;
1405
82
}
1406
1407
131
void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1408
131
  VisitValueDecl(D);
1409
131
  Record.AddSourceLocation(D->getUsingLoc());
1410
131
  Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1411
131
  Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1412
131
  Record.AddSourceLocation(D->getEllipsisLoc());
1413
131
  Code = serialization::DECL_UNRESOLVED_USING_VALUE;
1414
131
}
1415
1416
void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
1417
78
                                               UnresolvedUsingTypenameDecl *D) {
1418
78
  VisitTypeDecl(D);
1419
78
  Record.AddSourceLocation(D->getTypenameLoc());
1420
78
  Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1421
78
  Record.AddSourceLocation(D->getEllipsisLoc());
1422
78
  Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
1423
78
}
1424
1425
void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl(
1426
6
    UnresolvedUsingIfExistsDecl *D) {
1427
6
  VisitNamedDecl(D);
1428
6
  Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS;
1429
6
}
1430
1431
104k
void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
1432
104k
  VisitRecordDecl(D);
1433
1434
104k
  enum {
1435
104k
    CXXRecNotTemplate = 0,
1436
104k
    CXXRecTemplate,
1437
104k
    CXXRecMemberSpecialization,
1438
104k
    CXXLambda
1439
104k
  };
1440
104k
  if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1441
10.7k
    Record.push_back(CXXRecTemplate);
1442
10.7k
    Record.AddDeclRef(TemplD);
1443
94.2k
  } else if (MemberSpecializationInfo *MSInfo
1444
94.2k
               = D->getMemberSpecializationInfo()) {
1445
397
    Record.push_back(CXXRecMemberSpecialization);
1446
397
    Record.AddDeclRef(MSInfo->getInstantiatedFrom());
1447
397
    Record.push_back(MSInfo->getTemplateSpecializationKind());
1448
397
    Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
1449
93.8k
  } else if (D->isLambda()) {
1450
    // For a lambda, we need some information early for merging.
1451
768
    Record.push_back(CXXLambda);
1452
768
    if (auto *Context = D->getLambdaContextDecl()) {
1453
32
      Record.AddDeclRef(Context);
1454
32
      Record.push_back(D->getLambdaIndexInContext());
1455
736
    } else {
1456
736
      Record.push_back(0);
1457
736
    }
1458
93.1k
  } else {
1459
93.1k
    Record.push_back(CXXRecNotTemplate);
1460
93.1k
  }
1461
1462
104k
  Record.push_back(D->isThisDeclarationADefinition());
1463
104k
  if (D->isThisDeclarationADefinition())
1464
69.6k
    Record.AddCXXDefinitionData(D);
1465
1466
  // Store (what we currently believe to be) the key function to avoid
1467
  // deserializing every method so we can compute it.
1468
104k
  if (D->isCompleteDefinition())
1469
69.6k
    Record.AddDeclRef(Context.getCurrentKeyFunction(D));
1470
1471
104k
  Code = serialization::DECL_CXX_RECORD;
1472
104k
}
1473
1474
69.3k
void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
1475
69.3k
  VisitFunctionDecl(D);
1476
69.3k
  if (D->isCanonicalDecl()) {
1477
64.3k
    Record.push_back(D->size_overridden_methods());
1478
64.3k
    for (const CXXMethodDecl *MD : D->overridden_methods())
1479
983
      Record.AddDeclRef(MD);
1480
64.3k
  } else {
1481
    // We only need to record overridden methods once for the canonical decl.
1482
4.96k
    Record.push_back(0);
1483
4.96k
  }
1484
1485
69.3k
  if (D->getDeclContext() == D->getLexicalDeclContext() &&
1486
69.3k
      
D->getFirstDecl() == D->getMostRecentDecl()64.4k
&&
!D->isInvalidDecl()59.3k
&&
1487
69.3k
      
!D->hasAttrs()59.3k
&&
!D->isTopLevelDeclInObjCContainer()33.6k
&&
1488
69.3k
      
D->getDeclName().getNameKind() == DeclarationName::Identifier33.6k
&&
1489
69.3k
      
!D->hasExtInfo()7.94k
&&
!D->hasInheritedPrototype()7.90k
&&
1490
69.3k
      
D->hasWrittenPrototype()7.90k
&&
1491
69.3k
      
D->getTemplatedKind() == FunctionDecl::TK_NonTemplate7.90k
)
1492
3.63k
    AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1493
1494
69.3k
  Code = serialization::DECL_CXX_METHOD;
1495
69.3k
}
1496
1497
23.4k
void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
1498
23.4k
  static_assert(DeclContext::NumCXXConstructorDeclBits == 20,
1499
23.4k
                "You need to update the serializer after you change the "
1500
23.4k
                "CXXConstructorDeclBits");
1501
1502
23.4k
  Record.push_back(D->getTrailingAllocKind());
1503
23.4k
  addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1504
23.4k
  if (auto Inherited = D->getInheritedConstructor()) {
1505
3
    Record.AddDeclRef(Inherited.getShadowDecl());
1506
3
    Record.AddDeclRef(Inherited.getConstructor());
1507
3
  }
1508
1509
23.4k
  VisitCXXMethodDecl(D);
1510
23.4k
  Code = serialization::DECL_CXX_CONSTRUCTOR;
1511
23.4k
}
1512
1513
5.72k
void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
1514
5.72k
  VisitCXXMethodDecl(D);
1515
1516
5.72k
  Record.AddDeclRef(D->getOperatorDelete());
1517
5.72k
  if (D->getOperatorDelete())
1518
36
    Record.AddStmt(D->getOperatorDeleteThisArg());
1519
1520
5.72k
  Code = serialization::DECL_CXX_DESTRUCTOR;
1521
5.72k
}
1522
1523
1.28k
void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
1524
1.28k
  addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1525
1.28k
  VisitCXXMethodDecl(D);
1526
1.28k
  Code = serialization::DECL_CXX_CONVERSION;
1527
1.28k
}
1528
1529
42.1k
void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1530
42.1k
  VisitDecl(D);
1531
42.1k
  Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
1532
42.1k
  ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1533
42.1k
  Record.push_back(!IdentifierLocs.empty());
1534
42.1k
  if (IdentifierLocs.empty()) {
1535
41.7k
    Record.AddSourceLocation(D->getEndLoc());
1536
41.7k
    Record.push_back(1);
1537
41.7k
  } else {
1538
719
    for (unsigned I = 0, N = IdentifierLocs.size(); I != N; 
++I368
)
1539
368
      Record.AddSourceLocation(IdentifierLocs[I]);
1540
351
    Record.push_back(IdentifierLocs.size());
1541
351
  }
1542
  // Note: the number of source locations must always be the last element in
1543
  // the record.
1544
42.1k
  Code = serialization::DECL_IMPORT;
1545
42.1k
}
1546
1547
6.63k
void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
1548
6.63k
  VisitDecl(D);
1549
6.63k
  Record.AddSourceLocation(D->getColonLoc());
1550
6.63k
  Code = serialization::DECL_ACCESS_SPEC;
1551
6.63k
}
1552
1553
2.65k
void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
1554
  // Record the number of friend type template parameter lists here
1555
  // so as to simplify memory allocation during deserialization.
1556
2.65k
  Record.push_back(D->NumTPLists);
1557
2.65k
  VisitDecl(D);
1558
2.65k
  bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1559
2.65k
  Record.push_back(hasFriendDecl);
1560
2.65k
  if (hasFriendDecl)
1561
2.41k
    Record.AddDeclRef(D->getFriendDecl());
1562
243
  else
1563
243
    Record.AddTypeSourceInfo(D->getFriendType());
1564
2.65k
  for (unsigned i = 0; i < D->NumTPLists; 
++i0
)
1565
0
    Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1566
2.65k
  Record.AddDeclRef(D->getNextFriend());
1567
2.65k
  Record.push_back(D->UnsupportedFriend);
1568
2.65k
  Record.AddSourceLocation(D->FriendLoc);
1569
2.65k
  Code = serialization::DECL_FRIEND;
1570
2.65k
}
1571
1572
0
void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
1573
0
  VisitDecl(D);
1574
0
  Record.push_back(D->getNumTemplateParameters());
1575
0
  for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1576
0
    Record.AddTemplateParameterList(D->getTemplateParameterList(i));
1577
0
  Record.push_back(D->getFriendDecl() != nullptr);
1578
0
  if (D->getFriendDecl())
1579
0
    Record.AddDeclRef(D->getFriendDecl());
1580
0
  else
1581
0
    Record.AddTypeSourceInfo(D->getFriendType());
1582
0
  Record.AddSourceLocation(D->getFriendLoc());
1583
0
  Code = serialization::DECL_FRIEND_TEMPLATE;
1584
0
}
1585
1586
24.4k
void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
1587
24.4k
  VisitNamedDecl(D);
1588
1589
24.4k
  Record.AddTemplateParameterList(D->getTemplateParameters());
1590
24.4k
  Record.AddDeclRef(D->getTemplatedDecl());
1591
24.4k
}
1592
1593
58
void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) {
1594
58
  VisitTemplateDecl(D);
1595
58
  Record.AddStmt(D->getConstraintExpr());
1596
58
  Code = serialization::DECL_CONCEPT;
1597
58
}
1598
1599
void ASTDeclWriter::VisitImplicitConceptSpecializationDecl(
1600
73
    ImplicitConceptSpecializationDecl *D) {
1601
73
  Record.push_back(D->getTemplateArguments().size());
1602
73
  VisitDecl(D);
1603
73
  for (const TemplateArgument &Arg : D->getTemplateArguments())
1604
110
    Record.AddTemplateArgument(Arg);
1605
73
  Code = serialization::DECL_IMPLICIT_CONCEPT_SPECIALIZATION;
1606
73
}
1607
1608
24
void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
1609
24
  Code = serialization::DECL_REQUIRES_EXPR_BODY;
1610
24
}
1611
1612
23.9k
void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
1613
23.9k
  VisitRedeclarable(D);
1614
1615
  // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1616
  // getCommonPtr() can be used while this is still initializing.
1617
23.9k
  if (D->isFirstDecl()) {
1618
    // This declaration owns the 'common' pointer, so serialize that data now.
1619
21.3k
    Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
1620
21.3k
    if (D->getInstantiatedFromMemberTemplate())
1621
4.29k
      Record.push_back(D->isMemberSpecialization());
1622
21.3k
  }
1623
1624
23.9k
  VisitTemplateDecl(D);
1625
23.9k
  Record.push_back(D->getIdentifierNamespace());
1626
23.9k
}
1627
1628
6.20k
void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1629
6.20k
  VisitRedeclarableTemplateDecl(D);
1630
1631
6.20k
  if (D->isFirstDecl())
1632
5.47k
    AddTemplateSpecializations(D);
1633
6.20k
  Code = serialization::DECL_CLASS_TEMPLATE;
1634
6.20k
}
1635
1636
void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
1637
16.1k
                                           ClassTemplateSpecializationDecl *D) {
1638
16.1k
  RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1639
1640
16.1k
  VisitCXXRecordDecl(D);
1641
1642
16.1k
  llvm::PointerUnion<ClassTemplateDecl *,
1643
16.1k
                     ClassTemplatePartialSpecializationDecl *> InstFrom
1644
16.1k
    = D->getSpecializedTemplateOrPartial();
1645
16.1k
  if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
1646
14.1k
    Record.AddDeclRef(InstFromD);
1647
14.1k
  } else {
1648
2.06k
    Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1649
2.06k
    Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1650
2.06k
  }
1651
1652
16.1k
  Record.AddTemplateArgumentList(&D->getTemplateArgs());
1653
16.1k
  Record.AddSourceLocation(D->getPointOfInstantiation());
1654
16.1k
  Record.push_back(D->getSpecializationKind());
1655
16.1k
  Record.push_back(D->isCanonicalDecl());
1656
1657
16.1k
  if (D->isCanonicalDecl()) {
1658
    // When reading, we'll add it to the folding set of the following template.
1659
16.1k
    Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1660
16.1k
  }
1661
1662
  // Explicit info.
1663
16.1k
  Record.AddTypeSourceInfo(D->getTypeAsWritten());
1664
16.1k
  if (D->getTypeAsWritten()) {
1665
3.11k
    Record.AddSourceLocation(D->getExternLoc());
1666
3.11k
    Record.AddSourceLocation(D->getTemplateKeywordLoc());
1667
3.11k
  }
1668
1669
16.1k
  Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
1670
16.1k
}
1671
1672
void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
1673
1.71k
                                    ClassTemplatePartialSpecializationDecl *D) {
1674
1.71k
  Record.AddTemplateParameterList(D->getTemplateParameters());
1675
1.71k
  Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
1676
1677
1.71k
  VisitClassTemplateSpecializationDecl(D);
1678
1679
  // These are read/set from/to the first declaration.
1680
1.71k
  if (D->getPreviousDecl() == nullptr) {
1681
1.68k
    Record.AddDeclRef(D->getInstantiatedFromMember());
1682
1.68k
    Record.push_back(D->isMemberSpecialization());
1683
1.68k
  }
1684
1685
1.71k
  Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
1686
1.71k
}
1687
1688
339
void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1689
339
  VisitRedeclarableTemplateDecl(D);
1690
1691
339
  if (D->isFirstDecl())
1692
306
    AddTemplateSpecializations(D);
1693
339
  Code = serialization::DECL_VAR_TEMPLATE;
1694
339
}
1695
1696
void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1697
218
    VarTemplateSpecializationDecl *D) {
1698
218
  RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1699
1700
218
  llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1701
218
  InstFrom = D->getSpecializedTemplateOrPartial();
1702
218
  if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1703
216
    Record.AddDeclRef(InstFromD);
1704
216
  } else {
1705
2
    Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1706
2
    Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1707
2
  }
1708
1709
  // Explicit info.
1710
218
  Record.AddTypeSourceInfo(D->getTypeAsWritten());
1711
218
  if (D->getTypeAsWritten()) {
1712
9
    Record.AddSourceLocation(D->getExternLoc());
1713
9
    Record.AddSourceLocation(D->getTemplateKeywordLoc());
1714
9
  }
1715
1716
218
  Record.AddTemplateArgumentList(&D->getTemplateArgs());
1717
218
  Record.AddSourceLocation(D->getPointOfInstantiation());
1718
218
  Record.push_back(D->getSpecializationKind());
1719
218
  Record.push_back(D->IsCompleteDefinition);
1720
1721
218
  VisitVarDecl(D);
1722
1723
218
  Record.push_back(D->isCanonicalDecl());
1724
1725
218
  if (D->isCanonicalDecl()) {
1726
    // When reading, we'll add it to the folding set of the following template.
1727
186
    Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1728
186
  }
1729
1730
218
  Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1731
218
}
1732
1733
void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1734
48
    VarTemplatePartialSpecializationDecl *D) {
1735
48
  Record.AddTemplateParameterList(D->getTemplateParameters());
1736
48
  Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
1737
1738
48
  VisitVarTemplateSpecializationDecl(D);
1739
1740
  // These are read/set from/to the first declaration.
1741
48
  if (D->getPreviousDecl() == nullptr) {
1742
37
    Record.AddDeclRef(D->getInstantiatedFromMember());
1743
37
    Record.push_back(D->isMemberSpecialization());
1744
37
  }
1745
1746
48
  Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1747
48
}
1748
1749
void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1750
8
                                    ClassScopeFunctionSpecializationDecl *D) {
1751
8
  VisitDecl(D);
1752
8
  Record.AddDeclRef(D->getSpecialization());
1753
8
  Record.push_back(D->hasExplicitTemplateArgs());
1754
8
  if (D->hasExplicitTemplateArgs())
1755
4
    Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
1756
8
  Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1757
8
}
1758
1759
1760
16.4k
void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1761
16.4k
  VisitRedeclarableTemplateDecl(D);
1762
1763
16.4k
  if (D->isFirstDecl())
1764
14.5k
    AddTemplateSpecializations(D);
1765
16.4k
  Code = serialization::DECL_FUNCTION_TEMPLATE;
1766
16.4k
}
1767
1768
46.4k
void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
1769
46.4k
  Record.push_back(D->hasTypeConstraint());
1770
46.4k
  VisitTypeDecl(D);
1771
1772
46.4k
  Record.push_back(D->wasDeclaredWithTypename());
1773
1774
46.4k
  const TypeConstraint *TC = D->getTypeConstraint();
1775
46.4k
  Record.push_back(TC != nullptr);
1776
46.4k
  if (TC) {
1777
41
    auto *CR = TC->getConceptReference();
1778
41
    Record.push_back(CR != nullptr);
1779
41
    if (CR)
1780
41
      Record.AddConceptReference(CR);
1781
41
    Record.AddStmt(TC->getImmediatelyDeclaredConstraint());
1782
41
    Record.push_back(D->isExpandedParameterPack());
1783
41
    if (D->isExpandedParameterPack())
1784
0
      Record.push_back(D->getNumExpansionParameters());
1785
41
  }
1786
1787
46.4k
  bool OwnsDefaultArg = D->hasDefaultArgument() &&
1788
46.4k
                        
!D->defaultArgumentWasInherited()2.85k
;
1789
46.4k
  Record.push_back(OwnsDefaultArg);
1790
46.4k
  if (OwnsDefaultArg)
1791
2.59k
    Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
1792
1793
46.4k
  Code = serialization::DECL_TEMPLATE_TYPE_PARM;
1794
46.4k
}
1795
1796
8.25k
void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
1797
  // For an expanded parameter pack, record the number of expansion types here
1798
  // so that it's easier for deserialization to allocate the right amount of
1799
  // memory.
1800
8.25k
  Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1801
8.25k
  Record.push_back(!!TypeConstraint);
1802
8.25k
  if (D->isExpandedParameterPack())
1803
2
    Record.push_back(D->getNumExpansionTypes());
1804
1805
8.25k
  VisitDeclaratorDecl(D);
1806
  // TemplateParmPosition.
1807
8.25k
  Record.push_back(D->getDepth());
1808
8.25k
  Record.push_back(D->getPosition());
1809
8.25k
  if (TypeConstraint)
1810
0
    Record.AddStmt(TypeConstraint);
1811
1812
8.25k
  if (D->isExpandedParameterPack()) {
1813
6
    for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; 
++I4
) {
1814
4
      Record.AddTypeRef(D->getExpansionType(I));
1815
4
      Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
1816
4
    }
1817
1818
2
    Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1819
8.25k
  } else {
1820
    // Rest of NonTypeTemplateParmDecl.
1821
8.25k
    Record.push_back(D->isParameterPack());
1822
8.25k
    bool OwnsDefaultArg = D->hasDefaultArgument() &&
1823
8.25k
                          
!D->defaultArgumentWasInherited()2.47k
;
1824
8.25k
    Record.push_back(OwnsDefaultArg);
1825
8.25k
    if (OwnsDefaultArg)
1826
2.35k
      Record.AddStmt(D->getDefaultArgument());
1827
8.25k
    Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
1828
8.25k
  }
1829
8.25k
}
1830
1831
485
void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
1832
  // For an expanded parameter pack, record the number of expansion types here
1833
  // so that it's easier for deserialization to allocate the right amount of
1834
  // memory.
1835
485
  if (D->isExpandedParameterPack())
1836
2
    Record.push_back(D->getNumExpansionTemplateParameters());
1837
1838
485
  VisitTemplateDecl(D);
1839
  // TemplateParmPosition.
1840
485
  Record.push_back(D->getDepth());
1841
485
  Record.push_back(D->getPosition());
1842
1843
485
  if (D->isExpandedParameterPack()) {
1844
2
    for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1845
6
         I != N; 
++I4
)
1846
4
      Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
1847
2
    Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1848
483
  } else {
1849
    // Rest of TemplateTemplateParmDecl.
1850
483
    Record.push_back(D->isParameterPack());
1851
483
    bool OwnsDefaultArg = D->hasDefaultArgument() &&
1852
483
                          
!D->defaultArgumentWasInherited()101
;
1853
483
    Record.push_back(OwnsDefaultArg);
1854
483
    if (OwnsDefaultArg)
1855
97
      Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1856
483
    Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1857
483
  }
1858
485
}
1859
1860
983
void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1861
983
  VisitRedeclarableTemplateDecl(D);
1862
983
  Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1863
983
}
1864
1865
1.40k
void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1866
1.40k
  VisitDecl(D);
1867
1.40k
  Record.AddStmt(D->getAssertExpr());
1868
1.40k
  Record.push_back(D->isFailed());
1869
1.40k
  Record.AddStmt(D->getMessage());
1870
1.40k
  Record.AddSourceLocation(D->getRParenLoc());
1871
1.40k
  Code = serialization::DECL_STATIC_ASSERT;
1872
1.40k
}
1873
1874
/// Emit the DeclContext part of a declaration context decl.
1875
495k
void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1876
495k
  static_assert(DeclContext::NumDeclContextBits == 13,
1877
495k
                "You need to update the serializer after you change the "
1878
495k
                "DeclContextBits");
1879
1880
495k
  Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1881
495k
  Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
1882
495k
}
1883
1884
48.3k
const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
1885
48.3k
  assert(IsLocalDecl(D) && "expected a local declaration");
1886
1887
48.3k
  const Decl *Canon = D->getCanonicalDecl();
1888
48.3k
  if (IsLocalDecl(Canon))
1889
44.2k
    return Canon;
1890
1891
4.09k
  const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1892
4.09k
  if (CacheEntry)
1893
2.14k
    return CacheEntry;
1894
1895
294k
  
for (const Decl *Redecl = D; 1.95k
Redecl;
Redecl = Redecl->getPreviousDecl()292k
)
1896
292k
    if (IsLocalDecl(Redecl))
1897
2.87k
      D = Redecl;
1898
1.95k
  return CacheEntry = D;
1899
4.09k
}
1900
1901
template <typename T>
1902
1.36M
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
1.36M
  T *First = D->getFirstDecl();
1904
1.36M
  T *MostRecent = First->getMostRecentDecl();
1905
1.36M
  T *DAsT = static_cast<T *>(D);
1906
1.36M
  if (MostRecent != First) {
1907
45.5k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
45.5k
           "Not considered redeclarable?");
1909
1910
45.5k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
45.5k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
45.5k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
21.1k
      unsigned I = Record.size();
1920
21.1k
      Record.push_back(0);
1921
21.1k
      if (Writer.Chain)
1922
20.4k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
21.1k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
21.1k
      ASTWriter::RecordData LocalRedecls;
1929
21.1k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
21.1k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
169k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()148k
)
1932
148k
        if (!Prev->isFromASTFile())
1933
24.4k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
21.1k
      if (LocalRedecls.empty())
1938
2.29k
        Record.push_back(0);
1939
18.8k
      else
1940
18.8k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
24.4k
    } else {
1942
24.4k
      Record.push_back(0);
1943
24.4k
      Record.AddDeclRef(FirstLocal);
1944
24.4k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
45.5k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
45.5k
    (void)Writer.GetDeclRef(MostRecent);
1954
1.31M
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
1.31M
    Record.push_back(0);
1957
1.31M
  }
1958
1.36M
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::TypedefNameDecl>(clang::Redeclarable<clang::TypedefNameDecl>*)
Line
Count
Source
1902
61.5k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
61.5k
  T *First = D->getFirstDecl();
1904
61.5k
  T *MostRecent = First->getMostRecentDecl();
1905
61.5k
  T *DAsT = static_cast<T *>(D);
1906
61.5k
  if (MostRecent != First) {
1907
4.53k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
4.53k
           "Not considered redeclarable?");
1909
1910
4.53k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
4.53k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
4.53k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
2.17k
      unsigned I = Record.size();
1920
2.17k
      Record.push_back(0);
1921
2.17k
      if (Writer.Chain)
1922
2.17k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
2.17k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
2.17k
      ASTWriter::RecordData LocalRedecls;
1929
2.17k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
2.17k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
4.77k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()2.59k
)
1932
2.59k
        if (!Prev->isFromASTFile())
1933
2.35k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
2.17k
      if (LocalRedecls.empty())
1938
67
        Record.push_back(0);
1939
2.11k
      else
1940
2.11k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
2.35k
    } else {
1942
2.35k
      Record.push_back(0);
1943
2.35k
      Record.AddDeclRef(FirstLocal);
1944
2.35k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
4.53k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
4.53k
    (void)Writer.GetDeclRef(MostRecent);
1954
56.9k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
56.9k
    Record.push_back(0);
1957
56.9k
  }
1958
61.5k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::TagDecl>(clang::Redeclarable<clang::TagDecl>*)
Line
Count
Source
1902
123k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
123k
  T *First = D->getFirstDecl();
1904
123k
  T *MostRecent = First->getMostRecentDecl();
1905
123k
  T *DAsT = static_cast<T *>(D);
1906
123k
  if (MostRecent != First) {
1907
7.88k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
7.88k
           "Not considered redeclarable?");
1909
1910
7.88k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
7.88k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
7.88k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
3.51k
      unsigned I = Record.size();
1920
3.51k
      Record.push_back(0);
1921
3.51k
      if (Writer.Chain)
1922
3.46k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
3.51k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
3.51k
      ASTWriter::RecordData LocalRedecls;
1929
3.51k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
3.51k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
8.17k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()4.66k
)
1932
4.66k
        if (!Prev->isFromASTFile())
1933
4.37k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
3.51k
      if (LocalRedecls.empty())
1938
442
        Record.push_back(0);
1939
3.07k
      else
1940
3.07k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
4.37k
    } else {
1942
4.37k
      Record.push_back(0);
1943
4.37k
      Record.AddDeclRef(FirstLocal);
1944
4.37k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
7.88k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
7.88k
    (void)Writer.GetDeclRef(MostRecent);
1954
115k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
115k
    Record.push_back(0);
1957
115k
  }
1958
123k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::FunctionDecl>(clang::Redeclarable<clang::FunctionDecl>*)
Line
Count
Source
1902
261k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
261k
  T *First = D->getFirstDecl();
1904
261k
  T *MostRecent = First->getMostRecentDecl();
1905
261k
  T *DAsT = static_cast<T *>(D);
1906
261k
  if (MostRecent != First) {
1907
17.1k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
17.1k
           "Not considered redeclarable?");
1909
1910
17.1k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
17.1k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
17.1k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
8.49k
      unsigned I = Record.size();
1920
8.49k
      Record.push_back(0);
1921
8.49k
      if (Writer.Chain)
1922
8.10k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
8.49k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
8.49k
      ASTWriter::RecordData LocalRedecls;
1929
8.49k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
8.49k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
17.3k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()8.89k
)
1932
8.89k
        if (!Prev->isFromASTFile())
1933
8.62k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
8.49k
      if (LocalRedecls.empty())
1938
319
        Record.push_back(0);
1939
8.17k
      else
1940
8.17k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
8.62k
    } else {
1942
8.62k
      Record.push_back(0);
1943
8.62k
      Record.AddDeclRef(FirstLocal);
1944
8.62k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
17.1k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
17.1k
    (void)Writer.GetDeclRef(MostRecent);
1954
244k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
244k
    Record.push_back(0);
1957
244k
  }
1958
261k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::ObjCInterfaceDecl>(clang::Redeclarable<clang::ObjCInterfaceDecl>*)
Line
Count
Source
1902
6.13k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
6.13k
  T *First = D->getFirstDecl();
1904
6.13k
  T *MostRecent = First->getMostRecentDecl();
1905
6.13k
  T *DAsT = static_cast<T *>(D);
1906
6.13k
  if (MostRecent != First) {
1907
4.41k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
4.41k
           "Not considered redeclarable?");
1909
1910
4.41k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
4.41k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
4.41k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
1.08k
      unsigned I = Record.size();
1920
1.08k
      Record.push_back(0);
1921
1.08k
      if (Writer.Chain)
1922
1.08k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
1.08k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
1.08k
      ASTWriter::RecordData LocalRedecls;
1929
1.08k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
1.08k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
4.55k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()3.46k
)
1932
3.46k
        if (!Prev->isFromASTFile())
1933
3.32k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
1.08k
      if (LocalRedecls.empty())
1938
103
        Record.push_back(0);
1939
985
      else
1940
985
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
3.32k
    } else {
1942
3.32k
      Record.push_back(0);
1943
3.32k
      Record.AddDeclRef(FirstLocal);
1944
3.32k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
4.41k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
4.41k
    (void)Writer.GetDeclRef(MostRecent);
1954
4.41k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
1.71k
    Record.push_back(0);
1957
1.71k
  }
1958
6.13k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::ObjCProtocolDecl>(clang::Redeclarable<clang::ObjCProtocolDecl>*)
Line
Count
Source
1902
1.65k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
1.65k
  T *First = D->getFirstDecl();
1904
1.65k
  T *MostRecent = First->getMostRecentDecl();
1905
1.65k
  T *DAsT = static_cast<T *>(D);
1906
1.65k
  if (MostRecent != First) {
1907
766
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
766
           "Not considered redeclarable?");
1909
1910
766
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
766
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
766
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
320
      unsigned I = Record.size();
1920
320
      Record.push_back(0);
1921
320
      if (Writer.Chain)
1922
320
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
320
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
320
      ASTWriter::RecordData LocalRedecls;
1929
320
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
320
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
782
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()462
)
1932
462
        if (!Prev->isFromASTFile())
1933
446
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
320
      if (LocalRedecls.empty())
1938
28
        Record.push_back(0);
1939
292
      else
1940
292
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
446
    } else {
1942
446
      Record.push_back(0);
1943
446
      Record.AddDeclRef(FirstLocal);
1944
446
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
766
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
766
    (void)Writer.GetDeclRef(MostRecent);
1954
886
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
886
    Record.push_back(0);
1957
886
  }
1958
1.65k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::VarDecl>(clang::Redeclarable<clang::VarDecl>*)
Line
Count
Source
1902
875k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
875k
  T *First = D->getFirstDecl();
1904
875k
  T *MostRecent = First->getMostRecentDecl();
1905
875k
  T *DAsT = static_cast<T *>(D);
1906
875k
  if (MostRecent != First) {
1907
2.20k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
2.20k
           "Not considered redeclarable?");
1909
1910
2.20k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
2.20k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
2.20k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
1.17k
      unsigned I = Record.size();
1920
1.17k
      Record.push_back(0);
1921
1.17k
      if (Writer.Chain)
1922
952
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
1.17k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
1.17k
      ASTWriter::RecordData LocalRedecls;
1929
1.17k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
1.17k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
2.27k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()1.10k
)
1932
1.10k
        if (!Prev->isFromASTFile())
1933
1.02k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
1.17k
      if (LocalRedecls.empty())
1938
151
        Record.push_back(0);
1939
1.02k
      else
1940
1.02k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
1.17k
    } else {
1942
1.02k
      Record.push_back(0);
1943
1.02k
      Record.AddDeclRef(FirstLocal);
1944
1.02k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
2.20k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
2.20k
    (void)Writer.GetDeclRef(MostRecent);
1954
873k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
873k
    Record.push_back(0);
1957
873k
  }
1958
875k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::NamespaceDecl>(clang::Redeclarable<clang::NamespaceDecl>*)
Line
Count
Source
1902
4.83k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
4.83k
  T *First = D->getFirstDecl();
1904
4.83k
  T *MostRecent = First->getMostRecentDecl();
1905
4.83k
  T *DAsT = static_cast<T *>(D);
1906
4.83k
  if (MostRecent != First) {
1907
3.98k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
3.98k
           "Not considered redeclarable?");
1909
1910
3.98k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
3.98k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
3.98k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
2.15k
      unsigned I = Record.size();
1920
2.15k
      Record.push_back(0);
1921
2.15k
      if (Writer.Chain)
1922
2.14k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
2.15k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
2.15k
      ASTWriter::RecordData LocalRedecls;
1929
2.15k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
2.15k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
127k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()125k
)
1932
125k
        if (!Prev->isFromASTFile())
1933
1.83k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
2.15k
      if (LocalRedecls.empty())
1938
915
        Record.push_back(0);
1939
1.23k
      else
1940
1.23k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
2.15k
    } else {
1942
1.83k
      Record.push_back(0);
1943
1.83k
      Record.AddDeclRef(FirstLocal);
1944
1.83k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
3.98k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
3.98k
    (void)Writer.GetDeclRef(MostRecent);
1954
3.98k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
857
    Record.push_back(0);
1957
857
  }
1958
4.83k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::NamespaceAliasDecl>(clang::Redeclarable<clang::NamespaceAliasDecl>*)
Line
Count
Source
1902
12
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
12
  T *First = D->getFirstDecl();
1904
12
  T *MostRecent = First->getMostRecentDecl();
1905
12
  T *DAsT = static_cast<T *>(D);
1906
12
  if (MostRecent != First) {
1907
0
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
0
           "Not considered redeclarable?");
1909
1910
0
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
0
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
0
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
0
      unsigned I = Record.size();
1920
0
      Record.push_back(0);
1921
0
      if (Writer.Chain)
1922
0
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
0
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
0
      ASTWriter::RecordData LocalRedecls;
1929
0
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
0
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
0
           Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1932
0
        if (!Prev->isFromASTFile())
1933
0
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
0
      if (LocalRedecls.empty())
1938
0
        Record.push_back(0);
1939
0
      else
1940
0
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
0
    } else {
1942
0
      Record.push_back(0);
1943
0
      Record.AddDeclRef(FirstLocal);
1944
0
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
0
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
0
    (void)Writer.GetDeclRef(MostRecent);
1954
12
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
12
    Record.push_back(0);
1957
12
  }
1958
12
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::UsingShadowDecl>(clang::Redeclarable<clang::UsingShadowDecl>*)
Line
Count
Source
1902
4.81k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
4.81k
  T *First = D->getFirstDecl();
1904
4.81k
  T *MostRecent = First->getMostRecentDecl();
1905
4.81k
  T *DAsT = static_cast<T *>(D);
1906
4.81k
  if (MostRecent != First) {
1907
89
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
89
           "Not considered redeclarable?");
1909
1910
89
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
89
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
89
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
42
      unsigned I = Record.size();
1920
42
      Record.push_back(0);
1921
42
      if (Writer.Chain)
1922
42
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
42
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
42
      ASTWriter::RecordData LocalRedecls;
1929
42
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
42
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
89
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()47
)
1932
47
        if (!Prev->isFromASTFile())
1933
47
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
42
      if (LocalRedecls.empty())
1938
3
        Record.push_back(0);
1939
39
      else
1940
39
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
47
    } else {
1942
47
      Record.push_back(0);
1943
47
      Record.AddDeclRef(FirstLocal);
1944
47
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
89
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
89
    (void)Writer.GetDeclRef(MostRecent);
1954
4.73k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
4.73k
    Record.push_back(0);
1957
4.73k
  }
1958
4.81k
}
void clang::ASTDeclWriter::VisitRedeclarable<clang::RedeclarableTemplateDecl>(clang::Redeclarable<clang::RedeclarableTemplateDecl>*)
Line
Count
Source
1902
23.9k
void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
1903
23.9k
  T *First = D->getFirstDecl();
1904
23.9k
  T *MostRecent = First->getMostRecentDecl();
1905
23.9k
  T *DAsT = static_cast<T *>(D);
1906
23.9k
  if (MostRecent != First) {
1907
4.59k
    assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1908
4.59k
           "Not considered redeclarable?");
1909
1910
4.59k
    Record.AddDeclRef(First);
1911
1912
    // Write out a list of local redeclarations of this declaration if it's the
1913
    // first local declaration in the chain.
1914
4.59k
    const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1915
4.59k
    if (DAsT == FirstLocal) {
1916
      // Emit a list of all imported first declarations so that we can be sure
1917
      // that all redeclarations visible to this module are before D in the
1918
      // redecl chain.
1919
2.19k
      unsigned I = Record.size();
1920
2.19k
      Record.push_back(0);
1921
2.19k
      if (Writer.Chain)
1922
2.14k
        AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1923
      // This is the number of imported first declarations + 1.
1924
2.19k
      Record[I] = Record.size() - I;
1925
1926
      // Collect the set of local redeclarations of this declaration, from
1927
      // newest to oldest.
1928
2.19k
      ASTWriter::RecordData LocalRedecls;
1929
2.19k
      ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1930
2.19k
      for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1931
4.66k
           Prev != FirstLocal; 
Prev = Prev->getPreviousDecl()2.47k
)
1932
2.47k
        if (!Prev->isFromASTFile())
1933
2.40k
          LocalRedeclWriter.AddDeclRef(Prev);
1934
1935
      // If we have any redecls, write them now as a separate record preceding
1936
      // the declaration itself.
1937
2.19k
      if (LocalRedecls.empty())
1938
263
        Record.push_back(0);
1939
1.92k
      else
1940
1.92k
        Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1941
2.40k
    } else {
1942
2.40k
      Record.push_back(0);
1943
2.40k
      Record.AddDeclRef(FirstLocal);
1944
2.40k
    }
1945
1946
    // Make sure that we serialize both the previous and the most-recent
1947
    // declarations, which (transitively) ensures that all declarations in the
1948
    // chain get serialized.
1949
    //
1950
    // FIXME: This is not correct; when we reach an imported declaration we
1951
    // won't emit its previous declaration.
1952
4.59k
    (void)Writer.GetDeclRef(D->getPreviousDecl());
1953
4.59k
    (void)Writer.GetDeclRef(MostRecent);
1954
19.3k
  } else {
1955
    // We use the sentinel value 0 to indicate an only declaration.
1956
19.3k
    Record.push_back(0);
1957
19.3k
  }
1958
23.9k
}
1959
1960
2
void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
1961
2
  VisitNamedDecl(D);
1962
2
  VisitDeclContext(D);
1963
2
  Record.push_back(D->isCBuffer());
1964
2
  Record.AddSourceLocation(D->getLocStart());
1965
2
  Record.AddSourceLocation(D->getLBraceLoc());
1966
2
  Record.AddSourceLocation(D->getRBraceLoc());
1967
1968
2
  Code = serialization::DECL_HLSL_BUFFER;
1969
2
}
1970
1971
288
void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1972
288
  Record.writeOMPChildren(D->Data);
1973
288
  VisitDecl(D);
1974
288
  Code = serialization::DECL_OMP_THREADPRIVATE;
1975
288
}
1976
1977
178
void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1978
178
  Record.writeOMPChildren(D->Data);
1979
178
  VisitDecl(D);
1980
178
  Code = serialization::DECL_OMP_ALLOCATE;
1981
178
}
1982
1983
32
void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1984
32
  Record.writeOMPChildren(D->Data);
1985
32
  VisitDecl(D);
1986
32
  Code = serialization::DECL_OMP_REQUIRES;
1987
32
}
1988
1989
146
void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1990
146
  static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 2,
1991
146
                "You need to update the serializer after you change the "
1992
146
                "NumOMPDeclareReductionDeclBits");
1993
1994
146
  VisitValueDecl(D);
1995
146
  Record.AddSourceLocation(D->getBeginLoc());
1996
146
  Record.AddStmt(D->getCombinerIn());
1997
146
  Record.AddStmt(D->getCombinerOut());
1998
146
  Record.AddStmt(D->getCombiner());
1999
146
  Record.AddStmt(D->getInitOrig());
2000
146
  Record.AddStmt(D->getInitPriv());
2001
146
  Record.AddStmt(D->getInitializer());
2002
146
  Record.push_back(D->getInitializerKind());
2003
146
  Record.AddDeclRef(D->getPrevDeclInScope());
2004
146
  Code = serialization::DECL_OMP_DECLARE_REDUCTION;
2005
146
}
2006
2007
100
void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
2008
100
  Record.writeOMPChildren(D->Data);
2009
100
  VisitValueDecl(D);
2010
100
  Record.AddDeclarationName(D->getVarName());
2011
100
  Record.AddDeclRef(D->getPrevDeclInScope());
2012
100
  Code = serialization::DECL_OMP_DECLARE_MAPPER;
2013
100
}
2014
2015
5.19k
void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
2016
5.19k
  VisitVarDecl(D);
2017
5.19k
  Code = serialization::DECL_OMP_CAPTUREDEXPR;
2018
5.19k
}
2019
2020
//===----------------------------------------------------------------------===//
2021
// ASTWriter Implementation
2022
//===----------------------------------------------------------------------===//
2023
2024
7.24k
void ASTWriter::WriteDeclAbbrevs() {
2025
7.24k
  using namespace llvm;
2026
2027
7.24k
  std::shared_ptr<BitCodeAbbrev> Abv;
2028
2029
  // Abbreviation for DECL_FIELD
2030
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2031
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
2032
  // Decl
2033
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2034
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2035
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2036
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2037
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2038
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2039
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2040
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2041
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));  // AccessSpecifier
2042
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));  // ModuleOwnershipKind
2043
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2044
  // NamedDecl
2045
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2046
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2047
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2048
  // ValueDecl
2049
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2050
  // DeclaratorDecl
2051
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2052
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
2053
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2054
  // FieldDecl
2055
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2056
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // StorageKind
2057
  // Type Source Info
2058
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2059
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2060
7.24k
  DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
2061
2062
  // Abbreviation for DECL_OBJC_IVAR
2063
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2064
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
2065
  // Decl
2066
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2067
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2068
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2069
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2070
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2071
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2072
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2073
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2074
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));  // AccessSpecifier
2075
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3));  // ModuleOwnershipKind
2076
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2077
  // NamedDecl
2078
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2079
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2080
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2081
  // ValueDecl
2082
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2083
  // DeclaratorDecl
2084
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2085
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
2086
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2087
  // FieldDecl
2088
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2089
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
2090
  // ObjC Ivar
2091
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
2092
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
2093
  // Type Source Info
2094
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2095
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2096
7.24k
  DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2097
2098
  // Abbreviation for DECL_ENUM
2099
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2100
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
2101
  // Redeclarable
2102
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // No redeclaration
2103
  // Decl
2104
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2105
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2106
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2107
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2108
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2109
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2110
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2111
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2112
7.24k
  Abv->Add(BitCodeAbbrevOp(AS_none));                 // C++ AccessSpecifier
2113
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2114
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2115
  // NamedDecl
2116
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2117
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2118
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2119
  // TypeDecl
2120
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2121
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2122
  // TagDecl
2123
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // IdentifierNamespace
2124
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // getTagKind
2125
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
2126
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
2127
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
2128
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
2129
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // SourceLocation
2130
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // SourceLocation
2131
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // ExtInfoKind
2132
  // EnumDecl
2133
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // AddTypeRef
2134
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // IntegerType
2135
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // getPromotionType
2136
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // getNumPositiveBits
2137
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // getNumNegativeBits
2138
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
2139
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
2140
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
2141
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
2142
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // InstantiatedMembEnum
2143
  // DC
2144
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LexicalOffset
2145
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // VisibleOffset
2146
7.24k
  DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
2147
2148
  // Abbreviation for DECL_RECORD
2149
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2150
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
2151
  // Redeclarable
2152
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // No redeclaration
2153
  // Decl
2154
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2155
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2156
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2157
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2158
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2159
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2160
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2161
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2162
7.24k
  Abv->Add(BitCodeAbbrevOp(AS_none));                 // C++ AccessSpecifier
2163
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2164
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2165
  // NamedDecl
2166
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2167
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2168
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2169
  // TypeDecl
2170
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2171
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2172
  // TagDecl
2173
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // IdentifierNamespace
2174
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // getTagKind
2175
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
2176
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
2177
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
2178
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
2179
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // SourceLocation
2180
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // SourceLocation
2181
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // ExtInfoKind
2182
  // RecordDecl
2183
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
2184
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
2185
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
2186
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
2187
2188
  // isNonTrivialToPrimitiveDefaultInitialize
2189
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2190
  // isNonTrivialToPrimitiveCopy
2191
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2192
  // isNonTrivialToPrimitiveDestroy
2193
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2194
  // hasNonTrivialToPrimitiveDefaultInitializeCUnion
2195
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2196
  // hasNonTrivialToPrimitiveDestructCUnion
2197
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2198
  // hasNonTrivialToPrimitiveCopyCUnion
2199
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2200
  // isParamDestroyedInCallee
2201
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2202
  // getArgPassingRestrictions
2203
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
2204
  // ODRHash
2205
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26));
2206
2207
  // DC
2208
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LexicalOffset
2209
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // VisibleOffset
2210
7.24k
  DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
2211
2212
  // Abbreviation for DECL_PARM_VAR
2213
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2214
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
2215
  // Redeclarable
2216
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // No redeclaration
2217
  // Decl
2218
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2219
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2220
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2221
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2222
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2223
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2224
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2225
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2226
7.24k
  Abv->Add(BitCodeAbbrevOp(AS_none));                 // C++ AccessSpecifier
2227
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2228
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2229
  // NamedDecl
2230
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2231
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2232
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2233
  // ValueDecl
2234
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2235
  // DeclaratorDecl
2236
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2237
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
2238
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2239
  // VarDecl
2240
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // SClass
2241
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // TSCSpec
2242
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
2243
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
2244
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // Linkage
2245
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // ModulesCodegen
2246
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // VarKind (local enum)
2247
  // ParmVarDecl
2248
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
2249
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // ScopeDepth
2250
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
2251
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // ObjCDeclQualifier
2252
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // KNRPromoted
2253
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasInheritedDefaultArg
2254
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // HasUninstantiatedDefaultArg
2255
  // Type Source Info
2256
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2257
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2258
7.24k
  DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2259
2260
  // Abbreviation for DECL_TYPEDEF
2261
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2262
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
2263
  // Redeclarable
2264
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // No redeclaration
2265
  // Decl
2266
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2267
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2268
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2269
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2270
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2271
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
2272
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
2273
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2274
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
2275
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2276
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2277
  // NamedDecl
2278
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2279
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2280
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2281
  // TypeDecl
2282
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2283
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2284
  // TypedefDecl
2285
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2286
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2287
7.24k
  DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
2288
2289
  // Abbreviation for DECL_VAR
2290
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2291
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
2292
  // Redeclarable
2293
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // No redeclaration
2294
  // Decl
2295
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2296
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // LexicalDeclContext
2297
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isInvalidDecl
2298
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // HasAttrs
2299
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isImplicit
2300
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isUsed
2301
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // isReferenced
2302
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                   // TopLevelDeclInObjCContainer
2303
7.24k
  Abv->Add(BitCodeAbbrevOp(AS_none));                 // C++ AccessSpecifier
2304
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2305
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2306
  // NamedDecl
2307
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // NameKind = Identifier
2308
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2309
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // AnonDeclNumber
2310
  // ValueDecl
2311
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2312
  // DeclaratorDecl
2313
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2314
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
2315
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2316
  // VarDecl
2317
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2318
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2319
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
2320
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
2321
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
2322
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
2323
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
2324
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
2325
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
2326
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // isInline
2327
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // isInlineSpecified
2328
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // isConstexpr
2329
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // isInitCapture
2330
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // isPrevDeclInSameScope
2331
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // ImplicitParamKind
2332
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // EscapingByref
2333
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // HasDeducedType
2334
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2335
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // ModulesCodeGen
2336
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // VarKind (local enum)
2337
  // Type Source Info
2338
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2339
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2340
7.24k
  DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2341
2342
  // Abbreviation for DECL_CXX_METHOD
2343
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2344
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
2345
  // RedeclarableDecl
2346
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // CanonicalDecl
2347
  // FIXME: Implement abbreviation for other template kinds.
2348
7.24k
  Abv->Add(BitCodeAbbrevOp(FunctionDecl::TK_NonTemplate)); // TemplateKind
2349
  // Decl
2350
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // DeclContext
2351
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // LexicalDeclContext
2352
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // Invalid
2353
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // HasAttrs
2354
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
2355
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
2356
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
2357
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // InObjCContainer
2358
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
2359
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2360
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // SubmoduleID
2361
  // NamedDecl
2362
7.24k
  Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2363
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // Identifier
2364
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // AnonDeclNumber
2365
  // ValueDecl
2366
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // Type
2367
  // DeclaratorDecl
2368
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // InnerLocStart
2369
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // HasExtInfo
2370
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // TSIType
2371
  // FunctionDecl
2372
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2373
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
2374
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
2375
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
2376
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2377
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2378
7.24k
  Abv->Add(BitCodeAbbrevOp(0));                         // HasInheritedProto
2379
7.24k
  Abv->Add(BitCodeAbbrevOp(1));                         // HasWrittenProto
2380
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
2381
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
2382
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
2383
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2384
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2385
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsIneligibleOrNotSelected
2386
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2387
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Constexpr
2388
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
2389
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
2390
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
2391
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2392
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FriendConstraintRefersToEnclosingTemplate
2393
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2394
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // LocEnd
2395
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // Default
2396
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
2397
  // This Array slurps the rest of the record. Fortunately we want to encode
2398
  // (nearly) all the remaining (variable number of) fields in the same way.
2399
  //
2400
  // This is:
2401
  //         NumParams and Params[] from FunctionDecl, and
2402
  //         NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2403
  //
2404
  //  Add an AbbrevOp for 'size then elements' and use it here.
2405
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2406
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2407
7.24k
  DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
2408
2409
7.24k
  unsigned ExprDependenceBits = llvm::BitWidth<ExprDependence>;
2410
  // Abbreviation for EXPR_DECL_REF
2411
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2412
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2413
  //Stmt
2414
  // Expr
2415
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2416
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
2417
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2418
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2419
  //DeclRefExpr
2420
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2421
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2422
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
2423
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
2424
7.24k
  Abv->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture
2425
7.24k
  Abv->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason
2426
7.24k
  Abv->Add(BitCodeAbbrevOp(0)); // IsImmediateEscalating
2427
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2428
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2429
7.24k
  DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2430
2431
  // Abbreviation for EXPR_INTEGER_LITERAL
2432
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2433
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2434
  //Stmt
2435
  // Expr
2436
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2437
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
2438
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2439
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2440
  //Integer Literal
2441
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2442
7.24k
  Abv->Add(BitCodeAbbrevOp(32));                      // Bit Width
2443
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2444
7.24k
  IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2445
2446
  // Abbreviation for EXPR_CHARACTER_LITERAL
2447
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2448
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2449
  //Stmt
2450
  // Expr
2451
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2452
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
2453
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2454
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2455
  //Character Literal
2456
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2457
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2458
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
2459
7.24k
  CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2460
2461
  // Abbreviation for EXPR_IMPLICIT_CAST
2462
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2463
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2464
  // Stmt
2465
  // Expr
2466
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2467
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
2468
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2469
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2470
  // CastExpr
2471
7.24k
  Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2472
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasFPFeatures
2473
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2474
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast
2475
  // ImplicitCastExpr
2476
7.24k
  ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
2477
2478
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2479
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
2480
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2481
7.24k
  DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
2482
2483
7.24k
  Abv = std::make_shared<BitCodeAbbrev>();
2484
7.24k
  Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
2485
7.24k
  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2486
7.24k
  DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
2487
7.24k
}
2488
2489
/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2490
/// consumers of the AST.
2491
///
2492
/// Such decls will always be deserialized from the AST file, so we would like
2493
/// this to be as restrictive as possible. Currently the predicate is driven by
2494
/// code generation requirements, if other clients have a different notion of
2495
/// what is "required" then we may have to consider an alternate scheme where
2496
/// clients can iterate over the top-level decls and get information on them,
2497
/// without necessary deserializing them. We could explicitly require such
2498
/// clients to use a separate API call to "realize" the decl. This should be
2499
/// relatively painless since they would presumably only do it for top-level
2500
/// decls.
2501
static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2502
1.80M
                           Module *WritingModule) {
2503
  // Named modules have different semantics than header modules. Every named
2504
  // module units owns a translation unit. So the importer of named modules
2505
  // doesn't need to deserilize everything ahead of time.
2506
1.80M
  if (WritingModule && 
WritingModule->isModulePurview()1.33M
) {
2507
    // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension.
2508
    // And the behavior of MSVC for such cases will leak this to the module
2509
    // users. Given pragma is not a standard thing, the compiler has the space
2510
    // to do their own decision. Let's follow MSVC here.
2511
4.55k
    if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(D))
2512
2
      return true;
2513
4.54k
    return false;
2514
4.55k
  }
2515
2516
  // An ObjCMethodDecl is never considered as "required" because its
2517
  // implementation container always is.
2518
2519
  // File scoped assembly or obj-c or OMP declare target implementation must be
2520
  // seen.
2521
1.80M
  if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(D))
2522
104
    return true;
2523
2524
1.80M
  if (WritingModule && 
isPartOfPerModuleInitializer(D)1.32M
) {
2525
    // These declarations are part of the module initializer, and are emitted
2526
    // if and when the module is imported, rather than being emitted eagerly.
2527
644k
    return false;
2528
644k
  }
2529
2530
1.15M
  return Context.DeclMustBeEmitted(D);
2531
1.80M
}
2532
2533
1.80M
void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
2534
1.80M
  PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2535
1.80M
                                      "serializing");
2536
2537
  // Determine the ID for this declaration.
2538
1.80M
  serialization::DeclID ID;
2539
1.80M
  assert(!D->isFromASTFile() && "should not be emitting imported decl");
2540
1.80M
  serialization::DeclID &IDR = DeclIDs[D];
2541
1.80M
  if (IDR == 0)
2542
0
    IDR = NextDeclID++;
2543
2544
1.80M
  ID = IDR;
2545
2546
1.80M
  assert(ID >= FirstDeclID && "invalid decl ID");
2547
2548
1.80M
  RecordData Record;
2549
1.80M
  ASTDeclWriter W(*this, Context, Record);
2550
2551
  // Build a record for this declaration
2552
1.80M
  W.Visit(D);
2553
2554
  // Emit this declaration to the bitstream.
2555
1.80M
  uint64_t Offset = W.Emit(D);
2556
2557
  // Record the offset for this declaration
2558
1.80M
  SourceLocation Loc = D->getLocation();
2559
1.80M
  unsigned Index = ID - FirstDeclID;
2560
1.80M
  if (DeclOffsets.size() == Index)
2561
1.80M
    DeclOffsets.emplace_back(getAdjustedLocation(Loc), Offset,
2562
1.80M
                             DeclTypesBlockStartOffset);
2563
0
  else if (DeclOffsets.size() < Index) {
2564
    // FIXME: Can/should this happen?
2565
0
    DeclOffsets.resize(Index+1);
2566
0
    DeclOffsets[Index].setLocation(getAdjustedLocation(Loc));
2567
0
    DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
2568
0
  } else {
2569
0
    llvm_unreachable("declarations should be emitted in ID order");
2570
0
  }
2571
2572
1.80M
  SourceManager &SM = Context.getSourceManager();
2573
1.80M
  if (Loc.isValid() && 
SM.isLocalSourceLocation(Loc)1.63M
)
2574
1.61M
    associateDeclWithFile(D, ID);
2575
2576
  // Note declarations that should be deserialized eagerly so that we can add
2577
  // them to a record in the AST file later.
2578
1.80M
  if (isRequiredDecl(D, Context, WritingModule))
2579
11.0k
    EagerlyDeserializedDecls.push_back(ID);
2580
1.80M
}
2581
2582
94.2k
void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2583
  // Switch case IDs are per function body.
2584
94.2k
  Writer->ClearSwitchCaseIDs();
2585
2586
94.2k
  assert(FD->doesThisDeclarationHaveABody());
2587
94.2k
  bool ModulesCodegen = false;
2588
94.2k
  if (!FD->isDependentContext()) {
2589
69.7k
    std::optional<GVALinkage> Linkage;
2590
69.7k
    if (Writer->WritingModule &&
2591
69.7k
        
Writer->WritingModule->isInterfaceOrPartition()56.4k
) {
2592
      // When building a C++20 module interface unit or a partition unit, a
2593
      // strong definition in the module interface is provided by the
2594
      // compilation of that unit, not by its users. (Inline functions are still
2595
      // emitted in module users.)
2596
263
      Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2597
263
      ModulesCodegen = *Linkage >= GVA_StrongExternal;
2598
263
    }
2599
69.7k
    if (Writer->Context->getLangOpts().ModulesCodegen ||
2600
69.7k
        
(69.7k
FD->hasAttr<DLLExportAttr>()69.7k
&&
2601
69.7k
         
Writer->Context->getLangOpts().BuildingPCHWithObjectFile14
)) {
2602
2603
      // Under -fmodules-codegen, codegen is performed for all non-internal,
2604
      // non-always_inline functions, unless they are available elsewhere.
2605
32
      if (!FD->hasAttr<AlwaysInlineAttr>()) {
2606
31
        if (!Linkage)
2607
27
          Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2608
31
        ModulesCodegen =
2609
31
            *Linkage != GVA_Internal && 
*Linkage != GVA_AvailableExternally29
;
2610
31
      }
2611
32
    }
2612
69.7k
  }
2613
94.2k
  Record->push_back(ModulesCodegen);
2614
94.2k
  if (ModulesCodegen)
2615
156
    Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
2616
94.2k
  if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2617
9.80k
    Record->push_back(CD->getNumCtorInitializers());
2618
9.80k
    if (CD->getNumCtorInitializers())
2619
6.74k
      AddCXXCtorInitializers(llvm::ArrayRef(CD->init_begin(), CD->init_end()));
2620
9.80k
  }
2621
94.2k
  AddStmt(FD->getBody());
2622
94.2k
}