Coverage Report

Created: 2019-07-24 05:18

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