clang 20.0.0git
ASTWriterDecl.cpp
Go to the documentation of this file.
1//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements serialization for Declarations.
10//
11//===----------------------------------------------------------------------===//
12
13#include "ASTCommon.h"
14#include "clang/AST/Attr.h"
15#include "clang/AST/DeclCXX.h"
18#include "clang/AST/Expr.h"
24#include "llvm/Bitstream/BitstreamWriter.h"
25#include "llvm/Support/ErrorHandling.h"
26#include <optional>
27using namespace clang;
28using namespace serialization;
29
30//===----------------------------------------------------------------------===//
31// Declaration serialization
32//===----------------------------------------------------------------------===//
33
34namespace clang {
35 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
36 ASTWriter &Writer;
38
40 unsigned AbbrevToUse;
41
42 bool GeneratingReducedBMI = false;
43
44 public:
46 ASTWriter::RecordDataImpl &Record, bool GeneratingReducedBMI)
47 : Writer(Writer), Record(Context, Writer, Record),
48 Code((serialization::DeclCode)0), AbbrevToUse(0),
49 GeneratingReducedBMI(GeneratingReducedBMI) {}
50
51 uint64_t Emit(Decl *D) {
52 if (!Code)
53 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
54 D->getDeclKindName() + "'");
55 return Record.Emit(Code, AbbrevToUse);
56 }
57
58 void Visit(Decl *D);
59
60 void VisitDecl(Decl *D);
65 void VisitLabelDecl(LabelDecl *LD);
75 void VisitTagDecl(TagDecl *D);
103 void VisitVarDecl(VarDecl *D);
139 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
141
142 // FIXME: Put in the same order is DeclNodes.td?
163
164 /// Add an Objective-C type parameter list to the given record.
166 // Empty type parameter list.
167 if (!typeParams) {
168 Record.push_back(0);
169 return;
170 }
171
172 Record.push_back(typeParams->size());
173 for (auto *typeParam : *typeParams) {
174 Record.AddDeclRef(typeParam);
175 }
176 Record.AddSourceLocation(typeParams->getLAngleLoc());
177 Record.AddSourceLocation(typeParams->getRAngleLoc());
178 }
179
180 /// Collect the first declaration from each module file that provides a
181 /// declaration of D.
183 const Decl *D, bool IncludeLocal,
184 llvm::MapVector<ModuleFile *, const Decl *> &Firsts) {
185
186 // FIXME: We can skip entries that we know are implied by others.
187 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
188 if (R->isFromASTFile())
189 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
190 else if (IncludeLocal)
191 Firsts[nullptr] = R;
192 }
193 }
194
195 /// Add to the record the first declaration from each module file that
196 /// provides a declaration of D. The intent is to provide a sufficient
197 /// set such that reloading this set will load all current redeclarations.
198 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
199 llvm::MapVector<ModuleFile *, const Decl *> Firsts;
200 CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
201
202 for (const auto &F : Firsts)
203 Record.AddDeclRef(F.second);
204 }
205
206 /// Add to the record the first template specialization from each module
207 /// file that provides a declaration of D. We store the DeclId and an
208 /// ODRHash of the template arguments of D which should provide enough
209 /// information to load D only if the template instantiator needs it.
211 const Decl *D, llvm::SmallVectorImpl<const Decl *> &SpecsInMap,
212 llvm::SmallVectorImpl<const Decl *> &PartialSpecsInMap) {
213 assert((isa<ClassTemplateSpecializationDecl>(D) ||
214 isa<VarTemplateSpecializationDecl>(D) || isa<FunctionDecl>(D)) &&
215 "Must not be called with other decls");
216 llvm::MapVector<ModuleFile *, const Decl *> Firsts;
217 CollectFirstDeclFromEachModule(D, /*IncludeLocal*/ true, Firsts);
218
219 for (const auto &F : Firsts) {
222 PartialSpecsInMap.push_back(F.second);
223 else
224 SpecsInMap.push_back(F.second);
225 }
226 }
227
228 /// Get the specialization decl from an entry in the specialization list.
229 template <typename EntryType>
233 }
234
235 /// Get the list of partial specializations from a template's common ptr.
236 template<typename T>
237 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
238 return Common->PartialSpecializations;
239 }
242 return std::nullopt;
243 }
244
245 template<typename DeclTy>
247 auto *Common = D->getCommonPtr();
248
249 // If we have any lazy specializations, and the external AST source is
250 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
251 // we need to resolve them to actual declarations.
252 if (Writer.Chain != Record.getASTContext().getExternalSource() &&
253 Writer.Chain && Writer.Chain->haveUnloadedSpecializations(D)) {
254 D->LoadLazySpecializations();
255 assert(!Writer.Chain->haveUnloadedSpecializations(D));
256 }
257
258 // AddFirstSpecializationDeclFromEachModule might trigger deserialization,
259 // invalidating *Specializations iterators.
261 for (auto &Entry : Common->Specializations)
262 AllSpecs.push_back(getSpecializationDecl(Entry));
263 for (auto &Entry : getPartialSpecializations(Common))
264 AllSpecs.push_back(getSpecializationDecl(Entry));
265
268 for (auto *D : AllSpecs) {
269 assert(D->isCanonicalDecl() && "non-canonical decl in set");
270 AddFirstSpecializationDeclFromEachModule(D, Specs, PartialSpecs);
271 }
272
273 Record.AddOffset(Writer.WriteSpecializationInfoLookupTable(
274 D, Specs, /*IsPartial=*/false));
275
276 // Function Template Decl doesn't have partial decls.
277 if (isa<FunctionTemplateDecl>(D)) {
278 assert(PartialSpecs.empty());
279 return;
280 }
281
282 Record.AddOffset(Writer.WriteSpecializationInfoLookupTable(
283 D, PartialSpecs, /*IsPartial=*/true));
284 }
285
286 /// Ensure that this template specialization is associated with the specified
287 /// template on reload.
289 const Decl *Specialization) {
290 Template = Template->getCanonicalDecl();
291
292 // If the canonical template is local, we'll write out this specialization
293 // when we emit it.
294 // FIXME: We can do the same thing if there is any local declaration of
295 // the template, to avoid emitting an update record.
296 if (!Template->isFromASTFile())
297 return;
298
299 // We only need to associate the first local declaration of the
300 // specialization. The other declarations will get pulled in by it.
302 return;
303
306 Writer.PartialSpecializationsUpdates[cast<NamedDecl>(Template)]
307 .push_back(cast<NamedDecl>(Specialization));
308 else
309 Writer.SpecializationsUpdates[cast<NamedDecl>(Template)].push_back(
310 cast<NamedDecl>(Specialization));
311 }
312 };
313}
314
316 if (auto *FD = dyn_cast<FunctionDecl>(D)) {
317 if (FD->isInlined() || FD->isConstexpr())
318 return false;
319
320 if (FD->isDependentContext())
321 return false;
322
323 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
324 return false;
325 }
326
327 if (auto *VD = dyn_cast<VarDecl>(D)) {
328 if (!VD->getDeclContext()->getRedeclContext()->isFileContext() ||
329 VD->isInline() || VD->isConstexpr() || isa<ParmVarDecl>(VD) ||
330 // Constant initialized variable may not affect the ABI, but they
331 // may be used in constant evaluation in the frontend, so we have
332 // to remain them.
333 VD->hasConstantInitialization())
334 return false;
335
336 if (VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation)
337 return false;
338 }
339
340 return true;
341}
342
345
346 // Source locations require array (variable-length) abbreviations. The
347 // abbreviation infrastructure requires that arrays are encoded last, so
348 // we handle it here in the case of those classes derived from DeclaratorDecl
349 if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
350 if (auto *TInfo = DD->getTypeSourceInfo())
351 Record.AddTypeLoc(TInfo->getTypeLoc());
352 }
353
354 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
355 // have been written. We want it last because we will not read it back when
356 // retrieving it from the AST, we'll just lazily set the offset.
357 if (auto *FD = dyn_cast<FunctionDecl>(D)) {
358 if (!GeneratingReducedBMI || !CanElideDeclDef(FD)) {
359 Record.push_back(FD->doesThisDeclarationHaveABody());
360 if (FD->doesThisDeclarationHaveABody())
361 Record.AddFunctionDefinition(FD);
362 } else
363 Record.push_back(0);
364 }
365
366 // Similar to FunctionDecls, handle VarDecl's initializer here and write it
367 // after all other Stmts/Exprs. We will not read the initializer until after
368 // we have finished recursive deserialization, because it can recursively
369 // refer back to the variable.
370 if (auto *VD = dyn_cast<VarDecl>(D)) {
371 if (!GeneratingReducedBMI || !CanElideDeclDef(VD))
372 Record.AddVarDeclInit(VD);
373 else
374 Record.push_back(0);
375 }
376
377 // And similarly for FieldDecls. We already serialized whether there is a
378 // default member initializer.
379 if (auto *FD = dyn_cast<FieldDecl>(D)) {
380 if (FD->hasInClassInitializer()) {
381 if (Expr *Init = FD->getInClassInitializer()) {
382 Record.push_back(1);
383 Record.AddStmt(Init);
384 } else {
385 Record.push_back(0);
386 // Initializer has not been instantiated yet.
387 }
388 }
389 }
390
391 // If this declaration is also a DeclContext, write blocks for the
392 // declarations that lexically stored inside its context and those
393 // declarations that are visible from its context.
394 if (auto *DC = dyn_cast<DeclContext>(D))
396}
397
399 BitsPacker DeclBits;
400
401 // The order matters here. It will be better to put the bit with higher
402 // probability to be 0 in the end of the bits.
403 //
404 // Since we're using VBR6 format to store it.
405 // It will be pretty effient if all the higher bits are 0.
406 // For example, if we need to pack 8 bits into a value and the stored value
407 // is 0xf0, the actual stored value will be 0b000111'110000, which takes 12
408 // bits actually. However, if we changed the order to be 0x0f, then we can
409 // store it as 0b001111, which takes 6 bits only now.
410 DeclBits.addBits((uint64_t)D->getModuleOwnershipKind(), /*BitWidth=*/3);
411 DeclBits.addBit(D->isReferenced());
412 DeclBits.addBit(D->isUsed(false));
413 DeclBits.addBits(D->getAccess(), /*BitWidth=*/2);
414 DeclBits.addBit(D->isImplicit());
415 DeclBits.addBit(D->getDeclContext() != D->getLexicalDeclContext());
416 DeclBits.addBit(D->hasAttrs());
418 DeclBits.addBit(D->isInvalidDecl());
419 Record.push_back(DeclBits);
420
421 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
423 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
424
425 if (D->hasAttrs())
426 Record.AddAttributes(D->getAttrs());
427
428 Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
429
430 // If this declaration injected a name into a context different from its
431 // lexical context, and that context is an imported namespace, we need to
432 // update its visible declarations to include this name.
433 //
434 // This happens when we instantiate a class with a friend declaration or a
435 // function with a local extern declaration, for instance.
436 //
437 // FIXME: Can we handle this in AddedVisibleDecl instead?
438 if (D->isOutOfLine()) {
439 auto *DC = D->getDeclContext();
440 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
441 if (!NS->isFromASTFile())
442 break;
443 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
444 if (!NS->isInlineNamespace())
445 break;
446 DC = NS->getParent();
447 }
448 }
449}
450
452 StringRef Arg = D->getArg();
453 Record.push_back(Arg.size());
454 VisitDecl(D);
455 Record.AddSourceLocation(D->getBeginLoc());
456 Record.push_back(D->getCommentKind());
457 Record.AddString(Arg);
459}
460
463 StringRef Name = D->getName();
464 StringRef Value = D->getValue();
465 Record.push_back(Name.size() + 1 + Value.size());
466 VisitDecl(D);
467 Record.AddSourceLocation(D->getBeginLoc());
468 Record.AddString(Name);
469 Record.AddString(Value);
471}
472
474 llvm_unreachable("Translation units aren't directly serialized");
475}
476
478 VisitDecl(D);
479 Record.AddDeclarationName(D->getDeclName());
482 : 0);
483}
484
487 Record.AddSourceLocation(D->getBeginLoc());
488 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
489}
490
494 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
495 Record.push_back(D->isModed());
496 if (D->isModed())
497 Record.AddTypeRef(D->getUnderlyingType());
498 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
499}
500
504 !D->hasAttrs() &&
505 !D->isImplicit() &&
506 D->getFirstDecl() == D->getMostRecentDecl() &&
507 !D->isInvalidDecl() &&
509 !D->isModulePrivate() &&
511 D->getDeclName().getNameKind() == DeclarationName::Identifier)
512 AbbrevToUse = Writer.getDeclTypedefAbbrev();
513
515}
516
519 Record.AddDeclRef(D->getDescribedAliasTemplate());
521}
522
524 static_assert(DeclContext::NumTagDeclBits == 23,
525 "You need to update the serializer after you change the "
526 "TagDeclBits");
527
530 Record.push_back(D->getIdentifierNamespace());
531
532 BitsPacker TagDeclBits;
533 TagDeclBits.addBits(llvm::to_underlying(D->getTagKind()), /*BitWidth=*/3);
534 TagDeclBits.addBit(!isa<CXXRecordDecl>(D) ? D->isCompleteDefinition() : 0);
535 TagDeclBits.addBit(D->isEmbeddedInDeclarator());
536 TagDeclBits.addBit(D->isFreeStanding());
537 TagDeclBits.addBit(D->isCompleteDefinitionRequired());
538 TagDeclBits.addBits(
539 D->hasExtInfo() ? 1 : (D->getTypedefNameForAnonDecl() ? 2 : 0),
540 /*BitWidth=*/2);
541 Record.push_back(TagDeclBits);
542
543 Record.AddSourceRange(D->getBraceRange());
544
545 if (D->hasExtInfo()) {
546 Record.AddQualifierInfo(*D->getExtInfo());
547 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
548 Record.AddDeclRef(TD);
549 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
550 }
551}
552
554 static_assert(DeclContext::NumEnumDeclBits == 43,
555 "You need to update the serializer after you change the "
556 "EnumDeclBits");
557
559 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
560 if (!D->getIntegerTypeSourceInfo())
561 Record.AddTypeRef(D->getIntegerType());
562 Record.AddTypeRef(D->getPromotionType());
563
564 BitsPacker EnumDeclBits;
565 EnumDeclBits.addBits(D->getNumPositiveBits(), /*BitWidth=*/8);
566 EnumDeclBits.addBits(D->getNumNegativeBits(), /*BitWidth=*/8);
567 EnumDeclBits.addBit(D->isScoped());
568 EnumDeclBits.addBit(D->isScopedUsingClassTag());
569 EnumDeclBits.addBit(D->isFixed());
570 Record.push_back(EnumDeclBits);
571
572 Record.push_back(D->getODRHash());
573
574 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
575 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
576 Record.push_back(MemberInfo->getTemplateSpecializationKind());
577 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
578 } else {
579 Record.AddDeclRef(nullptr);
580 }
581
582 if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() &&
583 !D->isInvalidDecl() && !D->isImplicit() && !D->hasExtInfo() &&
584 !D->getTypedefNameForAnonDecl() &&
585 D->getFirstDecl() == D->getMostRecentDecl() &&
588 !D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() &&
590 D->getDeclName().getNameKind() == DeclarationName::Identifier)
591 AbbrevToUse = Writer.getDeclEnumAbbrev();
592
594}
595
597 static_assert(DeclContext::NumRecordDeclBits == 64,
598 "You need to update the serializer after you change the "
599 "RecordDeclBits");
600
602
603 BitsPacker RecordDeclBits;
604 RecordDeclBits.addBit(D->hasFlexibleArrayMember());
605 RecordDeclBits.addBit(D->isAnonymousStructOrUnion());
606 RecordDeclBits.addBit(D->hasObjectMember());
607 RecordDeclBits.addBit(D->hasVolatileMember());
608 RecordDeclBits.addBit(D->isNonTrivialToPrimitiveDefaultInitialize());
609 RecordDeclBits.addBit(D->isNonTrivialToPrimitiveCopy());
610 RecordDeclBits.addBit(D->isNonTrivialToPrimitiveDestroy());
611 RecordDeclBits.addBit(D->hasNonTrivialToPrimitiveDefaultInitializeCUnion());
612 RecordDeclBits.addBit(D->hasNonTrivialToPrimitiveDestructCUnion());
613 RecordDeclBits.addBit(D->hasNonTrivialToPrimitiveCopyCUnion());
614 RecordDeclBits.addBit(D->isParamDestroyedInCallee());
615 RecordDeclBits.addBits(llvm::to_underlying(D->getArgPassingRestrictions()), 2);
616 Record.push_back(RecordDeclBits);
617
618 // Only compute this for C/Objective-C, in C++ this is computed as part
619 // of CXXRecordDecl.
620 if (!isa<CXXRecordDecl>(D))
621 Record.push_back(D->getODRHash());
622
623 if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() &&
624 !D->isImplicit() && !D->isInvalidDecl() && !D->hasExtInfo() &&
625 !D->getTypedefNameForAnonDecl() &&
626 D->getFirstDecl() == D->getMostRecentDecl() &&
630 D->getDeclName().getNameKind() == DeclarationName::Identifier)
631 AbbrevToUse = Writer.getDeclRecordAbbrev();
632
634}
635
638 Record.AddTypeRef(D->getType());
639}
640
643 Record.push_back(D->getInitExpr()? 1 : 0);
644 if (D->getInitExpr())
645 Record.AddStmt(D->getInitExpr());
646 Record.AddAPSInt(D->getInitVal());
647
649}
650
653 Record.AddSourceLocation(D->getInnerLocStart());
654 Record.push_back(D->hasExtInfo());
655 if (D->hasExtInfo()) {
656 DeclaratorDecl::ExtInfo *Info = D->getExtInfo();
657 Record.AddQualifierInfo(*Info);
658 Record.AddStmt(Info->TrailingRequiresClause);
659 }
660 // The location information is deferred until the end of the record.
661 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
662 : QualType());
663}
664
666 static_assert(DeclContext::NumFunctionDeclBits == 44,
667 "You need to update the serializer after you change the "
668 "FunctionDeclBits");
669
671
672 Record.push_back(D->getTemplatedKind());
673 switch (D->getTemplatedKind()) {
675 break;
677 Record.AddDeclRef(D->getInstantiatedFromDecl());
678 break;
680 Record.AddDeclRef(D->getDescribedFunctionTemplate());
681 break;
683 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
684 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
685 Record.push_back(MemberInfo->getTemplateSpecializationKind());
686 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
687 break;
688 }
691 FTSInfo = D->getTemplateSpecializationInfo();
692
694
695 Record.AddDeclRef(FTSInfo->getTemplate());
696 Record.push_back(FTSInfo->getTemplateSpecializationKind());
697
698 // Template arguments.
699 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
700
701 // Template args as written.
702 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
703 if (FTSInfo->TemplateArgumentsAsWritten)
704 Record.AddASTTemplateArgumentListInfo(
706
707 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
708
709 if (MemberSpecializationInfo *MemberInfo =
710 FTSInfo->getMemberSpecializationInfo()) {
711 Record.push_back(1);
712 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
713 Record.push_back(MemberInfo->getTemplateSpecializationKind());
714 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
715 } else {
716 Record.push_back(0);
717 }
718
719 if (D->isCanonicalDecl()) {
720 // Write the template that contains the specializations set. We will
721 // add a FunctionTemplateSpecializationInfo to it when reading.
722 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
723 }
724 break;
725 }
728 DFTSInfo = D->getDependentSpecializationInfo();
729
730 // Candidates.
731 Record.push_back(DFTSInfo->getCandidates().size());
732 for (FunctionTemplateDecl *FTD : DFTSInfo->getCandidates())
733 Record.AddDeclRef(FTD);
734
735 // Templates args.
736 Record.push_back(DFTSInfo->TemplateArgumentsAsWritten != nullptr);
737 if (DFTSInfo->TemplateArgumentsAsWritten)
738 Record.AddASTTemplateArgumentListInfo(
740 break;
741 }
742 }
743
745 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
746 Record.push_back(D->getIdentifierNamespace());
747
748 // The order matters here. It will be better to put the bit with higher
749 // probability to be 0 in the end of the bits. See the comments in VisitDecl
750 // for details.
751 BitsPacker FunctionDeclBits;
752 // FIXME: stable encoding
753 FunctionDeclBits.addBits(llvm::to_underlying(D->getLinkageInternal()), 3);
754 FunctionDeclBits.addBits((uint32_t)D->getStorageClass(), /*BitWidth=*/3);
755 FunctionDeclBits.addBit(D->isInlineSpecified());
756 FunctionDeclBits.addBit(D->isInlined());
757 FunctionDeclBits.addBit(D->hasSkippedBody());
758 FunctionDeclBits.addBit(D->isVirtualAsWritten());
759 FunctionDeclBits.addBit(D->isPureVirtual());
760 FunctionDeclBits.addBit(D->hasInheritedPrototype());
761 FunctionDeclBits.addBit(D->hasWrittenPrototype());
762 FunctionDeclBits.addBit(D->isDeletedBit());
763 FunctionDeclBits.addBit(D->isTrivial());
764 FunctionDeclBits.addBit(D->isTrivialForCall());
765 FunctionDeclBits.addBit(D->isDefaulted());
766 FunctionDeclBits.addBit(D->isExplicitlyDefaulted());
767 FunctionDeclBits.addBit(D->isIneligibleOrNotSelected());
768 FunctionDeclBits.addBits((uint64_t)(D->getConstexprKind()), /*BitWidth=*/2);
769 FunctionDeclBits.addBit(D->hasImplicitReturnZero());
770 FunctionDeclBits.addBit(D->isMultiVersion());
771 FunctionDeclBits.addBit(D->isLateTemplateParsed());
772 FunctionDeclBits.addBit(D->FriendConstraintRefersToEnclosingTemplate());
773 FunctionDeclBits.addBit(D->usesSEHTry());
774 Record.push_back(FunctionDeclBits);
775
776 Record.AddSourceLocation(D->getEndLoc());
777 if (D->isExplicitlyDefaulted())
778 Record.AddSourceLocation(D->getDefaultLoc());
779
780 Record.push_back(D->getODRHash());
781
782 if (D->isDefaulted() || D->isDeletedAsWritten()) {
783 if (auto *FDI = D->getDefalutedOrDeletedInfo()) {
784 // Store both that there is an DefaultedOrDeletedInfo and whether it
785 // contains a DeletedMessage.
786 StringLiteral *DeletedMessage = FDI->getDeletedMessage();
787 Record.push_back(1 | (DeletedMessage ? 2 : 0));
788 if (DeletedMessage)
789 Record.AddStmt(DeletedMessage);
790
791 Record.push_back(FDI->getUnqualifiedLookups().size());
792 for (DeclAccessPair P : FDI->getUnqualifiedLookups()) {
793 Record.AddDeclRef(P.getDecl());
794 Record.push_back(P.getAccess());
795 }
796 } else {
797 Record.push_back(0);
798 }
799 }
800
801 if (D->getFriendObjectKind()) {
802 // For a function defined inline within a class template, we have to force
803 // the canonical definition to be the one inside the canonical definition of
804 // the template. Remember this relation to deserialize them together.
805 if (auto *RD = dyn_cast<CXXRecordDecl>(D->getLexicalParent()))
806 if (RD->isDependentContext() && RD->isThisDeclarationADefinition()) {
807 Writer.RelatedDeclsMap[Writer.GetDeclRef(RD)].push_back(
808 Writer.GetDeclRef(D));
809 }
810 }
811
812 Record.push_back(D->param_size());
813 for (auto *P : D->parameters())
814 Record.AddDeclRef(P);
816}
817
820 uint64_t Kind = static_cast<uint64_t>(ES.getKind());
821 Kind = Kind << 1 | static_cast<bool>(ES.getExpr());
822 Record.push_back(Kind);
823 if (ES.getExpr()) {
824 Record.AddStmt(ES.getExpr());
825 }
826}
827
829 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
830 Record.AddDeclRef(D->Ctor);
832 Record.push_back(static_cast<unsigned char>(D->getDeductionCandidateKind()));
834}
835
837 static_assert(DeclContext::NumObjCMethodDeclBits == 37,
838 "You need to update the serializer after you change the "
839 "ObjCMethodDeclBits");
840
842 // FIXME: convert to LazyStmtPtr?
843 // Unlike C/C++, method bodies will never be in header files.
844 bool HasBodyStuff = D->getBody() != nullptr;
845 Record.push_back(HasBodyStuff);
846 if (HasBodyStuff) {
847 Record.AddStmt(D->getBody());
848 }
849 Record.AddDeclRef(D->getSelfDecl());
850 Record.AddDeclRef(D->getCmdDecl());
851 Record.push_back(D->isInstanceMethod());
852 Record.push_back(D->isVariadic());
853 Record.push_back(D->isPropertyAccessor());
854 Record.push_back(D->isSynthesizedAccessorStub());
855 Record.push_back(D->isDefined());
856 Record.push_back(D->isOverriding());
857 Record.push_back(D->hasSkippedBody());
858
859 Record.push_back(D->isRedeclaration());
860 Record.push_back(D->hasRedeclaration());
861 if (D->hasRedeclaration()) {
862 assert(Record.getASTContext().getObjCMethodRedeclaration(D));
863 Record.AddDeclRef(Record.getASTContext().getObjCMethodRedeclaration(D));
864 }
865
866 // FIXME: stable encoding for @required/@optional
867 Record.push_back(llvm::to_underlying(D->getImplementationControl()));
868 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
869 Record.push_back(D->getObjCDeclQualifier());
870 Record.push_back(D->hasRelatedResultType());
871 Record.AddTypeRef(D->getReturnType());
872 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
873 Record.AddSourceLocation(D->getEndLoc());
874 Record.push_back(D->param_size());
875 for (const auto *P : D->parameters())
876 Record.AddDeclRef(P);
877
878 Record.push_back(D->getSelLocsKind());
879 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
880 SourceLocation *SelLocs = D->getStoredSelLocs();
881 Record.push_back(NumStoredSelLocs);
882 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
883 Record.AddSourceLocation(SelLocs[i]);
884
886}
887
890 Record.push_back(D->Variance);
891 Record.push_back(D->Index);
892 Record.AddSourceLocation(D->VarianceLoc);
893 Record.AddSourceLocation(D->ColonLoc);
894
896}
897
899 static_assert(DeclContext::NumObjCContainerDeclBits == 64,
900 "You need to update the serializer after you change the "
901 "ObjCContainerDeclBits");
902
904 Record.AddSourceLocation(D->getAtStartLoc());
905 Record.AddSourceRange(D->getAtEndRange());
906 // Abstract class (no need to define a stable serialization::DECL code).
907}
908
912 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
913 AddObjCTypeParamList(D->TypeParamList);
914
915 Record.push_back(D->isThisDeclarationADefinition());
916 if (D->isThisDeclarationADefinition()) {
917 // Write the DefinitionData
918 ObjCInterfaceDecl::DefinitionData &Data = D->data();
919
920 Record.AddTypeSourceInfo(D->getSuperClassTInfo());
921 Record.AddSourceLocation(D->getEndOfDefinitionLoc());
922 Record.push_back(Data.HasDesignatedInitializers);
923 Record.push_back(D->getODRHash());
924
925 // Write out the protocols that are directly referenced by the @interface.
926 Record.push_back(Data.ReferencedProtocols.size());
927 for (const auto *P : D->protocols())
928 Record.AddDeclRef(P);
929 for (const auto &PL : D->protocol_locs())
930 Record.AddSourceLocation(PL);
931
932 // Write out the protocols that are transitively referenced.
933 Record.push_back(Data.AllReferencedProtocols.size());
935 P = Data.AllReferencedProtocols.begin(),
936 PEnd = Data.AllReferencedProtocols.end();
937 P != PEnd; ++P)
938 Record.AddDeclRef(*P);
939
940
941 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
942 // Ensure that we write out the set of categories for this class.
943 Writer.ObjCClassesWithCategories.insert(D);
944
945 // Make sure that the categories get serialized.
946 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
947 (void)Writer.GetDeclRef(Cat);
948 }
949 }
950
952}
953
956 // FIXME: stable encoding for @public/@private/@protected/@package
957 Record.push_back(D->getAccessControl());
958 Record.push_back(D->getSynthesize());
959
961 !D->hasAttrs() &&
962 !D->isImplicit() &&
963 !D->isUsed(false) &&
964 !D->isInvalidDecl() &&
965 !D->isReferenced() &&
966 !D->isModulePrivate() &&
967 !D->getBitWidth() &&
968 !D->hasExtInfo() &&
969 D->getDeclName())
970 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
971
973}
974
978
979 Record.push_back(D->isThisDeclarationADefinition());
980 if (D->isThisDeclarationADefinition()) {
981 Record.push_back(D->protocol_size());
982 for (const auto *I : D->protocols())
983 Record.AddDeclRef(I);
984 for (const auto &PL : D->protocol_locs())
985 Record.AddSourceLocation(PL);
986 Record.push_back(D->getODRHash());
987 }
988
990}
991
995}
996
999 Record.AddSourceLocation(D->getCategoryNameLoc());
1000 Record.AddSourceLocation(D->getIvarLBraceLoc());
1001 Record.AddSourceLocation(D->getIvarRBraceLoc());
1002 Record.AddDeclRef(D->getClassInterface());
1003 AddObjCTypeParamList(D->TypeParamList);
1004 Record.push_back(D->protocol_size());
1005 for (const auto *I : D->protocols())
1006 Record.AddDeclRef(I);
1007 for (const auto &PL : D->protocol_locs())
1008 Record.AddSourceLocation(PL);
1010}
1011
1014 Record.AddDeclRef(D->getClassInterface());
1016}
1017
1020 Record.AddSourceLocation(D->getAtLoc());
1021 Record.AddSourceLocation(D->getLParenLoc());
1022 Record.AddTypeRef(D->getType());
1023 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
1024 // FIXME: stable encoding
1025 Record.push_back((unsigned)D->getPropertyAttributes());
1026 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
1027 // FIXME: stable encoding
1028 Record.push_back((unsigned)D->getPropertyImplementation());
1029 Record.AddDeclarationName(D->getGetterName());
1030 Record.AddSourceLocation(D->getGetterNameLoc());
1031 Record.AddDeclarationName(D->getSetterName());
1032 Record.AddSourceLocation(D->getSetterNameLoc());
1033 Record.AddDeclRef(D->getGetterMethodDecl());
1034 Record.AddDeclRef(D->getSetterMethodDecl());
1035 Record.AddDeclRef(D->getPropertyIvarDecl());
1037}
1038
1041 Record.AddDeclRef(D->getClassInterface());
1042 // Abstract class (no need to define a stable serialization::DECL code).
1043}
1044
1047 Record.AddSourceLocation(D->getCategoryNameLoc());
1049}
1050
1053 Record.AddDeclRef(D->getSuperClass());
1054 Record.AddSourceLocation(D->getSuperClassLoc());
1055 Record.AddSourceLocation(D->getIvarLBraceLoc());
1056 Record.AddSourceLocation(D->getIvarRBraceLoc());
1057 Record.push_back(D->hasNonZeroConstructors());
1058 Record.push_back(D->hasDestructors());
1059 Record.push_back(D->NumIvarInitializers);
1060 if (D->NumIvarInitializers)
1061 Record.AddCXXCtorInitializers(
1062 llvm::ArrayRef(D->init_begin(), D->init_end()));
1064}
1065
1067 VisitDecl(D);
1068 Record.AddSourceLocation(D->getBeginLoc());
1069 Record.AddDeclRef(D->getPropertyDecl());
1070 Record.AddDeclRef(D->getPropertyIvarDecl());
1071 Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
1072 Record.AddDeclRef(D->getGetterMethodDecl());
1073 Record.AddDeclRef(D->getSetterMethodDecl());
1074 Record.AddStmt(D->getGetterCXXConstructor());
1075 Record.AddStmt(D->getSetterCXXAssignment());
1077}
1078
1081 Record.push_back(D->isMutable());
1082
1083 Record.push_back((D->StorageKind << 1) | D->BitField);
1084 if (D->StorageKind == FieldDecl::ISK_CapturedVLAType)
1085 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
1086 else if (D->BitField)
1087 Record.AddStmt(D->getBitWidth());
1088
1089 if (!D->getDeclName() || D->isPlaceholderVar(Writer.getLangOpts()))
1090 Record.AddDeclRef(
1091 Record.getASTContext().getInstantiatedFromUnnamedFieldDecl(D));
1092
1093 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1094 !D->hasAttrs() &&
1095 !D->isImplicit() &&
1096 !D->isUsed(false) &&
1097 !D->isInvalidDecl() &&
1098 !D->isReferenced() &&
1100 !D->isModulePrivate() &&
1101 !D->getBitWidth() &&
1102 !D->hasInClassInitializer() &&
1103 !D->hasCapturedVLAType() &&
1104 !D->hasExtInfo() &&
1107 D->getDeclName())
1108 AbbrevToUse = Writer.getDeclFieldAbbrev();
1109
1111}
1112
1115 Record.AddIdentifierRef(D->getGetterId());
1116 Record.AddIdentifierRef(D->getSetterId());
1118}
1119
1122 MSGuidDecl::Parts Parts = D->getParts();
1123 Record.push_back(Parts.Part1);
1124 Record.push_back(Parts.Part2);
1125 Record.push_back(Parts.Part3);
1126 Record.append(std::begin(Parts.Part4And5), std::end(Parts.Part4And5));
1128}
1129
1133 Record.AddAPValue(D->getValue());
1135}
1136
1139 Record.AddAPValue(D->getValue());
1141}
1142
1145 Record.push_back(D->getChainingSize());
1146
1147 for (const auto *P : D->chain())
1148 Record.AddDeclRef(P);
1150}
1151
1155
1156 // The order matters here. It will be better to put the bit with higher
1157 // probability to be 0 in the end of the bits. See the comments in VisitDecl
1158 // for details.
1159 BitsPacker VarDeclBits;
1160 VarDeclBits.addBits(llvm::to_underlying(D->getLinkageInternal()),
1161 /*BitWidth=*/3);
1162
1163 bool ModulesCodegen = false;
1164 if (Writer.WritingModule && D->getStorageDuration() == SD_Static &&
1165 !D->getDescribedVarTemplate()) {
1166 // When building a C++20 module interface unit or a partition unit, a
1167 // strong definition in the module interface is provided by the
1168 // compilation of that unit, not by its users. (Inline variables are still
1169 // emitted in module users.)
1170 ModulesCodegen = (Writer.WritingModule->isInterfaceOrPartition() ||
1171 (D->hasAttr<DLLExportAttr>() &&
1172 Writer.getLangOpts().BuildingPCHWithObjectFile)) &&
1173 Record.getASTContext().GetGVALinkageForVariable(D) >=
1175 }
1176 VarDeclBits.addBit(ModulesCodegen);
1177
1178 VarDeclBits.addBits(D->getStorageClass(), /*BitWidth=*/3);
1179 VarDeclBits.addBits(D->getTSCSpec(), /*BitWidth=*/2);
1180 VarDeclBits.addBits(D->getInitStyle(), /*BitWidth=*/2);
1181 VarDeclBits.addBit(D->isARCPseudoStrong());
1182
1183 bool HasDeducedType = false;
1184 if (!isa<ParmVarDecl>(D)) {
1185 VarDeclBits.addBit(D->isThisDeclarationADemotedDefinition());
1186 VarDeclBits.addBit(D->isExceptionVariable());
1187 VarDeclBits.addBit(D->isNRVOVariable());
1188 VarDeclBits.addBit(D->isCXXForRangeDecl());
1189
1190 VarDeclBits.addBit(D->isInline());
1191 VarDeclBits.addBit(D->isInlineSpecified());
1192 VarDeclBits.addBit(D->isConstexpr());
1193 VarDeclBits.addBit(D->isInitCapture());
1194 VarDeclBits.addBit(D->isPreviousDeclInSameBlockScope());
1195
1196 VarDeclBits.addBit(D->isEscapingByref());
1197 HasDeducedType = D->getType()->getContainedDeducedType();
1198 VarDeclBits.addBit(HasDeducedType);
1199
1200 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
1201 VarDeclBits.addBits(llvm::to_underlying(IPD->getParameterKind()),
1202 /*Width=*/3);
1203 else
1204 VarDeclBits.addBits(0, /*Width=*/3);
1205
1206 VarDeclBits.addBit(D->isObjCForDecl());
1207 }
1208
1209 Record.push_back(VarDeclBits);
1210
1211 if (ModulesCodegen)
1212 Writer.AddDeclRef(D, Writer.ModularCodegenDecls);
1213
1214 if (D->hasAttr<BlocksAttr>()) {
1215 BlockVarCopyInit Init = Record.getASTContext().getBlockVarCopyInit(D);
1216 Record.AddStmt(Init.getCopyExpr());
1217 if (Init.getCopyExpr())
1218 Record.push_back(Init.canThrow());
1219 }
1220
1221 enum {
1222 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1223 };
1224 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
1225 Record.push_back(VarTemplate);
1226 Record.AddDeclRef(TemplD);
1227 } else if (MemberSpecializationInfo *SpecInfo
1228 = D->getMemberSpecializationInfo()) {
1229 Record.push_back(StaticDataMemberSpecialization);
1230 Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
1231 Record.push_back(SpecInfo->getTemplateSpecializationKind());
1232 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
1233 } else {
1234 Record.push_back(VarNotTemplate);
1235 }
1236
1237 if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() &&
1240 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1241 !D->hasExtInfo() && D->getFirstDecl() == D->getMostRecentDecl() &&
1242 D->getKind() == Decl::Var && !D->isInline() && !D->isConstexpr() &&
1243 !D->isInitCapture() && !D->isPreviousDeclInSameBlockScope() &&
1244 !D->isEscapingByref() && !HasDeducedType &&
1245 D->getStorageDuration() != SD_Static && !D->getDescribedVarTemplate() &&
1246 !D->getMemberSpecializationInfo() && !D->isObjCForDecl() &&
1247 !isa<ImplicitParamDecl>(D) && !D->isEscapingByref())
1248 AbbrevToUse = Writer.getDeclVarAbbrev();
1249
1251}
1252
1254 VisitVarDecl(D);
1256}
1257
1259 VisitVarDecl(D);
1260
1261 // See the implementation of `ParmVarDecl::getParameterIndex()`, which may
1262 // exceed the size of the normal bitfield. So it may be better to not pack
1263 // these bits.
1264 Record.push_back(D->getFunctionScopeIndex());
1265
1266 BitsPacker ParmVarDeclBits;
1267 ParmVarDeclBits.addBit(D->isObjCMethodParameter());
1268 ParmVarDeclBits.addBits(D->getFunctionScopeDepth(), /*BitsWidth=*/7);
1269 // FIXME: stable encoding
1270 ParmVarDeclBits.addBits(D->getObjCDeclQualifier(), /*BitsWidth=*/7);
1271 ParmVarDeclBits.addBit(D->isKNRPromoted());
1272 ParmVarDeclBits.addBit(D->hasInheritedDefaultArg());
1273 ParmVarDeclBits.addBit(D->hasUninstantiatedDefaultArg());
1274 ParmVarDeclBits.addBit(D->getExplicitObjectParamThisLoc().isValid());
1275 Record.push_back(ParmVarDeclBits);
1276
1277 if (D->hasUninstantiatedDefaultArg())
1278 Record.AddStmt(D->getUninstantiatedDefaultArg());
1279 if (D->getExplicitObjectParamThisLoc().isValid())
1280 Record.AddSourceLocation(D->getExplicitObjectParamThisLoc());
1282
1283 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1284 // we dynamically check for the properties that we optimize for, but don't
1285 // know are true of all PARM_VAR_DECLs.
1286 if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() &&
1287 !D->hasExtInfo() && D->getStorageClass() == 0 && !D->isInvalidDecl() &&
1289 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
1290 D->getInit() == nullptr) // No default expr.
1291 AbbrevToUse = Writer.getDeclParmVarAbbrev();
1292
1293 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1294 // just us assuming it.
1295 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
1296 assert(!D->isThisDeclarationADemotedDefinition()
1297 && "PARM_VAR_DECL can't be demoted definition.");
1298 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
1299 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
1300 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
1301 assert(!D->isStaticDataMember() &&
1302 "PARM_VAR_DECL can't be static data member");
1303}
1304
1306 // Record the number of bindings first to simplify deserialization.
1307 Record.push_back(D->bindings().size());
1308
1309 VisitVarDecl(D);
1310 for (auto *B : D->bindings())
1311 Record.AddDeclRef(B);
1313}
1314
1317 Record.AddStmt(D->getBinding());
1319}
1320
1322 VisitDecl(D);
1323 Record.AddStmt(D->getAsmString());
1324 Record.AddSourceLocation(D->getRParenLoc());
1326}
1327
1329 VisitDecl(D);
1330 Record.AddStmt(D->getStmt());
1332}
1333
1335 VisitDecl(D);
1337}
1338
1341 VisitDecl(D);
1342 Record.AddDeclRef(D->getExtendingDecl());
1343 Record.AddStmt(D->getTemporaryExpr());
1344 Record.push_back(static_cast<bool>(D->getValue()));
1345 if (D->getValue())
1346 Record.AddAPValue(*D->getValue());
1347 Record.push_back(D->getManglingNumber());
1349}
1351 VisitDecl(D);
1352 Record.AddStmt(D->getBody());
1353 Record.AddTypeSourceInfo(D->getSignatureAsWritten());
1354 Record.push_back(D->param_size());
1355 for (ParmVarDecl *P : D->parameters())
1356 Record.AddDeclRef(P);
1357 Record.push_back(D->isVariadic());
1358 Record.push_back(D->blockMissingReturnType());
1359 Record.push_back(D->isConversionFromLambda());
1360 Record.push_back(D->doesNotEscape());
1361 Record.push_back(D->canAvoidCopyToHeap());
1362 Record.push_back(D->capturesCXXThis());
1363 Record.push_back(D->getNumCaptures());
1364 for (const auto &capture : D->captures()) {
1365 Record.AddDeclRef(capture.getVariable());
1366
1367 unsigned flags = 0;
1368 if (capture.isByRef()) flags |= 1;
1369 if (capture.isNested()) flags |= 2;
1370 if (capture.hasCopyExpr()) flags |= 4;
1371 Record.push_back(flags);
1372
1373 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
1374 }
1375
1377}
1378
1380 Record.push_back(CD->getNumParams());
1381 VisitDecl(CD);
1382 Record.push_back(CD->getContextParamPosition());
1383 Record.push_back(CD->isNothrow() ? 1 : 0);
1384 // Body is stored by VisitCapturedStmt.
1385 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1386 Record.AddDeclRef(CD->getParam(I));
1388}
1389
1391 static_assert(DeclContext::NumLinkageSpecDeclBits == 17,
1392 "You need to update the serializer after you change the"
1393 "LinkageSpecDeclBits");
1394
1395 VisitDecl(D);
1396 Record.push_back(llvm::to_underlying(D->getLanguage()));
1397 Record.AddSourceLocation(D->getExternLoc());
1398 Record.AddSourceLocation(D->getRBraceLoc());
1400}
1401
1403 VisitDecl(D);
1404 Record.AddSourceLocation(D->getRBraceLoc());
1406}
1407
1410 Record.AddSourceLocation(D->getBeginLoc());
1412}
1413
1414
1418
1419 BitsPacker NamespaceDeclBits;
1420 NamespaceDeclBits.addBit(D->isInline());
1421 NamespaceDeclBits.addBit(D->isNested());
1422 Record.push_back(NamespaceDeclBits);
1423
1424 Record.AddSourceLocation(D->getBeginLoc());
1425 Record.AddSourceLocation(D->getRBraceLoc());
1426
1427 if (D->isFirstDecl())
1428 Record.AddDeclRef(D->getAnonymousNamespace());
1430
1431 if (Writer.hasChain() && D->isAnonymousNamespace() &&
1432 D == D->getMostRecentDecl()) {
1433 // This is a most recent reopening of the anonymous namespace. If its parent
1434 // is in a previous PCH (or is the TU), mark that parent for update, because
1435 // the original namespace always points to the latest re-opening of its
1436 // anonymous namespace.
1437 Decl *Parent = cast<Decl>(
1438 D->getParent()->getRedeclContext()->getPrimaryContext());
1439 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
1440 Writer.DeclUpdates[Parent].push_back(
1441 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
1442 }
1443 }
1444}
1445
1449 Record.AddSourceLocation(D->getNamespaceLoc());
1450 Record.AddSourceLocation(D->getTargetNameLoc());
1451 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1452 Record.AddDeclRef(D->getNamespace());
1454}
1455
1458 Record.AddSourceLocation(D->getUsingLoc());
1459 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1460 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1461 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1462 Record.push_back(D->hasTypename());
1463 Record.AddDeclRef(Record.getASTContext().getInstantiatedFromUsingDecl(D));
1465}
1466
1469 Record.AddSourceLocation(D->getUsingLoc());
1470 Record.AddSourceLocation(D->getEnumLoc());
1471 Record.AddTypeSourceInfo(D->getEnumType());
1472 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1473 Record.AddDeclRef(Record.getASTContext().getInstantiatedFromUsingEnumDecl(D));
1475}
1476
1478 Record.push_back(D->NumExpansions);
1480 Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1481 for (auto *E : D->expansions())
1482 Record.AddDeclRef(E);
1484}
1485
1489 Record.AddDeclRef(D->getTargetDecl());
1490 Record.push_back(D->getIdentifierNamespace());
1491 Record.AddDeclRef(D->UsingOrNextShadow);
1492 Record.AddDeclRef(
1493 Record.getASTContext().getInstantiatedFromUsingShadowDecl(D));
1494
1495 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1496 D->getFirstDecl() == D->getMostRecentDecl() && !D->hasAttrs() &&
1498 D->getDeclName().getNameKind() == DeclarationName::Identifier)
1499 AbbrevToUse = Writer.getDeclUsingShadowAbbrev();
1500
1502}
1503
1507 Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1508 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1509 Record.push_back(D->IsVirtual);
1511}
1512
1515 Record.AddSourceLocation(D->getUsingLoc());
1516 Record.AddSourceLocation(D->getNamespaceKeyLocation());
1517 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1518 Record.AddDeclRef(D->getNominatedNamespace());
1519 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
1521}
1522
1525 Record.AddSourceLocation(D->getUsingLoc());
1526 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1527 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1528 Record.AddSourceLocation(D->getEllipsisLoc());
1530}
1531
1535 Record.AddSourceLocation(D->getTypenameLoc());
1536 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1537 Record.AddSourceLocation(D->getEllipsisLoc());
1539}
1540
1545}
1546
1549
1550 enum {
1551 CXXRecNotTemplate = 0,
1552 CXXRecTemplate,
1553 CXXRecMemberSpecialization,
1554 CXXLambda
1555 };
1556 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1557 Record.push_back(CXXRecTemplate);
1558 Record.AddDeclRef(TemplD);
1559 } else if (MemberSpecializationInfo *MSInfo
1560 = D->getMemberSpecializationInfo()) {
1561 Record.push_back(CXXRecMemberSpecialization);
1562 Record.AddDeclRef(MSInfo->getInstantiatedFrom());
1563 Record.push_back(MSInfo->getTemplateSpecializationKind());
1564 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
1565 } else if (D->isLambda()) {
1566 // For a lambda, we need some information early for merging.
1567 Record.push_back(CXXLambda);
1568 if (auto *Context = D->getLambdaContextDecl()) {
1569 Record.AddDeclRef(Context);
1570 Record.push_back(D->getLambdaIndexInContext());
1571 } else {
1572 Record.push_back(0);
1573 }
1574 // For lambdas inside canonical FunctionDecl remember the mapping.
1575 if (auto FD = llvm::dyn_cast_or_null<FunctionDecl>(D->getDeclContext());
1576 FD && FD->isCanonicalDecl()) {
1577 Writer.RelatedDeclsMap[Writer.GetDeclRef(FD)].push_back(
1578 Writer.GetDeclRef(D));
1579 }
1580 } else {
1581 Record.push_back(CXXRecNotTemplate);
1582 }
1583
1584 Record.push_back(D->isThisDeclarationADefinition());
1585 if (D->isThisDeclarationADefinition())
1586 Record.AddCXXDefinitionData(D);
1587
1588 if (D->isCompleteDefinition() && D->isInNamedModule())
1589 Writer.AddDeclRef(D, Writer.ModularCodegenDecls);
1590
1591 // Store (what we currently believe to be) the key function to avoid
1592 // deserializing every method so we can compute it.
1593 //
1594 // FIXME: Avoid adding the key function if the class is defined in
1595 // module purview since in that case the key function is meaningless.
1596 if (D->isCompleteDefinition())
1597 Record.AddDeclRef(Record.getASTContext().getCurrentKeyFunction(D));
1598
1600}
1601
1604 if (D->isCanonicalDecl()) {
1605 Record.push_back(D->size_overridden_methods());
1606 for (const CXXMethodDecl *MD : D->overridden_methods())
1607 Record.AddDeclRef(MD);
1608 } else {
1609 // We only need to record overridden methods once for the canonical decl.
1610 Record.push_back(0);
1611 }
1612
1613 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1614 D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() &&
1616 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1617 !D->hasExtInfo() && !D->isExplicitlyDefaulted()) {
1618 if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate ||
1619 D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate ||
1620 D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization ||
1621 D->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate)
1622 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1623 else if (D->getTemplatedKind() ==
1626 D->getTemplateSpecializationInfo();
1627
1628 if (FTSInfo->TemplateArguments->size() == 1) {
1629 const TemplateArgument &TA = FTSInfo->TemplateArguments->get(0);
1630 if (TA.getKind() == TemplateArgument::Type &&
1631 !FTSInfo->TemplateArgumentsAsWritten &&
1632 !FTSInfo->getMemberSpecializationInfo())
1633 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1634 }
1635 } else if (D->getTemplatedKind() ==
1638 D->getDependentSpecializationInfo();
1639 if (!DFTSInfo->TemplateArgumentsAsWritten)
1640 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1641 }
1642 }
1643
1645}
1646
1648 static_assert(DeclContext::NumCXXConstructorDeclBits == 64,
1649 "You need to update the serializer after you change the "
1650 "CXXConstructorDeclBits");
1651
1652 Record.push_back(D->getTrailingAllocKind());
1653 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1654 if (auto Inherited = D->getInheritedConstructor()) {
1655 Record.AddDeclRef(Inherited.getShadowDecl());
1656 Record.AddDeclRef(Inherited.getConstructor());
1657 }
1658
1661}
1662
1665
1666 Record.AddDeclRef(D->getOperatorDelete());
1667 if (D->getOperatorDelete())
1668 Record.AddStmt(D->getOperatorDeleteThisArg());
1669
1671}
1672
1674 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1677}
1678
1680 VisitDecl(D);
1681 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
1682 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1683 Record.push_back(!IdentifierLocs.empty());
1684 if (IdentifierLocs.empty()) {
1685 Record.AddSourceLocation(D->getEndLoc());
1686 Record.push_back(1);
1687 } else {
1688 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1689 Record.AddSourceLocation(IdentifierLocs[I]);
1690 Record.push_back(IdentifierLocs.size());
1691 }
1692 // Note: the number of source locations must always be the last element in
1693 // the record.
1695}
1696
1698 VisitDecl(D);
1699 Record.AddSourceLocation(D->getColonLoc());
1701}
1702
1704 // Record the number of friend type template parameter lists here
1705 // so as to simplify memory allocation during deserialization.
1706 Record.push_back(D->NumTPLists);
1707 VisitDecl(D);
1708 bool hasFriendDecl = isa<NamedDecl *>(D->Friend);
1709 Record.push_back(hasFriendDecl);
1710 if (hasFriendDecl)
1711 Record.AddDeclRef(D->getFriendDecl());
1712 else
1713 Record.AddTypeSourceInfo(D->getFriendType());
1714 for (unsigned i = 0; i < D->NumTPLists; ++i)
1715 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1716 Record.AddDeclRef(D->getNextFriend());
1717 Record.push_back(D->UnsupportedFriend);
1718 Record.AddSourceLocation(D->FriendLoc);
1719 Record.AddSourceLocation(D->EllipsisLoc);
1721}
1722
1724 VisitDecl(D);
1725 Record.push_back(D->getNumTemplateParameters());
1726 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1727 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
1728 Record.push_back(D->getFriendDecl() != nullptr);
1729 if (D->getFriendDecl())
1730 Record.AddDeclRef(D->getFriendDecl());
1731 else
1732 Record.AddTypeSourceInfo(D->getFriendType());
1733 Record.AddSourceLocation(D->getFriendLoc());
1735}
1736
1739
1740 Record.AddTemplateParameterList(D->getTemplateParameters());
1741 Record.AddDeclRef(D->getTemplatedDecl());
1742}
1743
1746 Record.AddStmt(D->getConstraintExpr());
1748}
1749
1752 Record.push_back(D->getTemplateArguments().size());
1753 VisitDecl(D);
1754 for (const TemplateArgument &Arg : D->getTemplateArguments())
1755 Record.AddTemplateArgument(Arg);
1757}
1758
1761}
1762
1765
1766 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1767 // getCommonPtr() can be used while this is still initializing.
1768 if (D->isFirstDecl()) {
1769 // This declaration owns the 'common' pointer, so serialize that data now.
1770 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
1771 if (D->getInstantiatedFromMemberTemplate())
1772 Record.push_back(D->isMemberSpecialization());
1773 }
1774
1776 Record.push_back(D->getIdentifierNamespace());
1777}
1778
1781
1782 if (D->isFirstDecl())
1784
1785 // Force emitting the corresponding deduction guide in reduced BMI mode.
1786 // Otherwise, the deduction guide may be optimized out incorrectly.
1787 if (Writer.isGeneratingReducedBMI()) {
1788 auto Name =
1789 Record.getASTContext().DeclarationNames.getCXXDeductionGuideName(D);
1790 for (auto *DG : D->getDeclContext()->noload_lookup(Name))
1791 Writer.GetDeclRef(DG->getCanonicalDecl());
1792 }
1793
1795}
1796
1799 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1800
1802
1803 llvm::PointerUnion<ClassTemplateDecl *,
1805 = D->getSpecializedTemplateOrPartial();
1806 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
1807 Record.AddDeclRef(InstFromD);
1808 } else {
1809 Record.AddDeclRef(cast<ClassTemplatePartialSpecializationDecl *>(InstFrom));
1810 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1811 }
1812
1813 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1814 Record.AddSourceLocation(D->getPointOfInstantiation());
1815 Record.push_back(D->getSpecializationKind());
1816 Record.push_back(D->isCanonicalDecl());
1817
1818 if (D->isCanonicalDecl()) {
1819 // When reading, we'll add it to the folding set of the following template.
1820 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1821 }
1822
1823 bool ExplicitInstantiation =
1824 D->getTemplateSpecializationKind() ==
1826 D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition;
1827 Record.push_back(ExplicitInstantiation);
1828 if (ExplicitInstantiation) {
1829 Record.AddSourceLocation(D->getExternKeywordLoc());
1830 Record.AddSourceLocation(D->getTemplateKeywordLoc());
1831 }
1832
1833 const ASTTemplateArgumentListInfo *ArgsWritten =
1834 D->getTemplateArgsAsWritten();
1835 Record.push_back(!!ArgsWritten);
1836 if (ArgsWritten)
1837 Record.AddASTTemplateArgumentListInfo(ArgsWritten);
1838
1839 // Mention the implicitly generated C++ deduction guide to make sure the
1840 // deduction guide will be rewritten as expected.
1841 //
1842 // FIXME: Would it be more efficient to add a callback register function
1843 // in sema to register the deduction guide?
1844 if (Writer.isWritingStdCXXNamedModules()) {
1845 auto Name =
1846 Record.getASTContext().DeclarationNames.getCXXDeductionGuideName(
1847 D->getSpecializedTemplate());
1848 for (auto *DG : D->getDeclContext()->noload_lookup(Name))
1849 Writer.GetDeclRef(DG->getCanonicalDecl());
1850 }
1851
1853}
1854
1857 Record.AddTemplateParameterList(D->getTemplateParameters());
1858
1860
1861 // These are read/set from/to the first declaration.
1862 if (D->getPreviousDecl() == nullptr) {
1863 Record.AddDeclRef(D->getInstantiatedFromMember());
1864 Record.push_back(D->isMemberSpecialization());
1865 }
1866
1868}
1869
1872
1873 if (D->isFirstDecl())
1876}
1877
1880 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1881
1882 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1883 InstFrom = D->getSpecializedTemplateOrPartial();
1884 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1885 Record.AddDeclRef(InstFromD);
1886 } else {
1887 Record.AddDeclRef(cast<VarTemplatePartialSpecializationDecl *>(InstFrom));
1888 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1889 }
1890
1891 bool ExplicitInstantiation =
1892 D->getTemplateSpecializationKind() ==
1894 D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition;
1895 Record.push_back(ExplicitInstantiation);
1896 if (ExplicitInstantiation) {
1897 Record.AddSourceLocation(D->getExternKeywordLoc());
1898 Record.AddSourceLocation(D->getTemplateKeywordLoc());
1899 }
1900
1901 const ASTTemplateArgumentListInfo *ArgsWritten =
1902 D->getTemplateArgsAsWritten();
1903 Record.push_back(!!ArgsWritten);
1904 if (ArgsWritten)
1905 Record.AddASTTemplateArgumentListInfo(ArgsWritten);
1906
1907 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1908 Record.AddSourceLocation(D->getPointOfInstantiation());
1909 Record.push_back(D->getSpecializationKind());
1910 Record.push_back(D->IsCompleteDefinition);
1911
1912 VisitVarDecl(D);
1913
1914 Record.push_back(D->isCanonicalDecl());
1915
1916 if (D->isCanonicalDecl()) {
1917 // When reading, we'll add it to the folding set of the following template.
1918 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1919 }
1920
1922}
1923
1926 Record.AddTemplateParameterList(D->getTemplateParameters());
1927
1929
1930 // These are read/set from/to the first declaration.
1931 if (D->getPreviousDecl() == nullptr) {
1932 Record.AddDeclRef(D->getInstantiatedFromMember());
1933 Record.push_back(D->isMemberSpecialization());
1934 }
1935
1937}
1938
1941
1942 if (D->isFirstDecl())
1945}
1946
1948 Record.push_back(D->hasTypeConstraint());
1950
1951 Record.push_back(D->wasDeclaredWithTypename());
1952
1953 const TypeConstraint *TC = D->getTypeConstraint();
1954 assert((bool)TC == D->hasTypeConstraint());
1955 if (TC) {
1956 auto *CR = TC->getConceptReference();
1957 Record.push_back(CR != nullptr);
1958 if (CR)
1959 Record.AddConceptReference(CR);
1961 Record.push_back(D->isExpandedParameterPack());
1962 if (D->isExpandedParameterPack())
1963 Record.push_back(D->getNumExpansionParameters());
1964 }
1965
1966 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1967 !D->defaultArgumentWasInherited();
1968 Record.push_back(OwnsDefaultArg);
1969 if (OwnsDefaultArg)
1970 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1971
1972 if (!TC && !OwnsDefaultArg &&
1974 !D->isInvalidDecl() && !D->hasAttrs() &&
1976 D->getDeclName().getNameKind() == DeclarationName::Identifier)
1977 AbbrevToUse = Writer.getDeclTemplateTypeParmAbbrev();
1978
1980}
1981
1983 // For an expanded parameter pack, record the number of expansion types here
1984 // so that it's easier for deserialization to allocate the right amount of
1985 // memory.
1986 Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1987 Record.push_back(!!TypeConstraint);
1988 if (D->isExpandedParameterPack())
1989 Record.push_back(D->getNumExpansionTypes());
1990
1992 // TemplateParmPosition.
1993 Record.push_back(D->getDepth());
1994 Record.push_back(D->getPosition());
1995 if (TypeConstraint)
1996 Record.AddStmt(TypeConstraint);
1997
1998 if (D->isExpandedParameterPack()) {
1999 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
2000 Record.AddTypeRef(D->getExpansionType(I));
2001 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
2002 }
2003
2005 } else {
2006 // Rest of NonTypeTemplateParmDecl.
2007 Record.push_back(D->isParameterPack());
2008 bool OwnsDefaultArg = D->hasDefaultArgument() &&
2009 !D->defaultArgumentWasInherited();
2010 Record.push_back(OwnsDefaultArg);
2011 if (OwnsDefaultArg)
2012 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
2014 }
2015}
2016
2018 // For an expanded parameter pack, record the number of expansion types here
2019 // so that it's easier for deserialization to allocate the right amount of
2020 // memory.
2021 if (D->isExpandedParameterPack())
2022 Record.push_back(D->getNumExpansionTemplateParameters());
2023
2025 Record.push_back(D->wasDeclaredWithTypename());
2026 // TemplateParmPosition.
2027 Record.push_back(D->getDepth());
2028 Record.push_back(D->getPosition());
2029
2030 if (D->isExpandedParameterPack()) {
2031 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2032 I != N; ++I)
2033 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
2035 } else {
2036 // Rest of TemplateTemplateParmDecl.
2037 Record.push_back(D->isParameterPack());
2038 bool OwnsDefaultArg = D->hasDefaultArgument() &&
2039 !D->defaultArgumentWasInherited();
2040 Record.push_back(OwnsDefaultArg);
2041 if (OwnsDefaultArg)
2042 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
2044 }
2045}
2046
2050}
2051
2053 VisitDecl(D);
2054 Record.AddStmt(D->getAssertExpr());
2055 Record.push_back(D->isFailed());
2056 Record.AddStmt(D->getMessage());
2057 Record.AddSourceLocation(D->getRParenLoc());
2059}
2060
2061/// Emit the DeclContext part of a declaration context decl.
2063 static_assert(DeclContext::NumDeclContextBits == 13,
2064 "You need to update the serializer after you change the "
2065 "DeclContextBits");
2066
2067 uint64_t LexicalOffset = 0;
2068 uint64_t VisibleOffset = 0;
2069
2070 if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(DC) &&
2071 cast<NamespaceDecl>(DC)->isFromExplicitGlobalModule()) {
2072 // In reduced BMI, delay writing lexical and visible block for namespace
2073 // in the global module fragment. See the comments of DelayedNamespace for
2074 // details.
2075 Writer.DelayedNamespace.push_back(cast<NamespaceDecl>(DC));
2076 } else {
2077 LexicalOffset =
2078 Writer.WriteDeclContextLexicalBlock(Record.getASTContext(), DC);
2079 VisibleOffset =
2080 Writer.WriteDeclContextVisibleBlock(Record.getASTContext(), DC);
2081 }
2082
2083 Record.AddOffset(LexicalOffset);
2084 Record.AddOffset(VisibleOffset);
2085}
2086
2088 assert(IsLocalDecl(D) && "expected a local declaration");
2089
2090 const Decl *Canon = D->getCanonicalDecl();
2091 if (IsLocalDecl(Canon))
2092 return Canon;
2093
2094 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
2095 if (CacheEntry)
2096 return CacheEntry;
2097
2098 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
2099 if (IsLocalDecl(Redecl))
2100 D = Redecl;
2101 return CacheEntry = D;
2102}
2103
2104template <typename T>
2106 T *First = D->getFirstDecl();
2107 T *MostRecent = First->getMostRecentDecl();
2108 T *DAsT = static_cast<T *>(D);
2109 if (MostRecent != First) {
2110 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
2111 "Not considered redeclarable?");
2112
2113 Record.AddDeclRef(First);
2114
2115 // Write out a list of local redeclarations of this declaration if it's the
2116 // first local declaration in the chain.
2117 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
2118 if (DAsT == FirstLocal) {
2119 // Emit a list of all imported first declarations so that we can be sure
2120 // that all redeclarations visible to this module are before D in the
2121 // redecl chain.
2122 unsigned I = Record.size();
2123 Record.push_back(0);
2124 if (Writer.Chain)
2125 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
2126 // This is the number of imported first declarations + 1.
2127 Record[I] = Record.size() - I;
2128
2129 // Collect the set of local redeclarations of this declaration, from
2130 // newest to oldest.
2131 ASTWriter::RecordData LocalRedecls;
2132 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
2133 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
2134 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
2135 if (!Prev->isFromASTFile())
2136 LocalRedeclWriter.AddDeclRef(Prev);
2137
2138 // If we have any redecls, write them now as a separate record preceding
2139 // the declaration itself.
2140 if (LocalRedecls.empty())
2141 Record.push_back(0);
2142 else
2143 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
2144 } else {
2145 Record.push_back(0);
2146 Record.AddDeclRef(FirstLocal);
2147 }
2148
2149 // Make sure that we serialize both the previous and the most-recent
2150 // declarations, which (transitively) ensures that all declarations in the
2151 // chain get serialized.
2152 //
2153 // FIXME: This is not correct; when we reach an imported declaration we
2154 // won't emit its previous declaration.
2155 (void)Writer.GetDeclRef(D->getPreviousDecl());
2156 (void)Writer.GetDeclRef(MostRecent);
2157 } else {
2158 // We use the sentinel value 0 to indicate an only declaration.
2159 Record.push_back(0);
2160 }
2161}
2162
2166 Record.push_back(D->isCBuffer());
2167 Record.AddSourceLocation(D->getLocStart());
2168 Record.AddSourceLocation(D->getLBraceLoc());
2169 Record.AddSourceLocation(D->getRBraceLoc());
2170
2172}
2173
2175 Record.writeOMPChildren(D->Data);
2176 VisitDecl(D);
2178}
2179
2181 Record.writeOMPChildren(D->Data);
2182 VisitDecl(D);
2184}
2185
2187 Record.writeOMPChildren(D->Data);
2188 VisitDecl(D);
2190}
2191
2193 static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15,
2194 "You need to update the serializer after you change the "
2195 "NumOMPDeclareReductionDeclBits");
2196
2198 Record.AddSourceLocation(D->getBeginLoc());
2199 Record.AddStmt(D->getCombinerIn());
2200 Record.AddStmt(D->getCombinerOut());
2201 Record.AddStmt(D->getCombiner());
2202 Record.AddStmt(D->getInitOrig());
2203 Record.AddStmt(D->getInitPriv());
2204 Record.AddStmt(D->getInitializer());
2205 Record.push_back(llvm::to_underlying(D->getInitializerKind()));
2206 Record.AddDeclRef(D->getPrevDeclInScope());
2208}
2209
2211 Record.writeOMPChildren(D->Data);
2213 Record.AddDeclarationName(D->getVarName());
2214 Record.AddDeclRef(D->getPrevDeclInScope());
2216}
2217
2219 VisitVarDecl(D);
2221}
2222
2223//===----------------------------------------------------------------------===//
2224// ASTWriter Implementation
2225//===----------------------------------------------------------------------===//
2226
2227namespace {
2228template <FunctionDecl::TemplatedKind Kind>
2229std::shared_ptr<llvm::BitCodeAbbrev>
2230getFunctionDeclAbbrev(serialization::DeclCode Code) {
2231 using namespace llvm;
2232
2233 auto Abv = std::make_shared<BitCodeAbbrev>();
2234 Abv->Add(BitCodeAbbrevOp(Code));
2235 // RedeclarableDecl
2236 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2237 Abv->Add(BitCodeAbbrevOp(Kind));
2238 if constexpr (Kind == FunctionDecl::TK_NonTemplate) {
2239
2240 } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) {
2241 // DescribedFunctionTemplate
2242 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2243 } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) {
2244 // Instantiated From Decl
2245 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2246 } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) {
2247 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom
2248 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2249 3)); // TemplateSpecializationKind
2250 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location
2251 } else if constexpr (Kind ==
2253 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template
2254 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2255 3)); // TemplateSpecializationKind
2256 Abv->Add(BitCodeAbbrevOp(1)); // Template Argument Size
2257 Abv->Add(BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind
2258 Abv->Add(
2259 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type
2260 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted
2261 Abv->Add(BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten
2262 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2263 Abv->Add(BitCodeAbbrevOp(0));
2264 Abv->Add(
2265 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template
2266 } else if constexpr (Kind == FunctionDecl::
2268 // Candidates of specialization
2269 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2270 Abv->Add(BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten
2271 } else {
2272 llvm_unreachable("Unknown templated kind?");
2273 }
2274 // Decl
2275 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2276 8)); // Packed DeclBits: ModuleOwnershipKind,
2277 // isUsed, isReferenced, AccessSpecifier,
2278 // isImplicit
2279 //
2280 // The following bits should be 0:
2281 // HasStandaloneLexicalDC, HasAttrs,
2282 // TopLevelDeclInObjCContainer,
2283 // isInvalidDecl
2284 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2285 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2286 // NamedDecl
2287 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2288 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
2289 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2290 // ValueDecl
2291 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2292 // DeclaratorDecl
2293 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2294 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
2295 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2296 // FunctionDecl
2297 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2298 Abv->Add(BitCodeAbbrevOp(
2299 BitCodeAbbrevOp::Fixed,
2300 28)); // Packed Function Bits: StorageClass, Inline, InlineSpecified,
2301 // VirtualAsWritten, Pure, HasInheritedProto, HasWrittenProto,
2302 // Deleted, Trivial, TrivialForCall, Defaulted, ExplicitlyDefaulted,
2303 // IsIneligibleOrNotSelected, ImplicitReturnZero, Constexpr,
2304 // UsesSEHTry, SkippedBody, MultiVersion, LateParsed,
2305 // FriendConstraintRefersToEnclosingTemplate, Linkage,
2306 // ShouldSkipCheckingODR
2307 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
2308 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
2309 // This Array slurps the rest of the record. Fortunately we want to encode
2310 // (nearly) all the remaining (variable number of) fields in the same way.
2311 //
2312 // This is:
2313 // NumParams and Params[] from FunctionDecl, and
2314 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2315 //
2316 // Add an AbbrevOp for 'size then elements' and use it here.
2317 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2318 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2319 return Abv;
2320}
2321
2322template <FunctionDecl::TemplatedKind Kind>
2323std::shared_ptr<llvm::BitCodeAbbrev> getCXXMethodAbbrev() {
2324 return getFunctionDeclAbbrev<Kind>(serialization::DECL_CXX_METHOD);
2325}
2326} // namespace
2327
2328void ASTWriter::WriteDeclAbbrevs() {
2329 using namespace llvm;
2330
2331 std::shared_ptr<BitCodeAbbrev> Abv;
2332
2333 // Abbreviation for DECL_FIELD
2334 Abv = std::make_shared<BitCodeAbbrev>();
2335 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
2336 // Decl
2337 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2338 7)); // Packed DeclBits: ModuleOwnershipKind,
2339 // isUsed, isReferenced, AccessSpecifier,
2340 //
2341 // The following bits should be 0:
2342 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2343 // TopLevelDeclInObjCContainer,
2344 // isInvalidDecl
2345 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2346 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2347 // NamedDecl
2348 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2349 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2350 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2351 // ValueDecl
2352 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2353 // DeclaratorDecl
2354 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2355 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2356 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2357 // FieldDecl
2358 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2359 Abv->Add(BitCodeAbbrevOp(0)); // StorageKind
2360 // Type Source Info
2361 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2362 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2363 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
2364
2365 // Abbreviation for DECL_OBJC_IVAR
2366 Abv = std::make_shared<BitCodeAbbrev>();
2367 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
2368 // Decl
2369 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2370 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2371 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2372 // isReferenced, TopLevelDeclInObjCContainer,
2373 // AccessSpecifier, ModuleOwnershipKind
2374 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2375 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2376 // NamedDecl
2377 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2378 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2379 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2380 // ValueDecl
2381 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2382 // DeclaratorDecl
2383 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2384 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2385 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2386 // FieldDecl
2387 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2388 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
2389 // ObjC Ivar
2390 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
2391 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
2392 // Type Source Info
2393 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2394 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2395 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2396
2397 // Abbreviation for DECL_ENUM
2398 Abv = std::make_shared<BitCodeAbbrev>();
2399 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
2400 // Redeclarable
2401 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2402 // Decl
2403 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2404 7)); // Packed DeclBits: ModuleOwnershipKind,
2405 // isUsed, isReferenced, AccessSpecifier,
2406 //
2407 // The following bits should be 0:
2408 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2409 // TopLevelDeclInObjCContainer,
2410 // isInvalidDecl
2411 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2412 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2413 // NamedDecl
2414 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2415 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2416 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2417 // TypeDecl
2418 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2419 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2420 // TagDecl
2421 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2422 Abv->Add(BitCodeAbbrevOp(
2423 BitCodeAbbrevOp::Fixed,
2424 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition,
2425 // EmbeddedInDeclarator, IsFreeStanding,
2426 // isCompleteDefinitionRequired, ExtInfoKind
2427 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2428 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2429 // EnumDecl
2430 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
2431 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
2432 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
2433 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits
2434 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
2435 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
2436 // DC
2437 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2438 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2439 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
2440
2441 // Abbreviation for DECL_RECORD
2442 Abv = std::make_shared<BitCodeAbbrev>();
2443 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
2444 // Redeclarable
2445 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2446 // Decl
2447 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2448 7)); // Packed DeclBits: ModuleOwnershipKind,
2449 // isUsed, isReferenced, AccessSpecifier,
2450 //
2451 // The following bits should be 0:
2452 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2453 // TopLevelDeclInObjCContainer,
2454 // isInvalidDecl
2455 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2456 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2457 // NamedDecl
2458 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2459 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2460 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2461 // TypeDecl
2462 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2463 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2464 // TagDecl
2465 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2466 Abv->Add(BitCodeAbbrevOp(
2467 BitCodeAbbrevOp::Fixed,
2468 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition,
2469 // EmbeddedInDeclarator, IsFreeStanding,
2470 // isCompleteDefinitionRequired, ExtInfoKind
2471 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2472 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2473 // RecordDecl
2474 Abv->Add(BitCodeAbbrevOp(
2475 BitCodeAbbrevOp::Fixed,
2476 13)); // Packed Record Decl Bits: FlexibleArrayMember,
2477 // AnonymousStructUnion, hasObjectMember, hasVolatileMember,
2478 // isNonTrivialToPrimitiveDefaultInitialize,
2479 // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy,
2480 // hasNonTrivialToPrimitiveDefaultInitializeCUnion,
2481 // hasNonTrivialToPrimitiveDestructCUnion,
2482 // hasNonTrivialToPrimitiveCopyCUnion, isParamDestroyedInCallee,
2483 // getArgPassingRestrictions
2484 // ODRHash
2485 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26));
2486
2487 // DC
2488 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2489 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2490 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
2491
2492 // Abbreviation for DECL_PARM_VAR
2493 Abv = std::make_shared<BitCodeAbbrev>();
2494 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
2495 // Redeclarable
2496 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2497 // Decl
2498 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2499 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed,
2500 // isReferenced, AccessSpecifier,
2501 // HasStandaloneLexicalDC, HasAttrs, isImplicit,
2502 // TopLevelDeclInObjCContainer,
2503 // isInvalidDecl,
2504 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2505 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2506 // NamedDecl
2507 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2508 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2509 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2510 // ValueDecl
2511 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2512 // DeclaratorDecl
2513 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2514 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2515 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2516 // VarDecl
2517 Abv->Add(
2518 BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2519 12)); // Packed Var Decl bits: SClass, TSCSpec, InitStyle,
2520 // isARCPseudoStrong, Linkage, ModulesCodegen
2521 Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2522 // ParmVarDecl
2523 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
2524 Abv->Add(BitCodeAbbrevOp(
2525 BitCodeAbbrevOp::Fixed,
2526 19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth,
2527 // ObjCDeclQualifier, KNRPromoted,
2528 // HasInheritedDefaultArg, HasUninstantiatedDefaultArg
2529 // Type Source Info
2530 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2531 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2532 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2533
2534 // Abbreviation for DECL_TYPEDEF
2535 Abv = std::make_shared<BitCodeAbbrev>();
2536 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
2537 // Redeclarable
2538 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2539 // Decl
2540 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2541 7)); // Packed DeclBits: ModuleOwnershipKind,
2542 // isReferenced, isUsed, AccessSpecifier. Other
2543 // higher bits should be 0: isImplicit,
2544 // HasStandaloneLexicalDC, HasAttrs,
2545 // TopLevelDeclInObjCContainer, isInvalidDecl
2546 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2547 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2548 // NamedDecl
2549 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2550 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2551 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2552 // TypeDecl
2553 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2554 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2555 // TypedefDecl
2556 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2557 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2558 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
2559
2560 // Abbreviation for DECL_VAR
2561 Abv = std::make_shared<BitCodeAbbrev>();
2562 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
2563 // Redeclarable
2564 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2565 // Decl
2566 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2567 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2568 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2569 // isReferenced, TopLevelDeclInObjCContainer,
2570 // AccessSpecifier, ModuleOwnershipKind
2571 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2572 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2573 // NamedDecl
2574 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2575 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2576 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2577 // ValueDecl
2578 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2579 // DeclaratorDecl
2580 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2581 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2582 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2583 // VarDecl
2584 Abv->Add(BitCodeAbbrevOp(
2585 BitCodeAbbrevOp::Fixed,
2586 21)); // Packed Var Decl bits: Linkage, ModulesCodegen,
2587 // SClass, TSCSpec, InitStyle,
2588 // isARCPseudoStrong, IsThisDeclarationADemotedDefinition,
2589 // isExceptionVariable, isNRVOVariable, isCXXForRangeDecl,
2590 // isInline, isInlineSpecified, isConstexpr,
2591 // isInitCapture, isPrevDeclInSameScope,
2592 // EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl
2593 Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2594 // Type Source Info
2595 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2596 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2597 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2598
2599 // Abbreviation for DECL_CXX_METHOD
2600 DeclCXXMethodAbbrev =
2601 Stream.EmitAbbrev(getCXXMethodAbbrev<FunctionDecl::TK_NonTemplate>());
2602 DeclTemplateCXXMethodAbbrev = Stream.EmitAbbrev(
2603 getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplate>());
2604 DeclDependentNonTemplateCXXMethodAbbrev = Stream.EmitAbbrev(
2605 getCXXMethodAbbrev<FunctionDecl::TK_DependentNonTemplate>());
2606 DeclMemberSpecializedCXXMethodAbbrev = Stream.EmitAbbrev(
2607 getCXXMethodAbbrev<FunctionDecl::TK_MemberSpecialization>());
2608 DeclTemplateSpecializedCXXMethodAbbrev = Stream.EmitAbbrev(
2609 getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplateSpecialization>());
2610 DeclDependentSpecializationCXXMethodAbbrev = Stream.EmitAbbrev(
2611 getCXXMethodAbbrev<
2613
2614 // Abbreviation for DECL_TEMPLATE_TYPE_PARM
2615 Abv = std::make_shared<BitCodeAbbrev>();
2616 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TEMPLATE_TYPE_PARM));
2617 Abv->Add(BitCodeAbbrevOp(0)); // hasTypeConstraint
2618 // Decl
2619 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2620 7)); // Packed DeclBits: ModuleOwnershipKind,
2621 // isReferenced, isUsed, AccessSpecifier. Other
2622 // higher bits should be 0: isImplicit,
2623 // HasStandaloneLexicalDC, HasAttrs,
2624 // TopLevelDeclInObjCContainer, isInvalidDecl
2625 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2626 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2627 // NamedDecl
2628 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2629 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2630 Abv->Add(BitCodeAbbrevOp(0));
2631 // TypeDecl
2632 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2633 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2634 // TemplateTypeParmDecl
2635 Abv->Add(
2636 BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename
2637 Abv->Add(BitCodeAbbrevOp(0)); // OwnsDefaultArg
2638 DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(std::move(Abv));
2639
2640 // Abbreviation for DECL_USING_SHADOW
2641 Abv = std::make_shared<BitCodeAbbrev>();
2642 Abv->Add(BitCodeAbbrevOp(serialization::DECL_USING_SHADOW));
2643 // Redeclarable
2644 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2645 // Decl
2646 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2647 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2648 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2649 // isReferenced, TopLevelDeclInObjCContainer,
2650 // AccessSpecifier, ModuleOwnershipKind
2651 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2652 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2653 // NamedDecl
2654 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2655 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2656 Abv->Add(BitCodeAbbrevOp(0));
2657 // UsingShadowDecl
2658 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl
2659 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2660 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow
2661 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR,
2662 6)); // InstantiatedFromUsingShadowDecl
2663 DeclUsingShadowAbbrev = Stream.EmitAbbrev(std::move(Abv));
2664
2665 // Abbreviation for EXPR_DECL_REF
2666 Abv = std::make_shared<BitCodeAbbrev>();
2667 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2668 // Stmt
2669 // Expr
2670 // PackingBits: DependenceKind, ValueKind. ObjectKind should be 0.
2671 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
2672 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2673 // DeclRefExpr
2674 // Packing Bits: , HadMultipleCandidates, RefersToEnclosingVariableOrCapture,
2675 // IsImmediateEscalating, NonOdrUseReason.
2676 // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0.
2677 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2678 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2679 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2680 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2681
2682 // Abbreviation for EXPR_INTEGER_LITERAL
2683 Abv = std::make_shared<BitCodeAbbrev>();
2684 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2685 //Stmt
2686 // Expr
2687 // DependenceKind, ValueKind, ObjectKind
2688 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2689 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2690 // Integer Literal
2691 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2692 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2693 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2694 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2695
2696 // Abbreviation for EXPR_CHARACTER_LITERAL
2697 Abv = std::make_shared<BitCodeAbbrev>();
2698 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2699 //Stmt
2700 // Expr
2701 // DependenceKind, ValueKind, ObjectKind
2702 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2703 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2704 // Character Literal
2705 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2706 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
2708 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2709
2710 // Abbreviation for EXPR_IMPLICIT_CAST
2711 Abv = std::make_shared<BitCodeAbbrev>();
2712 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2713 // Stmt
2714 // Expr
2715 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2716 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2717 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2718 // CastExpr
2719 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2720 // Packing Bits: CastKind, StoredFPFeatures, isPartOfExplicitCast
2721 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 9));
2722 // ImplicitCastExpr
2723 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
2724
2725 // Abbreviation for EXPR_BINARY_OPERATOR
2726 Abv = std::make_shared<BitCodeAbbrev>();
2727 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_BINARY_OPERATOR));
2728 // Stmt
2729 // Expr
2730 // Packing Bits: DependenceKind. ValueKind and ObjectKind should
2731 // be 0 in this case.
2732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2733 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2734 // BinaryOperator
2735 Abv->Add(
2736 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures
2737 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2738 BinaryOperatorAbbrev = Stream.EmitAbbrev(std::move(Abv));
2739
2740 // Abbreviation for EXPR_COMPOUND_ASSIGN_OPERATOR
2741 Abv = std::make_shared<BitCodeAbbrev>();
2742 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_COMPOUND_ASSIGN_OPERATOR));
2743 // Stmt
2744 // Expr
2745 // Packing Bits: DependenceKind. ValueKind and ObjectKind should
2746 // be 0 in this case.
2747 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2748 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2749 // BinaryOperator
2750 // Packing Bits: OpCode. The HasFPFeatures bit should be 0
2751 Abv->Add(
2752 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures
2753 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2754 // CompoundAssignOperator
2755 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHSType
2756 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Result Type
2757 CompoundAssignOperatorAbbrev = Stream.EmitAbbrev(std::move(Abv));
2758
2759 // Abbreviation for EXPR_CALL
2760 Abv = std::make_shared<BitCodeAbbrev>();
2761 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CALL));
2762 // Stmt
2763 // Expr
2764 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2765 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2766 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2767 // CallExpr
2768 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2769 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2771 CallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2772
2773 // Abbreviation for EXPR_CXX_OPERATOR_CALL
2774 Abv = std::make_shared<BitCodeAbbrev>();
2775 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CXX_OPERATOR_CALL));
2776 // Stmt
2777 // Expr
2778 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2780 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2781 // CallExpr
2782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2783 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2785 // CXXOperatorCallExpr
2786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind
2787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2788 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2789 CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2790
2791 // Abbreviation for EXPR_CXX_MEMBER_CALL
2792 Abv = std::make_shared<BitCodeAbbrev>();
2793 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CXX_MEMBER_CALL));
2794 // Stmt
2795 // Expr
2796 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2797 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2798 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2799 // CallExpr
2800 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2801 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2802 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2803 // CXXMemberCallExpr
2804 CXXMemberCallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2805
2806 // Abbreviation for STMT_COMPOUND
2807 Abv = std::make_shared<BitCodeAbbrev>();
2808 Abv->Add(BitCodeAbbrevOp(serialization::STMT_COMPOUND));
2809 // Stmt
2810 // CompoundStmt
2811 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Num Stmts
2812 Abv->Add(BitCodeAbbrevOp(0)); // hasStoredFPFeatures
2813 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2815 CompoundStmtAbbrev = Stream.EmitAbbrev(std::move(Abv));
2816
2817 Abv = std::make_shared<BitCodeAbbrev>();
2818 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
2819 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2820 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
2821
2822 Abv = std::make_shared<BitCodeAbbrev>();
2823 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
2824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2825 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
2826
2827 Abv = std::make_shared<BitCodeAbbrev>();
2828 Abv->Add(BitCodeAbbrevOp(serialization::DECL_SPECIALIZATIONS));
2829 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2830 DeclSpecializationsAbbrev = Stream.EmitAbbrev(std::move(Abv));
2831
2832 Abv = std::make_shared<BitCodeAbbrev>();
2833 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARTIAL_SPECIALIZATIONS));
2834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2835 DeclPartialSpecializationsAbbrev = Stream.EmitAbbrev(std::move(Abv));
2836}
2837
2838/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2839/// consumers of the AST.
2840///
2841/// Such decls will always be deserialized from the AST file, so we would like
2842/// this to be as restrictive as possible. Currently the predicate is driven by
2843/// code generation requirements, if other clients have a different notion of
2844/// what is "required" then we may have to consider an alternate scheme where
2845/// clients can iterate over the top-level decls and get information on them,
2846/// without necessary deserializing them. We could explicitly require such
2847/// clients to use a separate API call to "realize" the decl. This should be
2848/// relatively painless since they would presumably only do it for top-level
2849/// decls.
2850static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2851 Module *WritingModule) {
2852 // Named modules have different semantics than header modules. Every named
2853 // module units owns a translation unit. So the importer of named modules
2854 // doesn't need to deserilize everything ahead of time.
2855 if (WritingModule && WritingModule->isNamedModule()) {
2856 // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension.
2857 // And the behavior of MSVC for such cases will leak this to the module
2858 // users. Given pragma is not a standard thing, the compiler has the space
2859 // to do their own decision. Let's follow MSVC here.
2860 if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(D))
2861 return true;
2862 return false;
2863 }
2864
2865 // An ObjCMethodDecl is never considered as "required" because its
2866 // implementation container always is.
2867
2868 // File scoped assembly or obj-c or OMP declare target implementation must be
2869 // seen.
2870 if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(D))
2871 return true;
2872
2873 if (WritingModule && isPartOfPerModuleInitializer(D)) {
2874 // These declarations are part of the module initializer, and are emitted
2875 // if and when the module is imported, rather than being emitted eagerly.
2876 return false;
2877 }
2878
2879 return Context.DeclMustBeEmitted(D);
2880}
2881
2882void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
2883 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2884 "serializing");
2885
2886 // Determine the ID for this declaration.
2888 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2889 LocalDeclID &IDR = DeclIDs[D];
2890 if (IDR.isInvalid())
2891 IDR = NextDeclID++;
2892
2893 ID = IDR;
2894
2895 assert(ID >= FirstDeclID && "invalid decl ID");
2896
2898 ASTDeclWriter W(*this, Context, Record, GeneratingReducedBMI);
2899
2900 // Build a record for this declaration
2901 W.Visit(D);
2902
2903 // Emit this declaration to the bitstream.
2904 uint64_t Offset = W.Emit(D);
2905
2906 // Record the offset for this declaration
2909 getRawSourceLocationEncoding(getAdjustedLocation(Loc));
2910
2911 unsigned Index = ID.getRawValue() - FirstDeclID.getRawValue();
2912 if (DeclOffsets.size() == Index)
2913 DeclOffsets.emplace_back(RawLoc, Offset, DeclTypesBlockStartOffset);
2914 else if (DeclOffsets.size() < Index) {
2915 // FIXME: Can/should this happen?
2916 DeclOffsets.resize(Index+1);
2917 DeclOffsets[Index].setRawLoc(RawLoc);
2918 DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
2919 } else {
2920 llvm_unreachable("declarations should be emitted in ID order");
2921 }
2922
2923 SourceManager &SM = Context.getSourceManager();
2924 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2925 associateDeclWithFile(D, ID);
2926
2927 // Note declarations that should be deserialized eagerly so that we can add
2928 // them to a record in the AST file later.
2929 if (isRequiredDecl(D, Context, WritingModule))
2930 AddDeclRef(D, EagerlyDeserializedDecls);
2931}
2932
2934 // Switch case IDs are per function body.
2935 Writer->ClearSwitchCaseIDs();
2936
2937 assert(FD->doesThisDeclarationHaveABody());
2938 bool ModulesCodegen = false;
2939 if (!FD->isDependentContext()) {
2940 std::optional<GVALinkage> Linkage;
2941 if (Writer->WritingModule &&
2942 Writer->WritingModule->isInterfaceOrPartition()) {
2943 // When building a C++20 module interface unit or a partition unit, a
2944 // strong definition in the module interface is provided by the
2945 // compilation of that unit, not by its users. (Inline functions are still
2946 // emitted in module users.)
2947 Linkage = getASTContext().GetGVALinkageForFunction(FD);
2948 ModulesCodegen = *Linkage >= GVA_StrongExternal;
2949 }
2950 if (Writer->getLangOpts().ModulesCodegen ||
2951 (FD->hasAttr<DLLExportAttr>() &&
2952 Writer->getLangOpts().BuildingPCHWithObjectFile)) {
2953
2954 // Under -fmodules-codegen, codegen is performed for all non-internal,
2955 // non-always_inline functions, unless they are available elsewhere.
2956 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2957 if (!Linkage)
2958 Linkage = getASTContext().GetGVALinkageForFunction(FD);
2959 ModulesCodegen =
2961 }
2962 }
2963 }
2964 Record->push_back(ModulesCodegen);
2965 if (ModulesCodegen)
2966 Writer->AddDeclRef(FD, Writer->ModularCodegenDecls);
2967 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2968 Record->push_back(CD->getNumCtorInitializers());
2969 if (CD->getNumCtorInitializers())
2970 AddCXXCtorInitializers(llvm::ArrayRef(CD->init_begin(), CD->init_end()));
2971 }
2972 AddStmt(FD->getBody());
2973}
NodeId Parent
Definition: ASTDiff.cpp:191
StringRef P
static void addExplicitSpecifier(ExplicitSpecifier ES, ASTRecordWriter &Record)
static bool isRequiredDecl(const Decl *D, ASTContext &Context, Module *WritingModule)
isRequiredDecl - Check if this is a "required" Decl, which must be seen by consumers of the AST.
#define SM(sm)
Definition: Cuda.cpp:84
const Decl * D
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
llvm::MachO::Record Record
Definition: MachO.h:31
This file defines OpenMP AST classes for clauses.
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
SourceManager & getSourceManager()
Definition: ASTContext.h:741
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
MutableArrayRef< FunctionTemplateSpecializationInfo > getPartialSpecializations(FunctionTemplateDecl::Common *)
void VisitBindingDecl(BindingDecl *D)
void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
void VisitEmptyDecl(EmptyDecl *D)
void VisitCXXMethodDecl(CXXMethodDecl *D)
void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D)
void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
void VisitOMPRequiresDecl(OMPRequiresDecl *D)
void VisitNamedDecl(NamedDecl *D)
void CollectFirstDeclFromEachModule(const Decl *D, bool IncludeLocal, llvm::MapVector< ModuleFile *, const Decl * > &Firsts)
Collect the first declaration from each module file that provides a declaration of D.
RedeclarableTemplateDecl::SpecEntryTraits< EntryType >::DeclType * getSpecializationDecl(EntryType &T)
Get the specialization decl from an entry in the specialization list.
void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D)
void VisitNamespaceDecl(NamespaceDecl *D)
void VisitOMPAllocateDecl(OMPAllocateDecl *D)
void VisitExportDecl(ExportDecl *D)
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D)
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
void VisitParmVarDecl(ParmVarDecl *D)
void VisitRedeclarable(Redeclarable< T > *D)
void VisitFriendDecl(FriendDecl *D)
void VisitDeclaratorDecl(DeclaratorDecl *D)
void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D)
void VisitConceptDecl(ConceptDecl *D)
void AddFirstSpecializationDeclFromEachModule(const Decl *D, llvm::SmallVectorImpl< const Decl * > &SpecsInMap, llvm::SmallVectorImpl< const Decl * > &PartialSpecsInMap)
Add to the record the first template specialization from each module file that provides a declaration...
void VisitObjCPropertyDecl(ObjCPropertyDecl *D)
void VisitBlockDecl(BlockDecl *D)
void VisitLabelDecl(LabelDecl *LD)
void VisitTemplateDecl(TemplateDecl *D)
void VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
void VisitCXXDestructorDecl(CXXDestructorDecl *D)
void VisitFieldDecl(FieldDecl *D)
void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D)
void VisitObjCContainerDecl(ObjCContainerDecl *D)
void RegisterTemplateSpecialization(const Decl *Template, const Decl *Specialization)
Ensure that this template specialization is associated with the specified template on reload.
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
void VisitVarTemplatePartialSpecializationDecl(VarTemplatePartialSpecializationDecl *D)
void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D)
void VisitCXXConversionDecl(CXXConversionDecl *D)
void VisitUsingShadowDecl(UsingShadowDecl *D)
void VisitValueDecl(ValueDecl *D)
void VisitIndirectFieldDecl(IndirectFieldDecl *D)
void VisitImplicitParamDecl(ImplicitParamDecl *D)
decltype(T::PartialSpecializations) & getPartialSpecializations(T *Common)
Get the list of partial specializations from a template's common ptr.
void VisitObjCProtocolDecl(ObjCProtocolDecl *D)
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
void VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
void VisitObjCCategoryDecl(ObjCCategoryDecl *D)
void VisitTopLevelStmtDecl(TopLevelStmtDecl *D)
void VisitLinkageSpecDecl(LinkageSpecDecl *D)
void VisitAccessSpecDecl(AccessSpecDecl *D)
ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, ASTWriter::RecordDataImpl &Record, bool GeneratingReducedBMI)
void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
void VisitDecl(Decl *D)
void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
void VisitMSPropertyDecl(MSPropertyDecl *D)
void VisitUsingEnumDecl(UsingEnumDecl *D)
void VisitTypeDecl(TypeDecl *D)
void VisitClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl *D)
void VisitEnumConstantDecl(EnumConstantDecl *D)
void VisitObjCIvarDecl(ObjCIvarDecl *D)
void VisitCapturedDecl(CapturedDecl *D)
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D)
void VisitPragmaCommentDecl(PragmaCommentDecl *D)
void VisitRecordDecl(RecordDecl *D)
void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D)
void VisitTypedefDecl(TypedefDecl *D)
void VisitMSGuidDecl(MSGuidDecl *D)
void VisitTypedefNameDecl(TypedefNameDecl *D)
void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
void VisitUsingDecl(UsingDecl *D)
void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
void AddTemplateSpecializations(DeclTy *D)
void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D)
void VisitObjCImplementationDecl(ObjCImplementationDecl *D)
void VisitFriendTemplateDecl(FriendTemplateDecl *D)
void VisitObjCMethodDecl(ObjCMethodDecl *D)
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
uint64_t Emit(Decl *D)
void VisitVarTemplateDecl(VarTemplateDecl *D)
void VisitHLSLBufferDecl(HLSLBufferDecl *D)
void VisitObjCImplDecl(ObjCImplDecl *D)
void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D)
void VisitVarDecl(VarDecl *D)
void VisitImportDecl(ImportDecl *D)
void VisitCXXRecordDecl(CXXRecordDecl *D)
void VisitCXXConstructorDecl(CXXConstructorDecl *D)
void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D)
void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
void VisitFileScopeAsmDecl(FileScopeAsmDecl *D)
void VisitClassTemplateDecl(ClassTemplateDecl *D)
void VisitFunctionDecl(FunctionDecl *D)
void VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
void VisitEnumDecl(EnumDecl *D)
void VisitTranslationUnitDecl(TranslationUnitDecl *D)
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D)
void VisitStaticAssertDecl(StaticAssertDecl *D)
void VisitDeclContext(DeclContext *DC)
Emit the DeclContext part of a declaration context decl.
void AddObjCTypeParamList(ObjCTypeParamList *typeParams)
Add an Objective-C type parameter list to the given record.
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal)
Add to the record the first declaration from each module file that provides a declaration of D.
void VisitUsingPackDecl(UsingPackDecl *D)
void VisitDecompositionDecl(DecompositionDecl *D)
void VisitTagDecl(TagDecl *D)
void VisitTypeAliasDecl(TypeAliasDecl *D)
void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D)
ModuleFile * getOwningModuleFile(const Decl *D) const
Retrieve the module file that owns the given declaration, or NULL if the declaration is not from a mo...
Definition: ASTReader.cpp:7908
bool haveUnloadedSpecializations(const Decl *D) const
If we have any unloaded specialization for D.
Definition: ASTReader.cpp:8436
An object for streaming information to a record.
void AddFunctionDefinition(const FunctionDecl *FD)
Add a definition for the given function to the queue of statements to emit.
uint64_t Emit(unsigned Code, unsigned Abbrev=0)
Emit the record to the stream, followed by its substatements, and return its offset.
void AddStmt(Stmt *S)
Add the given statement or expression to the queue of statements to emit.
void AddCXXCtorInitializers(ArrayRef< CXXCtorInitializer * > CtorInits)
Emit a CXXCtorInitializer array.
Definition: ASTWriter.cpp:6888
void AddDeclRef(const Decl *D)
Emit a reference to a declaration.
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:89
unsigned getDeclParmVarAbbrev() const
Definition: ASTWriter.h:832
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:856
bool isWritingStdCXXNamedModules() const
Definition: ASTWriter.h:880
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:838
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:834
bool hasChain() const
Definition: ASTWriter.h:875
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:859
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:884
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:835
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:837
bool IsLocalDecl(const Decl *D)
Is this a local declaration (that is, one that will be written to our AST file)? This is the case for...
Definition: ASTWriter.h:755
LocalDeclID GetDeclRef(const Decl *D)
Force a declaration to be emitted and get its local ID to the module file been writing.
Definition: ASTWriter.cpp:6552
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:839
const Decl * getFirstLocalDecl(const Decl *D)
Find the first local declaration of a given local redeclarable decl.
SourceLocationEncoding::RawLocEncoding getRawSourceLocationEncoding(SourceLocation Loc, LocSeq *Seq=nullptr)
Return the raw encodings for source locations.
Definition: ASTWriter.cpp:6323
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6660
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:836
const LangOptions & getLangOpts() const
Definition: ASTWriter.cpp:5096
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:833
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6548
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
A binding in a decomposition declaration.
Definition: DeclCXX.h:4125
A simple helper class to pack several bits in order into (a) 32 bit integer(s).
Definition: ASTWriter.h:1029
void addBit(bool Value)
Definition: ASTWriter.h:1049
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1050
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4474
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2880
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1967
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
static bool classofKind(Kind K)
Definition: DeclCXX.h:1904
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4673
unsigned getNumParams() const
Definition: Decl.h:4715
unsigned getContextParamPosition() const
Definition: Decl.h:4744
bool isNothrow() const
Definition: Decl.cpp:5466
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4717
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
Declaration of a C++20 concept.
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3616
A POD class for pairing a NamedDecl* with an access specifier.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1334
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1919
DeclID getRawValue() const
Definition: DeclID.h:118
bool isInvalid() const
Definition: DeclID.h:126
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Definition: DeclBase.h:1050
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1065
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition: DeclBase.h:645
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1215
bool hasAttrs() const
Definition: DeclBase.h:521
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
bool isInNamedModule() const
Whether this declaration comes from a named module.
Definition: DeclBase.cpp:1164
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
Definition: Decl.cpp:99
ModuleOwnershipKind getModuleOwnershipKind() const
Get the kind of module ownership for this declaration.
Definition: DeclBase.h:865
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:239
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition: DeclBase.h:1076
bool isReferenced() const
Whether any declaration of this entity was referenced.
Definition: DeclBase.cpp:574
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:973
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:835
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: DeclBase.h:1059
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:786
bool isInvalidDecl() const
Definition: DeclBase.h:591
unsigned getIdentifierNamespace() const
Definition: DeclBase.h:878
SourceLocation getLocation() const
Definition: DeclBase.h:442
const char * getDeclKindName() const
Definition: DeclBase.cpp:142
bool isTopLevelDeclInObjCContainer() const
Whether this declaration is a top-level declaration (function, global variable, etc....
Definition: DeclBase.h:631
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:549
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
AttrVec & getAttrs()
Definition: DeclBase.h:527
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:907
bool hasAttr() const
Definition: DeclBase.h:580
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:967
Kind getKind() const
Definition: DeclBase.h:445
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:735
A decomposition declaration.
Definition: DeclCXX.h:4184
Provides information about a dependent function-template specialization declaration.
Definition: DeclTemplate.h:694
ArrayRef< FunctionTemplateDecl * > getCandidates() const
Returns the candidates for the primary function template.
Definition: DeclTemplate.h:713
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:706
Represents an empty-declaration.
Definition: Decl.h:4912
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3277
Represents an enum.
Definition: Decl.h:3847
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1912
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1920
const Expr * getExpr() const
Definition: DeclCXX.h:1921
Represents a standard C++ module export declaration.
Definition: Decl.h:4865
This represents one expression.
Definition: Expr.h:110
Represents a member of a struct/union/class.
Definition: Decl.h:3033
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
Declaration of a friend template.
Represents a function declaration or definition.
Definition: Decl.h:1935
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3243
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition: Decl.h:2261
@ TK_MemberSpecialization
Definition: Decl.h:1947
@ TK_DependentNonTemplate
Definition: Decl.h:1956
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1951
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1954
Declaration of a template function.
Definition: DeclTemplate.h:959
FunctionTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:472
TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
Definition: DeclTemplate.h:486
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
Definition: DeclTemplate.h:527
MemberSpecializationInfo * getMemberSpecializationInfo() const
Get the specialization info if this function template specialization is also a member specialization:
Definition: DeclTemplate.h:598
const ASTTemplateArgumentListInfo * TemplateArgumentsAsWritten
The template arguments as written in the sources, if provided.
Definition: DeclTemplate.h:490
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this function template specialization.
Definition: DeclTemplate.h:558
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:530
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Definition: Decl.h:4927
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4786
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3321
Represents the declaration of a label.
Definition: Decl.h:503
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3247
Represents a linkage specification.
Definition: DeclCXX.h:2952
A global _GUID constant.
Definition: DeclCXX.h:4307
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:4253
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:620
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:642
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:660
NamedDecl * getInstantiatedFrom() const
Retrieve the member declaration from which this member was instantiated.
Definition: DeclTemplate.h:639
Describes a module or submodule.
Definition: Module.h:115
bool isInterfaceOrPartition() const
Definition: Module.h:642
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Definition: Module.h:195
This represents a decl that may have a name.
Definition: Decl.h:253
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
Represent a C++ namespace.
Definition: Decl.h:551
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
This represents '#pragma omp allocate ...' directive.
Definition: DeclOpenMP.h:474
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:383
This represents '#pragma omp declare mapper ...' directive.
Definition: DeclOpenMP.h:287
This represents '#pragma omp declare reduction ...' directive.
Definition: DeclOpenMP.h:177
This represents '#pragma omp requires...' directive.
Definition: DeclOpenMP.h:417
This represents '#pragma omp threadprivate ...' directive.
Definition: DeclOpenMP.h:110
Represents a field declaration created by an @defs(...).
Definition: DeclObjC.h:2029
static bool classofKind(Kind K)
Definition: DeclObjC.h:2050
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2544
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2774
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:947
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2596
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
static bool classofKind(Kind K)
Definition: DeclObjC.h:2014
T *const * iterator
Definition: DeclObjC.h:88
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2804
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:659
unsigned size() const
Determine the number of type parameters in this list.
Definition: DeclObjC.h:686
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a parameter to a function.
Definition: Decl.h:1725
Represents a #pragma comment line.
Definition: Decl.h:146
Represents a #pragma detect_mismatch line.
Definition: Decl.h:180
PrettyDeclStackTraceEntry - If a crash occurs in the parser while parsing something related to a decl...
A (possibly-)qualified type.
Definition: Type.h:929
Represents a struct/union/class.
Definition: Decl.h:4148
Declaration of a redeclarable template.
Definition: DeclTemplate.h:721
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
Represents the body of a requires-expression.
Definition: DeclCXX.h:2047
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4076
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
const TemplateArgument & get(unsigned Idx) const
Retrieve the template argument at a given index.
Definition: DeclTemplate.h:271
Represents a template argument.
Definition: TemplateBase.h:61
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
A template parameter object.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
A declaration that models statements at global scope.
Definition: Decl.h:4437
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3535
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:227
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
Definition: ASTConcept.h:242
ConceptReference * getConceptReference() const
Definition: ASTConcept.h:246
Represents a declaration of a type.
Definition: Decl.h:3370
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3514
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4364
This node is generated when a using-declaration that was annotated with attribute((using_if_exists)) ...
Definition: DeclCXX.h:4058
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3977
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3880
Represents a C++ using-declaration.
Definition: DeclCXX.h:3530
Represents C++ using-directive.
Definition: DeclCXX.h:3033
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3731
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3812
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3338
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
Represents a variable declaration or definition.
Definition: Decl.h:882
@ CInit
C-style initialization with assignment.
Definition: Decl.h:887
Declaration of a variable template.
Represents a variable template specialization, which refers to a variable template with a given set o...
RetTy Visit(PTR(Decl) D)
Definition: DeclVisitor.h:37
const unsigned int LOCAL_REDECLARATIONS
Record code for a list of local redeclarations of a declaration.
Definition: ASTBitCodes.h:1219
DeclCode
Record codes for each kind of declaration.
Definition: ASTBitCodes.h:1227
@ DECL_EMPTY
An EmptyDecl record.
Definition: ASTBitCodes.h:1475
@ DECL_CAPTURED
A CapturedDecl record.
Definition: ASTBitCodes.h:1316
@ DECL_CXX_RECORD
A CXXRecordDecl record.
Definition: ASTBitCodes.h:1377
@ DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION
A VarTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1419
@ DECL_OMP_ALLOCATE
An OMPAllocateDcl record.
Definition: ASTBitCodes.h:1472
@ DECL_MS_PROPERTY
A MSPropertyDecl record.
Definition: ASTBitCodes.h:1283
@ DECL_OMP_DECLARE_MAPPER
An OMPDeclareMapperDecl record.
Definition: ASTBitCodes.h:1496
@ DECL_TOP_LEVEL_STMT_DECL
A TopLevelStmtDecl record.
Definition: ASTBitCodes.h:1310
@ DECL_REQUIRES_EXPR_BODY
A RequiresExprBodyDecl record.
Definition: ASTBitCodes.h:1481
@ DECL_STATIC_ASSERT
A StaticAssertDecl record.
Definition: ASTBitCodes.h:1443
@ DECL_INDIRECTFIELD
A IndirectFieldDecl record.
Definition: ASTBitCodes.h:1452
@ DECL_TEMPLATE_TEMPLATE_PARM
A TemplateTemplateParmDecl record.
Definition: ASTBitCodes.h:1431
@ DECL_IMPORT
An ImportDecl recording a module import.
Definition: ASTBitCodes.h:1463
@ DECL_UNNAMED_GLOBAL_CONSTANT
A UnnamedGlobalConstantDecl record.
Definition: ASTBitCodes.h:1502
@ DECL_ACCESS_SPEC
An AccessSpecDecl record.
Definition: ASTBitCodes.h:1395
@ DECL_OBJC_TYPE_PARAM
An ObjCTypeParamDecl record.
Definition: ASTBitCodes.h:1484
@ DECL_OBJC_CATEGORY_IMPL
A ObjCCategoryImplDecl record.
Definition: ASTBitCodes.h:1265
@ DECL_ENUM_CONSTANT
An EnumConstantDecl record.
Definition: ASTBitCodes.h:1241
@ DECL_PARM_VAR
A ParmVarDecl record.
Definition: ASTBitCodes.h:1298
@ DECL_TYPEDEF
A TypedefDecl record.
Definition: ASTBitCodes.h:1229
@ DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK
A TemplateTemplateParmDecl record that stores an expanded template template parameter pack.
Definition: ASTBitCodes.h:1460
@ DECL_HLSL_BUFFER
A HLSLBufferDecl record.
Definition: ASTBitCodes.h:1505
@ DECL_NAMESPACE_ALIAS
A NamespaceAliasDecl record.
Definition: ASTBitCodes.h:1344
@ DECL_TYPEALIAS
A TypeAliasDecl record.
Definition: ASTBitCodes.h:1232
@ DECL_FUNCTION_TEMPLATE
A FunctionTemplateDecl record.
Definition: ASTBitCodes.h:1422
@ DECL_MS_GUID
A MSGuidDecl record.
Definition: ASTBitCodes.h:1286
@ DECL_UNRESOLVED_USING_TYPENAME
An UnresolvedUsingTypenameDecl record.
Definition: ASTBitCodes.h:1368
@ DECL_CLASS_TEMPLATE_SPECIALIZATION
A ClassTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1407
@ DECL_FILE_SCOPE_ASM
A FileScopeAsmDecl record.
Definition: ASTBitCodes.h:1307
@ DECL_CXX_CONSTRUCTOR
A CXXConstructorDecl record.
Definition: ASTBitCodes.h:1386
@ DECL_CXX_CONVERSION
A CXXConversionDecl record.
Definition: ASTBitCodes.h:1392
@ DECL_FIELD
A FieldDecl record.
Definition: ASTBitCodes.h:1280
@ DECL_LINKAGE_SPEC
A LinkageSpecDecl record.
Definition: ASTBitCodes.h:1371
@ DECL_NAMESPACE
A NamespaceDecl record.
Definition: ASTBitCodes.h:1341
@ DECL_NON_TYPE_TEMPLATE_PARM
A NonTypeTemplateParmDecl record.
Definition: ASTBitCodes.h:1428
@ DECL_USING_PACK
A UsingPackDecl record.
Definition: ASTBitCodes.h:1353
@ DECL_FUNCTION
A FunctionDecl record.
Definition: ASTBitCodes.h:1244
@ DECL_USING_DIRECTIVE
A UsingDirecitveDecl record.
Definition: ASTBitCodes.h:1362
@ DECL_RECORD
A RecordDecl record.
Definition: ASTBitCodes.h:1238
@ DECL_CONTEXT_LEXICAL
A record that stores the set of declarations that are lexically stored within a given DeclContext.
Definition: ASTBitCodes.h:1326
@ DECL_BLOCK
A BlockDecl record.
Definition: ASTBitCodes.h:1313
@ DECL_UNRESOLVED_USING_VALUE
An UnresolvedUsingValueDecl record.
Definition: ASTBitCodes.h:1365
@ DECL_TYPE_ALIAS_TEMPLATE
A TypeAliasTemplateDecl record.
Definition: ASTBitCodes.h:1434
@ DECL_OBJC_CATEGORY
A ObjCCategoryDecl record.
Definition: ASTBitCodes.h:1262
@ DECL_VAR
A VarDecl record.
Definition: ASTBitCodes.h:1292
@ DECL_UNRESOLVED_USING_IF_EXISTS
An UnresolvedUsingIfExistsDecl record.
Definition: ASTBitCodes.h:1440
@ DECL_USING
A UsingDecl record.
Definition: ASTBitCodes.h:1347
@ DECL_OBJC_PROTOCOL
A ObjCProtocolDecl record.
Definition: ASTBitCodes.h:1253
@ DECL_TEMPLATE_TYPE_PARM
A TemplateTypeParmDecl record.
Definition: ASTBitCodes.h:1425
@ DECL_VAR_TEMPLATE_SPECIALIZATION
A VarTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1416
@ DECL_OBJC_IMPLEMENTATION
A ObjCImplementationDecl record.
Definition: ASTBitCodes.h:1268
@ DECL_LABEL
A LabelDecl record.
Definition: ASTBitCodes.h:1338
@ DECL_OBJC_COMPATIBLE_ALIAS
A ObjCCompatibleAliasDecl record.
Definition: ASTBitCodes.h:1271
@ DECL_CONSTRUCTOR_USING_SHADOW
A ConstructorUsingShadowDecl record.
Definition: ASTBitCodes.h:1359
@ DECL_USING_ENUM
A UsingEnumDecl record.
Definition: ASTBitCodes.h:1350
@ DECL_FRIEND_TEMPLATE
A FriendTemplateDecl record.
Definition: ASTBitCodes.h:1401
@ DECL_PRAGMA_DETECT_MISMATCH
A PragmaDetectMismatchDecl record.
Definition: ASTBitCodes.h:1493
@ DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
A NonTypeTemplateParmDecl record that stores an expanded non-type template parameter pack.
Definition: ASTBitCodes.h:1456
@ DECL_OBJC_AT_DEFS_FIELD
A ObjCAtDefsFieldDecl record.
Definition: ASTBitCodes.h:1259
@ DECL_IMPLICIT_PARAM
An ImplicitParamDecl record.
Definition: ASTBitCodes.h:1295
@ DECL_FRIEND
A FriendDecl record.
Definition: ASTBitCodes.h:1398
@ DECL_CXX_METHOD
A CXXMethodDecl record.
Definition: ASTBitCodes.h:1383
@ DECL_EXPORT
An ExportDecl record.
Definition: ASTBitCodes.h:1374
@ DECL_BINDING
A BindingDecl record.
Definition: ASTBitCodes.h:1304
@ DECL_PRAGMA_COMMENT
A PragmaCommentDecl record.
Definition: ASTBitCodes.h:1490
@ DECL_ENUM
An EnumDecl record.
Definition: ASTBitCodes.h:1235
@ DECL_DECOMPOSITION
A DecompositionDecl record.
Definition: ASTBitCodes.h:1301
@ DECL_OMP_DECLARE_REDUCTION
An OMPDeclareReductionDecl record.
Definition: ASTBitCodes.h:1499
@ DECL_OMP_THREADPRIVATE
An OMPThreadPrivateDecl record.
Definition: ASTBitCodes.h:1466
@ DECL_OBJC_METHOD
A ObjCMethodDecl record.
Definition: ASTBitCodes.h:1247
@ DECL_CXX_DESTRUCTOR
A CXXDestructorDecl record.
Definition: ASTBitCodes.h:1389
@ DECL_OMP_CAPTUREDEXPR
An OMPCapturedExprDecl record.
Definition: ASTBitCodes.h:1487
@ DECL_CLASS_TEMPLATE
A ClassTemplateDecl record.
Definition: ASTBitCodes.h:1404
@ DECL_USING_SHADOW
A UsingShadowDecl record.
Definition: ASTBitCodes.h:1356
@ DECL_CONCEPT
A ConceptDecl record.
Definition: ASTBitCodes.h:1437
@ DECL_CXX_DEDUCTION_GUIDE
A CXXDeductionGuideDecl record.
Definition: ASTBitCodes.h:1380
@ DECL_OMP_REQUIRES
An OMPRequiresDecl record.
Definition: ASTBitCodes.h:1469
@ DECL_OBJC_IVAR
A ObjCIvarDecl record.
Definition: ASTBitCodes.h:1256
@ DECL_OBJC_PROPERTY
A ObjCPropertyDecl record.
Definition: ASTBitCodes.h:1274
@ DECL_TEMPLATE_PARAM_OBJECT
A TemplateParamObjectDecl record.
Definition: ASTBitCodes.h:1289
@ DECL_OBJC_INTERFACE
A ObjCInterfaceDecl record.
Definition: ASTBitCodes.h:1250
@ DECL_VAR_TEMPLATE
A VarTemplateDecl record.
Definition: ASTBitCodes.h:1413
@ DECL_LIFETIME_EXTENDED_TEMPORARY
An LifetimeExtendedTemporaryDecl record.
Definition: ASTBitCodes.h:1478
@ DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
A ClassTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1410
@ DECL_IMPLICIT_CONCEPT_SPECIALIZATION
An ImplicitConceptSpecializationDecl record.
Definition: ASTBitCodes.h:1508
@ DECL_CONTEXT_VISIBLE
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1335
@ DECL_OBJC_PROPERTY_IMPL
A ObjCPropertyImplDecl record.
Definition: ASTBitCodes.h:1277
@ EXPR_COMPOUND_ASSIGN_OPERATOR
A CompoundAssignOperator record.
Definition: ASTBitCodes.h:1652
@ EXPR_CXX_OPERATOR_CALL
A CXXOperatorCallExpr record.
Definition: ASTBitCodes.h:1810
@ EXPR_IMPLICIT_CAST
An ImplicitCastExpr record.
Definition: ASTBitCodes.h:1658
@ EXPR_CHARACTER_LITERAL
A CharacterLiteral record.
Definition: ASTBitCodes.h:1619
@ STMT_COMPOUND
A CompoundStmt record.
Definition: ASTBitCodes.h:1541
@ EXPR_CALL
A CallExpr record.
Definition: ASTBitCodes.h:1643
@ EXPR_BINARY_OPERATOR
A BinaryOperator record.
Definition: ASTBitCodes.h:1649
@ EXPR_DECL_REF
A DeclRefExpr record.
Definition: ASTBitCodes.h:1604
@ EXPR_INTEGER_LITERAL
An IntegerLiteral record.
Definition: ASTBitCodes.h:1607
@ EXPR_CXX_MEMBER_CALL
A CXXMemberCallExpr record.
Definition: ASTBitCodes.h:1813
bool isRedeclarableDeclKind(unsigned Kind)
Determine whether the given declaration kind is redeclarable.
Definition: ASTCommon.cpp:368
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:472
bool isPartOfPerModuleInitializer(const Decl *D)
Determine whether the given declaration will be included in the per-module initializer if it needs to...
Definition: ASTCommon.h:92
@ UPD_CXX_ADDED_ANONYMOUS_NAMESPACE
Definition: ASTCommon.h:27
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:328
@ GVA_StrongExternal
Definition: Linkage.h:76
@ GVA_AvailableExternally
Definition: Linkage.h:74
@ GVA_Internal
Definition: Linkage.h:73
@ Specialization
We are substituting template parameters for template arguments in order to form a template specializa...
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
@ SD_Static
Static storage duration.
Definition: Specifiers.h:331
bool CanElideDeclDef(const Decl *D)
If we can elide the definition of.
const FunctionProtoType * T
@ TSK_ExplicitInstantiationDefinition
This template specialization was instantiated from a template due to an explicit instantiation defini...
Definition: Specifiers.h:206
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:202
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:194
@ AS_none
Definition: Specifiers.h:127
unsigned long uint64_t
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
Copy initialization expr of a __block variable and a boolean flag that indicates whether the expressi...
Definition: Expr.h:6460
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:965
Parts of a decomposed MSGuidDecl.
Definition: DeclCXX.h:4282
uint16_t Part2
...-89ab-...
Definition: DeclCXX.h:4286
uint32_t Part1
{01234567-...
Definition: DeclCXX.h:4284
uint16_t Part3
...-cdef-...
Definition: DeclCXX.h:4288
uint8_t Part4And5[8]
...-0123-456789abcdef}
Definition: DeclCXX.h:4290
static DeclType * getDecl(EntryType *D)
Definition: DeclTemplate.h:742