1 //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements serialization for Declarations.
11 //===----------------------------------------------------------------------===//
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"
27 using namespace clang
;
28 using namespace serialization
;
30 //===----------------------------------------------------------------------===//
31 // Declaration serialization
32 //===----------------------------------------------------------------------===//
35 class ASTDeclWriter
: public DeclVisitor
<ASTDeclWriter
, void> {
38 ASTRecordWriter Record
;
40 serialization::DeclCode Code
;
44 ASTDeclWriter(ASTWriter
&Writer
, ASTContext
&Context
,
45 ASTWriter::RecordDataImpl
&Record
)
46 : Writer(Writer
), Context(Context
), Record(Writer
, Record
),
47 Code((serialization::DeclCode
)0), AbbrevToUse(0) {}
49 uint64_t Emit(Decl
*D
) {
51 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
52 D
->getDeclKindName() + "'");
53 return Record
.Emit(Code
, AbbrevToUse
);
58 void VisitDecl(Decl
*D
);
59 void VisitPragmaCommentDecl(PragmaCommentDecl
*D
);
60 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl
*D
);
61 void VisitTranslationUnitDecl(TranslationUnitDecl
*D
);
62 void VisitNamedDecl(NamedDecl
*D
);
63 void VisitLabelDecl(LabelDecl
*LD
);
64 void VisitNamespaceDecl(NamespaceDecl
*D
);
65 void VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
);
66 void VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
);
67 void VisitTypeDecl(TypeDecl
*D
);
68 void VisitTypedefNameDecl(TypedefNameDecl
*D
);
69 void VisitTypedefDecl(TypedefDecl
*D
);
70 void VisitTypeAliasDecl(TypeAliasDecl
*D
);
71 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl
*D
);
72 void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl
*D
);
73 void VisitTagDecl(TagDecl
*D
);
74 void VisitEnumDecl(EnumDecl
*D
);
75 void VisitRecordDecl(RecordDecl
*D
);
76 void VisitCXXRecordDecl(CXXRecordDecl
*D
);
77 void VisitClassTemplateSpecializationDecl(
78 ClassTemplateSpecializationDecl
*D
);
79 void VisitClassTemplatePartialSpecializationDecl(
80 ClassTemplatePartialSpecializationDecl
*D
);
81 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl
*D
);
82 void VisitVarTemplatePartialSpecializationDecl(
83 VarTemplatePartialSpecializationDecl
*D
);
84 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
);
85 void VisitValueDecl(ValueDecl
*D
);
86 void VisitEnumConstantDecl(EnumConstantDecl
*D
);
87 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
);
88 void VisitDeclaratorDecl(DeclaratorDecl
*D
);
89 void VisitFunctionDecl(FunctionDecl
*D
);
90 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl
*D
);
91 void VisitCXXMethodDecl(CXXMethodDecl
*D
);
92 void VisitCXXConstructorDecl(CXXConstructorDecl
*D
);
93 void VisitCXXDestructorDecl(CXXDestructorDecl
*D
);
94 void VisitCXXConversionDecl(CXXConversionDecl
*D
);
95 void VisitFieldDecl(FieldDecl
*D
);
96 void VisitMSPropertyDecl(MSPropertyDecl
*D
);
97 void VisitMSGuidDecl(MSGuidDecl
*D
);
98 void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl
*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 VisitImplicitConceptSpecializationDecl(
110 ImplicitConceptSpecializationDecl
*D
);
111 void VisitRequiresExprBodyDecl(RequiresExprBodyDecl
*D
);
112 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
);
113 void VisitClassTemplateDecl(ClassTemplateDecl
*D
);
114 void VisitVarTemplateDecl(VarTemplateDecl
*D
);
115 void VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
);
116 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
);
117 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl
*D
);
118 void VisitUsingDecl(UsingDecl
*D
);
119 void VisitUsingEnumDecl(UsingEnumDecl
*D
);
120 void VisitUsingPackDecl(UsingPackDecl
*D
);
121 void VisitUsingShadowDecl(UsingShadowDecl
*D
);
122 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl
*D
);
123 void VisitLinkageSpecDecl(LinkageSpecDecl
*D
);
124 void VisitExportDecl(ExportDecl
*D
);
125 void VisitFileScopeAsmDecl(FileScopeAsmDecl
*D
);
126 void VisitTopLevelStmtDecl(TopLevelStmtDecl
*D
);
127 void VisitImportDecl(ImportDecl
*D
);
128 void VisitAccessSpecDecl(AccessSpecDecl
*D
);
129 void VisitFriendDecl(FriendDecl
*D
);
130 void VisitFriendTemplateDecl(FriendTemplateDecl
*D
);
131 void VisitStaticAssertDecl(StaticAssertDecl
*D
);
132 void VisitBlockDecl(BlockDecl
*D
);
133 void VisitCapturedDecl(CapturedDecl
*D
);
134 void VisitEmptyDecl(EmptyDecl
*D
);
135 void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl
*D
);
136 void VisitDeclContext(DeclContext
*DC
);
137 template <typename T
> void VisitRedeclarable(Redeclarable
<T
> *D
);
138 void VisitHLSLBufferDecl(HLSLBufferDecl
*D
);
140 // FIXME: Put in the same order is DeclNodes.td?
141 void VisitObjCMethodDecl(ObjCMethodDecl
*D
);
142 void VisitObjCTypeParamDecl(ObjCTypeParamDecl
*D
);
143 void VisitObjCContainerDecl(ObjCContainerDecl
*D
);
144 void VisitObjCInterfaceDecl(ObjCInterfaceDecl
*D
);
145 void VisitObjCIvarDecl(ObjCIvarDecl
*D
);
146 void VisitObjCProtocolDecl(ObjCProtocolDecl
*D
);
147 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*D
);
148 void VisitObjCCategoryDecl(ObjCCategoryDecl
*D
);
149 void VisitObjCImplDecl(ObjCImplDecl
*D
);
150 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
);
151 void VisitObjCImplementationDecl(ObjCImplementationDecl
*D
);
152 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*D
);
153 void VisitObjCPropertyDecl(ObjCPropertyDecl
*D
);
154 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
);
155 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl
*D
);
156 void VisitOMPAllocateDecl(OMPAllocateDecl
*D
);
157 void VisitOMPRequiresDecl(OMPRequiresDecl
*D
);
158 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl
*D
);
159 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl
*D
);
160 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl
*D
);
162 /// Add an Objective-C type parameter list to the given record.
163 void AddObjCTypeParamList(ObjCTypeParamList
*typeParams
) {
164 // Empty type parameter list.
170 Record
.push_back(typeParams
->size());
171 for (auto *typeParam
: *typeParams
) {
172 Record
.AddDeclRef(typeParam
);
174 Record
.AddSourceLocation(typeParams
->getLAngleLoc());
175 Record
.AddSourceLocation(typeParams
->getRAngleLoc());
178 /// Add to the record the first declaration from each module file that
179 /// provides a declaration of D. The intent is to provide a sufficient
180 /// set such that reloading this set will load all current redeclarations.
181 void AddFirstDeclFromEachModule(const Decl
*D
, bool IncludeLocal
) {
182 llvm::MapVector
<ModuleFile
*, const Decl
*> Firsts
;
183 // FIXME: We can skip entries that we know are implied by others.
184 for (const Decl
*R
= D
->getMostRecentDecl(); R
; R
= R
->getPreviousDecl()) {
185 if (R
->isFromASTFile())
186 Firsts
[Writer
.Chain
->getOwningModuleFile(R
)] = R
;
187 else if (IncludeLocal
)
190 for (const auto &F
: Firsts
)
191 Record
.AddDeclRef(F
.second
);
194 /// Get the specialization decl from an entry in the specialization list.
195 template <typename EntryType
>
196 typename
RedeclarableTemplateDecl::SpecEntryTraits
<EntryType
>::DeclType
*
197 getSpecializationDecl(EntryType
&T
) {
198 return RedeclarableTemplateDecl::SpecEntryTraits
<EntryType
>::getDecl(&T
);
201 /// Get the list of partial specializations from a template's common ptr.
203 decltype(T::PartialSpecializations
) &getPartialSpecializations(T
*Common
) {
204 return Common
->PartialSpecializations
;
206 ArrayRef
<Decl
> getPartialSpecializations(FunctionTemplateDecl::Common
*) {
210 template<typename DeclTy
>
211 void AddTemplateSpecializations(DeclTy
*D
) {
212 auto *Common
= D
->getCommonPtr();
214 // If we have any lazy specializations, and the external AST source is
215 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
216 // we need to resolve them to actual declarations.
217 if (Writer
.Chain
!= Writer
.Context
->getExternalSource() &&
218 Common
->LazySpecializations
) {
219 D
->LoadLazySpecializations();
220 assert(!Common
->LazySpecializations
);
223 ArrayRef
<DeclID
> LazySpecializations
;
224 if (auto *LS
= Common
->LazySpecializations
)
225 LazySpecializations
= llvm::ArrayRef(LS
+ 1, LS
[0]);
227 // Add a slot to the record for the number of specializations.
228 unsigned I
= Record
.size();
231 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
232 // *Specializations iterators.
233 llvm::SmallVector
<const Decl
*, 16> Specs
;
234 for (auto &Entry
: Common
->Specializations
)
235 Specs
.push_back(getSpecializationDecl(Entry
));
236 for (auto &Entry
: getPartialSpecializations(Common
))
237 Specs
.push_back(getSpecializationDecl(Entry
));
239 for (auto *D
: Specs
) {
240 assert(D
->isCanonicalDecl() && "non-canonical decl in set");
241 AddFirstDeclFromEachModule(D
, /*IncludeLocal*/true);
243 Record
.append(LazySpecializations
.begin(), LazySpecializations
.end());
245 // Update the size entry we added earlier.
246 Record
[I
] = Record
.size() - I
- 1;
249 /// Ensure that this template specialization is associated with the specified
250 /// template on reload.
251 void RegisterTemplateSpecialization(const Decl
*Template
,
252 const Decl
*Specialization
) {
253 Template
= Template
->getCanonicalDecl();
255 // If the canonical template is local, we'll write out this specialization
257 // FIXME: We can do the same thing if there is any local declaration of
258 // the template, to avoid emitting an update record.
259 if (!Template
->isFromASTFile())
262 // We only need to associate the first local declaration of the
263 // specialization. The other declarations will get pulled in by it.
264 if (Writer
.getFirstLocalDecl(Specialization
) != Specialization
)
267 Writer
.DeclUpdates
[Template
].push_back(ASTWriter::DeclUpdate(
268 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION
, Specialization
));
273 void ASTDeclWriter::Visit(Decl
*D
) {
274 DeclVisitor
<ASTDeclWriter
>::Visit(D
);
276 // Source locations require array (variable-length) abbreviations. The
277 // abbreviation infrastructure requires that arrays are encoded last, so
278 // we handle it here in the case of those classes derived from DeclaratorDecl
279 if (auto *DD
= dyn_cast
<DeclaratorDecl
>(D
)) {
280 if (auto *TInfo
= DD
->getTypeSourceInfo())
281 Record
.AddTypeLoc(TInfo
->getTypeLoc());
284 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
285 // have been written. We want it last because we will not read it back when
286 // retrieving it from the AST, we'll just lazily set the offset.
287 if (auto *FD
= dyn_cast
<FunctionDecl
>(D
)) {
288 Record
.push_back(FD
->doesThisDeclarationHaveABody());
289 if (FD
->doesThisDeclarationHaveABody())
290 Record
.AddFunctionDefinition(FD
);
293 // Similar to FunctionDecls, handle VarDecl's initializer here and write it
294 // after all other Stmts/Exprs. We will not read the initializer until after
295 // we have finished recursive deserialization, because it can recursively
296 // refer back to the variable.
297 if (auto *VD
= dyn_cast
<VarDecl
>(D
)) {
298 Record
.AddVarDeclInit(VD
);
301 // And similarly for FieldDecls. We already serialized whether there is a
302 // default member initializer.
303 if (auto *FD
= dyn_cast
<FieldDecl
>(D
)) {
304 if (FD
->hasInClassInitializer()) {
305 if (Expr
*Init
= FD
->getInClassInitializer()) {
307 Record
.AddStmt(Init
);
310 // Initializer has not been instantiated yet.
315 // If this declaration is also a DeclContext, write blocks for the
316 // declarations that lexically stored inside its context and those
317 // declarations that are visible from its context.
318 if (auto *DC
= dyn_cast
<DeclContext
>(D
))
319 VisitDeclContext(DC
);
322 void ASTDeclWriter::VisitDecl(Decl
*D
) {
323 Record
.AddDeclRef(cast_or_null
<Decl
>(D
->getDeclContext()));
324 if (D
->getDeclContext() != D
->getLexicalDeclContext())
325 Record
.AddDeclRef(cast_or_null
<Decl
>(D
->getLexicalDeclContext()));
328 Record
.push_back(D
->isInvalidDecl());
329 Record
.push_back(D
->hasAttrs());
331 Record
.AddAttributes(D
->getAttrs());
332 Record
.push_back(D
->isImplicit());
333 Record
.push_back(D
->isUsed(false));
334 Record
.push_back(D
->isReferenced());
335 Record
.push_back(D
->isTopLevelDeclInObjCContainer());
336 Record
.push_back(D
->getAccess());
337 Record
.push_back((uint64_t)D
->getModuleOwnershipKind());
338 Record
.push_back(Writer
.getSubmoduleID(D
->getOwningModule()));
340 // If this declaration injected a name into a context different from its
341 // lexical context, and that context is an imported namespace, we need to
342 // update its visible declarations to include this name.
344 // This happens when we instantiate a class with a friend declaration or a
345 // function with a local extern declaration, for instance.
347 // FIXME: Can we handle this in AddedVisibleDecl instead?
348 if (D
->isOutOfLine()) {
349 auto *DC
= D
->getDeclContext();
350 while (auto *NS
= dyn_cast
<NamespaceDecl
>(DC
->getRedeclContext())) {
351 if (!NS
->isFromASTFile())
353 Writer
.UpdatedDeclContexts
.insert(NS
->getPrimaryContext());
354 if (!NS
->isInlineNamespace())
356 DC
= NS
->getParent();
361 void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl
*D
) {
362 StringRef Arg
= D
->getArg();
363 Record
.push_back(Arg
.size());
365 Record
.AddSourceLocation(D
->getBeginLoc());
366 Record
.push_back(D
->getCommentKind());
367 Record
.AddString(Arg
);
368 Code
= serialization::DECL_PRAGMA_COMMENT
;
371 void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
372 PragmaDetectMismatchDecl
*D
) {
373 StringRef Name
= D
->getName();
374 StringRef Value
= D
->getValue();
375 Record
.push_back(Name
.size() + 1 + Value
.size());
377 Record
.AddSourceLocation(D
->getBeginLoc());
378 Record
.AddString(Name
);
379 Record
.AddString(Value
);
380 Code
= serialization::DECL_PRAGMA_DETECT_MISMATCH
;
383 void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl
*D
) {
384 llvm_unreachable("Translation units aren't directly serialized");
387 void ASTDeclWriter::VisitNamedDecl(NamedDecl
*D
) {
389 Record
.AddDeclarationName(D
->getDeclName());
390 Record
.push_back(needsAnonymousDeclarationNumber(D
)
391 ? Writer
.getAnonymousDeclarationNumber(D
)
395 void ASTDeclWriter::VisitTypeDecl(TypeDecl
*D
) {
397 Record
.AddSourceLocation(D
->getBeginLoc());
398 Record
.AddTypeRef(QualType(D
->getTypeForDecl(), 0));
401 void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl
*D
) {
402 VisitRedeclarable(D
);
404 Record
.AddTypeSourceInfo(D
->getTypeSourceInfo());
405 Record
.push_back(D
->isModed());
407 Record
.AddTypeRef(D
->getUnderlyingType());
408 Record
.AddDeclRef(D
->getAnonDeclWithTypedefName(false));
411 void ASTDeclWriter::VisitTypedefDecl(TypedefDecl
*D
) {
412 VisitTypedefNameDecl(D
);
413 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
416 D
->getFirstDecl() == D
->getMostRecentDecl() &&
417 !D
->isInvalidDecl() &&
418 !D
->isTopLevelDeclInObjCContainer() &&
419 !D
->isModulePrivate() &&
420 !needsAnonymousDeclarationNumber(D
) &&
421 D
->getDeclName().getNameKind() == DeclarationName::Identifier
)
422 AbbrevToUse
= Writer
.getDeclTypedefAbbrev();
424 Code
= serialization::DECL_TYPEDEF
;
427 void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl
*D
) {
428 VisitTypedefNameDecl(D
);
429 Record
.AddDeclRef(D
->getDescribedAliasTemplate());
430 Code
= serialization::DECL_TYPEALIAS
;
433 void ASTDeclWriter::VisitTagDecl(TagDecl
*D
) {
434 static_assert(DeclContext::NumTagDeclBits
== 23,
435 "You need to update the serializer after you change the "
438 VisitRedeclarable(D
);
440 Record
.push_back(D
->getIdentifierNamespace());
441 Record
.push_back((unsigned)D
->getTagKind()); // FIXME: stable encoding
442 if (!isa
<CXXRecordDecl
>(D
))
443 Record
.push_back(D
->isCompleteDefinition());
444 Record
.push_back(D
->isEmbeddedInDeclarator());
445 Record
.push_back(D
->isFreeStanding());
446 Record
.push_back(D
->isCompleteDefinitionRequired());
447 Record
.AddSourceRange(D
->getBraceRange());
449 if (D
->hasExtInfo()) {
451 Record
.AddQualifierInfo(*D
->getExtInfo());
452 } else if (auto *TD
= D
->getTypedefNameForAnonDecl()) {
454 Record
.AddDeclRef(TD
);
455 Record
.AddIdentifierRef(TD
->getDeclName().getAsIdentifierInfo());
461 void ASTDeclWriter::VisitEnumDecl(EnumDecl
*D
) {
462 static_assert(DeclContext::NumEnumDeclBits
== 43,
463 "You need to update the serializer after you change the "
467 Record
.AddTypeSourceInfo(D
->getIntegerTypeSourceInfo());
468 if (!D
->getIntegerTypeSourceInfo())
469 Record
.AddTypeRef(D
->getIntegerType());
470 Record
.AddTypeRef(D
->getPromotionType());
471 Record
.push_back(D
->getNumPositiveBits());
472 Record
.push_back(D
->getNumNegativeBits());
473 Record
.push_back(D
->isScoped());
474 Record
.push_back(D
->isScopedUsingClassTag());
475 Record
.push_back(D
->isFixed());
476 Record
.push_back(D
->getODRHash());
478 if (MemberSpecializationInfo
*MemberInfo
= D
->getMemberSpecializationInfo()) {
479 Record
.AddDeclRef(MemberInfo
->getInstantiatedFrom());
480 Record
.push_back(MemberInfo
->getTemplateSpecializationKind());
481 Record
.AddSourceLocation(MemberInfo
->getPointOfInstantiation());
483 Record
.AddDeclRef(nullptr);
486 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
491 !D
->getTypedefNameForAnonDecl() &&
492 D
->getFirstDecl() == D
->getMostRecentDecl() &&
493 !D
->isInvalidDecl() &&
494 !D
->isReferenced() &&
495 !D
->isTopLevelDeclInObjCContainer() &&
496 D
->getAccess() == AS_none
&&
497 !D
->isModulePrivate() &&
498 !CXXRecordDecl::classofKind(D
->getKind()) &&
499 !D
->getIntegerTypeSourceInfo() &&
500 !D
->getMemberSpecializationInfo() &&
501 !needsAnonymousDeclarationNumber(D
) &&
502 D
->getDeclName().getNameKind() == DeclarationName::Identifier
)
503 AbbrevToUse
= Writer
.getDeclEnumAbbrev();
505 Code
= serialization::DECL_ENUM
;
508 void ASTDeclWriter::VisitRecordDecl(RecordDecl
*D
) {
509 static_assert(DeclContext::NumRecordDeclBits
== 64,
510 "You need to update the serializer after you change the "
514 Record
.push_back(D
->hasFlexibleArrayMember());
515 Record
.push_back(D
->isAnonymousStructOrUnion());
516 Record
.push_back(D
->hasObjectMember());
517 Record
.push_back(D
->hasVolatileMember());
518 Record
.push_back(D
->isNonTrivialToPrimitiveDefaultInitialize());
519 Record
.push_back(D
->isNonTrivialToPrimitiveCopy());
520 Record
.push_back(D
->isNonTrivialToPrimitiveDestroy());
521 Record
.push_back(D
->hasNonTrivialToPrimitiveDefaultInitializeCUnion());
522 Record
.push_back(D
->hasNonTrivialToPrimitiveDestructCUnion());
523 Record
.push_back(D
->hasNonTrivialToPrimitiveCopyCUnion());
524 Record
.push_back(D
->isParamDestroyedInCallee());
525 Record
.push_back(llvm::to_underlying(D
->getArgPassingRestrictions()));
526 // Only compute this for C/Objective-C, in C++ this is computed as part
528 if (!isa
<CXXRecordDecl
>(D
))
529 Record
.push_back(D
->getODRHash());
531 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
536 !D
->getTypedefNameForAnonDecl() &&
537 D
->getFirstDecl() == D
->getMostRecentDecl() &&
538 !D
->isInvalidDecl() &&
539 !D
->isReferenced() &&
540 !D
->isTopLevelDeclInObjCContainer() &&
541 D
->getAccess() == AS_none
&&
542 !D
->isModulePrivate() &&
543 !CXXRecordDecl::classofKind(D
->getKind()) &&
544 !needsAnonymousDeclarationNumber(D
) &&
545 D
->getDeclName().getNameKind() == DeclarationName::Identifier
)
546 AbbrevToUse
= Writer
.getDeclRecordAbbrev();
548 Code
= serialization::DECL_RECORD
;
551 void ASTDeclWriter::VisitValueDecl(ValueDecl
*D
) {
553 Record
.AddTypeRef(D
->getType());
556 void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl
*D
) {
558 Record
.push_back(D
->getInitExpr()? 1 : 0);
559 if (D
->getInitExpr())
560 Record
.AddStmt(D
->getInitExpr());
561 Record
.AddAPSInt(D
->getInitVal());
563 Code
= serialization::DECL_ENUM_CONSTANT
;
566 void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl
*D
) {
568 Record
.AddSourceLocation(D
->getInnerLocStart());
569 Record
.push_back(D
->hasExtInfo());
570 if (D
->hasExtInfo()) {
571 DeclaratorDecl::ExtInfo
*Info
= D
->getExtInfo();
572 Record
.AddQualifierInfo(*Info
);
573 Record
.AddStmt(Info
->TrailingRequiresClause
);
575 // The location information is deferred until the end of the record.
576 Record
.AddTypeRef(D
->getTypeSourceInfo() ? D
->getTypeSourceInfo()->getType()
580 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl
*D
) {
581 static_assert(DeclContext::NumFunctionDeclBits
== 44,
582 "You need to update the serializer after you change the "
585 VisitRedeclarable(D
);
587 Record
.push_back(D
->getTemplatedKind());
588 switch (D
->getTemplatedKind()) {
589 case FunctionDecl::TK_NonTemplate
:
591 case FunctionDecl::TK_DependentNonTemplate
:
592 Record
.AddDeclRef(D
->getInstantiatedFromDecl());
594 case FunctionDecl::TK_FunctionTemplate
:
595 Record
.AddDeclRef(D
->getDescribedFunctionTemplate());
597 case FunctionDecl::TK_MemberSpecialization
: {
598 MemberSpecializationInfo
*MemberInfo
= D
->getMemberSpecializationInfo();
599 Record
.AddDeclRef(MemberInfo
->getInstantiatedFrom());
600 Record
.push_back(MemberInfo
->getTemplateSpecializationKind());
601 Record
.AddSourceLocation(MemberInfo
->getPointOfInstantiation());
604 case FunctionDecl::TK_FunctionTemplateSpecialization
: {
605 FunctionTemplateSpecializationInfo
*
606 FTSInfo
= D
->getTemplateSpecializationInfo();
608 RegisterTemplateSpecialization(FTSInfo
->getTemplate(), D
);
610 Record
.AddDeclRef(FTSInfo
->getTemplate());
611 Record
.push_back(FTSInfo
->getTemplateSpecializationKind());
613 // Template arguments.
614 Record
.AddTemplateArgumentList(FTSInfo
->TemplateArguments
);
616 // Template args as written.
617 Record
.push_back(FTSInfo
->TemplateArgumentsAsWritten
!= nullptr);
618 if (FTSInfo
->TemplateArgumentsAsWritten
)
619 Record
.AddASTTemplateArgumentListInfo(
620 FTSInfo
->TemplateArgumentsAsWritten
);
622 Record
.AddSourceLocation(FTSInfo
->getPointOfInstantiation());
624 if (MemberSpecializationInfo
*MemberInfo
=
625 FTSInfo
->getMemberSpecializationInfo()) {
627 Record
.AddDeclRef(MemberInfo
->getInstantiatedFrom());
628 Record
.push_back(MemberInfo
->getTemplateSpecializationKind());
629 Record
.AddSourceLocation(MemberInfo
->getPointOfInstantiation());
634 if (D
->isCanonicalDecl()) {
635 // Write the template that contains the specializations set. We will
636 // add a FunctionTemplateSpecializationInfo to it when reading.
637 Record
.AddDeclRef(FTSInfo
->getTemplate()->getCanonicalDecl());
641 case FunctionDecl::TK_DependentFunctionTemplateSpecialization
: {
642 DependentFunctionTemplateSpecializationInfo
*
643 DFTSInfo
= D
->getDependentSpecializationInfo();
646 Record
.push_back(DFTSInfo
->getCandidates().size());
647 for (FunctionTemplateDecl
*FTD
: DFTSInfo
->getCandidates())
648 Record
.AddDeclRef(FTD
);
651 Record
.push_back(DFTSInfo
->TemplateArgumentsAsWritten
!= nullptr);
652 if (DFTSInfo
->TemplateArgumentsAsWritten
)
653 Record
.AddASTTemplateArgumentListInfo(
654 DFTSInfo
->TemplateArgumentsAsWritten
);
659 VisitDeclaratorDecl(D
);
660 Record
.AddDeclarationNameLoc(D
->DNLoc
, D
->getDeclName());
661 Record
.push_back(D
->getIdentifierNamespace());
663 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
664 // after everything else is written.
666 static_cast<int>(D
->getStorageClass())); // FIXME: stable encoding
667 Record
.push_back(D
->isInlineSpecified());
668 Record
.push_back(D
->isInlined());
669 Record
.push_back(D
->isVirtualAsWritten());
670 Record
.push_back(D
->isPure());
671 Record
.push_back(D
->hasInheritedPrototype());
672 Record
.push_back(D
->hasWrittenPrototype());
673 Record
.push_back(D
->isDeletedBit());
674 Record
.push_back(D
->isTrivial());
675 Record
.push_back(D
->isTrivialForCall());
676 Record
.push_back(D
->isDefaulted());
677 Record
.push_back(D
->isExplicitlyDefaulted());
678 Record
.push_back(D
->isIneligibleOrNotSelected());
679 Record
.push_back(D
->hasImplicitReturnZero());
680 Record
.push_back(static_cast<uint64_t>(D
->getConstexprKind()));
681 Record
.push_back(D
->usesSEHTry());
682 Record
.push_back(D
->hasSkippedBody());
683 Record
.push_back(D
->isMultiVersion());
684 Record
.push_back(D
->isLateTemplateParsed());
685 Record
.push_back(D
->FriendConstraintRefersToEnclosingTemplate());
686 Record
.push_back(D
->getLinkageInternal());
687 Record
.AddSourceLocation(D
->getEndLoc());
688 Record
.AddSourceLocation(D
->getDefaultLoc());
690 Record
.push_back(D
->getODRHash());
692 if (D
->isDefaulted()) {
693 if (auto *FDI
= D
->getDefaultedFunctionInfo()) {
694 Record
.push_back(FDI
->getUnqualifiedLookups().size());
695 for (DeclAccessPair P
: FDI
->getUnqualifiedLookups()) {
696 Record
.AddDeclRef(P
.getDecl());
697 Record
.push_back(P
.getAccess());
704 Record
.push_back(D
->param_size());
705 for (auto *P
: D
->parameters())
706 Record
.AddDeclRef(P
);
707 Code
= serialization::DECL_FUNCTION
;
710 static void addExplicitSpecifier(ExplicitSpecifier ES
,
711 ASTRecordWriter
&Record
) {
712 uint64_t Kind
= static_cast<uint64_t>(ES
.getKind());
713 Kind
= Kind
<< 1 | static_cast<bool>(ES
.getExpr());
714 Record
.push_back(Kind
);
716 Record
.AddStmt(ES
.getExpr());
720 void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl
*D
) {
721 addExplicitSpecifier(D
->getExplicitSpecifier(), Record
);
722 Record
.AddDeclRef(D
->Ctor
);
723 VisitFunctionDecl(D
);
724 Record
.push_back(static_cast<unsigned char>(D
->getDeductionCandidateKind()));
725 Code
= serialization::DECL_CXX_DEDUCTION_GUIDE
;
728 void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl
*D
) {
729 static_assert(DeclContext::NumObjCMethodDeclBits
== 37,
730 "You need to update the serializer after you change the "
731 "ObjCMethodDeclBits");
734 // FIXME: convert to LazyStmtPtr?
735 // Unlike C/C++, method bodies will never be in header files.
736 bool HasBodyStuff
= D
->getBody() != nullptr;
737 Record
.push_back(HasBodyStuff
);
739 Record
.AddStmt(D
->getBody());
741 Record
.AddDeclRef(D
->getSelfDecl());
742 Record
.AddDeclRef(D
->getCmdDecl());
743 Record
.push_back(D
->isInstanceMethod());
744 Record
.push_back(D
->isVariadic());
745 Record
.push_back(D
->isPropertyAccessor());
746 Record
.push_back(D
->isSynthesizedAccessorStub());
747 Record
.push_back(D
->isDefined());
748 Record
.push_back(D
->isOverriding());
749 Record
.push_back(D
->hasSkippedBody());
751 Record
.push_back(D
->isRedeclaration());
752 Record
.push_back(D
->hasRedeclaration());
753 if (D
->hasRedeclaration()) {
754 assert(Context
.getObjCMethodRedeclaration(D
));
755 Record
.AddDeclRef(Context
.getObjCMethodRedeclaration(D
));
758 // FIXME: stable encoding for @required/@optional
759 Record
.push_back(llvm::to_underlying(D
->getImplementationControl()));
760 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
761 Record
.push_back(D
->getObjCDeclQualifier());
762 Record
.push_back(D
->hasRelatedResultType());
763 Record
.AddTypeRef(D
->getReturnType());
764 Record
.AddTypeSourceInfo(D
->getReturnTypeSourceInfo());
765 Record
.AddSourceLocation(D
->getEndLoc());
766 Record
.push_back(D
->param_size());
767 for (const auto *P
: D
->parameters())
768 Record
.AddDeclRef(P
);
770 Record
.push_back(D
->getSelLocsKind());
771 unsigned NumStoredSelLocs
= D
->getNumStoredSelLocs();
772 SourceLocation
*SelLocs
= D
->getStoredSelLocs();
773 Record
.push_back(NumStoredSelLocs
);
774 for (unsigned i
= 0; i
!= NumStoredSelLocs
; ++i
)
775 Record
.AddSourceLocation(SelLocs
[i
]);
777 Code
= serialization::DECL_OBJC_METHOD
;
780 void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl
*D
) {
781 VisitTypedefNameDecl(D
);
782 Record
.push_back(D
->Variance
);
783 Record
.push_back(D
->Index
);
784 Record
.AddSourceLocation(D
->VarianceLoc
);
785 Record
.AddSourceLocation(D
->ColonLoc
);
787 Code
= serialization::DECL_OBJC_TYPE_PARAM
;
790 void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl
*D
) {
791 static_assert(DeclContext::NumObjCContainerDeclBits
== 64,
792 "You need to update the serializer after you change the "
793 "ObjCContainerDeclBits");
796 Record
.AddSourceLocation(D
->getAtStartLoc());
797 Record
.AddSourceRange(D
->getAtEndRange());
798 // Abstract class (no need to define a stable serialization::DECL code).
801 void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl
*D
) {
802 VisitRedeclarable(D
);
803 VisitObjCContainerDecl(D
);
804 Record
.AddTypeRef(QualType(D
->getTypeForDecl(), 0));
805 AddObjCTypeParamList(D
->TypeParamList
);
807 Record
.push_back(D
->isThisDeclarationADefinition());
808 if (D
->isThisDeclarationADefinition()) {
809 // Write the DefinitionData
810 ObjCInterfaceDecl::DefinitionData
&Data
= D
->data();
812 Record
.AddTypeSourceInfo(D
->getSuperClassTInfo());
813 Record
.AddSourceLocation(D
->getEndOfDefinitionLoc());
814 Record
.push_back(Data
.HasDesignatedInitializers
);
815 Record
.push_back(D
->getODRHash());
817 // Write out the protocols that are directly referenced by the @interface.
818 Record
.push_back(Data
.ReferencedProtocols
.size());
819 for (const auto *P
: D
->protocols())
820 Record
.AddDeclRef(P
);
821 for (const auto &PL
: D
->protocol_locs())
822 Record
.AddSourceLocation(PL
);
824 // Write out the protocols that are transitively referenced.
825 Record
.push_back(Data
.AllReferencedProtocols
.size());
826 for (ObjCList
<ObjCProtocolDecl
>::iterator
827 P
= Data
.AllReferencedProtocols
.begin(),
828 PEnd
= Data
.AllReferencedProtocols
.end();
830 Record
.AddDeclRef(*P
);
833 if (ObjCCategoryDecl
*Cat
= D
->getCategoryListRaw()) {
834 // Ensure that we write out the set of categories for this class.
835 Writer
.ObjCClassesWithCategories
.insert(D
);
837 // Make sure that the categories get serialized.
838 for (; Cat
; Cat
= Cat
->getNextClassCategoryRaw())
839 (void)Writer
.GetDeclRef(Cat
);
843 Code
= serialization::DECL_OBJC_INTERFACE
;
846 void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl
*D
) {
848 // FIXME: stable encoding for @public/@private/@protected/@package
849 Record
.push_back(D
->getAccessControl());
850 Record
.push_back(D
->getSynthesize());
852 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
856 !D
->isInvalidDecl() &&
857 !D
->isReferenced() &&
858 !D
->isModulePrivate() &&
862 AbbrevToUse
= Writer
.getDeclObjCIvarAbbrev();
864 Code
= serialization::DECL_OBJC_IVAR
;
867 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl
*D
) {
868 VisitRedeclarable(D
);
869 VisitObjCContainerDecl(D
);
871 Record
.push_back(D
->isThisDeclarationADefinition());
872 if (D
->isThisDeclarationADefinition()) {
873 Record
.push_back(D
->protocol_size());
874 for (const auto *I
: D
->protocols())
875 Record
.AddDeclRef(I
);
876 for (const auto &PL
: D
->protocol_locs())
877 Record
.AddSourceLocation(PL
);
878 Record
.push_back(D
->getODRHash());
881 Code
= serialization::DECL_OBJC_PROTOCOL
;
884 void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*D
) {
886 Code
= serialization::DECL_OBJC_AT_DEFS_FIELD
;
889 void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl
*D
) {
890 VisitObjCContainerDecl(D
);
891 Record
.AddSourceLocation(D
->getCategoryNameLoc());
892 Record
.AddSourceLocation(D
->getIvarLBraceLoc());
893 Record
.AddSourceLocation(D
->getIvarRBraceLoc());
894 Record
.AddDeclRef(D
->getClassInterface());
895 AddObjCTypeParamList(D
->TypeParamList
);
896 Record
.push_back(D
->protocol_size());
897 for (const auto *I
: D
->protocols())
898 Record
.AddDeclRef(I
);
899 for (const auto &PL
: D
->protocol_locs())
900 Record
.AddSourceLocation(PL
);
901 Code
= serialization::DECL_OBJC_CATEGORY
;
904 void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*D
) {
906 Record
.AddDeclRef(D
->getClassInterface());
907 Code
= serialization::DECL_OBJC_COMPATIBLE_ALIAS
;
910 void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl
*D
) {
912 Record
.AddSourceLocation(D
->getAtLoc());
913 Record
.AddSourceLocation(D
->getLParenLoc());
914 Record
.AddTypeRef(D
->getType());
915 Record
.AddTypeSourceInfo(D
->getTypeSourceInfo());
916 // FIXME: stable encoding
917 Record
.push_back((unsigned)D
->getPropertyAttributes());
918 Record
.push_back((unsigned)D
->getPropertyAttributesAsWritten());
919 // FIXME: stable encoding
920 Record
.push_back((unsigned)D
->getPropertyImplementation());
921 Record
.AddDeclarationName(D
->getGetterName());
922 Record
.AddSourceLocation(D
->getGetterNameLoc());
923 Record
.AddDeclarationName(D
->getSetterName());
924 Record
.AddSourceLocation(D
->getSetterNameLoc());
925 Record
.AddDeclRef(D
->getGetterMethodDecl());
926 Record
.AddDeclRef(D
->getSetterMethodDecl());
927 Record
.AddDeclRef(D
->getPropertyIvarDecl());
928 Code
= serialization::DECL_OBJC_PROPERTY
;
931 void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl
*D
) {
932 VisitObjCContainerDecl(D
);
933 Record
.AddDeclRef(D
->getClassInterface());
934 // Abstract class (no need to define a stable serialization::DECL code).
937 void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
) {
938 VisitObjCImplDecl(D
);
939 Record
.AddSourceLocation(D
->getCategoryNameLoc());
940 Code
= serialization::DECL_OBJC_CATEGORY_IMPL
;
943 void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl
*D
) {
944 VisitObjCImplDecl(D
);
945 Record
.AddDeclRef(D
->getSuperClass());
946 Record
.AddSourceLocation(D
->getSuperClassLoc());
947 Record
.AddSourceLocation(D
->getIvarLBraceLoc());
948 Record
.AddSourceLocation(D
->getIvarRBraceLoc());
949 Record
.push_back(D
->hasNonZeroConstructors());
950 Record
.push_back(D
->hasDestructors());
951 Record
.push_back(D
->NumIvarInitializers
);
952 if (D
->NumIvarInitializers
)
953 Record
.AddCXXCtorInitializers(
954 llvm::ArrayRef(D
->init_begin(), D
->init_end()));
955 Code
= serialization::DECL_OBJC_IMPLEMENTATION
;
958 void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
) {
960 Record
.AddSourceLocation(D
->getBeginLoc());
961 Record
.AddDeclRef(D
->getPropertyDecl());
962 Record
.AddDeclRef(D
->getPropertyIvarDecl());
963 Record
.AddSourceLocation(D
->getPropertyIvarDeclLoc());
964 Record
.AddDeclRef(D
->getGetterMethodDecl());
965 Record
.AddDeclRef(D
->getSetterMethodDecl());
966 Record
.AddStmt(D
->getGetterCXXConstructor());
967 Record
.AddStmt(D
->getSetterCXXAssignment());
968 Code
= serialization::DECL_OBJC_PROPERTY_IMPL
;
971 void ASTDeclWriter::VisitFieldDecl(FieldDecl
*D
) {
972 VisitDeclaratorDecl(D
);
973 Record
.push_back(D
->isMutable());
975 Record
.push_back((D
->StorageKind
<< 1) | D
->BitField
);
976 if (D
->StorageKind
== FieldDecl::ISK_CapturedVLAType
)
977 Record
.AddTypeRef(QualType(D
->getCapturedVLAType(), 0));
978 else if (D
->BitField
)
979 Record
.AddStmt(D
->getBitWidth());
981 if (!D
->getDeclName())
982 Record
.AddDeclRef(Context
.getInstantiatedFromUnnamedFieldDecl(D
));
984 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
988 !D
->isInvalidDecl() &&
989 !D
->isReferenced() &&
990 !D
->isTopLevelDeclInObjCContainer() &&
991 !D
->isModulePrivate() &&
993 !D
->hasInClassInitializer() &&
994 !D
->hasCapturedVLAType() &&
996 !ObjCIvarDecl::classofKind(D
->getKind()) &&
997 !ObjCAtDefsFieldDecl::classofKind(D
->getKind()) &&
999 AbbrevToUse
= Writer
.getDeclFieldAbbrev();
1001 Code
= serialization::DECL_FIELD
;
1004 void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl
*D
) {
1005 VisitDeclaratorDecl(D
);
1006 Record
.AddIdentifierRef(D
->getGetterId());
1007 Record
.AddIdentifierRef(D
->getSetterId());
1008 Code
= serialization::DECL_MS_PROPERTY
;
1011 void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl
*D
) {
1013 MSGuidDecl::Parts Parts
= D
->getParts();
1014 Record
.push_back(Parts
.Part1
);
1015 Record
.push_back(Parts
.Part2
);
1016 Record
.push_back(Parts
.Part3
);
1017 Record
.append(std::begin(Parts
.Part4And5
), std::end(Parts
.Part4And5
));
1018 Code
= serialization::DECL_MS_GUID
;
1021 void ASTDeclWriter::VisitUnnamedGlobalConstantDecl(
1022 UnnamedGlobalConstantDecl
*D
) {
1024 Record
.AddAPValue(D
->getValue());
1025 Code
= serialization::DECL_UNNAMED_GLOBAL_CONSTANT
;
1028 void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl
*D
) {
1030 Record
.AddAPValue(D
->getValue());
1031 Code
= serialization::DECL_TEMPLATE_PARAM_OBJECT
;
1034 void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl
*D
) {
1036 Record
.push_back(D
->getChainingSize());
1038 for (const auto *P
: D
->chain())
1039 Record
.AddDeclRef(P
);
1040 Code
= serialization::DECL_INDIRECTFIELD
;
1043 void ASTDeclWriter::VisitVarDecl(VarDecl
*D
) {
1044 VisitRedeclarable(D
);
1045 VisitDeclaratorDecl(D
);
1046 Record
.push_back(D
->getStorageClass());
1047 Record
.push_back(D
->getTSCSpec());
1048 Record
.push_back(D
->getInitStyle());
1049 Record
.push_back(D
->isARCPseudoStrong());
1050 bool HasDeducedType
= false;
1051 if (!isa
<ParmVarDecl
>(D
)) {
1052 Record
.push_back(D
->isThisDeclarationADemotedDefinition());
1053 Record
.push_back(D
->isExceptionVariable());
1054 Record
.push_back(D
->isNRVOVariable());
1055 Record
.push_back(D
->isCXXForRangeDecl());
1056 Record
.push_back(D
->isObjCForDecl());
1057 Record
.push_back(D
->isInline());
1058 Record
.push_back(D
->isInlineSpecified());
1059 Record
.push_back(D
->isConstexpr());
1060 Record
.push_back(D
->isInitCapture());
1061 Record
.push_back(D
->isPreviousDeclInSameBlockScope());
1062 if (const auto *IPD
= dyn_cast
<ImplicitParamDecl
>(D
))
1063 Record
.push_back(static_cast<unsigned>(IPD
->getParameterKind()));
1065 Record
.push_back(0);
1066 Record
.push_back(D
->isEscapingByref());
1067 HasDeducedType
= D
->getType()->getContainedDeducedType();
1068 Record
.push_back(HasDeducedType
);
1070 Record
.push_back(D
->getLinkageInternal());
1072 if (D
->hasAttr
<BlocksAttr
>()) {
1073 BlockVarCopyInit Init
= Writer
.Context
->getBlockVarCopyInit(D
);
1074 Record
.AddStmt(Init
.getCopyExpr());
1075 if (Init
.getCopyExpr())
1076 Record
.push_back(Init
.canThrow());
1079 bool ModulesCodegen
= false;
1080 if (Writer
.WritingModule
&& D
->getStorageDuration() == SD_Static
&&
1081 !D
->getDescribedVarTemplate()) {
1082 // When building a C++20 module interface unit or a partition unit, a
1083 // strong definition in the module interface is provided by the
1084 // compilation of that unit, not by its users. (Inline variables are still
1085 // emitted in module users.)
1087 (Writer
.WritingModule
->isInterfaceOrPartition() ||
1088 (D
->hasAttr
<DLLExportAttr
>() &&
1089 Writer
.Context
->getLangOpts().BuildingPCHWithObjectFile
)) &&
1090 Writer
.Context
->GetGVALinkageForVariable(D
) >= GVA_StrongExternal
;
1092 Record
.push_back(ModulesCodegen
);
1094 Writer
.ModularCodegenDecls
.push_back(Writer
.GetDeclRef(D
));
1097 VarNotTemplate
= 0, VarTemplate
, StaticDataMemberSpecialization
1099 if (VarTemplateDecl
*TemplD
= D
->getDescribedVarTemplate()) {
1100 Record
.push_back(VarTemplate
);
1101 Record
.AddDeclRef(TemplD
);
1102 } else if (MemberSpecializationInfo
*SpecInfo
1103 = D
->getMemberSpecializationInfo()) {
1104 Record
.push_back(StaticDataMemberSpecialization
);
1105 Record
.AddDeclRef(SpecInfo
->getInstantiatedFrom());
1106 Record
.push_back(SpecInfo
->getTemplateSpecializationKind());
1107 Record
.AddSourceLocation(SpecInfo
->getPointOfInstantiation());
1109 Record
.push_back(VarNotTemplate
);
1112 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
1115 !D
->isUsed(false) &&
1116 !D
->isInvalidDecl() &&
1117 !D
->isReferenced() &&
1118 !D
->isTopLevelDeclInObjCContainer() &&
1119 D
->getAccess() == AS_none
&&
1120 !D
->isModulePrivate() &&
1121 !needsAnonymousDeclarationNumber(D
) &&
1122 D
->getDeclName().getNameKind() == DeclarationName::Identifier
&&
1124 D
->getFirstDecl() == D
->getMostRecentDecl() &&
1125 D
->getKind() == Decl::Var
&&
1127 !D
->isConstexpr() &&
1128 !D
->isInitCapture() &&
1129 !D
->isPreviousDeclInSameBlockScope() &&
1130 !D
->isEscapingByref() &&
1132 D
->getStorageDuration() != SD_Static
&&
1133 !D
->getDescribedVarTemplate() &&
1134 !D
->getMemberSpecializationInfo())
1135 AbbrevToUse
= Writer
.getDeclVarAbbrev();
1137 Code
= serialization::DECL_VAR
;
1140 void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl
*D
) {
1142 Code
= serialization::DECL_IMPLICIT_PARAM
;
1145 void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl
*D
) {
1147 Record
.push_back(D
->isObjCMethodParameter());
1148 Record
.push_back(D
->getFunctionScopeDepth());
1149 Record
.push_back(D
->getFunctionScopeIndex());
1150 Record
.push_back(D
->getObjCDeclQualifier()); // FIXME: stable encoding
1151 Record
.push_back(D
->isKNRPromoted());
1152 Record
.push_back(D
->hasInheritedDefaultArg());
1153 Record
.push_back(D
->hasUninstantiatedDefaultArg());
1154 if (D
->hasUninstantiatedDefaultArg())
1155 Record
.AddStmt(D
->getUninstantiatedDefaultArg());
1156 Record
.AddSourceLocation(D
->getExplicitObjectParamThisLoc());
1157 Code
= serialization::DECL_PARM_VAR
;
1159 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1160 // we dynamically check for the properties that we optimize for, but don't
1161 // know are true of all PARM_VAR_DECLs.
1162 if (D
->getDeclContext() == D
->getLexicalDeclContext() && !D
->hasAttrs() &&
1163 !D
->hasExtInfo() && !D
->isImplicit() && !D
->isUsed(false) &&
1164 !D
->isInvalidDecl() && !D
->isReferenced() && D
->getAccess() == AS_none
&&
1165 !D
->isModulePrivate() && D
->getStorageClass() == 0 &&
1166 D
->getInitStyle() == VarDecl::CInit
&& // Can params have anything else?
1167 D
->getFunctionScopeDepth() == 0 && D
->getObjCDeclQualifier() == 0 &&
1168 !D
->isKNRPromoted() && !D
->isExplicitObjectParameter() &&
1169 !D
->hasInheritedDefaultArg() && D
->getInit() == nullptr &&
1170 !D
->hasUninstantiatedDefaultArg()) // No default expr.
1171 AbbrevToUse
= Writer
.getDeclParmVarAbbrev();
1173 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1174 // just us assuming it.
1175 assert(!D
->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
1176 assert(!D
->isThisDeclarationADemotedDefinition()
1177 && "PARM_VAR_DECL can't be demoted definition.");
1178 assert(D
->getAccess() == AS_none
&& "PARM_VAR_DECL can't be public/private");
1179 assert(!D
->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
1180 assert(D
->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
1181 assert(!D
->isStaticDataMember() &&
1182 "PARM_VAR_DECL can't be static data member");
1185 void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl
*D
) {
1186 // Record the number of bindings first to simplify deserialization.
1187 Record
.push_back(D
->bindings().size());
1190 for (auto *B
: D
->bindings())
1191 Record
.AddDeclRef(B
);
1192 Code
= serialization::DECL_DECOMPOSITION
;
1195 void ASTDeclWriter::VisitBindingDecl(BindingDecl
*D
) {
1197 Record
.AddStmt(D
->getBinding());
1198 Code
= serialization::DECL_BINDING
;
1201 void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl
*D
) {
1203 Record
.AddStmt(D
->getAsmString());
1204 Record
.AddSourceLocation(D
->getRParenLoc());
1205 Code
= serialization::DECL_FILE_SCOPE_ASM
;
1208 void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl
*D
) {
1210 Record
.AddStmt(D
->getStmt());
1211 Code
= serialization::DECL_TOP_LEVEL_STMT_DECL
;
1214 void ASTDeclWriter::VisitEmptyDecl(EmptyDecl
*D
) {
1216 Code
= serialization::DECL_EMPTY
;
1219 void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(
1220 LifetimeExtendedTemporaryDecl
*D
) {
1222 Record
.AddDeclRef(D
->getExtendingDecl());
1223 Record
.AddStmt(D
->getTemporaryExpr());
1224 Record
.push_back(static_cast<bool>(D
->getValue()));
1226 Record
.AddAPValue(*D
->getValue());
1227 Record
.push_back(D
->getManglingNumber());
1228 Code
= serialization::DECL_LIFETIME_EXTENDED_TEMPORARY
;
1230 void ASTDeclWriter::VisitBlockDecl(BlockDecl
*D
) {
1232 Record
.AddStmt(D
->getBody());
1233 Record
.AddTypeSourceInfo(D
->getSignatureAsWritten());
1234 Record
.push_back(D
->param_size());
1235 for (ParmVarDecl
*P
: D
->parameters())
1236 Record
.AddDeclRef(P
);
1237 Record
.push_back(D
->isVariadic());
1238 Record
.push_back(D
->blockMissingReturnType());
1239 Record
.push_back(D
->isConversionFromLambda());
1240 Record
.push_back(D
->doesNotEscape());
1241 Record
.push_back(D
->canAvoidCopyToHeap());
1242 Record
.push_back(D
->capturesCXXThis());
1243 Record
.push_back(D
->getNumCaptures());
1244 for (const auto &capture
: D
->captures()) {
1245 Record
.AddDeclRef(capture
.getVariable());
1248 if (capture
.isByRef()) flags
|= 1;
1249 if (capture
.isNested()) flags
|= 2;
1250 if (capture
.hasCopyExpr()) flags
|= 4;
1251 Record
.push_back(flags
);
1253 if (capture
.hasCopyExpr()) Record
.AddStmt(capture
.getCopyExpr());
1256 Code
= serialization::DECL_BLOCK
;
1259 void ASTDeclWriter::VisitCapturedDecl(CapturedDecl
*CD
) {
1260 Record
.push_back(CD
->getNumParams());
1262 Record
.push_back(CD
->getContextParamPosition());
1263 Record
.push_back(CD
->isNothrow() ? 1 : 0);
1264 // Body is stored by VisitCapturedStmt.
1265 for (unsigned I
= 0; I
< CD
->getNumParams(); ++I
)
1266 Record
.AddDeclRef(CD
->getParam(I
));
1267 Code
= serialization::DECL_CAPTURED
;
1270 void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl
*D
) {
1271 static_assert(DeclContext::NumLinkageSpecDeclBits
== 17,
1272 "You need to update the serializer after you change the"
1273 "LinkageSpecDeclBits");
1276 Record
.push_back(llvm::to_underlying(D
->getLanguage()));
1277 Record
.AddSourceLocation(D
->getExternLoc());
1278 Record
.AddSourceLocation(D
->getRBraceLoc());
1279 Code
= serialization::DECL_LINKAGE_SPEC
;
1282 void ASTDeclWriter::VisitExportDecl(ExportDecl
*D
) {
1284 Record
.AddSourceLocation(D
->getRBraceLoc());
1285 Code
= serialization::DECL_EXPORT
;
1288 void ASTDeclWriter::VisitLabelDecl(LabelDecl
*D
) {
1290 Record
.AddSourceLocation(D
->getBeginLoc());
1291 Code
= serialization::DECL_LABEL
;
1295 void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl
*D
) {
1296 VisitRedeclarable(D
);
1298 Record
.push_back(D
->isInline());
1299 Record
.push_back(D
->isNested());
1300 Record
.AddSourceLocation(D
->getBeginLoc());
1301 Record
.AddSourceLocation(D
->getRBraceLoc());
1303 if (D
->isOriginalNamespace())
1304 Record
.AddDeclRef(D
->getAnonymousNamespace());
1305 Code
= serialization::DECL_NAMESPACE
;
1307 if (Writer
.hasChain() && D
->isAnonymousNamespace() &&
1308 D
== D
->getMostRecentDecl()) {
1309 // This is a most recent reopening of the anonymous namespace. If its parent
1310 // is in a previous PCH (or is the TU), mark that parent for update, because
1311 // the original namespace always points to the latest re-opening of its
1312 // anonymous namespace.
1313 Decl
*Parent
= cast
<Decl
>(
1314 D
->getParent()->getRedeclContext()->getPrimaryContext());
1315 if (Parent
->isFromASTFile() || isa
<TranslationUnitDecl
>(Parent
)) {
1316 Writer
.DeclUpdates
[Parent
].push_back(
1317 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE
, D
));
1322 void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
) {
1323 VisitRedeclarable(D
);
1325 Record
.AddSourceLocation(D
->getNamespaceLoc());
1326 Record
.AddSourceLocation(D
->getTargetNameLoc());
1327 Record
.AddNestedNameSpecifierLoc(D
->getQualifierLoc());
1328 Record
.AddDeclRef(D
->getNamespace());
1329 Code
= serialization::DECL_NAMESPACE_ALIAS
;
1332 void ASTDeclWriter::VisitUsingDecl(UsingDecl
*D
) {
1334 Record
.AddSourceLocation(D
->getUsingLoc());
1335 Record
.AddNestedNameSpecifierLoc(D
->getQualifierLoc());
1336 Record
.AddDeclarationNameLoc(D
->DNLoc
, D
->getDeclName());
1337 Record
.AddDeclRef(D
->FirstUsingShadow
.getPointer());
1338 Record
.push_back(D
->hasTypename());
1339 Record
.AddDeclRef(Context
.getInstantiatedFromUsingDecl(D
));
1340 Code
= serialization::DECL_USING
;
1343 void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl
*D
) {
1345 Record
.AddSourceLocation(D
->getUsingLoc());
1346 Record
.AddSourceLocation(D
->getEnumLoc());
1347 Record
.AddTypeSourceInfo(D
->getEnumType());
1348 Record
.AddDeclRef(D
->FirstUsingShadow
.getPointer());
1349 Record
.AddDeclRef(Context
.getInstantiatedFromUsingEnumDecl(D
));
1350 Code
= serialization::DECL_USING_ENUM
;
1353 void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl
*D
) {
1354 Record
.push_back(D
->NumExpansions
);
1356 Record
.AddDeclRef(D
->getInstantiatedFromUsingDecl());
1357 for (auto *E
: D
->expansions())
1358 Record
.AddDeclRef(E
);
1359 Code
= serialization::DECL_USING_PACK
;
1362 void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl
*D
) {
1363 VisitRedeclarable(D
);
1365 Record
.AddDeclRef(D
->getTargetDecl());
1366 Record
.push_back(D
->getIdentifierNamespace());
1367 Record
.AddDeclRef(D
->UsingOrNextShadow
);
1368 Record
.AddDeclRef(Context
.getInstantiatedFromUsingShadowDecl(D
));
1369 Code
= serialization::DECL_USING_SHADOW
;
1372 void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1373 ConstructorUsingShadowDecl
*D
) {
1374 VisitUsingShadowDecl(D
);
1375 Record
.AddDeclRef(D
->NominatedBaseClassShadowDecl
);
1376 Record
.AddDeclRef(D
->ConstructedBaseClassShadowDecl
);
1377 Record
.push_back(D
->IsVirtual
);
1378 Code
= serialization::DECL_CONSTRUCTOR_USING_SHADOW
;
1381 void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
) {
1383 Record
.AddSourceLocation(D
->getUsingLoc());
1384 Record
.AddSourceLocation(D
->getNamespaceKeyLocation());
1385 Record
.AddNestedNameSpecifierLoc(D
->getQualifierLoc());
1386 Record
.AddDeclRef(D
->getNominatedNamespace());
1387 Record
.AddDeclRef(dyn_cast
<Decl
>(D
->getCommonAncestor()));
1388 Code
= serialization::DECL_USING_DIRECTIVE
;
1391 void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
) {
1393 Record
.AddSourceLocation(D
->getUsingLoc());
1394 Record
.AddNestedNameSpecifierLoc(D
->getQualifierLoc());
1395 Record
.AddDeclarationNameLoc(D
->DNLoc
, D
->getDeclName());
1396 Record
.AddSourceLocation(D
->getEllipsisLoc());
1397 Code
= serialization::DECL_UNRESOLVED_USING_VALUE
;
1400 void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
1401 UnresolvedUsingTypenameDecl
*D
) {
1403 Record
.AddSourceLocation(D
->getTypenameLoc());
1404 Record
.AddNestedNameSpecifierLoc(D
->getQualifierLoc());
1405 Record
.AddSourceLocation(D
->getEllipsisLoc());
1406 Code
= serialization::DECL_UNRESOLVED_USING_TYPENAME
;
1409 void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl(
1410 UnresolvedUsingIfExistsDecl
*D
) {
1412 Code
= serialization::DECL_UNRESOLVED_USING_IF_EXISTS
;
1415 void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl
*D
) {
1419 CXXRecNotTemplate
= 0,
1421 CXXRecMemberSpecialization
,
1424 if (ClassTemplateDecl
*TemplD
= D
->getDescribedClassTemplate()) {
1425 Record
.push_back(CXXRecTemplate
);
1426 Record
.AddDeclRef(TemplD
);
1427 } else if (MemberSpecializationInfo
*MSInfo
1428 = D
->getMemberSpecializationInfo()) {
1429 Record
.push_back(CXXRecMemberSpecialization
);
1430 Record
.AddDeclRef(MSInfo
->getInstantiatedFrom());
1431 Record
.push_back(MSInfo
->getTemplateSpecializationKind());
1432 Record
.AddSourceLocation(MSInfo
->getPointOfInstantiation());
1433 } else if (D
->isLambda()) {
1434 // For a lambda, we need some information early for merging.
1435 Record
.push_back(CXXLambda
);
1436 if (auto *Context
= D
->getLambdaContextDecl()) {
1437 Record
.AddDeclRef(Context
);
1438 Record
.push_back(D
->getLambdaIndexInContext());
1440 Record
.push_back(0);
1443 Record
.push_back(CXXRecNotTemplate
);
1446 Record
.push_back(D
->isThisDeclarationADefinition());
1447 if (D
->isThisDeclarationADefinition())
1448 Record
.AddCXXDefinitionData(D
);
1450 // Store (what we currently believe to be) the key function to avoid
1451 // deserializing every method so we can compute it.
1452 if (D
->isCompleteDefinition())
1453 Record
.AddDeclRef(Context
.getCurrentKeyFunction(D
));
1455 Code
= serialization::DECL_CXX_RECORD
;
1458 void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl
*D
) {
1459 VisitFunctionDecl(D
);
1460 if (D
->isCanonicalDecl()) {
1461 Record
.push_back(D
->size_overridden_methods());
1462 for (const CXXMethodDecl
*MD
: D
->overridden_methods())
1463 Record
.AddDeclRef(MD
);
1465 // We only need to record overridden methods once for the canonical decl.
1466 Record
.push_back(0);
1469 if (D
->getDeclContext() == D
->getLexicalDeclContext() &&
1470 D
->getFirstDecl() == D
->getMostRecentDecl() && !D
->isInvalidDecl() &&
1471 !D
->hasAttrs() && !D
->isTopLevelDeclInObjCContainer() &&
1472 D
->getDeclName().getNameKind() == DeclarationName::Identifier
&&
1473 !D
->hasExtInfo() && !D
->hasInheritedPrototype() &&
1474 D
->hasWrittenPrototype() &&
1475 D
->getTemplatedKind() == FunctionDecl::TK_NonTemplate
)
1476 AbbrevToUse
= Writer
.getDeclCXXMethodAbbrev();
1478 Code
= serialization::DECL_CXX_METHOD
;
1481 void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl
*D
) {
1482 static_assert(DeclContext::NumCXXConstructorDeclBits
== 64,
1483 "You need to update the serializer after you change the "
1484 "CXXConstructorDeclBits");
1486 Record
.push_back(D
->getTrailingAllocKind());
1487 addExplicitSpecifier(D
->getExplicitSpecifier(), Record
);
1488 if (auto Inherited
= D
->getInheritedConstructor()) {
1489 Record
.AddDeclRef(Inherited
.getShadowDecl());
1490 Record
.AddDeclRef(Inherited
.getConstructor());
1493 VisitCXXMethodDecl(D
);
1494 Code
= serialization::DECL_CXX_CONSTRUCTOR
;
1497 void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl
*D
) {
1498 VisitCXXMethodDecl(D
);
1500 Record
.AddDeclRef(D
->getOperatorDelete());
1501 if (D
->getOperatorDelete())
1502 Record
.AddStmt(D
->getOperatorDeleteThisArg());
1504 Code
= serialization::DECL_CXX_DESTRUCTOR
;
1507 void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl
*D
) {
1508 addExplicitSpecifier(D
->getExplicitSpecifier(), Record
);
1509 VisitCXXMethodDecl(D
);
1510 Code
= serialization::DECL_CXX_CONVERSION
;
1513 void ASTDeclWriter::VisitImportDecl(ImportDecl
*D
) {
1515 Record
.push_back(Writer
.getSubmoduleID(D
->getImportedModule()));
1516 ArrayRef
<SourceLocation
> IdentifierLocs
= D
->getIdentifierLocs();
1517 Record
.push_back(!IdentifierLocs
.empty());
1518 if (IdentifierLocs
.empty()) {
1519 Record
.AddSourceLocation(D
->getEndLoc());
1520 Record
.push_back(1);
1522 for (unsigned I
= 0, N
= IdentifierLocs
.size(); I
!= N
; ++I
)
1523 Record
.AddSourceLocation(IdentifierLocs
[I
]);
1524 Record
.push_back(IdentifierLocs
.size());
1526 // Note: the number of source locations must always be the last element in
1528 Code
= serialization::DECL_IMPORT
;
1531 void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl
*D
) {
1533 Record
.AddSourceLocation(D
->getColonLoc());
1534 Code
= serialization::DECL_ACCESS_SPEC
;
1537 void ASTDeclWriter::VisitFriendDecl(FriendDecl
*D
) {
1538 // Record the number of friend type template parameter lists here
1539 // so as to simplify memory allocation during deserialization.
1540 Record
.push_back(D
->NumTPLists
);
1542 bool hasFriendDecl
= D
->Friend
.is
<NamedDecl
*>();
1543 Record
.push_back(hasFriendDecl
);
1545 Record
.AddDeclRef(D
->getFriendDecl());
1547 Record
.AddTypeSourceInfo(D
->getFriendType());
1548 for (unsigned i
= 0; i
< D
->NumTPLists
; ++i
)
1549 Record
.AddTemplateParameterList(D
->getFriendTypeTemplateParameterList(i
));
1550 Record
.AddDeclRef(D
->getNextFriend());
1551 Record
.push_back(D
->UnsupportedFriend
);
1552 Record
.AddSourceLocation(D
->FriendLoc
);
1553 Code
= serialization::DECL_FRIEND
;
1556 void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl
*D
) {
1558 Record
.push_back(D
->getNumTemplateParameters());
1559 for (unsigned i
= 0, e
= D
->getNumTemplateParameters(); i
!= e
; ++i
)
1560 Record
.AddTemplateParameterList(D
->getTemplateParameterList(i
));
1561 Record
.push_back(D
->getFriendDecl() != nullptr);
1562 if (D
->getFriendDecl())
1563 Record
.AddDeclRef(D
->getFriendDecl());
1565 Record
.AddTypeSourceInfo(D
->getFriendType());
1566 Record
.AddSourceLocation(D
->getFriendLoc());
1567 Code
= serialization::DECL_FRIEND_TEMPLATE
;
1570 void ASTDeclWriter::VisitTemplateDecl(TemplateDecl
*D
) {
1573 Record
.AddTemplateParameterList(D
->getTemplateParameters());
1574 Record
.AddDeclRef(D
->getTemplatedDecl());
1577 void ASTDeclWriter::VisitConceptDecl(ConceptDecl
*D
) {
1578 VisitTemplateDecl(D
);
1579 Record
.AddStmt(D
->getConstraintExpr());
1580 Code
= serialization::DECL_CONCEPT
;
1583 void ASTDeclWriter::VisitImplicitConceptSpecializationDecl(
1584 ImplicitConceptSpecializationDecl
*D
) {
1585 Record
.push_back(D
->getTemplateArguments().size());
1587 for (const TemplateArgument
&Arg
: D
->getTemplateArguments())
1588 Record
.AddTemplateArgument(Arg
);
1589 Code
= serialization::DECL_IMPLICIT_CONCEPT_SPECIALIZATION
;
1592 void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl
*D
) {
1593 Code
= serialization::DECL_REQUIRES_EXPR_BODY
;
1596 void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
) {
1597 VisitRedeclarable(D
);
1599 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1600 // getCommonPtr() can be used while this is still initializing.
1601 if (D
->isFirstDecl()) {
1602 // This declaration owns the 'common' pointer, so serialize that data now.
1603 Record
.AddDeclRef(D
->getInstantiatedFromMemberTemplate());
1604 if (D
->getInstantiatedFromMemberTemplate())
1605 Record
.push_back(D
->isMemberSpecialization());
1608 VisitTemplateDecl(D
);
1609 Record
.push_back(D
->getIdentifierNamespace());
1612 void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl
*D
) {
1613 VisitRedeclarableTemplateDecl(D
);
1615 if (D
->isFirstDecl())
1616 AddTemplateSpecializations(D
);
1617 Code
= serialization::DECL_CLASS_TEMPLATE
;
1620 void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
1621 ClassTemplateSpecializationDecl
*D
) {
1622 RegisterTemplateSpecialization(D
->getSpecializedTemplate(), D
);
1624 VisitCXXRecordDecl(D
);
1626 llvm::PointerUnion
<ClassTemplateDecl
*,
1627 ClassTemplatePartialSpecializationDecl
*> InstFrom
1628 = D
->getSpecializedTemplateOrPartial();
1629 if (Decl
*InstFromD
= InstFrom
.dyn_cast
<ClassTemplateDecl
*>()) {
1630 Record
.AddDeclRef(InstFromD
);
1632 Record
.AddDeclRef(InstFrom
.get
<ClassTemplatePartialSpecializationDecl
*>());
1633 Record
.AddTemplateArgumentList(&D
->getTemplateInstantiationArgs());
1636 Record
.AddTemplateArgumentList(&D
->getTemplateArgs());
1637 Record
.AddSourceLocation(D
->getPointOfInstantiation());
1638 Record
.push_back(D
->getSpecializationKind());
1639 Record
.push_back(D
->isCanonicalDecl());
1641 if (D
->isCanonicalDecl()) {
1642 // When reading, we'll add it to the folding set of the following template.
1643 Record
.AddDeclRef(D
->getSpecializedTemplate()->getCanonicalDecl());
1647 Record
.AddTypeSourceInfo(D
->getTypeAsWritten());
1648 if (D
->getTypeAsWritten()) {
1649 Record
.AddSourceLocation(D
->getExternLoc());
1650 Record
.AddSourceLocation(D
->getTemplateKeywordLoc());
1653 Code
= serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION
;
1656 void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
1657 ClassTemplatePartialSpecializationDecl
*D
) {
1658 Record
.AddTemplateParameterList(D
->getTemplateParameters());
1659 Record
.AddASTTemplateArgumentListInfo(D
->getTemplateArgsAsWritten());
1661 VisitClassTemplateSpecializationDecl(D
);
1663 // These are read/set from/to the first declaration.
1664 if (D
->getPreviousDecl() == nullptr) {
1665 Record
.AddDeclRef(D
->getInstantiatedFromMember());
1666 Record
.push_back(D
->isMemberSpecialization());
1669 Code
= serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
;
1672 void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl
*D
) {
1673 VisitRedeclarableTemplateDecl(D
);
1675 if (D
->isFirstDecl())
1676 AddTemplateSpecializations(D
);
1677 Code
= serialization::DECL_VAR_TEMPLATE
;
1680 void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1681 VarTemplateSpecializationDecl
*D
) {
1682 RegisterTemplateSpecialization(D
->getSpecializedTemplate(), D
);
1684 llvm::PointerUnion
<VarTemplateDecl
*, VarTemplatePartialSpecializationDecl
*>
1685 InstFrom
= D
->getSpecializedTemplateOrPartial();
1686 if (Decl
*InstFromD
= InstFrom
.dyn_cast
<VarTemplateDecl
*>()) {
1687 Record
.AddDeclRef(InstFromD
);
1689 Record
.AddDeclRef(InstFrom
.get
<VarTemplatePartialSpecializationDecl
*>());
1690 Record
.AddTemplateArgumentList(&D
->getTemplateInstantiationArgs());
1694 Record
.AddTypeSourceInfo(D
->getTypeAsWritten());
1695 if (D
->getTypeAsWritten()) {
1696 Record
.AddSourceLocation(D
->getExternLoc());
1697 Record
.AddSourceLocation(D
->getTemplateKeywordLoc());
1700 Record
.AddTemplateArgumentList(&D
->getTemplateArgs());
1701 Record
.AddSourceLocation(D
->getPointOfInstantiation());
1702 Record
.push_back(D
->getSpecializationKind());
1703 Record
.push_back(D
->IsCompleteDefinition
);
1707 Record
.push_back(D
->isCanonicalDecl());
1709 if (D
->isCanonicalDecl()) {
1710 // When reading, we'll add it to the folding set of the following template.
1711 Record
.AddDeclRef(D
->getSpecializedTemplate()->getCanonicalDecl());
1714 Code
= serialization::DECL_VAR_TEMPLATE_SPECIALIZATION
;
1717 void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1718 VarTemplatePartialSpecializationDecl
*D
) {
1719 Record
.AddTemplateParameterList(D
->getTemplateParameters());
1720 Record
.AddASTTemplateArgumentListInfo(D
->getTemplateArgsAsWritten());
1722 VisitVarTemplateSpecializationDecl(D
);
1724 // These are read/set from/to the first declaration.
1725 if (D
->getPreviousDecl() == nullptr) {
1726 Record
.AddDeclRef(D
->getInstantiatedFromMember());
1727 Record
.push_back(D
->isMemberSpecialization());
1730 Code
= serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION
;
1733 void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
) {
1734 VisitRedeclarableTemplateDecl(D
);
1736 if (D
->isFirstDecl())
1737 AddTemplateSpecializations(D
);
1738 Code
= serialization::DECL_FUNCTION_TEMPLATE
;
1741 void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
) {
1742 Record
.push_back(D
->hasTypeConstraint());
1745 Record
.push_back(D
->wasDeclaredWithTypename());
1747 const TypeConstraint
*TC
= D
->getTypeConstraint();
1748 Record
.push_back(TC
!= nullptr);
1750 auto *CR
= TC
->getConceptReference();
1751 Record
.push_back(CR
!= nullptr);
1753 Record
.AddConceptReference(CR
);
1754 Record
.AddStmt(TC
->getImmediatelyDeclaredConstraint());
1755 Record
.push_back(D
->isExpandedParameterPack());
1756 if (D
->isExpandedParameterPack())
1757 Record
.push_back(D
->getNumExpansionParameters());
1760 bool OwnsDefaultArg
= D
->hasDefaultArgument() &&
1761 !D
->defaultArgumentWasInherited();
1762 Record
.push_back(OwnsDefaultArg
);
1764 Record
.AddTypeSourceInfo(D
->getDefaultArgumentInfo());
1766 Code
= serialization::DECL_TEMPLATE_TYPE_PARM
;
1769 void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
*D
) {
1770 // For an expanded parameter pack, record the number of expansion types here
1771 // so that it's easier for deserialization to allocate the right amount of
1773 Expr
*TypeConstraint
= D
->getPlaceholderTypeConstraint();
1774 Record
.push_back(!!TypeConstraint
);
1775 if (D
->isExpandedParameterPack())
1776 Record
.push_back(D
->getNumExpansionTypes());
1778 VisitDeclaratorDecl(D
);
1779 // TemplateParmPosition.
1780 Record
.push_back(D
->getDepth());
1781 Record
.push_back(D
->getPosition());
1783 Record
.AddStmt(TypeConstraint
);
1785 if (D
->isExpandedParameterPack()) {
1786 for (unsigned I
= 0, N
= D
->getNumExpansionTypes(); I
!= N
; ++I
) {
1787 Record
.AddTypeRef(D
->getExpansionType(I
));
1788 Record
.AddTypeSourceInfo(D
->getExpansionTypeSourceInfo(I
));
1791 Code
= serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
;
1793 // Rest of NonTypeTemplateParmDecl.
1794 Record
.push_back(D
->isParameterPack());
1795 bool OwnsDefaultArg
= D
->hasDefaultArgument() &&
1796 !D
->defaultArgumentWasInherited();
1797 Record
.push_back(OwnsDefaultArg
);
1799 Record
.AddStmt(D
->getDefaultArgument());
1800 Code
= serialization::DECL_NON_TYPE_TEMPLATE_PARM
;
1804 void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
) {
1805 // For an expanded parameter pack, record the number of expansion types here
1806 // so that it's easier for deserialization to allocate the right amount of
1808 if (D
->isExpandedParameterPack())
1809 Record
.push_back(D
->getNumExpansionTemplateParameters());
1811 VisitTemplateDecl(D
);
1812 // TemplateParmPosition.
1813 Record
.push_back(D
->getDepth());
1814 Record
.push_back(D
->getPosition());
1816 if (D
->isExpandedParameterPack()) {
1817 for (unsigned I
= 0, N
= D
->getNumExpansionTemplateParameters();
1819 Record
.AddTemplateParameterList(D
->getExpansionTemplateParameters(I
));
1820 Code
= serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK
;
1822 // Rest of TemplateTemplateParmDecl.
1823 Record
.push_back(D
->isParameterPack());
1824 bool OwnsDefaultArg
= D
->hasDefaultArgument() &&
1825 !D
->defaultArgumentWasInherited();
1826 Record
.push_back(OwnsDefaultArg
);
1828 Record
.AddTemplateArgumentLoc(D
->getDefaultArgument());
1829 Code
= serialization::DECL_TEMPLATE_TEMPLATE_PARM
;
1833 void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl
*D
) {
1834 VisitRedeclarableTemplateDecl(D
);
1835 Code
= serialization::DECL_TYPE_ALIAS_TEMPLATE
;
1838 void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl
*D
) {
1840 Record
.AddStmt(D
->getAssertExpr());
1841 Record
.push_back(D
->isFailed());
1842 Record
.AddStmt(D
->getMessage());
1843 Record
.AddSourceLocation(D
->getRParenLoc());
1844 Code
= serialization::DECL_STATIC_ASSERT
;
1847 /// Emit the DeclContext part of a declaration context decl.
1848 void ASTDeclWriter::VisitDeclContext(DeclContext
*DC
) {
1849 static_assert(DeclContext::NumDeclContextBits
== 13,
1850 "You need to update the serializer after you change the "
1853 Record
.AddOffset(Writer
.WriteDeclContextLexicalBlock(Context
, DC
));
1854 Record
.AddOffset(Writer
.WriteDeclContextVisibleBlock(Context
, DC
));
1857 const Decl
*ASTWriter::getFirstLocalDecl(const Decl
*D
) {
1858 assert(IsLocalDecl(D
) && "expected a local declaration");
1860 const Decl
*Canon
= D
->getCanonicalDecl();
1861 if (IsLocalDecl(Canon
))
1864 const Decl
*&CacheEntry
= FirstLocalDeclCache
[Canon
];
1868 for (const Decl
*Redecl
= D
; Redecl
; Redecl
= Redecl
->getPreviousDecl())
1869 if (IsLocalDecl(Redecl
))
1871 return CacheEntry
= D
;
1874 template <typename T
>
1875 void ASTDeclWriter::VisitRedeclarable(Redeclarable
<T
> *D
) {
1876 T
*First
= D
->getFirstDecl();
1877 T
*MostRecent
= First
->getMostRecentDecl();
1878 T
*DAsT
= static_cast<T
*>(D
);
1879 if (MostRecent
!= First
) {
1880 assert(isRedeclarableDeclKind(DAsT
->getKind()) &&
1881 "Not considered redeclarable?");
1883 Record
.AddDeclRef(First
);
1885 // Write out a list of local redeclarations of this declaration if it's the
1886 // first local declaration in the chain.
1887 const Decl
*FirstLocal
= Writer
.getFirstLocalDecl(DAsT
);
1888 if (DAsT
== FirstLocal
) {
1889 // Emit a list of all imported first declarations so that we can be sure
1890 // that all redeclarations visible to this module are before D in the
1892 unsigned I
= Record
.size();
1893 Record
.push_back(0);
1895 AddFirstDeclFromEachModule(DAsT
, /*IncludeLocal*/false);
1896 // This is the number of imported first declarations + 1.
1897 Record
[I
] = Record
.size() - I
;
1899 // Collect the set of local redeclarations of this declaration, from
1900 // newest to oldest.
1901 ASTWriter::RecordData LocalRedecls
;
1902 ASTRecordWriter
LocalRedeclWriter(Record
, LocalRedecls
);
1903 for (const Decl
*Prev
= FirstLocal
->getMostRecentDecl();
1904 Prev
!= FirstLocal
; Prev
= Prev
->getPreviousDecl())
1905 if (!Prev
->isFromASTFile())
1906 LocalRedeclWriter
.AddDeclRef(Prev
);
1908 // If we have any redecls, write them now as a separate record preceding
1909 // the declaration itself.
1910 if (LocalRedecls
.empty())
1911 Record
.push_back(0);
1913 Record
.AddOffset(LocalRedeclWriter
.Emit(LOCAL_REDECLARATIONS
));
1915 Record
.push_back(0);
1916 Record
.AddDeclRef(FirstLocal
);
1919 // Make sure that we serialize both the previous and the most-recent
1920 // declarations, which (transitively) ensures that all declarations in the
1921 // chain get serialized.
1923 // FIXME: This is not correct; when we reach an imported declaration we
1924 // won't emit its previous declaration.
1925 (void)Writer
.GetDeclRef(D
->getPreviousDecl());
1926 (void)Writer
.GetDeclRef(MostRecent
);
1928 // We use the sentinel value 0 to indicate an only declaration.
1929 Record
.push_back(0);
1933 void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl
*D
) {
1935 VisitDeclContext(D
);
1936 Record
.push_back(D
->isCBuffer());
1937 Record
.AddSourceLocation(D
->getLocStart());
1938 Record
.AddSourceLocation(D
->getLBraceLoc());
1939 Record
.AddSourceLocation(D
->getRBraceLoc());
1941 Code
= serialization::DECL_HLSL_BUFFER
;
1944 void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl
*D
) {
1945 Record
.writeOMPChildren(D
->Data
);
1947 Code
= serialization::DECL_OMP_THREADPRIVATE
;
1950 void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl
*D
) {
1951 Record
.writeOMPChildren(D
->Data
);
1953 Code
= serialization::DECL_OMP_ALLOCATE
;
1956 void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl
*D
) {
1957 Record
.writeOMPChildren(D
->Data
);
1959 Code
= serialization::DECL_OMP_REQUIRES
;
1962 void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl
*D
) {
1963 static_assert(DeclContext::NumOMPDeclareReductionDeclBits
== 15,
1964 "You need to update the serializer after you change the "
1965 "NumOMPDeclareReductionDeclBits");
1968 Record
.AddSourceLocation(D
->getBeginLoc());
1969 Record
.AddStmt(D
->getCombinerIn());
1970 Record
.AddStmt(D
->getCombinerOut());
1971 Record
.AddStmt(D
->getCombiner());
1972 Record
.AddStmt(D
->getInitOrig());
1973 Record
.AddStmt(D
->getInitPriv());
1974 Record
.AddStmt(D
->getInitializer());
1975 Record
.push_back(llvm::to_underlying(D
->getInitializerKind()));
1976 Record
.AddDeclRef(D
->getPrevDeclInScope());
1977 Code
= serialization::DECL_OMP_DECLARE_REDUCTION
;
1980 void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl
*D
) {
1981 Record
.writeOMPChildren(D
->Data
);
1983 Record
.AddDeclarationName(D
->getVarName());
1984 Record
.AddDeclRef(D
->getPrevDeclInScope());
1985 Code
= serialization::DECL_OMP_DECLARE_MAPPER
;
1988 void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl
*D
) {
1990 Code
= serialization::DECL_OMP_CAPTUREDEXPR
;
1993 //===----------------------------------------------------------------------===//
1994 // ASTWriter Implementation
1995 //===----------------------------------------------------------------------===//
1997 void ASTWriter::WriteDeclAbbrevs() {
1998 using namespace llvm
;
2000 std::shared_ptr
<BitCodeAbbrev
> Abv
;
2002 // Abbreviation for DECL_FIELD
2003 Abv
= std::make_shared
<BitCodeAbbrev
>();
2004 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_FIELD
));
2006 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2007 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2008 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2009 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2010 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2011 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2012 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2013 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2014 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // AccessSpecifier
2015 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2016 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2018 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2019 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2020 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2022 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2024 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InnerStartLoc
2025 Abv
->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2026 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TSIType
2028 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isMutable
2029 Abv
->Add(BitCodeAbbrevOp(0)); // StorageKind
2031 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2032 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TypeLoc
2033 DeclFieldAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2035 // Abbreviation for DECL_OBJC_IVAR
2036 Abv
= std::make_shared
<BitCodeAbbrev
>();
2037 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR
));
2039 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2040 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2041 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2042 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2043 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2044 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2045 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2046 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2047 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // AccessSpecifier
2048 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2049 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2051 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2052 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2053 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2055 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2057 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InnerStartLoc
2058 Abv
->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2059 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TSIType
2061 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isMutable
2062 Abv
->Add(BitCodeAbbrevOp(0)); // InitStyle
2064 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getAccessControl
2065 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getSynthesize
2067 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2068 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TypeLoc
2069 DeclObjCIvarAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2071 // Abbreviation for DECL_ENUM
2072 Abv
= std::make_shared
<BitCodeAbbrev
>();
2073 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_ENUM
));
2075 Abv
->Add(BitCodeAbbrevOp(0)); // No redeclaration
2077 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2078 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2079 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2080 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2081 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2082 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2083 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2084 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2085 Abv
->Add(BitCodeAbbrevOp(AS_none
)); // C++ AccessSpecifier
2086 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2087 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2089 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2090 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2091 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2093 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Source Location
2094 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type Ref
2096 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // IdentifierNamespace
2097 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getTagKind
2098 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isCompleteDefinition
2099 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // EmbeddedInDeclarator
2100 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsFreeStanding
2101 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsCompleteDefinitionRequired
2102 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SourceLocation
2103 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SourceLocation
2104 Abv
->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
2106 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // AddTypeRef
2107 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // IntegerType
2108 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getPromotionType
2109 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getNumPositiveBits
2110 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getNumNegativeBits
2111 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isScoped
2112 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isScopedUsingClassTag
2113 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isFixed
2114 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 32));// ODRHash
2115 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InstantiatedMembEnum
2117 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // LexicalOffset
2118 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // VisibleOffset
2119 DeclEnumAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2121 // Abbreviation for DECL_RECORD
2122 Abv
= std::make_shared
<BitCodeAbbrev
>();
2123 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_RECORD
));
2125 Abv
->Add(BitCodeAbbrevOp(0)); // No redeclaration
2127 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2128 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2129 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2130 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2131 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2132 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2133 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2134 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2135 Abv
->Add(BitCodeAbbrevOp(AS_none
)); // C++ AccessSpecifier
2136 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2137 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2139 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2140 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2141 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2143 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Source Location
2144 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type Ref
2146 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // IdentifierNamespace
2147 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getTagKind
2148 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isCompleteDefinition
2149 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // EmbeddedInDeclarator
2150 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsFreeStanding
2151 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsCompleteDefinitionRequired
2152 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SourceLocation
2153 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SourceLocation
2154 Abv
->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
2156 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // FlexibleArrayMember
2157 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // AnonymousStructUnion
2158 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // hasObjectMember
2159 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // hasVolatileMember
2161 // isNonTrivialToPrimitiveDefaultInitialize
2162 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2163 // isNonTrivialToPrimitiveCopy
2164 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2165 // isNonTrivialToPrimitiveDestroy
2166 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2167 // hasNonTrivialToPrimitiveDefaultInitializeCUnion
2168 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2169 // hasNonTrivialToPrimitiveDestructCUnion
2170 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2171 // hasNonTrivialToPrimitiveCopyCUnion
2172 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2173 // isParamDestroyedInCallee
2174 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1));
2175 // getArgPassingRestrictions
2176 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2));
2178 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 26));
2181 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // LexicalOffset
2182 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // VisibleOffset
2183 DeclRecordAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2185 // Abbreviation for DECL_PARM_VAR
2186 Abv
= std::make_shared
<BitCodeAbbrev
>();
2187 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR
));
2189 Abv
->Add(BitCodeAbbrevOp(0)); // No redeclaration
2191 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2192 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2193 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2194 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2195 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2196 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2197 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2198 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2199 Abv
->Add(BitCodeAbbrevOp(AS_none
)); // C++ AccessSpecifier
2200 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2201 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2203 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2204 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2205 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2207 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2209 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InnerStartLoc
2210 Abv
->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2211 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TSIType
2213 Abv
->Add(BitCodeAbbrevOp(0)); // SClass
2214 Abv
->Add(BitCodeAbbrevOp(0)); // TSCSpec
2215 Abv
->Add(BitCodeAbbrevOp(0)); // InitStyle
2216 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isARCPseudoStrong
2217 Abv
->Add(BitCodeAbbrevOp(0)); // Linkage
2218 Abv
->Add(BitCodeAbbrevOp(0)); // ModulesCodegen
2219 Abv
->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2221 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsObjCMethodParameter
2222 Abv
->Add(BitCodeAbbrevOp(0)); // ScopeDepth
2223 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // ScopeIndex
2224 Abv
->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
2225 Abv
->Add(BitCodeAbbrevOp(0)); // KNRPromoted
2226 Abv
->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
2227 Abv
->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
2229 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2230 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TypeLoc
2231 DeclParmVarAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2233 // Abbreviation for DECL_TYPEDEF
2234 Abv
= std::make_shared
<BitCodeAbbrev
>();
2235 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF
));
2237 Abv
->Add(BitCodeAbbrevOp(0)); // No redeclaration
2239 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2240 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2241 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2242 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2243 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2244 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isUsed
2245 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isReferenced
2246 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2247 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // C++ AccessSpecifier
2248 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2249 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2251 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2252 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2253 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2255 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Source Location
2256 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type Ref
2258 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2259 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TypeLoc
2260 DeclTypedefAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2262 // Abbreviation for DECL_VAR
2263 Abv
= std::make_shared
<BitCodeAbbrev
>();
2264 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_VAR
));
2266 Abv
->Add(BitCodeAbbrevOp(0)); // No redeclaration
2268 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2269 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2270 Abv
->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2271 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2272 Abv
->Add(BitCodeAbbrevOp(0)); // isImplicit
2273 Abv
->Add(BitCodeAbbrevOp(0)); // isUsed
2274 Abv
->Add(BitCodeAbbrevOp(0)); // isReferenced
2275 Abv
->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2276 Abv
->Add(BitCodeAbbrevOp(AS_none
)); // C++ AccessSpecifier
2277 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2278 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2280 Abv
->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2281 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Name
2282 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2284 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2286 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InnerStartLoc
2287 Abv
->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2288 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TSIType
2290 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // SClass
2291 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // TSCSpec
2292 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // InitStyle
2293 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isARCPseudoStrong
2294 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsThisDeclarationADemotedDefinition
2295 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isExceptionVariable
2296 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isNRVOVariable
2297 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isCXXForRangeDecl
2298 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // isObjCForDecl
2299 Abv
->Add(BitCodeAbbrevOp(0)); // isInline
2300 Abv
->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
2301 Abv
->Add(BitCodeAbbrevOp(0)); // isConstexpr
2302 Abv
->Add(BitCodeAbbrevOp(0)); // isInitCapture
2303 Abv
->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
2304 Abv
->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
2305 Abv
->Add(BitCodeAbbrevOp(0)); // EscapingByref
2306 Abv
->Add(BitCodeAbbrevOp(0)); // HasDeducedType
2307 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // Linkage
2308 Abv
->Add(BitCodeAbbrevOp(0)); // ModulesCodeGen
2309 Abv
->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2311 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2312 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TypeLoc
2313 DeclVarAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2315 // Abbreviation for DECL_CXX_METHOD
2316 Abv
= std::make_shared
<BitCodeAbbrev
>();
2317 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD
));
2319 Abv
->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2320 // FIXME: Implement abbreviation for other template kinds.
2321 Abv
->Add(BitCodeAbbrevOp(FunctionDecl::TK_NonTemplate
)); // TemplateKind
2323 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclContext
2324 Abv
->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2325 Abv
->Add(BitCodeAbbrevOp(0)); // Invalid
2326 Abv
->Add(BitCodeAbbrevOp(0)); // HasAttrs
2327 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Implicit
2328 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Used
2329 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Referenced
2330 Abv
->Add(BitCodeAbbrevOp(0)); // InObjCContainer
2331 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // Access
2332 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // ModuleOwnershipKind
2333 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // SubmoduleID
2335 Abv
->Add(BitCodeAbbrevOp(DeclarationName::Identifier
)); // NameKind
2336 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Identifier
2337 Abv
->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2339 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2341 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // InnerLocStart
2342 Abv
->Add(BitCodeAbbrevOp(0)); // HasExtInfo
2343 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // TSIType
2345 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 11)); // IDNS
2346 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // StorageClass
2347 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Inline
2348 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // InlineSpecified
2349 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // VirtualAsWritten
2350 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Pure
2351 Abv
->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2352 Abv
->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
2353 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Deleted
2354 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Trivial
2355 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // TrivialForCall
2356 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // Defaulted
2357 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // ExplicitlyDefaulted
2358 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // IsIneligibleOrNotSelected
2359 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // ImplicitReturnZero
2360 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 2)); // Constexpr
2361 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // UsesSEHTry
2362 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // SkippedBody
2363 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // MultiVersion
2364 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // LateParsed
2365 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // FriendConstraintRefersToEnclosingTemplate
2366 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // Linkage
2367 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // LocEnd
2368 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Default
2369 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 32)); // ODRHash
2370 // This Array slurps the rest of the record. Fortunately we want to encode
2371 // (nearly) all the remaining (variable number of) fields in the same way.
2374 // NumParams and Params[] from FunctionDecl, and
2375 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2377 // Add an AbbrevOp for 'size then elements' and use it here.
2378 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array
));
2379 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6));
2380 DeclCXXMethodAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2382 unsigned ExprDependenceBits
= llvm::BitWidth
<ExprDependence
>;
2383 // Abbreviation for EXPR_DECL_REF
2384 Abv
= std::make_shared
<BitCodeAbbrev
>();
2385 Abv
->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF
));
2388 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2389 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, ExprDependenceBits
));
2390 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetValueKind
2391 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetObjectKind
2393 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); //HasQualifier
2394 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); //GetDeclFound
2395 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); //ExplicitTemplateArgs
2396 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); //HadMultipleCandidates
2397 Abv
->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture
2398 Abv
->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason
2399 Abv
->Add(BitCodeAbbrevOp(0)); // IsImmediateEscalating
2400 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // DeclRef
2401 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Location
2402 DeclRefExprAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2404 // Abbreviation for EXPR_INTEGER_LITERAL
2405 Abv
= std::make_shared
<BitCodeAbbrev
>();
2406 Abv
->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL
));
2409 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2410 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, ExprDependenceBits
));
2411 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetValueKind
2412 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetObjectKind
2414 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Location
2415 Abv
->Add(BitCodeAbbrevOp(32)); // Bit Width
2416 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Value
2417 IntegerLiteralAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2419 // Abbreviation for EXPR_CHARACTER_LITERAL
2420 Abv
= std::make_shared
<BitCodeAbbrev
>();
2421 Abv
->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL
));
2424 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2425 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, ExprDependenceBits
));
2426 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetValueKind
2427 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetObjectKind
2429 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // getValue
2430 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Location
2431 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); // getKind
2432 CharacterLiteralAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2434 // Abbreviation for EXPR_IMPLICIT_CAST
2435 Abv
= std::make_shared
<BitCodeAbbrev
>();
2436 Abv
->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST
));
2439 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR
, 6)); // Type
2440 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, ExprDependenceBits
));
2441 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetValueKind
2442 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 3)); //GetObjectKind
2444 Abv
->Add(BitCodeAbbrevOp(0)); // PathSize
2445 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // HasFPFeatures
2446 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 6)); // CastKind
2447 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed
, 1)); // PartOfExplicitCast
2449 ExprImplicitCastAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2451 Abv
= std::make_shared
<BitCodeAbbrev
>();
2452 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL
));
2453 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob
));
2454 DeclContextLexicalAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2456 Abv
= std::make_shared
<BitCodeAbbrev
>();
2457 Abv
->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE
));
2458 Abv
->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob
));
2459 DeclContextVisibleLookupAbbrev
= Stream
.EmitAbbrev(std::move(Abv
));
2462 /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2463 /// consumers of the AST.
2465 /// Such decls will always be deserialized from the AST file, so we would like
2466 /// this to be as restrictive as possible. Currently the predicate is driven by
2467 /// code generation requirements, if other clients have a different notion of
2468 /// what is "required" then we may have to consider an alternate scheme where
2469 /// clients can iterate over the top-level decls and get information on them,
2470 /// without necessary deserializing them. We could explicitly require such
2471 /// clients to use a separate API call to "realize" the decl. This should be
2472 /// relatively painless since they would presumably only do it for top-level
2474 static bool isRequiredDecl(const Decl
*D
, ASTContext
&Context
,
2475 Module
*WritingModule
) {
2476 // Named modules have different semantics than header modules. Every named
2477 // module units owns a translation unit. So the importer of named modules
2478 // doesn't need to deserilize everything ahead of time.
2479 if (WritingModule
&& WritingModule
->isModulePurview()) {
2480 // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension.
2481 // And the behavior of MSVC for such cases will leak this to the module
2482 // users. Given pragma is not a standard thing, the compiler has the space
2483 // to do their own decision. Let's follow MSVC here.
2484 if (isa
<PragmaCommentDecl
, PragmaDetectMismatchDecl
>(D
))
2489 // An ObjCMethodDecl is never considered as "required" because its
2490 // implementation container always is.
2492 // File scoped assembly or obj-c or OMP declare target implementation must be
2494 if (isa
<FileScopeAsmDecl
, TopLevelStmtDecl
, ObjCImplDecl
>(D
))
2497 if (WritingModule
&& isPartOfPerModuleInitializer(D
)) {
2498 // These declarations are part of the module initializer, and are emitted
2499 // if and when the module is imported, rather than being emitted eagerly.
2503 return Context
.DeclMustBeEmitted(D
);
2506 void ASTWriter::WriteDecl(ASTContext
&Context
, Decl
*D
) {
2507 PrettyDeclStackTraceEntry
CrashInfo(Context
, D
, SourceLocation(),
2510 // Determine the ID for this declaration.
2511 serialization::DeclID ID
;
2512 assert(!D
->isFromASTFile() && "should not be emitting imported decl");
2513 serialization::DeclID
&IDR
= DeclIDs
[D
];
2519 assert(ID
>= FirstDeclID
&& "invalid decl ID");
2522 ASTDeclWriter
W(*this, Context
, Record
);
2524 // Build a record for this declaration
2527 // Emit this declaration to the bitstream.
2528 uint64_t Offset
= W
.Emit(D
);
2530 // Record the offset for this declaration
2531 SourceLocation Loc
= D
->getLocation();
2532 unsigned Index
= ID
- FirstDeclID
;
2533 if (DeclOffsets
.size() == Index
)
2534 DeclOffsets
.emplace_back(getAdjustedLocation(Loc
), Offset
,
2535 DeclTypesBlockStartOffset
);
2536 else if (DeclOffsets
.size() < Index
) {
2537 // FIXME: Can/should this happen?
2538 DeclOffsets
.resize(Index
+1);
2539 DeclOffsets
[Index
].setLocation(getAdjustedLocation(Loc
));
2540 DeclOffsets
[Index
].setBitOffset(Offset
, DeclTypesBlockStartOffset
);
2542 llvm_unreachable("declarations should be emitted in ID order");
2545 SourceManager
&SM
= Context
.getSourceManager();
2546 if (Loc
.isValid() && SM
.isLocalSourceLocation(Loc
))
2547 associateDeclWithFile(D
, ID
);
2549 // Note declarations that should be deserialized eagerly so that we can add
2550 // them to a record in the AST file later.
2551 if (isRequiredDecl(D
, Context
, WritingModule
))
2552 EagerlyDeserializedDecls
.push_back(ID
);
2555 void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl
*FD
) {
2556 // Switch case IDs are per function body.
2557 Writer
->ClearSwitchCaseIDs();
2559 assert(FD
->doesThisDeclarationHaveABody());
2560 bool ModulesCodegen
= false;
2561 if (!FD
->isDependentContext()) {
2562 std::optional
<GVALinkage
> Linkage
;
2563 if (Writer
->WritingModule
&&
2564 Writer
->WritingModule
->isInterfaceOrPartition()) {
2565 // When building a C++20 module interface unit or a partition unit, a
2566 // strong definition in the module interface is provided by the
2567 // compilation of that unit, not by its users. (Inline functions are still
2568 // emitted in module users.)
2569 Linkage
= Writer
->Context
->GetGVALinkageForFunction(FD
);
2570 ModulesCodegen
= *Linkage
>= GVA_StrongExternal
;
2572 if (Writer
->Context
->getLangOpts().ModulesCodegen
||
2573 (FD
->hasAttr
<DLLExportAttr
>() &&
2574 Writer
->Context
->getLangOpts().BuildingPCHWithObjectFile
)) {
2576 // Under -fmodules-codegen, codegen is performed for all non-internal,
2577 // non-always_inline functions, unless they are available elsewhere.
2578 if (!FD
->hasAttr
<AlwaysInlineAttr
>()) {
2580 Linkage
= Writer
->Context
->GetGVALinkageForFunction(FD
);
2582 *Linkage
!= GVA_Internal
&& *Linkage
!= GVA_AvailableExternally
;
2586 Record
->push_back(ModulesCodegen
);
2588 Writer
->ModularCodegenDecls
.push_back(Writer
->GetDeclRef(FD
));
2589 if (auto *CD
= dyn_cast
<CXXConstructorDecl
>(FD
)) {
2590 Record
->push_back(CD
->getNumCtorInitializers());
2591 if (CD
->getNumCtorInitializers())
2592 AddCXXCtorInitializers(llvm::ArrayRef(CD
->init_begin(), CD
->init_end()));
2594 AddStmt(FD
->getBody());