Coverage Report

Created: 2022-01-25 06:29

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