clang 19.0.0git
ASTReaderDecl.cpp
Go to the documentation of this file.
1//===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===//
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 the ASTReader::readDeclRecord method, which is the
10// entrypoint for loading a decl.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ASTCommon.h"
15#include "ASTReaderInternals.h"
19#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/DeclBase.h"
23#include "clang/AST/DeclCXX.h"
25#include "clang/AST/DeclObjC.h"
30#include "clang/AST/Expr.h"
36#include "clang/AST/Stmt.h"
38#include "clang/AST/Type.h"
44#include "clang/Basic/LLVM.h"
45#include "clang/Basic/Lambda.h"
47#include "clang/Basic/Linkage.h"
48#include "clang/Basic/Module.h"
57#include "llvm/ADT/DenseMap.h"
58#include "llvm/ADT/FoldingSet.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/SmallPtrSet.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/ADT/iterator_range.h"
63#include "llvm/Bitstream/BitstreamReader.h"
64#include "llvm/Support/Casting.h"
65#include "llvm/Support/ErrorHandling.h"
66#include "llvm/Support/SaveAndRestore.h"
67#include <algorithm>
68#include <cassert>
69#include <cstdint>
70#include <cstring>
71#include <string>
72#include <utility>
73
74using namespace clang;
75using namespace serialization;
76
77//===----------------------------------------------------------------------===//
78// Declaration deserialization
79//===----------------------------------------------------------------------===//
80
81namespace clang {
82
83 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
84 ASTReader &Reader;
86 ASTReader::RecordLocation Loc;
87 const DeclID ThisDeclID;
88 const SourceLocation ThisDeclLoc;
89
91
92 TypeID DeferredTypeID = 0;
93 unsigned AnonymousDeclNumber = 0;
94 GlobalDeclID NamedDeclForTagDecl = 0;
95 IdentifierInfo *TypedefNameForLinkage = nullptr;
96
97 ///A flag to carry the information for a decl from the entity is
98 /// used. We use it to delay the marking of the canonical decl as used until
99 /// the entire declaration is deserialized and merged.
100 bool IsDeclMarkedUsed = false;
101
102 uint64_t GetCurrentCursorOffset();
103
104 uint64_t ReadLocalOffset() {
105 uint64_t LocalOffset = Record.readInt();
106 assert(LocalOffset < Loc.Offset && "offset point after current record");
107 return LocalOffset ? Loc.Offset - LocalOffset : 0;
108 }
109
110 uint64_t ReadGlobalOffset() {
111 uint64_t Local = ReadLocalOffset();
112 return Local ? Record.getGlobalBitOffset(Local) : 0;
113 }
114
115 SourceLocation readSourceLocation() {
116 return Record.readSourceLocation();
117 }
118
119 SourceRange readSourceRange() {
120 return Record.readSourceRange();
121 }
122
123 TypeSourceInfo *readTypeSourceInfo() {
124 return Record.readTypeSourceInfo();
125 }
126
127 serialization::DeclID readDeclID() {
128 return Record.readDeclID();
129 }
130
131 std::string readString() {
132 return Record.readString();
133 }
134
135 void readDeclIDList(SmallVectorImpl<DeclID> &IDs) {
136 for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I)
137 IDs.push_back(readDeclID());
138 }
139
140 Decl *readDecl() {
141 return Record.readDecl();
142 }
143
144 template<typename T>
145 T *readDeclAs() {
146 return Record.readDeclAs<T>();
147 }
148
149 serialization::SubmoduleID readSubmoduleID() {
150 if (Record.getIdx() == Record.size())
151 return 0;
152
153 return Record.getGlobalSubmoduleID(Record.readInt());
154 }
155
156 Module *readModule() {
157 return Record.getSubmodule(readSubmoduleID());
158 }
159
160 void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
161 Decl *LambdaContext = nullptr,
162 unsigned IndexInLambdaContext = 0);
163 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
164 const CXXRecordDecl *D, Decl *LambdaContext,
165 unsigned IndexInLambdaContext);
166 void MergeDefinitionData(CXXRecordDecl *D,
167 struct CXXRecordDecl::DefinitionData &&NewDD);
168 void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data);
169 void MergeDefinitionData(ObjCInterfaceDecl *D,
170 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
171 void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data);
172 void MergeDefinitionData(ObjCProtocolDecl *D,
173 struct ObjCProtocolDecl::DefinitionData &&NewDD);
174
175 static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC);
176
177 static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader,
178 DeclContext *DC,
179 unsigned Index);
180 static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC,
181 unsigned Index, NamedDecl *D);
182
183 /// Commit to a primary definition of the class RD, which is known to be
184 /// a definition of the class. We might not have read the definition data
185 /// for it yet. If we haven't then allocate placeholder definition data
186 /// now too.
187 static CXXRecordDecl *getOrFakePrimaryClassDefinition(ASTReader &Reader,
188 CXXRecordDecl *RD);
189
190 /// Results from loading a RedeclarableDecl.
191 class RedeclarableResult {
192 Decl *MergeWith;
193 GlobalDeclID FirstID;
194 bool IsKeyDecl;
195
196 public:
197 RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl)
198 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
199
200 /// Retrieve the first ID.
201 GlobalDeclID getFirstID() const { return FirstID; }
202
203 /// Is this declaration a key declaration?
204 bool isKeyDecl() const { return IsKeyDecl; }
205
206 /// Get a known declaration that this should be merged with, if
207 /// any.
208 Decl *getKnownMergeTarget() const { return MergeWith; }
209 };
210
211 /// Class used to capture the result of searching for an existing
212 /// declaration of a specific kind and name, along with the ability
213 /// to update the place where this result was found (the declaration
214 /// chain hanging off an identifier or the DeclContext we searched in)
215 /// if requested.
216 class FindExistingResult {
217 ASTReader &Reader;
218 NamedDecl *New = nullptr;
219 NamedDecl *Existing = nullptr;
220 bool AddResult = false;
221 unsigned AnonymousDeclNumber = 0;
222 IdentifierInfo *TypedefNameForLinkage = nullptr;
223
224 public:
225 FindExistingResult(ASTReader &Reader) : Reader(Reader) {}
226
227 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing,
228 unsigned AnonymousDeclNumber,
229 IdentifierInfo *TypedefNameForLinkage)
230 : Reader(Reader), New(New), Existing(Existing), AddResult(true),
231 AnonymousDeclNumber(AnonymousDeclNumber),
232 TypedefNameForLinkage(TypedefNameForLinkage) {}
233
234 FindExistingResult(FindExistingResult &&Other)
235 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
236 AddResult(Other.AddResult),
237 AnonymousDeclNumber(Other.AnonymousDeclNumber),
238 TypedefNameForLinkage(Other.TypedefNameForLinkage) {
239 Other.AddResult = false;
240 }
241
242 FindExistingResult &operator=(FindExistingResult &&) = delete;
243 ~FindExistingResult();
244
245 /// Suppress the addition of this result into the known set of
246 /// names.
247 void suppress() { AddResult = false; }
248
249 operator NamedDecl*() const { return Existing; }
250
251 template<typename T>
252 operator T*() const { return dyn_cast_or_null<T>(Existing); }
253 };
254
255 static DeclContext *getPrimaryContextForMerging(ASTReader &Reader,
256 DeclContext *DC);
257 FindExistingResult findExisting(NamedDecl *D);
258
259 public:
261 ASTReader::RecordLocation Loc,
262 DeclID thisDeclID, SourceLocation ThisDeclLoc)
263 : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID),
264 ThisDeclLoc(ThisDeclLoc) {}
265
266 template <typename T> static
269 if (IDs.empty())
270 return;
271
272 // FIXME: We should avoid this pattern of getting the ASTContext.
273 ASTContext &C = D->getASTContext();
274
275 auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
276
277 if (auto &Old = LazySpecializations) {
278 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
279 llvm::sort(IDs);
280 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
281 }
282
283 auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
284 *Result = IDs.size();
285 std::copy(IDs.begin(), IDs.end(), Result + 1);
286
287 LazySpecializations = Result;
288 }
289
290 template <typename DeclT>
292 static Decl *getMostRecentDeclImpl(...);
293 static Decl *getMostRecentDecl(Decl *D);
294
295 static void mergeInheritableAttributes(ASTReader &Reader, Decl *D,
296 Decl *Previous);
297
298 template <typename DeclT>
299 static void attachPreviousDeclImpl(ASTReader &Reader,
301 Decl *Canon);
302 static void attachPreviousDeclImpl(ASTReader &Reader, ...);
303 static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous,
304 Decl *Canon);
305
306 template <typename DeclT>
307 static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest);
308 static void attachLatestDeclImpl(...);
309 static void attachLatestDecl(Decl *D, Decl *latest);
310
311 template <typename DeclT>
313 static void markIncompleteDeclChainImpl(...);
314
316 void Visit(Decl *D);
317
319
321 ObjCCategoryDecl *Next) {
322 Cat->NextClassCategory = Next;
323 }
324
325 void VisitDecl(Decl *D);
329 void VisitNamedDecl(NamedDecl *ND);
330 void VisitLabelDecl(LabelDecl *LD);
335 void VisitTypeDecl(TypeDecl *TD);
336 RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD);
341 RedeclarableResult VisitTagDecl(TagDecl *TD);
342 void VisitEnumDecl(EnumDecl *ED);
343 RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
344 void VisitRecordDecl(RecordDecl *RD);
345 RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
349
353 }
354
357 RedeclarableResult
359
362 }
363
367 void VisitValueDecl(ValueDecl *VD);
377 void VisitFieldDecl(FieldDecl *FD);
383 RedeclarableResult VisitVarDeclImpl(VarDecl *D);
384 void ReadVarDeclInit(VarDecl *VD);
403 void VisitUsingDecl(UsingDecl *D);
417 void VisitBlockDecl(BlockDecl *BD);
419 void VisitEmptyDecl(EmptyDecl *D);
421
422 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
423
424 template<typename T>
425 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
426
427 template <typename T>
428 void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl);
429
430 void mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl,
431 Decl *Context, unsigned Number);
432
434 RedeclarableResult &Redecl);
435
436 template <typename T>
437 void mergeRedeclarable(Redeclarable<T> *D, T *Existing,
438 RedeclarableResult &Redecl);
439
440 template<typename T>
442
444
446 RedeclarableTemplateDecl *Existing,
447 bool IsKeyDecl);
448
450
451 // FIXME: Reorder according to DeclNodes.td?
472 };
473
474} // namespace clang
475
476namespace {
477
478/// Iterator over the redeclarations of a declaration that have already
479/// been merged into the same redeclaration chain.
480template <typename DeclT> class MergedRedeclIterator {
481 DeclT *Start = nullptr;
482 DeclT *Canonical = nullptr;
483 DeclT *Current = nullptr;
484
485public:
486 MergedRedeclIterator() = default;
487 MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
488
489 DeclT *operator*() { return Current; }
490
491 MergedRedeclIterator &operator++() {
492 if (Current->isFirstDecl()) {
493 Canonical = Current;
494 Current = Current->getMostRecentDecl();
495 } else
496 Current = Current->getPreviousDecl();
497
498 // If we started in the merged portion, we'll reach our start position
499 // eventually. Otherwise, we'll never reach it, but the second declaration
500 // we reached was the canonical declaration, so stop when we see that one
501 // again.
502 if (Current == Start || Current == Canonical)
503 Current = nullptr;
504 return *this;
505 }
506
507 friend bool operator!=(const MergedRedeclIterator &A,
508 const MergedRedeclIterator &B) {
509 return A.Current != B.Current;
510 }
511};
512
513} // namespace
514
515template <typename DeclT>
516static llvm::iterator_range<MergedRedeclIterator<DeclT>>
517merged_redecls(DeclT *D) {
518 return llvm::make_range(MergedRedeclIterator<DeclT>(D),
519 MergedRedeclIterator<DeclT>());
520}
521
522uint64_t ASTDeclReader::GetCurrentCursorOffset() {
523 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
524}
525
527 if (Record.readInt()) {
528 Reader.DefinitionSource[FD] =
529 Loc.F->Kind == ModuleKind::MK_MainFile ||
530 Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
531 }
532 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
533 CD->setNumCtorInitializers(Record.readInt());
534 if (CD->getNumCtorInitializers())
535 CD->CtorInitializers = ReadGlobalOffset();
536 }
537 // Store the offset of the body so we can lazily load it later.
538 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
539}
540
543
544 // At this point we have deserialized and merged the decl and it is safe to
545 // update its canonical decl to signal that the entire entity is used.
546 D->getCanonicalDecl()->Used |= IsDeclMarkedUsed;
547 IsDeclMarkedUsed = false;
548
549 if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
550 if (auto *TInfo = DD->getTypeSourceInfo())
551 Record.readTypeLoc(TInfo->getTypeLoc());
552 }
553
554 if (auto *TD = dyn_cast<TypeDecl>(D)) {
555 // We have a fully initialized TypeDecl. Read its type now.
556 TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull());
557
558 // If this is a tag declaration with a typedef name for linkage, it's safe
559 // to load that typedef now.
560 if (NamedDeclForTagDecl)
561 cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
562 cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl));
563 } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
564 // if we have a fully initialized TypeDecl, we can safely read its type now.
565 ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull();
566 } else if (auto *FD = dyn_cast<FunctionDecl>(D)) {
567 // FunctionDecl's body was written last after all other Stmts/Exprs.
568 if (Record.readInt())
570 } else if (auto *VD = dyn_cast<VarDecl>(D)) {
571 ReadVarDeclInit(VD);
572 } else if (auto *FD = dyn_cast<FieldDecl>(D)) {
573 if (FD->hasInClassInitializer() && Record.readInt()) {
574 FD->setLazyInClassInitializer(LazyDeclStmtPtr(GetCurrentCursorOffset()));
575 }
576 }
577}
578
580 BitsUnpacker DeclBits(Record.readInt());
581 auto ModuleOwnership =
582 (Decl::ModuleOwnershipKind)DeclBits.getNextBits(/*Width=*/3);
583 D->setReferenced(DeclBits.getNextBit());
584 D->Used = DeclBits.getNextBit();
585 IsDeclMarkedUsed |= D->Used;
586 D->setAccess((AccessSpecifier)DeclBits.getNextBits(/*Width=*/2));
587 D->setImplicit(DeclBits.getNextBit());
588 bool HasStandaloneLexicalDC = DeclBits.getNextBit();
589 bool HasAttrs = DeclBits.getNextBit();
591 D->InvalidDecl = DeclBits.getNextBit();
592 D->FromASTFile = true;
593
595 isa<ParmVarDecl, ObjCTypeParamDecl>(D)) {
596 // We don't want to deserialize the DeclContext of a template
597 // parameter or of a parameter of a function template immediately. These
598 // entities might be used in the formulation of its DeclContext (for
599 // example, a function parameter can be used in decltype() in trailing
600 // return type of the function). Use the translation unit DeclContext as a
601 // placeholder.
602 GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
603 GlobalDeclID LexicalDCIDForTemplateParmDecl =
604 HasStandaloneLexicalDC ? readDeclID() : 0;
605 if (!LexicalDCIDForTemplateParmDecl)
606 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
607 Reader.addPendingDeclContextInfo(D,
608 SemaDCIDForTemplateParmDecl,
609 LexicalDCIDForTemplateParmDecl);
611 } else {
612 auto *SemaDC = readDeclAs<DeclContext>();
613 auto *LexicalDC =
614 HasStandaloneLexicalDC ? readDeclAs<DeclContext>() : nullptr;
615 if (!LexicalDC)
616 LexicalDC = SemaDC;
617 // If the context is a class, we might not have actually merged it yet, in
618 // the case where the definition comes from an update record.
619 DeclContext *MergedSemaDC;
620 if (auto *RD = dyn_cast<CXXRecordDecl>(SemaDC))
621 MergedSemaDC = getOrFakePrimaryClassDefinition(Reader, RD);
622 else
623 MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
624 // Avoid calling setLexicalDeclContext() directly because it uses
625 // Decl::getASTContext() internally which is unsafe during derialization.
626 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
627 Reader.getContext());
628 }
629 D->setLocation(ThisDeclLoc);
630
631 if (HasAttrs) {
632 AttrVec Attrs;
633 Record.readAttributes(Attrs);
634 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
635 // internally which is unsafe during derialization.
636 D->setAttrsImpl(Attrs, Reader.getContext());
637 }
638
639 // Determine whether this declaration is part of a (sub)module. If so, it
640 // may not yet be visible.
641 bool ModulePrivate =
642 (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
643 if (unsigned SubmoduleID = readSubmoduleID()) {
644 switch (ModuleOwnership) {
647 break;
652 break;
653 }
654
655 D->setModuleOwnershipKind(ModuleOwnership);
656 // Store the owning submodule ID in the declaration.
658
659 if (ModulePrivate) {
660 // Module-private declarations are never visible, so there is no work to
661 // do.
662 } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
663 // If local visibility is being tracked, this declaration will become
664 // hidden and visible as the owning module does.
665 } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
666 // Mark the declaration as visible when its owning module becomes visible.
667 if (Owner->NameVisibility == Module::AllVisible)
669 else
670 Reader.HiddenNamesMap[Owner].push_back(D);
671 }
672 } else if (ModulePrivate) {
674 }
675}
676
678 VisitDecl(D);
679 D->setLocation(readSourceLocation());
680 D->CommentKind = (PragmaMSCommentKind)Record.readInt();
681 std::string Arg = readString();
682 memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size());
683 D->getTrailingObjects<char>()[Arg.size()] = '\0';
684}
685
687 VisitDecl(D);
688 D->setLocation(readSourceLocation());
689 std::string Name = readString();
690 memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size());
691 D->getTrailingObjects<char>()[Name.size()] = '\0';
692
693 D->ValueStart = Name.size() + 1;
694 std::string Value = readString();
695 memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(),
696 Value.size());
697 D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0';
698}
699
701 llvm_unreachable("Translation units are not serialized");
702}
703
705 VisitDecl(ND);
706 ND->setDeclName(Record.readDeclarationName());
707 AnonymousDeclNumber = Record.readInt();
708}
709
711 VisitNamedDecl(TD);
712 TD->setLocStart(readSourceLocation());
713 // Delay type reading until after we have fully initialized the decl.
714 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
715}
716
717ASTDeclReader::RedeclarableResult
719 RedeclarableResult Redecl = VisitRedeclarable(TD);
720 VisitTypeDecl(TD);
721 TypeSourceInfo *TInfo = readTypeSourceInfo();
722 if (Record.readInt()) { // isModed
723 QualType modedT = Record.readType();
724 TD->setModedTypeSourceInfo(TInfo, modedT);
725 } else
726 TD->setTypeSourceInfo(TInfo);
727 // Read and discard the declaration for which this is a typedef name for
728 // linkage, if it exists. We cannot rely on our type to pull in this decl,
729 // because it might have been merged with a type from another module and
730 // thus might not refer to our version of the declaration.
731 readDecl();
732 return Redecl;
733}
734
736 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
737 mergeRedeclarable(TD, Redecl);
738}
739
741 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
742 if (auto *Template = readDeclAs<TypeAliasTemplateDecl>())
743 // Merged when we merge the template.
744 TD->setDescribedAliasTemplate(Template);
745 else
746 mergeRedeclarable(TD, Redecl);
747}
748
749ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) {
750 RedeclarableResult Redecl = VisitRedeclarable(TD);
751 VisitTypeDecl(TD);
752
753 TD->IdentifierNamespace = Record.readInt();
754
755 BitsUnpacker TagDeclBits(Record.readInt());
756 TD->setTagKind(
757 static_cast<TagTypeKind>(TagDeclBits.getNextBits(/*Width=*/3)));
758 TD->setCompleteDefinition(TagDeclBits.getNextBit());
759 TD->setEmbeddedInDeclarator(TagDeclBits.getNextBit());
760 TD->setFreeStanding(TagDeclBits.getNextBit());
761 TD->setCompleteDefinitionRequired(TagDeclBits.getNextBit());
762 TD->setBraceRange(readSourceRange());
763
764 switch (TagDeclBits.getNextBits(/*Width=*/2)) {
765 case 0:
766 break;
767 case 1: { // ExtInfo
768 auto *Info = new (Reader.getContext()) TagDecl::ExtInfo();
769 Record.readQualifierInfo(*Info);
770 TD->TypedefNameDeclOrQualifier = Info;
771 break;
772 }
773 case 2: // TypedefNameForAnonDecl
774 NamedDeclForTagDecl = readDeclID();
775 TypedefNameForLinkage = Record.readIdentifier();
776 break;
777 default:
778 llvm_unreachable("unexpected tag info kind");
779 }
780
781 if (!isa<CXXRecordDecl>(TD))
782 mergeRedeclarable(TD, Redecl);
783 return Redecl;
784}
785
787 VisitTagDecl(ED);
788 if (TypeSourceInfo *TI = readTypeSourceInfo())
790 else
791 ED->setIntegerType(Record.readType());
792 ED->setPromotionType(Record.readType());
793
794 BitsUnpacker EnumDeclBits(Record.readInt());
795 ED->setNumPositiveBits(EnumDeclBits.getNextBits(/*Width=*/8));
796 ED->setNumNegativeBits(EnumDeclBits.getNextBits(/*Width=*/8));
797 bool ShouldSkipCheckingODR = EnumDeclBits.getNextBit();
798 ED->setScoped(EnumDeclBits.getNextBit());
799 ED->setScopedUsingClassTag(EnumDeclBits.getNextBit());
800 ED->setFixed(EnumDeclBits.getNextBit());
801
802 if (!ShouldSkipCheckingODR) {
803 ED->setHasODRHash(true);
804 ED->ODRHash = Record.readInt();
805 }
806
807 // If this is a definition subject to the ODR, and we already have a
808 // definition, merge this one into it.
809 if (ED->isCompleteDefinition() &&
810 Reader.getContext().getLangOpts().Modules &&
811 Reader.getContext().getLangOpts().CPlusPlus) {
812 EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
813 if (!OldDef) {
814 // This is the first time we've seen an imported definition. Look for a
815 // local definition before deciding that we are the first definition.
816 for (auto *D : merged_redecls(ED->getCanonicalDecl())) {
817 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
818 OldDef = D;
819 break;
820 }
821 }
822 }
823 if (OldDef) {
824 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
826 Reader.mergeDefinitionVisibility(OldDef, ED);
827 // We don't want to check the ODR hash value for declarations from global
828 // module fragment.
829 if (!shouldSkipCheckingODR(ED) &&
830 OldDef->getODRHash() != ED->getODRHash())
831 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
832 } else {
833 OldDef = ED;
834 }
835 }
836
837 if (auto *InstED = readDeclAs<EnumDecl>()) {
838 auto TSK = (TemplateSpecializationKind)Record.readInt();
839 SourceLocation POI = readSourceLocation();
840 ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK);
842 }
843}
844
845ASTDeclReader::RedeclarableResult
847 RedeclarableResult Redecl = VisitTagDecl(RD);
848
849 BitsUnpacker RecordDeclBits(Record.readInt());
850 RD->setHasFlexibleArrayMember(RecordDeclBits.getNextBit());
851 RD->setAnonymousStructOrUnion(RecordDeclBits.getNextBit());
852 RD->setHasObjectMember(RecordDeclBits.getNextBit());
853 RD->setHasVolatileMember(RecordDeclBits.getNextBit());
855 RD->setNonTrivialToPrimitiveCopy(RecordDeclBits.getNextBit());
856 RD->setNonTrivialToPrimitiveDestroy(RecordDeclBits.getNextBit());
858 RecordDeclBits.getNextBit());
861 RD->setParamDestroyedInCallee(RecordDeclBits.getNextBit());
863 (RecordArgPassingKind)RecordDeclBits.getNextBits(/*Width=*/2));
864 return Redecl;
865}
866
869 // We should only reach here if we're in C/Objective-C. There is no
870 // global module fragment.
871 assert(!shouldSkipCheckingODR(RD));
872 RD->setODRHash(Record.readInt());
873
874 // Maintain the invariant of a redeclaration chain containing only
875 // a single definition.
876 if (RD->isCompleteDefinition()) {
877 RecordDecl *Canon = static_cast<RecordDecl *>(RD->getCanonicalDecl());
878 RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
879 if (!OldDef) {
880 // This is the first time we've seen an imported definition. Look for a
881 // local definition before deciding that we are the first definition.
882 for (auto *D : merged_redecls(Canon)) {
883 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
884 OldDef = D;
885 break;
886 }
887 }
888 }
889 if (OldDef) {
890 Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
892 Reader.mergeDefinitionVisibility(OldDef, RD);
893 if (OldDef->getODRHash() != RD->getODRHash())
894 Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
895 } else {
896 OldDef = RD;
897 }
898 }
899}
900
902 VisitNamedDecl(VD);
903 // For function or variable declarations, defer reading the type in case the
904 // declaration has a deduced type that references an entity declared within
905 // the function definition or variable initializer.
906 if (isa<FunctionDecl, VarDecl>(VD))
907 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
908 else
909 VD->setType(Record.readType());
910}
911
913 VisitValueDecl(ECD);
914 if (Record.readInt())
915 ECD->setInitExpr(Record.readExpr());
916 ECD->setInitVal(Reader.getContext(), Record.readAPSInt());
917 mergeMergeable(ECD);
918}
919
921 VisitValueDecl(DD);
922 DD->setInnerLocStart(readSourceLocation());
923 if (Record.readInt()) { // hasExtInfo
924 auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
925 Record.readQualifierInfo(*Info);
926 Info->TrailingRequiresClause = Record.readExpr();
927 DD->DeclInfo = Info;
928 }
929 QualType TSIType = Record.readType();
931 TSIType.isNull() ? nullptr
932 : Reader.getContext().CreateTypeSourceInfo(TSIType));
933}
934
936 RedeclarableResult Redecl = VisitRedeclarable(FD);
937
938 FunctionDecl *Existing = nullptr;
939
940 switch ((FunctionDecl::TemplatedKind)Record.readInt()) {
942 break;
944 FD->setInstantiatedFromDecl(readDeclAs<FunctionDecl>());
945 break;
947 auto *Template = readDeclAs<FunctionTemplateDecl>();
948 Template->init(FD);
949 FD->setDescribedFunctionTemplate(Template);
950 break;
951 }
953 auto *InstFD = readDeclAs<FunctionDecl>();
954 auto TSK = (TemplateSpecializationKind)Record.readInt();
955 SourceLocation POI = readSourceLocation();
956 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
958 break;
959 }
961 auto *Template = readDeclAs<FunctionTemplateDecl>();
962 auto TSK = (TemplateSpecializationKind)Record.readInt();
963
964 // Template arguments.
966 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
967
968 // Template args as written.
969 TemplateArgumentListInfo TemplArgsWritten;
970 bool HasTemplateArgumentsAsWritten = Record.readBool();
971 if (HasTemplateArgumentsAsWritten)
972 Record.readTemplateArgumentListInfo(TemplArgsWritten);
973
974 SourceLocation POI = readSourceLocation();
975
976 ASTContext &C = Reader.getContext();
977 TemplateArgumentList *TemplArgList =
979
980 MemberSpecializationInfo *MSInfo = nullptr;
981 if (Record.readInt()) {
982 auto *FD = readDeclAs<FunctionDecl>();
983 auto TSK = (TemplateSpecializationKind)Record.readInt();
984 SourceLocation POI = readSourceLocation();
985
986 MSInfo = new (C) MemberSpecializationInfo(FD, TSK);
987 MSInfo->setPointOfInstantiation(POI);
988 }
989
992 C, FD, Template, TSK, TemplArgList,
993 HasTemplateArgumentsAsWritten ? &TemplArgsWritten : nullptr, POI,
994 MSInfo);
995 FD->TemplateOrSpecialization = FTInfo;
996
997 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
998 // The template that contains the specializations set. It's not safe to
999 // use getCanonicalDecl on Template since it may still be initializing.
1000 auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>();
1001 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
1002 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
1003 // FunctionTemplateSpecializationInfo's Profile().
1004 // We avoid getASTContext because a decl in the parent hierarchy may
1005 // be initializing.
1006 llvm::FoldingSetNodeID ID;
1008 void *InsertPos = nullptr;
1009 FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr();
1011 CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos);
1012 if (InsertPos)
1013 CommonPtr->Specializations.InsertNode(FTInfo, InsertPos);
1014 else {
1015 assert(Reader.getContext().getLangOpts().Modules &&
1016 "already deserialized this template specialization");
1017 Existing = ExistingInfo->getFunction();
1018 }
1019 }
1020 break;
1021 }
1023 // Templates.
1024 UnresolvedSet<8> Candidates;
1025 unsigned NumCandidates = Record.readInt();
1026 while (NumCandidates--)
1027 Candidates.addDecl(readDeclAs<NamedDecl>());
1028
1029 // Templates args.
1030 TemplateArgumentListInfo TemplArgsWritten;
1031 bool HasTemplateArgumentsAsWritten = Record.readBool();
1032 if (HasTemplateArgumentsAsWritten)
1033 Record.readTemplateArgumentListInfo(TemplArgsWritten);
1034
1036 Reader.getContext(), Candidates,
1037 HasTemplateArgumentsAsWritten ? &TemplArgsWritten : nullptr);
1038 // These are not merged; we don't need to merge redeclarations of dependent
1039 // template friends.
1040 break;
1041 }
1042 }
1043
1045
1046 // Attach a type to this function. Use the real type if possible, but fall
1047 // back to the type as written if it involves a deduced return type.
1048 if (FD->getTypeSourceInfo() && FD->getTypeSourceInfo()
1049 ->getType()
1050 ->castAs<FunctionType>()
1051 ->getReturnType()
1053 // We'll set up the real type in Visit, once we've finished loading the
1054 // function.
1055 FD->setType(FD->getTypeSourceInfo()->getType());
1056 Reader.PendingDeducedFunctionTypes.push_back({FD, DeferredTypeID});
1057 } else {
1058 FD->setType(Reader.GetType(DeferredTypeID));
1059 }
1060 DeferredTypeID = 0;
1061
1062 FD->DNLoc = Record.readDeclarationNameLoc(FD->getDeclName());
1063 FD->IdentifierNamespace = Record.readInt();
1064
1065 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
1066 // after everything else is read.
1067 BitsUnpacker FunctionDeclBits(Record.readInt());
1068
1069 FD->setCachedLinkage((Linkage)FunctionDeclBits.getNextBits(/*Width=*/3));
1070 FD->setStorageClass((StorageClass)FunctionDeclBits.getNextBits(/*Width=*/3));
1071 bool ShouldSkipCheckingODR = FunctionDeclBits.getNextBit();
1072 FD->setInlineSpecified(FunctionDeclBits.getNextBit());
1073 FD->setImplicitlyInline(FunctionDeclBits.getNextBit());
1074 FD->setHasSkippedBody(FunctionDeclBits.getNextBit());
1075 FD->setVirtualAsWritten(FunctionDeclBits.getNextBit());
1076 // We defer calling `FunctionDecl::setPure()` here as for methods of
1077 // `CXXTemplateSpecializationDecl`s, we may not have connected up the
1078 // definition (which is required for `setPure`).
1079 const bool Pure = FunctionDeclBits.getNextBit();
1080 FD->setHasInheritedPrototype(FunctionDeclBits.getNextBit());
1081 FD->setHasWrittenPrototype(FunctionDeclBits.getNextBit());
1082 FD->setDeletedAsWritten(FunctionDeclBits.getNextBit());
1083 FD->setTrivial(FunctionDeclBits.getNextBit());
1084 FD->setTrivialForCall(FunctionDeclBits.getNextBit());
1085 FD->setDefaulted(FunctionDeclBits.getNextBit());
1086 FD->setExplicitlyDefaulted(FunctionDeclBits.getNextBit());
1087 FD->setIneligibleOrNotSelected(FunctionDeclBits.getNextBit());
1088 FD->setConstexprKind(
1089 (ConstexprSpecKind)FunctionDeclBits.getNextBits(/*Width=*/2));
1090 FD->setHasImplicitReturnZero(FunctionDeclBits.getNextBit());
1091 FD->setIsMultiVersion(FunctionDeclBits.getNextBit());
1092 FD->setLateTemplateParsed(FunctionDeclBits.getNextBit());
1094 FunctionDeclBits.getNextBit());
1095 FD->setUsesSEHTry(FunctionDeclBits.getNextBit());
1096
1097 FD->EndRangeLoc = readSourceLocation();
1098 if (FD->isExplicitlyDefaulted())
1099 FD->setDefaultLoc(readSourceLocation());
1100
1101 if (!ShouldSkipCheckingODR) {
1102 FD->ODRHash = Record.readInt();
1103 FD->setHasODRHash(true);
1104 }
1105
1106 if (FD->isDefaulted() || FD->isDeletedAsWritten()) {
1107 // If 'Info' is nonzero, we need to read an DefaultedOrDeletedInfo; if,
1108 // additionally, the second bit is also set, we also need to read
1109 // a DeletedMessage for the DefaultedOrDeletedInfo.
1110 if (auto Info = Record.readInt()) {
1111 bool HasMessage = Info & 2;
1112 StringLiteral *DeletedMessage =
1113 HasMessage ? cast<StringLiteral>(Record.readExpr()) : nullptr;
1114
1115 unsigned NumLookups = Record.readInt();
1117 for (unsigned I = 0; I != NumLookups; ++I) {
1118 NamedDecl *ND = Record.readDeclAs<NamedDecl>();
1119 AccessSpecifier AS = (AccessSpecifier)Record.readInt();
1120 Lookups.push_back(DeclAccessPair::make(ND, AS));
1121 }
1122
1125 Reader.getContext(), Lookups, DeletedMessage));
1126 }
1127 }
1128
1129 if (Existing)
1130 mergeRedeclarable(FD, Existing, Redecl);
1131 else if (auto Kind = FD->getTemplatedKind();
1134 // Function Templates have their FunctionTemplateDecls merged instead of
1135 // their FunctionDecls.
1136 auto merge = [this, &Redecl, FD](auto &&F) {
1137 auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1138 RedeclarableResult NewRedecl(Existing ? F(Existing) : nullptr,
1139 Redecl.getFirstID(), Redecl.isKeyDecl());
1140 mergeRedeclarableTemplate(F(FD), NewRedecl);
1141 };
1143 merge(
1144 [](FunctionDecl *FD) { return FD->getDescribedFunctionTemplate(); });
1145 else
1146 merge([](FunctionDecl *FD) {
1147 return FD->getTemplateSpecializationInfo()->getTemplate();
1148 });
1149 } else
1150 mergeRedeclarable(FD, Redecl);
1151
1152 // Defer calling `setPure` until merging above has guaranteed we've set
1153 // `DefinitionData` (as this will need to access it).
1154 FD->setIsPureVirtual(Pure);
1155
1156 // Read in the parameters.
1157 unsigned NumParams = Record.readInt();
1159 Params.reserve(NumParams);
1160 for (unsigned I = 0; I != NumParams; ++I)
1161 Params.push_back(readDeclAs<ParmVarDecl>());
1162 FD->setParams(Reader.getContext(), Params);
1163}
1164
1166 VisitNamedDecl(MD);
1167 if (Record.readInt()) {
1168 // Load the body on-demand. Most clients won't care, because method
1169 // definitions rarely show up in headers.
1170 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1171 }
1172 MD->setSelfDecl(readDeclAs<ImplicitParamDecl>());
1173 MD->setCmdDecl(readDeclAs<ImplicitParamDecl>());
1174 MD->setInstanceMethod(Record.readInt());
1175 MD->setVariadic(Record.readInt());
1176 MD->setPropertyAccessor(Record.readInt());
1177 MD->setSynthesizedAccessorStub(Record.readInt());
1178 MD->setDefined(Record.readInt());
1179 MD->setOverriding(Record.readInt());
1180 MD->setHasSkippedBody(Record.readInt());
1181
1182 MD->setIsRedeclaration(Record.readInt());
1183 MD->setHasRedeclaration(Record.readInt());
1184 if (MD->hasRedeclaration())
1186 readDeclAs<ObjCMethodDecl>());
1187
1189 static_cast<ObjCImplementationControl>(Record.readInt()));
1191 MD->setRelatedResultType(Record.readInt());
1192 MD->setReturnType(Record.readType());
1193 MD->setReturnTypeSourceInfo(readTypeSourceInfo());
1194 MD->DeclEndLoc = readSourceLocation();
1195 unsigned NumParams = Record.readInt();
1197 Params.reserve(NumParams);
1198 for (unsigned I = 0; I != NumParams; ++I)
1199 Params.push_back(readDeclAs<ParmVarDecl>());
1200
1201 MD->setSelLocsKind((SelectorLocationsKind)Record.readInt());
1202 unsigned NumStoredSelLocs = Record.readInt();
1204 SelLocs.reserve(NumStoredSelLocs);
1205 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
1206 SelLocs.push_back(readSourceLocation());
1207
1208 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
1209}
1210
1213
1214 D->Variance = Record.readInt();
1215 D->Index = Record.readInt();
1216 D->VarianceLoc = readSourceLocation();
1217 D->ColonLoc = readSourceLocation();
1218}
1219
1221 VisitNamedDecl(CD);
1222 CD->setAtStartLoc(readSourceLocation());
1223 CD->setAtEndRange(readSourceRange());
1224}
1225
1227 unsigned numParams = Record.readInt();
1228 if (numParams == 0)
1229 return nullptr;
1230
1232 typeParams.reserve(numParams);
1233 for (unsigned i = 0; i != numParams; ++i) {
1234 auto *typeParam = readDeclAs<ObjCTypeParamDecl>();
1235 if (!typeParam)
1236 return nullptr;
1237
1238 typeParams.push_back(typeParam);
1239 }
1240
1241 SourceLocation lAngleLoc = readSourceLocation();
1242 SourceLocation rAngleLoc = readSourceLocation();
1243
1244 return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc,
1245 typeParams, rAngleLoc);
1246}
1247
1248void ASTDeclReader::ReadObjCDefinitionData(
1249 struct ObjCInterfaceDecl::DefinitionData &Data) {
1250 // Read the superclass.
1251 Data.SuperClassTInfo = readTypeSourceInfo();
1252
1253 Data.EndLoc = readSourceLocation();
1254 Data.HasDesignatedInitializers = Record.readInt();
1255 Data.ODRHash = Record.readInt();
1256 Data.HasODRHash = true;
1257
1258 // Read the directly referenced protocols and their SourceLocations.
1259 unsigned NumProtocols = Record.readInt();
1261 Protocols.reserve(NumProtocols);
1262 for (unsigned I = 0; I != NumProtocols; ++I)
1263 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1265 ProtoLocs.reserve(NumProtocols);
1266 for (unsigned I = 0; I != NumProtocols; ++I)
1267 ProtoLocs.push_back(readSourceLocation());
1268 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1269 Reader.getContext());
1270
1271 // Read the transitive closure of protocols referenced by this class.
1272 NumProtocols = Record.readInt();
1273 Protocols.clear();
1274 Protocols.reserve(NumProtocols);
1275 for (unsigned I = 0; I != NumProtocols; ++I)
1276 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1277 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1278 Reader.getContext());
1279}
1280
1281void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
1282 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1283 struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1284 if (DD.Definition == NewDD.Definition)
1285 return;
1286
1287 Reader.MergedDeclContexts.insert(
1288 std::make_pair(NewDD.Definition, DD.Definition));
1289 Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
1290
1291 if (D->getODRHash() != NewDD.ODRHash)
1292 Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back(
1293 {NewDD.Definition, &NewDD});
1294}
1295
1297 RedeclarableResult Redecl = VisitRedeclarable(ID);
1299 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
1300 mergeRedeclarable(ID, Redecl);
1301
1302 ID->TypeParamList = ReadObjCTypeParamList();
1303 if (Record.readInt()) {
1304 // Read the definition.
1305 ID->allocateDefinitionData();
1306
1307 ReadObjCDefinitionData(ID->data());
1308 ObjCInterfaceDecl *Canon = ID->getCanonicalDecl();
1309 if (Canon->Data.getPointer()) {
1310 // If we already have a definition, keep the definition invariant and
1311 // merge the data.
1312 MergeDefinitionData(Canon, std::move(ID->data()));
1313 ID->Data = Canon->Data;
1314 } else {
1315 // Set the definition data of the canonical declaration, so other
1316 // redeclarations will see it.
1317 ID->getCanonicalDecl()->Data = ID->Data;
1318
1319 // We will rebuild this list lazily.
1320 ID->setIvarList(nullptr);
1321 }
1322
1323 // Note that we have deserialized a definition.
1324 Reader.PendingDefinitions.insert(ID);
1325
1326 // Note that we've loaded this Objective-C class.
1327 Reader.ObjCClassesLoaded.push_back(ID);
1328 } else {
1329 ID->Data = ID->getCanonicalDecl()->Data;
1330 }
1331}
1332
1334 VisitFieldDecl(IVD);
1336 // This field will be built lazily.
1337 IVD->setNextIvar(nullptr);
1338 bool synth = Record.readInt();
1339 IVD->setSynthesize(synth);
1340
1341 // Check ivar redeclaration.
1342 if (IVD->isInvalidDecl())
1343 return;
1344 // Don't check ObjCInterfaceDecl as interfaces are named and mismatches can be
1345 // detected in VisitObjCInterfaceDecl. Here we are looking for redeclarations
1346 // in extensions.
1347 if (isa<ObjCInterfaceDecl>(IVD->getDeclContext()))
1348 return;
1349 ObjCInterfaceDecl *CanonIntf =
1351 IdentifierInfo *II = IVD->getIdentifier();
1352 ObjCIvarDecl *PrevIvar = CanonIntf->lookupInstanceVariable(II);
1353 if (PrevIvar && PrevIvar != IVD) {
1354 auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->getDeclContext());
1355 auto *PrevParentExt =
1356 dyn_cast<ObjCCategoryDecl>(PrevIvar->getDeclContext());
1357 if (ParentExt && PrevParentExt) {
1358 // Postpone diagnostic as we should merge identical extensions from
1359 // different modules.
1360 Reader
1361 .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt,
1362 PrevParentExt)]
1363 .push_back(std::make_pair(IVD, PrevIvar));
1364 } else if (ParentExt || PrevParentExt) {
1365 // Duplicate ivars in extension + implementation are never compatible.
1366 // Compatibility of implementation + implementation should be handled in
1367 // VisitObjCImplementationDecl.
1368 Reader.Diag(IVD->getLocation(), diag::err_duplicate_ivar_declaration)
1369 << II;
1370 Reader.Diag(PrevIvar->getLocation(), diag::note_previous_definition);
1371 }
1372 }
1373}
1374
1375void ASTDeclReader::ReadObjCDefinitionData(
1376 struct ObjCProtocolDecl::DefinitionData &Data) {
1377 unsigned NumProtoRefs = Record.readInt();
1379 ProtoRefs.reserve(NumProtoRefs);
1380 for (unsigned I = 0; I != NumProtoRefs; ++I)
1381 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1383 ProtoLocs.reserve(NumProtoRefs);
1384 for (unsigned I = 0; I != NumProtoRefs; ++I)
1385 ProtoLocs.push_back(readSourceLocation());
1386 Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1387 ProtoLocs.data(), Reader.getContext());
1388 Data.ODRHash = Record.readInt();
1389 Data.HasODRHash = true;
1390}
1391
1392void ASTDeclReader::MergeDefinitionData(
1393 ObjCProtocolDecl *D, struct ObjCProtocolDecl::DefinitionData &&NewDD) {
1394 struct ObjCProtocolDecl::DefinitionData &DD = D->data();
1395 if (DD.Definition == NewDD.Definition)
1396 return;
1397
1398 Reader.MergedDeclContexts.insert(
1399 std::make_pair(NewDD.Definition, DD.Definition));
1400 Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
1401
1402 if (D->getODRHash() != NewDD.ODRHash)
1403 Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back(
1404 {NewDD.Definition, &NewDD});
1405}
1406
1408 RedeclarableResult Redecl = VisitRedeclarable(PD);
1410 mergeRedeclarable(PD, Redecl);
1411
1412 if (Record.readInt()) {
1413 // Read the definition.
1414 PD->allocateDefinitionData();
1415
1416 ReadObjCDefinitionData(PD->data());
1417
1418 ObjCProtocolDecl *Canon = PD->getCanonicalDecl();
1419 if (Canon->Data.getPointer()) {
1420 // If we already have a definition, keep the definition invariant and
1421 // merge the data.
1422 MergeDefinitionData(Canon, std::move(PD->data()));
1423 PD->Data = Canon->Data;
1424 } else {
1425 // Set the definition data of the canonical declaration, so other
1426 // redeclarations will see it.
1427 PD->getCanonicalDecl()->Data = PD->Data;
1428 }
1429 // Note that we have deserialized a definition.
1430 Reader.PendingDefinitions.insert(PD);
1431 } else {
1432 PD->Data = PD->getCanonicalDecl()->Data;
1433 }
1434}
1435
1437 VisitFieldDecl(FD);
1438}
1439
1442 CD->setCategoryNameLoc(readSourceLocation());
1443 CD->setIvarLBraceLoc(readSourceLocation());
1444 CD->setIvarRBraceLoc(readSourceLocation());
1445
1446 // Note that this category has been deserialized. We do this before
1447 // deserializing the interface declaration, so that it will consider this
1448 /// category.
1449 Reader.CategoriesDeserialized.insert(CD);
1450
1451 CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>();
1452 CD->TypeParamList = ReadObjCTypeParamList();
1453 unsigned NumProtoRefs = Record.readInt();
1455 ProtoRefs.reserve(NumProtoRefs);
1456 for (unsigned I = 0; I != NumProtoRefs; ++I)
1457 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1459 ProtoLocs.reserve(NumProtoRefs);
1460 for (unsigned I = 0; I != NumProtoRefs; ++I)
1461 ProtoLocs.push_back(readSourceLocation());
1462 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
1463 Reader.getContext());
1464
1465 // Protocols in the class extension belong to the class.
1466 if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension())
1467 CD->ClassInterface->mergeClassExtensionProtocolList(
1468 (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs,
1469 Reader.getContext());
1470}
1471
1473 VisitNamedDecl(CAD);
1474 CAD->setClassInterface(readDeclAs<ObjCInterfaceDecl>());
1475}
1476
1478 VisitNamedDecl(D);
1479 D->setAtLoc(readSourceLocation());
1480 D->setLParenLoc(readSourceLocation());
1481 QualType T = Record.readType();
1482 TypeSourceInfo *TSI = readTypeSourceInfo();
1483 D->setType(T, TSI);
1489 DeclarationName GetterName = Record.readDeclarationName();
1490 SourceLocation GetterLoc = readSourceLocation();
1491 D->setGetterName(GetterName.getObjCSelector(), GetterLoc);
1492 DeclarationName SetterName = Record.readDeclarationName();
1493 SourceLocation SetterLoc = readSourceLocation();
1494 D->setSetterName(SetterName.getObjCSelector(), SetterLoc);
1495 D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1496 D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1497 D->setPropertyIvarDecl(readDeclAs<ObjCIvarDecl>());
1498}
1499
1502 D->setClassInterface(readDeclAs<ObjCInterfaceDecl>());
1503}
1504
1507 D->CategoryNameLoc = readSourceLocation();
1508}
1509
1512 D->setSuperClass(readDeclAs<ObjCInterfaceDecl>());
1513 D->SuperLoc = readSourceLocation();
1514 D->setIvarLBraceLoc(readSourceLocation());
1515 D->setIvarRBraceLoc(readSourceLocation());
1516 D->setHasNonZeroConstructors(Record.readInt());
1517 D->setHasDestructors(Record.readInt());
1518 D->NumIvarInitializers = Record.readInt();
1519 if (D->NumIvarInitializers)
1520 D->IvarInitializers = ReadGlobalOffset();
1521}
1522
1524 VisitDecl(D);
1525 D->setAtLoc(readSourceLocation());
1526 D->setPropertyDecl(readDeclAs<ObjCPropertyDecl>());
1527 D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>();
1528 D->IvarLoc = readSourceLocation();
1529 D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1530 D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1531 D->setGetterCXXConstructor(Record.readExpr());
1532 D->setSetterCXXAssignment(Record.readExpr());
1533}
1534
1537 FD->Mutable = Record.readInt();
1538
1539 unsigned Bits = Record.readInt();
1540 FD->StorageKind = Bits >> 1;
1541 if (FD->StorageKind == FieldDecl::ISK_CapturedVLAType)
1542 FD->CapturedVLAType =
1543 cast<VariableArrayType>(Record.readType().getTypePtr());
1544 else if (Bits & 1)
1545 FD->setBitWidth(Record.readExpr());
1546
1547 if (!FD->getDeclName()) {
1548 if (auto *Tmpl = readDeclAs<FieldDecl>())
1550 }
1551 mergeMergeable(FD);
1552}
1553
1556 PD->GetterId = Record.readIdentifier();
1557 PD->SetterId = Record.readIdentifier();
1558}
1559
1561 VisitValueDecl(D);
1562 D->PartVal.Part1 = Record.readInt();
1563 D->PartVal.Part2 = Record.readInt();
1564 D->PartVal.Part3 = Record.readInt();
1565 for (auto &C : D->PartVal.Part4And5)
1566 C = Record.readInt();
1567
1568 // Add this GUID to the AST context's lookup structure, and merge if needed.
1569 if (MSGuidDecl *Existing = Reader.getContext().MSGuidDecls.GetOrInsertNode(D))
1570 Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1571}
1572
1575 VisitValueDecl(D);
1576 D->Value = Record.readAPValue();
1577
1578 // Add this to the AST context's lookup structure, and merge if needed.
1579 if (UnnamedGlobalConstantDecl *Existing =
1580 Reader.getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D))
1581 Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1582}
1583
1585 VisitValueDecl(D);
1586 D->Value = Record.readAPValue();
1587
1588 // Add this template parameter object to the AST context's lookup structure,
1589 // and merge if needed.
1590 if (TemplateParamObjectDecl *Existing =
1591 Reader.getContext().TemplateParamObjectDecls.GetOrInsertNode(D))
1592 Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl());
1593}
1594
1596 VisitValueDecl(FD);
1597
1598 FD->ChainingSize = Record.readInt();
1599 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
1600 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
1601
1602 for (unsigned I = 0; I != FD->ChainingSize; ++I)
1603 FD->Chaining[I] = readDeclAs<NamedDecl>();
1604
1605 mergeMergeable(FD);
1606}
1607
1608ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
1609 RedeclarableResult Redecl = VisitRedeclarable(VD);
1611
1612 BitsUnpacker VarDeclBits(Record.readInt());
1613 auto VarLinkage = Linkage(VarDeclBits.getNextBits(/*Width=*/3));
1614 bool DefGeneratedInModule = VarDeclBits.getNextBit();
1615 VD->VarDeclBits.SClass = (StorageClass)VarDeclBits.getNextBits(/*Width=*/3);
1616 VD->VarDeclBits.TSCSpec = VarDeclBits.getNextBits(/*Width=*/2);
1617 VD->VarDeclBits.InitStyle = VarDeclBits.getNextBits(/*Width=*/2);
1618 VD->VarDeclBits.ARCPseudoStrong = VarDeclBits.getNextBit();
1619 bool HasDeducedType = false;
1620 if (!isa<ParmVarDecl>(VD)) {
1621 VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =
1622 VarDeclBits.getNextBit();
1623 VD->NonParmVarDeclBits.ExceptionVar = VarDeclBits.getNextBit();
1624 VD->NonParmVarDeclBits.NRVOVariable = VarDeclBits.getNextBit();
1625 VD->NonParmVarDeclBits.CXXForRangeDecl = VarDeclBits.getNextBit();
1626
1627 VD->NonParmVarDeclBits.IsInline = VarDeclBits.getNextBit();
1628 VD->NonParmVarDeclBits.IsInlineSpecified = VarDeclBits.getNextBit();
1629 VD->NonParmVarDeclBits.IsConstexpr = VarDeclBits.getNextBit();
1630 VD->NonParmVarDeclBits.IsInitCapture = VarDeclBits.getNextBit();
1631 VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope =
1632 VarDeclBits.getNextBit();
1633
1634 VD->NonParmVarDeclBits.EscapingByref = VarDeclBits.getNextBit();
1635 HasDeducedType = VarDeclBits.getNextBit();
1636 VD->NonParmVarDeclBits.ImplicitParamKind =
1637 VarDeclBits.getNextBits(/*Width*/ 3);
1638
1639 VD->NonParmVarDeclBits.ObjCForDecl = VarDeclBits.getNextBit();
1640 }
1641
1642 // If this variable has a deduced type, defer reading that type until we are
1643 // done deserializing this variable, because the type might refer back to the
1644 // variable.
1645 if (HasDeducedType)
1646 Reader.PendingDeducedVarTypes.push_back({VD, DeferredTypeID});
1647 else
1648 VD->setType(Reader.GetType(DeferredTypeID));
1649 DeferredTypeID = 0;
1650
1651 VD->setCachedLinkage(VarLinkage);
1652
1653 // Reconstruct the one piece of the IdentifierNamespace that we need.
1654 if (VD->getStorageClass() == SC_Extern && VarLinkage != Linkage::None &&
1656 VD->setLocalExternDecl();
1657
1658 if (DefGeneratedInModule) {
1659 Reader.DefinitionSource[VD] =
1660 Loc.F->Kind == ModuleKind::MK_MainFile ||
1661 Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
1662 }
1663
1664 if (VD->hasAttr<BlocksAttr>()) {
1665 Expr *CopyExpr = Record.readExpr();
1666 if (CopyExpr)
1667 Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt());
1668 }
1669
1670 enum VarKind {
1671 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1672 };
1673 switch ((VarKind)Record.readInt()) {
1674 case VarNotTemplate:
1675 // Only true variables (not parameters or implicit parameters) can be
1676 // merged; the other kinds are not really redeclarable at all.
1677 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1678 !isa<VarTemplateSpecializationDecl>(VD))
1679 mergeRedeclarable(VD, Redecl);
1680 break;
1681 case VarTemplate:
1682 // Merged when we merge the template.
1683 VD->setDescribedVarTemplate(readDeclAs<VarTemplateDecl>());
1684 break;
1685 case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo.
1686 auto *Tmpl = readDeclAs<VarDecl>();
1687 auto TSK = (TemplateSpecializationKind)Record.readInt();
1688 SourceLocation POI = readSourceLocation();
1689 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
1690 mergeRedeclarable(VD, Redecl);
1691 break;
1692 }
1693 }
1694
1695 return Redecl;
1696}
1697
1699 if (uint64_t Val = Record.readInt()) {
1700 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
1701 Eval->HasConstantInitialization = (Val & 2) != 0;
1702 Eval->HasConstantDestruction = (Val & 4) != 0;
1703 Eval->WasEvaluated = (Val & 8) != 0;
1704 if (Eval->WasEvaluated) {
1705 Eval->Evaluated = Record.readAPValue();
1706 if (Eval->Evaluated.needsCleanup())
1707 Reader.getContext().addDestruction(&Eval->Evaluated);
1708 }
1709
1710 // Store the offset of the initializer. Don't deserialize it yet: it might
1711 // not be needed, and might refer back to the variable, for example if it
1712 // contains a lambda.
1713 Eval->Value = GetCurrentCursorOffset();
1714 }
1715}
1716
1718 VisitVarDecl(PD);
1719}
1720
1722 VisitVarDecl(PD);
1723
1724 unsigned scopeIndex = Record.readInt();
1725 BitsUnpacker ParmVarDeclBits(Record.readInt());
1726 unsigned isObjCMethodParam = ParmVarDeclBits.getNextBit();
1727 unsigned scopeDepth = ParmVarDeclBits.getNextBits(/*Width=*/7);
1728 unsigned declQualifier = ParmVarDeclBits.getNextBits(/*Width=*/7);
1729 if (isObjCMethodParam) {
1730 assert(scopeDepth == 0);
1731 PD->setObjCMethodScopeInfo(scopeIndex);
1732 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
1733 } else {
1734 PD->setScopeInfo(scopeDepth, scopeIndex);
1735 }
1736 PD->ParmVarDeclBits.IsKNRPromoted = ParmVarDeclBits.getNextBit();
1737
1738 PD->ParmVarDeclBits.HasInheritedDefaultArg = ParmVarDeclBits.getNextBit();
1739 if (ParmVarDeclBits.getNextBit()) // hasUninstantiatedDefaultArg.
1740 PD->setUninstantiatedDefaultArg(Record.readExpr());
1741
1742 if (ParmVarDeclBits.getNextBit()) // Valid explicit object parameter
1743 PD->ExplicitObjectParameterIntroducerLoc = Record.readSourceLocation();
1744
1745 // FIXME: If this is a redeclaration of a function from another module, handle
1746 // inheritance of default arguments.
1747}
1748
1750 VisitVarDecl(DD);
1751 auto **BDs = DD->getTrailingObjects<BindingDecl *>();
1752 for (unsigned I = 0; I != DD->NumBindings; ++I) {
1753 BDs[I] = readDeclAs<BindingDecl>();
1754 BDs[I]->setDecomposedDecl(DD);
1755 }
1756}
1757
1759 VisitValueDecl(BD);
1760 BD->Binding = Record.readExpr();
1761}
1762
1764 VisitDecl(AD);
1765 AD->setAsmString(cast<StringLiteral>(Record.readExpr()));
1766 AD->setRParenLoc(readSourceLocation());
1767}
1768
1770 VisitDecl(D);
1771 D->Statement = Record.readStmt();
1772}
1773
1775 VisitDecl(BD);
1776 BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt()));
1777 BD->setSignatureAsWritten(readTypeSourceInfo());
1778 unsigned NumParams = Record.readInt();
1780 Params.reserve(NumParams);
1781 for (unsigned I = 0; I != NumParams; ++I)
1782 Params.push_back(readDeclAs<ParmVarDecl>());
1783 BD->setParams(Params);
1784
1785 BD->setIsVariadic(Record.readInt());
1786 BD->setBlockMissingReturnType(Record.readInt());
1787 BD->setIsConversionFromLambda(Record.readInt());
1788 BD->setDoesNotEscape(Record.readInt());
1789 BD->setCanAvoidCopyToHeap(Record.readInt());
1790
1791 bool capturesCXXThis = Record.readInt();
1792 unsigned numCaptures = Record.readInt();
1794 captures.reserve(numCaptures);
1795 for (unsigned i = 0; i != numCaptures; ++i) {
1796 auto *decl = readDeclAs<VarDecl>();
1797 unsigned flags = Record.readInt();
1798 bool byRef = (flags & 1);
1799 bool nested = (flags & 2);
1800 Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr);
1801
1802 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1803 }
1804 BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
1805}
1806
1808 VisitDecl(CD);
1809 unsigned ContextParamPos = Record.readInt();
1810 CD->setNothrow(Record.readInt() != 0);
1811 // Body is set by VisitCapturedStmt.
1812 for (unsigned I = 0; I < CD->NumParams; ++I) {
1813 if (I != ContextParamPos)
1814 CD->setParam(I, readDeclAs<ImplicitParamDecl>());
1815 else
1816 CD->setContextParam(I, readDeclAs<ImplicitParamDecl>());
1817 }
1818}
1819
1821 VisitDecl(D);
1822 D->setLanguage(static_cast<LinkageSpecLanguageIDs>(Record.readInt()));
1823 D->setExternLoc(readSourceLocation());
1824 D->setRBraceLoc(readSourceLocation());
1825}
1826
1828 VisitDecl(D);
1829 D->RBraceLoc = readSourceLocation();
1830}
1831
1833 VisitNamedDecl(D);
1834 D->setLocStart(readSourceLocation());
1835}
1836
1838 RedeclarableResult Redecl = VisitRedeclarable(D);
1839 VisitNamedDecl(D);
1840
1841 BitsUnpacker NamespaceDeclBits(Record.readInt());
1842 D->setInline(NamespaceDeclBits.getNextBit());
1843 D->setNested(NamespaceDeclBits.getNextBit());
1844 D->LocStart = readSourceLocation();
1845 D->RBraceLoc = readSourceLocation();
1846
1847 // Defer loading the anonymous namespace until we've finished merging
1848 // this namespace; loading it might load a later declaration of the
1849 // same namespace, and we have an invariant that older declarations
1850 // get merged before newer ones try to merge.
1851 GlobalDeclID AnonNamespace = 0;
1852 if (Redecl.getFirstID() == ThisDeclID) {
1853 AnonNamespace = readDeclID();
1854 } else {
1855 // Link this namespace back to the first declaration, which has already
1856 // been deserialized.
1857 D->AnonOrFirstNamespaceAndFlags.setPointer(D->getFirstDecl());
1858 }
1859
1860 mergeRedeclarable(D, Redecl);
1861
1862 if (AnonNamespace) {
1863 // Each module has its own anonymous namespace, which is disjoint from
1864 // any other module's anonymous namespaces, so don't attach the anonymous
1865 // namespace at all.
1866 auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace));
1867 if (!Record.isModule())
1868 D->setAnonymousNamespace(Anon);
1869 }
1870}
1871
1873 VisitNamedDecl(D);
1875 D->IsCBuffer = Record.readBool();
1876 D->KwLoc = readSourceLocation();
1877 D->LBraceLoc = readSourceLocation();
1878 D->RBraceLoc = readSourceLocation();
1879}
1880
1882 RedeclarableResult Redecl = VisitRedeclarable(D);
1883 VisitNamedDecl(D);
1884 D->NamespaceLoc = readSourceLocation();
1885 D->IdentLoc = readSourceLocation();
1886 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1887 D->Namespace = readDeclAs<NamedDecl>();
1888 mergeRedeclarable(D, Redecl);
1889}
1890
1892 VisitNamedDecl(D);
1893 D->setUsingLoc(readSourceLocation());
1894 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1895 D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName());
1896 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1897 D->setTypename(Record.readInt());
1898 if (auto *Pattern = readDeclAs<NamedDecl>())
1899 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
1900 mergeMergeable(D);
1901}
1902
1904 VisitNamedDecl(D);
1905 D->setUsingLoc(readSourceLocation());
1906 D->setEnumLoc(readSourceLocation());
1907 D->setEnumType(Record.readTypeSourceInfo());
1908 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1909 if (auto *Pattern = readDeclAs<UsingEnumDecl>())
1910 Reader.getContext().setInstantiatedFromUsingEnumDecl(D, Pattern);
1911 mergeMergeable(D);
1912}
1913
1915 VisitNamedDecl(D);
1916 D->InstantiatedFrom = readDeclAs<NamedDecl>();
1917 auto **Expansions = D->getTrailingObjects<NamedDecl *>();
1918 for (unsigned I = 0; I != D->NumExpansions; ++I)
1919 Expansions[I] = readDeclAs<NamedDecl>();
1920 mergeMergeable(D);
1921}
1922
1924 RedeclarableResult Redecl = VisitRedeclarable(D);
1925 VisitNamedDecl(D);
1926 D->Underlying = readDeclAs<NamedDecl>();
1927 D->IdentifierNamespace = Record.readInt();
1928 D->UsingOrNextShadow = readDeclAs<NamedDecl>();
1929 auto *Pattern = readDeclAs<UsingShadowDecl>();
1930 if (Pattern)
1932 mergeRedeclarable(D, Redecl);
1933}
1934
1938 D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1939 D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1940 D->IsVirtual = Record.readInt();
1941}
1942
1944 VisitNamedDecl(D);
1945 D->UsingLoc = readSourceLocation();
1946 D->NamespaceLoc = readSourceLocation();
1947 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1948 D->NominatedNamespace = readDeclAs<NamedDecl>();
1949 D->CommonAncestor = readDeclAs<DeclContext>();
1950}
1951
1953 VisitValueDecl(D);
1954 D->setUsingLoc(readSourceLocation());
1955 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1956 D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName());
1957 D->EllipsisLoc = readSourceLocation();
1958 mergeMergeable(D);
1959}
1960
1963 VisitTypeDecl(D);
1964 D->TypenameLocation = readSourceLocation();
1965 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1966 D->EllipsisLoc = readSourceLocation();
1967 mergeMergeable(D);
1968}
1969
1972 VisitNamedDecl(D);
1973}
1974
1975void ASTDeclReader::ReadCXXDefinitionData(
1976 struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D,
1977 Decl *LambdaContext, unsigned IndexInLambdaContext) {
1978
1979 BitsUnpacker CXXRecordDeclBits = Record.readInt();
1980
1981 bool ShouldSkipCheckingODR = CXXRecordDeclBits.getNextBit();
1982
1983#define FIELD(Name, Width, Merge) \
1984 if (!CXXRecordDeclBits.canGetNextNBits(Width)) \
1985 CXXRecordDeclBits.updateValue(Record.readInt()); \
1986 Data.Name = CXXRecordDeclBits.getNextBits(Width);
1987
1988#include "clang/AST/CXXRecordDeclDefinitionBits.def"
1989#undef FIELD
1990
1991 // We only perform ODR checks for decls not in GMF.
1992 if (!ShouldSkipCheckingODR) {
1993 // Note: the caller has deserialized the IsLambda bit already.
1994 Data.ODRHash = Record.readInt();
1995 Data.HasODRHash = true;
1996 }
1997
1998 if (Record.readInt()) {
1999 Reader.DefinitionSource[D] =
2000 Loc.F->Kind == ModuleKind::MK_MainFile ||
2001 Reader.getContext().getLangOpts().BuildingPCHWithObjectFile;
2002 }
2003
2004 Record.readUnresolvedSet(Data.Conversions);
2005 Data.ComputedVisibleConversions = Record.readInt();
2006 if (Data.ComputedVisibleConversions)
2007 Record.readUnresolvedSet(Data.VisibleConversions);
2008 assert(Data.Definition && "Data.Definition should be already set!");
2009
2010 if (!Data.IsLambda) {
2011 assert(!LambdaContext && !IndexInLambdaContext &&
2012 "given lambda context for non-lambda");
2013
2014 Data.NumBases = Record.readInt();
2015 if (Data.NumBases)
2016 Data.Bases = ReadGlobalOffset();
2017
2018 Data.NumVBases = Record.readInt();
2019 if (Data.NumVBases)
2020 Data.VBases = ReadGlobalOffset();
2021
2022 Data.FirstFriend = readDeclID();
2023 } else {
2024 using Capture = LambdaCapture;
2025
2026 auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data);
2027
2028 BitsUnpacker LambdaBits(Record.readInt());
2029 Lambda.DependencyKind = LambdaBits.getNextBits(/*Width=*/2);
2030 Lambda.IsGenericLambda = LambdaBits.getNextBit();
2031 Lambda.CaptureDefault = LambdaBits.getNextBits(/*Width=*/2);
2032 Lambda.NumCaptures = LambdaBits.getNextBits(/*Width=*/15);
2033 Lambda.HasKnownInternalLinkage = LambdaBits.getNextBit();
2034
2035 Lambda.NumExplicitCaptures = Record.readInt();
2036 Lambda.ManglingNumber = Record.readInt();
2037 if (unsigned DeviceManglingNumber = Record.readInt())
2038 Reader.getContext().DeviceLambdaManglingNumbers[D] = DeviceManglingNumber;
2039 Lambda.IndexInContext = IndexInLambdaContext;
2040 Lambda.ContextDecl = LambdaContext;
2041 Capture *ToCapture = nullptr;
2042 if (Lambda.NumCaptures) {
2043 ToCapture = (Capture *)Reader.getContext().Allocate(sizeof(Capture) *
2044 Lambda.NumCaptures);
2045 Lambda.AddCaptureList(Reader.getContext(), ToCapture);
2046 }
2047 Lambda.MethodTyInfo = readTypeSourceInfo();
2048 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
2049 SourceLocation Loc = readSourceLocation();
2050 BitsUnpacker CaptureBits(Record.readInt());
2051 bool IsImplicit = CaptureBits.getNextBit();
2052 auto Kind =
2053 static_cast<LambdaCaptureKind>(CaptureBits.getNextBits(/*Width=*/3));
2054 switch (Kind) {
2055 case LCK_StarThis:
2056 case LCK_This:
2057 case LCK_VLAType:
2058 new (ToCapture)
2059 Capture(Loc, IsImplicit, Kind, nullptr, SourceLocation());
2060 ToCapture++;
2061 break;
2062 case LCK_ByCopy:
2063 case LCK_ByRef:
2064 auto *Var = readDeclAs<ValueDecl>();
2065 SourceLocation EllipsisLoc = readSourceLocation();
2066 new (ToCapture) Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
2067 ToCapture++;
2068 break;
2069 }
2070 }
2071 }
2072}
2073
2074void ASTDeclReader::MergeDefinitionData(
2075 CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) {
2076 assert(D->DefinitionData &&
2077 "merging class definition into non-definition");
2078 auto &DD = *D->DefinitionData;
2079
2080 if (DD.Definition != MergeDD.Definition) {
2081 // Track that we merged the definitions.
2082 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
2083 DD.Definition));
2084 Reader.PendingDefinitions.erase(MergeDD.Definition);
2085 MergeDD.Definition->setCompleteDefinition(false);
2086 Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
2087 assert(!Reader.Lookups.contains(MergeDD.Definition) &&
2088 "already loaded pending lookups for merged definition");
2089 }
2090
2091 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
2092 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
2093 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
2094 // We faked up this definition data because we found a class for which we'd
2095 // not yet loaded the definition. Replace it with the real thing now.
2096 assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
2097 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
2098
2099 // Don't change which declaration is the definition; that is required
2100 // to be invariant once we select it.
2101 auto *Def = DD.Definition;
2102 DD = std::move(MergeDD);
2103 DD.Definition = Def;
2104 return;
2105 }
2106
2107 bool DetectedOdrViolation = false;
2108
2109 #define FIELD(Name, Width, Merge) Merge(Name)
2110 #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
2111 #define NO_MERGE(Field) \
2112 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
2113 MERGE_OR(Field)
2114 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2115 NO_MERGE(IsLambda)
2116 #undef NO_MERGE
2117 #undef MERGE_OR
2118
2119 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
2120 DetectedOdrViolation = true;
2121 // FIXME: Issue a diagnostic if the base classes don't match when we come
2122 // to lazily load them.
2123
2124 // FIXME: Issue a diagnostic if the list of conversion functions doesn't
2125 // match when we come to lazily load them.
2126 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
2127 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
2128 DD.ComputedVisibleConversions = true;
2129 }
2130
2131 // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
2132 // lazily load it.
2133
2134 if (DD.IsLambda) {
2135 auto &Lambda1 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(DD);
2136 auto &Lambda2 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(MergeDD);
2137 DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind;
2138 DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda;
2139 DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault;
2140 DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures;
2141 DetectedOdrViolation |=
2142 Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures;
2143 DetectedOdrViolation |=
2144 Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage;
2145 DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber;
2146
2147 if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) {
2148 for (unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) {
2149 LambdaCapture &Cap1 = Lambda1.Captures.front()[I];
2150 LambdaCapture &Cap2 = Lambda2.Captures.front()[I];
2151 DetectedOdrViolation |= Cap1.getCaptureKind() != Cap2.getCaptureKind();
2152 }
2153 Lambda1.AddCaptureList(Reader.getContext(), Lambda2.Captures.front());
2154 }
2155 }
2156
2157 // We don't want to check ODR for decls in the global module fragment.
2158 if (shouldSkipCheckingODR(MergeDD.Definition))
2159 return;
2160
2161 if (D->getODRHash() != MergeDD.ODRHash) {
2162 DetectedOdrViolation = true;
2163 }
2164
2165 if (DetectedOdrViolation)
2166 Reader.PendingOdrMergeFailures[DD.Definition].push_back(
2167 {MergeDD.Definition, &MergeDD});
2168}
2169
2170void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update,
2171 Decl *LambdaContext,
2172 unsigned IndexInLambdaContext) {
2173 struct CXXRecordDecl::DefinitionData *DD;
2174 ASTContext &C = Reader.getContext();
2175
2176 // Determine whether this is a lambda closure type, so that we can
2177 // allocate the appropriate DefinitionData structure.
2178 bool IsLambda = Record.readInt();
2179 assert(!(IsLambda && Update) &&
2180 "lambda definition should not be added by update record");
2181 if (IsLambda)
2182 DD = new (C) CXXRecordDecl::LambdaDefinitionData(
2183 D, nullptr, CXXRecordDecl::LDK_Unknown, false, LCD_None);
2184 else
2185 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
2186
2187 CXXRecordDecl *Canon = D->getCanonicalDecl();
2188 // Set decl definition data before reading it, so that during deserialization
2189 // when we read CXXRecordDecl, it already has definition data and we don't
2190 // set fake one.
2191 if (!Canon->DefinitionData)
2192 Canon->DefinitionData = DD;
2193 D->DefinitionData = Canon->DefinitionData;
2194 ReadCXXDefinitionData(*DD, D, LambdaContext, IndexInLambdaContext);
2195
2196 // We might already have a different definition for this record. This can
2197 // happen either because we're reading an update record, or because we've
2198 // already done some merging. Either way, just merge into it.
2199 if (Canon->DefinitionData != DD) {
2200 MergeDefinitionData(Canon, std::move(*DD));
2201 return;
2202 }
2203
2204 // Mark this declaration as being a definition.
2205 D->setCompleteDefinition(true);
2206
2207 // If this is not the first declaration or is an update record, we can have
2208 // other redeclarations already. Make a note that we need to propagate the
2209 // DefinitionData pointer onto them.
2210 if (Update || Canon != D)
2211 Reader.PendingDefinitions.insert(D);
2212}
2213
2214ASTDeclReader::RedeclarableResult
2216 RedeclarableResult Redecl = VisitRecordDeclImpl(D);
2217
2218 ASTContext &C = Reader.getContext();
2219
2220 enum CXXRecKind {
2221 CXXRecNotTemplate = 0,
2222 CXXRecTemplate,
2223 CXXRecMemberSpecialization,
2224 CXXLambda
2225 };
2226
2227 Decl *LambdaContext = nullptr;
2228 unsigned IndexInLambdaContext = 0;
2229
2230 switch ((CXXRecKind)Record.readInt()) {
2231 case CXXRecNotTemplate:
2232 // Merged when we merge the folding set entry in the primary template.
2233 if (!isa<ClassTemplateSpecializationDecl>(D))
2234 mergeRedeclarable(D, Redecl);
2235 break;
2236 case CXXRecTemplate: {
2237 // Merged when we merge the template.
2238 auto *Template = readDeclAs<ClassTemplateDecl>();
2239 D->TemplateOrInstantiation = Template;
2240 if (!Template->getTemplatedDecl()) {
2241 // We've not actually loaded the ClassTemplateDecl yet, because we're
2242 // currently being loaded as its pattern. Rely on it to set up our
2243 // TypeForDecl (see VisitClassTemplateDecl).
2244 //
2245 // Beware: we do not yet know our canonical declaration, and may still
2246 // get merged once the surrounding class template has got off the ground.
2247 DeferredTypeID = 0;
2248 }
2249 break;
2250 }
2251 case CXXRecMemberSpecialization: {
2252 auto *RD = readDeclAs<CXXRecordDecl>();
2253 auto TSK = (TemplateSpecializationKind)Record.readInt();
2254 SourceLocation POI = readSourceLocation();
2256 MSI->setPointOfInstantiation(POI);
2257 D->TemplateOrInstantiation = MSI;
2258 mergeRedeclarable(D, Redecl);
2259 break;
2260 }
2261 case CXXLambda: {
2262 LambdaContext = readDecl();
2263 if (LambdaContext)
2264 IndexInLambdaContext = Record.readInt();
2265 mergeLambda(D, Redecl, LambdaContext, IndexInLambdaContext);
2266 break;
2267 }
2268 }
2269
2270 bool WasDefinition = Record.readInt();
2271 if (WasDefinition)
2272 ReadCXXRecordDefinition(D, /*Update=*/false, LambdaContext,
2273 IndexInLambdaContext);
2274 else
2275 // Propagate DefinitionData pointer from the canonical declaration.
2276 D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
2277
2278 // Lazily load the key function to avoid deserializing every method so we can
2279 // compute it.
2280 if (WasDefinition) {
2281 DeclID KeyFn = readDeclID();
2282 if (KeyFn && D->isCompleteDefinition())
2283 // FIXME: This is wrong for the ARM ABI, where some other module may have
2284 // made this function no longer be a key function. We need an update
2285 // record or similar for that case.
2286 C.KeyFunctions[D] = KeyFn;
2287 }
2288
2289 return Redecl;
2290}
2291
2293 D->setExplicitSpecifier(Record.readExplicitSpec());
2294 D->Ctor = readDeclAs<CXXConstructorDecl>();
2297 static_cast<DeductionCandidate>(Record.readInt()));
2298}
2299
2302
2303 unsigned NumOverridenMethods = Record.readInt();
2304 if (D->isCanonicalDecl()) {
2305 while (NumOverridenMethods--) {
2306 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
2307 // MD may be initializing.
2308 if (auto *MD = readDeclAs<CXXMethodDecl>())
2310 }
2311 } else {
2312 // We don't care about which declarations this used to override; we get
2313 // the relevant information from the canonical declaration.
2314 Record.skipInts(NumOverridenMethods);
2315 }
2316}
2317
2319 // We need the inherited constructor information to merge the declaration,
2320 // so we have to read it before we call VisitCXXMethodDecl.
2321 D->setExplicitSpecifier(Record.readExplicitSpec());
2322 if (D->isInheritingConstructor()) {
2323 auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>();
2324 auto *Ctor = readDeclAs<CXXConstructorDecl>();
2325 *D->getTrailingObjects<InheritedConstructor>() =
2326 InheritedConstructor(Shadow, Ctor);
2327 }
2328
2330}
2331
2334
2335 if (auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
2336 CXXDestructorDecl *Canon = D->getCanonicalDecl();
2337 auto *ThisArg = Record.readExpr();
2338 // FIXME: Check consistency if we have an old and new operator delete.
2339 if (!Canon->OperatorDelete) {
2340 Canon->OperatorDelete = OperatorDelete;
2341 Canon->OperatorDeleteThisArg = ThisArg;
2342 }
2343 }
2344}
2345
2347 D->setExplicitSpecifier(Record.readExplicitSpec());
2349}
2350
2352 VisitDecl(D);
2353 D->ImportedModule = readModule();
2354 D->setImportComplete(Record.readInt());
2355 auto *StoredLocs = D->getTrailingObjects<SourceLocation>();
2356 for (unsigned I = 0, N = Record.back(); I != N; ++I)
2357 StoredLocs[I] = readSourceLocation();
2358 Record.skipInts(1); // The number of stored source locations.
2359}
2360
2362 VisitDecl(D);
2363 D->setColonLoc(readSourceLocation());
2364}
2365
2367 VisitDecl(D);
2368 if (Record.readInt()) // hasFriendDecl
2369 D->Friend = readDeclAs<NamedDecl>();
2370 else
2371 D->Friend = readTypeSourceInfo();
2372 for (unsigned i = 0; i != D->NumTPLists; ++i)
2373 D->getTrailingObjects<TemplateParameterList *>()[i] =
2374 Record.readTemplateParameterList();
2375 D->NextFriend = readDeclID();
2376 D->UnsupportedFriend = (Record.readInt() != 0);
2377 D->FriendLoc = readSourceLocation();
2378}
2379
2381 VisitDecl(D);
2382 unsigned NumParams = Record.readInt();
2383 D->NumParams = NumParams;
2384 D->Params = new (Reader.getContext()) TemplateParameterList *[NumParams];
2385 for (unsigned i = 0; i != NumParams; ++i)
2386 D->Params[i] = Record.readTemplateParameterList();
2387 if (Record.readInt()) // HasFriendDecl
2388 D->Friend = readDeclAs<NamedDecl>();
2389 else
2390 D->Friend = readTypeSourceInfo();
2391 D->FriendLoc = readSourceLocation();
2392}
2393
2395 VisitNamedDecl(D);
2396
2397 assert(!D->TemplateParams && "TemplateParams already set!");
2398 D->TemplateParams = Record.readTemplateParameterList();
2399 D->init(readDeclAs<NamedDecl>());
2400}
2401
2404 D->ConstraintExpr = Record.readExpr();
2405 mergeMergeable(D);
2406}
2407
2410 // The size of the template list was read during creation of the Decl, so we
2411 // don't have to re-read it here.
2412 VisitDecl(D);
2414 for (unsigned I = 0; I < D->NumTemplateArgs; ++I)
2415 Args.push_back(Record.readTemplateArgument(/*Canonicalize=*/true));
2416 D->setTemplateArguments(Args);
2417}
2418
2420}
2421
2422ASTDeclReader::RedeclarableResult
2424 RedeclarableResult Redecl = VisitRedeclarable(D);
2425
2426 // Make sure we've allocated the Common pointer first. We do this before
2427 // VisitTemplateDecl so that getCommonPtr() can be used during initialization.
2429 if (!CanonD->Common) {
2430 CanonD->Common = CanonD->newCommon(Reader.getContext());
2431 Reader.PendingDefinitions.insert(CanonD);
2432 }
2433 D->Common = CanonD->Common;
2434
2435 // If this is the first declaration of the template, fill in the information
2436 // for the 'common' pointer.
2437 if (ThisDeclID == Redecl.getFirstID()) {
2438 if (auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) {
2439 assert(RTD->getKind() == D->getKind() &&
2440 "InstantiatedFromMemberTemplate kind mismatch");
2442 if (Record.readInt())
2444 }
2445 }
2446
2448 D->IdentifierNamespace = Record.readInt();
2449
2450 return Redecl;
2451}
2452
2454 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2455 mergeRedeclarableTemplate(D, Redecl);
2456
2457 if (ThisDeclID == Redecl.getFirstID()) {
2458 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
2459 // the specializations.
2461 readDeclIDList(SpecIDs);
2463 }
2464
2465 if (D->getTemplatedDecl()->TemplateOrInstantiation) {
2466 // We were loaded before our templated declaration was. We've not set up
2467 // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct
2468 // it now.
2471 }
2472}
2473
2475 llvm_unreachable("BuiltinTemplates are not serialized");
2476}
2477
2478/// TODO: Unify with ClassTemplateDecl version?
2479/// May require unifying ClassTemplateDecl and
2480/// VarTemplateDecl beyond TemplateDecl...
2482 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2483 mergeRedeclarableTemplate(D, Redecl);
2484
2485 if (ThisDeclID == Redecl.getFirstID()) {
2486 // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of
2487 // the specializations.
2489 readDeclIDList(SpecIDs);
2491 }
2492}
2493
2494ASTDeclReader::RedeclarableResult
2497 RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D);
2498
2499 ASTContext &C = Reader.getContext();
2500 if (Decl *InstD = readDecl()) {
2501 if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2502 D->SpecializedTemplate = CTD;
2503 } else {
2505 Record.readTemplateArgumentList(TemplArgs);
2506 TemplateArgumentList *ArgList
2507 = TemplateArgumentList::CreateCopy(C, TemplArgs);
2508 auto *PS =
2510 SpecializedPartialSpecialization();
2511 PS->PartialSpecialization
2512 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2513 PS->TemplateArgs = ArgList;
2514 D->SpecializedTemplate = PS;
2515 }
2516 }
2517
2519 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2520 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2521 D->PointOfInstantiation = readSourceLocation();
2522 D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2523
2524 bool writtenAsCanonicalDecl = Record.readInt();
2525 if (writtenAsCanonicalDecl) {
2526 auto *CanonPattern = readDeclAs<ClassTemplateDecl>();
2527 if (D->isCanonicalDecl()) { // It's kept in the folding set.
2528 // Set this as, or find, the canonical declaration for this specialization
2530 if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
2531 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2532 .GetOrInsertNode(Partial);
2533 } else {
2534 CanonSpec =
2535 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2536 }
2537 // If there was already a canonical specialization, merge into it.
2538 if (CanonSpec != D) {
2539 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2540
2541 // This declaration might be a definition. Merge with any existing
2542 // definition.
2543 if (auto *DDD = D->DefinitionData) {
2544 if (CanonSpec->DefinitionData)
2545 MergeDefinitionData(CanonSpec, std::move(*DDD));
2546 else
2547 CanonSpec->DefinitionData = D->DefinitionData;
2548 }
2549 D->DefinitionData = CanonSpec->DefinitionData;
2550 }
2551 }
2552 }
2553
2554 // Explicit info.
2555 if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) {
2556 auto *ExplicitInfo =
2557 new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2558 ExplicitInfo->TypeAsWritten = TyInfo;
2559 ExplicitInfo->ExternLoc = readSourceLocation();
2560 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2561 D->ExplicitInfo = ExplicitInfo;
2562 }
2563
2564 return Redecl;
2565}
2566
2569 // We need to read the template params first because redeclarable is going to
2570 // need them for profiling
2571 TemplateParameterList *Params = Record.readTemplateParameterList();
2572 D->TemplateParams = Params;
2573 D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2574
2575 RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D);
2576
2577 // These are read/set from/to the first declaration.
2578 if (ThisDeclID == Redecl.getFirstID()) {
2579 D->InstantiatedFromMember.setPointer(
2580 readDeclAs<ClassTemplatePartialSpecializationDecl>());
2581 D->InstantiatedFromMember.setInt(Record.readInt());
2582 }
2583}
2584
2586 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2587
2588 if (ThisDeclID == Redecl.getFirstID()) {
2589 // This FunctionTemplateDecl owns a CommonPtr; read it.
2591 readDeclIDList(SpecIDs);
2593 }
2594}
2595
2596/// TODO: Unify with ClassTemplateSpecializationDecl version?
2597/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2598/// VarTemplate(Partial)SpecializationDecl with a new data
2599/// structure Template(Partial)SpecializationDecl, and
2600/// using Template(Partial)SpecializationDecl as input type.
2601ASTDeclReader::RedeclarableResult
2604 ASTContext &C = Reader.getContext();
2605 if (Decl *InstD = readDecl()) {
2606 if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2607 D->SpecializedTemplate = VTD;
2608 } else {
2610 Record.readTemplateArgumentList(TemplArgs);
2612 C, TemplArgs);
2613 auto *PS =
2614 new (C)
2615 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2616 PS->PartialSpecialization =
2617 cast<VarTemplatePartialSpecializationDecl>(InstD);
2618 PS->TemplateArgs = ArgList;
2619 D->SpecializedTemplate = PS;
2620 }
2621 }
2622
2623 // Explicit info.
2624 if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) {
2625 auto *ExplicitInfo =
2626 new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2627 ExplicitInfo->TypeAsWritten = TyInfo;
2628 ExplicitInfo->ExternLoc = readSourceLocation();
2629 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2630 D->ExplicitInfo = ExplicitInfo;
2631 }
2632
2634 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2635 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2636 D->PointOfInstantiation = readSourceLocation();
2637 D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2638 D->IsCompleteDefinition = Record.readInt();
2639
2640 RedeclarableResult Redecl = VisitVarDeclImpl(D);
2641
2642 bool writtenAsCanonicalDecl = Record.readInt();
2643 if (writtenAsCanonicalDecl) {
2644 auto *CanonPattern = readDeclAs<VarTemplateDecl>();
2645 if (D->isCanonicalDecl()) { // It's kept in the folding set.
2647 if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
2648 CanonSpec = CanonPattern->getCommonPtr()
2649 ->PartialSpecializations.GetOrInsertNode(Partial);
2650 } else {
2651 CanonSpec =
2652 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2653 }
2654 // If we already have a matching specialization, merge it.
2655 if (CanonSpec != D)
2656 mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl);
2657 }
2658 }
2659
2660 return Redecl;
2661}
2662
2663/// TODO: Unify with ClassTemplatePartialSpecializationDecl version?
2664/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2665/// VarTemplate(Partial)SpecializationDecl with a new data
2666/// structure Template(Partial)SpecializationDecl, and
2667/// using Template(Partial)SpecializationDecl as input type.
2670 TemplateParameterList *Params = Record.readTemplateParameterList();
2671 D->TemplateParams = Params;
2672 D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2673
2674 RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D);
2675
2676 // These are read/set from/to the first declaration.
2677 if (ThisDeclID == Redecl.getFirstID()) {
2678 D->InstantiatedFromMember.setPointer(
2679 readDeclAs<VarTemplatePartialSpecializationDecl>());
2680 D->InstantiatedFromMember.setInt(Record.readInt());
2681 }
2682}
2683
2685 VisitTypeDecl(D);
2686
2687 D->setDeclaredWithTypename(Record.readInt());
2688
2689 if (D->hasTypeConstraint()) {
2690 ConceptReference *CR = nullptr;
2691 if (Record.readBool())
2692 CR = Record.readConceptReference();
2693 Expr *ImmediatelyDeclaredConstraint = Record.readExpr();
2694
2695 D->setTypeConstraint(CR, ImmediatelyDeclaredConstraint);
2696 if ((D->ExpandedParameterPack = Record.readInt()))
2697 D->NumExpanded = Record.readInt();
2698 }
2699
2700 if (Record.readInt())
2701 D->setDefaultArgument(readTypeSourceInfo());
2702}
2703
2706 // TemplateParmPosition.
2707 D->setDepth(Record.readInt());
2708 D->setPosition(Record.readInt());
2710 D->setPlaceholderTypeConstraint(Record.readExpr());
2711 if (D->isExpandedParameterPack()) {
2712 auto TypesAndInfos =
2713 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2714 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
2715 new (&TypesAndInfos[I].first) QualType(Record.readType());
2716 TypesAndInfos[I].second = readTypeSourceInfo();
2717 }
2718 } else {
2719 // Rest of NonTypeTemplateParmDecl.
2720 D->ParameterPack = Record.readInt();
2721 if (Record.readInt())
2722 D->setDefaultArgument(Record.readExpr());
2723 }
2724}
2725
2728 D->setDeclaredWithTypename(Record.readBool());
2729 // TemplateParmPosition.
2730 D->setDepth(Record.readInt());
2731 D->setPosition(Record.readInt());
2732 if (D->isExpandedParameterPack()) {
2733 auto **Data = D->getTrailingObjects<TemplateParameterList *>();
2734 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2735 I != N; ++I)
2736 Data[I] = Record.readTemplateParameterList();
2737 } else {
2738 // Rest of TemplateTemplateParmDecl.
2739 D->ParameterPack = Record.readInt();
2740 if (Record.readInt())
2741 D->setDefaultArgument(Reader.getContext(),
2742 Record.readTemplateArgumentLoc());
2743 }
2744}
2745
2747 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2748 mergeRedeclarableTemplate(D, Redecl);
2749}
2750
2752 VisitDecl(D);
2753 D->AssertExprAndFailed.setPointer(Record.readExpr());
2754 D->AssertExprAndFailed.setInt(Record.readInt());
2755 D->Message = cast_or_null<StringLiteral>(Record.readExpr());
2756 D->RParenLoc = readSourceLocation();
2757}
2758
2760 VisitDecl(D);
2761}
2762
2765 VisitDecl(D);
2766 D->ExtendingDecl = readDeclAs<ValueDecl>();
2767 D->ExprWithTemporary = Record.readStmt();
2768 if (Record.readInt()) {
2769 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
2770 D->getASTContext().addDestruction(D->Value);
2771 }
2772 D->ManglingNumber = Record.readInt();
2773 mergeMergeable(D);
2774}
2775
2776std::pair<uint64_t, uint64_t>
2778 uint64_t LexicalOffset = ReadLocalOffset();
2779 uint64_t VisibleOffset = ReadLocalOffset();
2780 return std::make_pair(LexicalOffset, VisibleOffset);
2781}
2782
2783template <typename T>
2784ASTDeclReader::RedeclarableResult
2786 DeclID FirstDeclID = readDeclID();
2787 Decl *MergeWith = nullptr;
2788
2789 bool IsKeyDecl = ThisDeclID == FirstDeclID;
2790 bool IsFirstLocalDecl = false;
2791
2792 uint64_t RedeclOffset = 0;
2793
2794 // 0 indicates that this declaration was the only declaration of its entity,
2795 // and is used for space optimization.
2796 if (FirstDeclID == 0) {
2797 FirstDeclID = ThisDeclID;
2798 IsKeyDecl = true;
2799 IsFirstLocalDecl = true;
2800 } else if (unsigned N = Record.readInt()) {
2801 // This declaration was the first local declaration, but may have imported
2802 // other declarations.
2803 IsKeyDecl = N == 1;
2804 IsFirstLocalDecl = true;
2805
2806 // We have some declarations that must be before us in our redeclaration
2807 // chain. Read them now, and remember that we ought to merge with one of
2808 // them.
2809 // FIXME: Provide a known merge target to the second and subsequent such
2810 // declaration.
2811 for (unsigned I = 0; I != N - 1; ++I)
2812 MergeWith = readDecl();
2813
2814 RedeclOffset = ReadLocalOffset();
2815 } else {
2816 // This declaration was not the first local declaration. Read the first
2817 // local declaration now, to trigger the import of other redeclarations.
2818 (void)readDecl();
2819 }
2820
2821 auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2822 if (FirstDecl != D) {
2823 // We delay loading of the redeclaration chain to avoid deeply nested calls.
2824 // We temporarily set the first (canonical) declaration as the previous one
2825 // which is the one that matters and mark the real previous DeclID to be
2826 // loaded & attached later on.
2828 D->First = FirstDecl->getCanonicalDecl();
2829 }
2830
2831 auto *DAsT = static_cast<T *>(D);
2832
2833 // Note that we need to load local redeclarations of this decl and build a
2834 // decl chain for them. This must happen *after* we perform the preloading
2835 // above; this ensures that the redeclaration chain is built in the correct
2836 // order.
2837 if (IsFirstLocalDecl)
2838 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2839
2840 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2841}
2842
2843/// Attempts to merge the given declaration (D) with another declaration
2844/// of the same entity.
2845template <typename T>
2847 RedeclarableResult &Redecl) {
2848 // If modules are not available, there is no reason to perform this merge.
2849 if (!Reader.getContext().getLangOpts().Modules)
2850 return;
2851
2852 // If we're not the canonical declaration, we don't need to merge.
2853 if (!DBase->isFirstDecl())
2854 return;
2855
2856 auto *D = static_cast<T *>(DBase);
2857
2858 if (auto *Existing = Redecl.getKnownMergeTarget())
2859 // We already know of an existing declaration we should merge with.
2860 mergeRedeclarable(D, cast<T>(Existing), Redecl);
2861 else if (FindExistingResult ExistingRes = findExisting(D))
2862 if (T *Existing = ExistingRes)
2863 mergeRedeclarable(D, Existing, Redecl);
2864}
2865
2866/// Attempt to merge D with a previous declaration of the same lambda, which is
2867/// found by its index within its context declaration, if it has one.
2868///
2869/// We can't look up lambdas in their enclosing lexical or semantic context in
2870/// general, because for lambdas in variables, both of those might be a
2871/// namespace or the translation unit.
2872void ASTDeclReader::mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl,
2873 Decl *Context, unsigned IndexInContext) {
2874 // If we don't have a mangling context, treat this like any other
2875 // declaration.
2876 if (!Context)
2877 return mergeRedeclarable(D, Redecl);
2878
2879 // If modules are not available, there is no reason to perform this merge.
2880 if (!Reader.getContext().getLangOpts().Modules)
2881 return;
2882
2883 // If we're not the canonical declaration, we don't need to merge.
2884 if (!D->isFirstDecl())
2885 return;
2886
2887 if (auto *Existing = Redecl.getKnownMergeTarget())
2888 // We already know of an existing declaration we should merge with.
2889 mergeRedeclarable(D, cast<TagDecl>(Existing), Redecl);
2890
2891 // Look up this lambda to see if we've seen it before. If so, merge with the
2892 // one we already loaded.
2893 NamedDecl *&Slot = Reader.LambdaDeclarationsForMerging[{
2894 Context->getCanonicalDecl(), IndexInContext}];
2895 if (Slot)
2896 mergeRedeclarable(D, cast<TagDecl>(Slot), Redecl);
2897 else
2898 Slot = D;
2899}
2900
2902 RedeclarableResult &Redecl) {
2903 mergeRedeclarable(D, Redecl);
2904 // If we merged the template with a prior declaration chain, merge the
2905 // common pointer.
2906 // FIXME: Actually merge here, don't just overwrite.
2907 D->Common = D->getCanonicalDecl()->Common;
2908}
2909
2910/// "Cast" to type T, asserting if we don't have an implicit conversion.
2911/// We use this to put code in a template that will only be valid for certain
2912/// instantiations.
2913template<typename T> static T assert_cast(T t) { return t; }
2914template<typename T> static T assert_cast(...) {
2915 llvm_unreachable("bad assert_cast");
2916}
2917
2918/// Merge together the pattern declarations from two template
2919/// declarations.
2921 RedeclarableTemplateDecl *Existing,
2922 bool IsKeyDecl) {
2923 auto *DPattern = D->getTemplatedDecl();
2924 auto *ExistingPattern = Existing->getTemplatedDecl();
2925 RedeclarableResult Result(/*MergeWith*/ ExistingPattern,
2926 DPattern->getCanonicalDecl()->getGlobalID(),
2927 IsKeyDecl);
2928
2929 if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2930 // Merge with any existing definition.
2931 // FIXME: This is duplicated in several places. Refactor.
2932 auto *ExistingClass =
2933 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2934 if (auto *DDD = DClass->DefinitionData) {
2935 if (ExistingClass->DefinitionData) {
2936 MergeDefinitionData(ExistingClass, std::move(*DDD));
2937 } else {
2938 ExistingClass->DefinitionData = DClass->DefinitionData;
2939 // We may have skipped this before because we thought that DClass
2940 // was the canonical declaration.
2941 Reader.PendingDefinitions.insert(DClass);
2942 }
2943 }
2944 DClass->DefinitionData = ExistingClass->DefinitionData;
2945
2946 return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern),
2947 Result);
2948 }
2949 if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2950 return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern),
2951 Result);
2952 if (auto *DVar = dyn_cast<VarDecl>(DPattern))
2953 return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result);
2954 if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2955 return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern),
2956 Result);
2957 llvm_unreachable("merged an unknown kind of redeclarable template");
2958}
2959
2960/// Attempts to merge the given declaration (D) with another declaration
2961/// of the same entity.
2962template <typename T>
2964 RedeclarableResult &Redecl) {
2965 auto *D = static_cast<T *>(DBase);
2966 T *ExistingCanon = Existing->getCanonicalDecl();
2967 T *DCanon = D->getCanonicalDecl();
2968 if (ExistingCanon != DCanon) {
2969 // Have our redeclaration link point back at the canonical declaration
2970 // of the existing declaration, so that this declaration has the
2971 // appropriate canonical declaration.
2973 D->First = ExistingCanon;
2974 ExistingCanon->Used |= D->Used;
2975 D->Used = false;
2976
2977 // When we merge a namespace, update its pointer to the first namespace.
2978 // We cannot have loaded any redeclarations of this declaration yet, so
2979 // there's nothing else that needs to be updated.
2980 if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2981 Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2982 assert_cast<NamespaceDecl *>(ExistingCanon));
2983
2984 // When we merge a template, merge its pattern.
2985 if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2987 DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2988 Redecl.isKeyDecl());
2989
2990 // If this declaration is a key declaration, make a note of that.
2991 if (Redecl.isKeyDecl())
2992 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2993 }
2994}
2995
2996/// ODR-like semantics for C/ObjC allow us to merge tag types and a structural
2997/// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89
2998/// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee
2999/// that some types are mergeable during deserialization, otherwise name
3000/// lookup fails. This is the case for EnumConstantDecl.
3002 if (!ND)
3003 return false;
3004 // TODO: implement merge for other necessary decls.
3005 if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
3006 return true;
3007 return false;
3008}
3009
3010/// Attempts to merge LifetimeExtendedTemporaryDecl with
3011/// identical class definitions from two different modules.
3013 // If modules are not available, there is no reason to perform this merge.
3014 if (!Reader.getContext().getLangOpts().Modules)
3015 return;
3016
3017 LifetimeExtendedTemporaryDecl *LETDecl = D;
3018
3020 Reader.LETemporaryForMerging[std::make_pair(
3021 LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())];
3022 if (LookupResult)
3023 Reader.getContext().setPrimaryMergedDecl(LETDecl,
3024 LookupResult->getCanonicalDecl());
3025 else
3026 LookupResult = LETDecl;
3027}
3028
3029/// Attempts to merge the given declaration (D) with another declaration
3030/// of the same entity, for the case where the entity is not actually
3031/// redeclarable. This happens, for instance, when merging the fields of
3032/// identical class definitions from two different modules.
3033template<typename T>
3035 // If modules are not available, there is no reason to perform this merge.
3036 if (!Reader.getContext().getLangOpts().Modules)
3037 return;
3038
3039 // ODR-based merging is performed in C++ and in some cases (tag types) in C.
3040 // Note that C identically-named things in different translation units are
3041 // not redeclarations, but may still have compatible types, where ODR-like
3042 // semantics may apply.
3043 if (!Reader.getContext().getLangOpts().CPlusPlus &&
3044 !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D))))
3045 return;
3046
3047 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
3048 if (T *Existing = ExistingRes)
3049 Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
3050 Existing->getCanonicalDecl());
3051}
3052
3054 Record.readOMPChildren(D->Data);
3055 VisitDecl(D);
3056}
3057
3059 Record.readOMPChildren(D->Data);
3060 VisitDecl(D);
3061}
3062
3064 Record.readOMPChildren(D->Data);
3065 VisitDecl(D);
3066}
3067
3069 VisitValueDecl(D);
3070 D->setLocation(readSourceLocation());
3071 Expr *In = Record.readExpr();
3072 Expr *Out = Record.readExpr();
3073 D->setCombinerData(In, Out);
3074 Expr *Combiner = Record.readExpr();
3075 D->setCombiner(Combiner);
3076 Expr *Orig = Record.readExpr();
3077 Expr *Priv = Record.readExpr();
3078 D->setInitializerData(Orig, Priv);
3079 Expr *Init = Record.readExpr();
3080 auto IK = static_cast<OMPDeclareReductionInitKind>(Record.readInt());
3081 D->setInitializer(Init, IK);
3082 D->PrevDeclInScope = readDeclID();
3083}
3084
3086 Record.readOMPChildren(D->Data);
3087 VisitValueDecl(D);
3088 D->VarName = Record.readDeclarationName();
3089 D->PrevDeclInScope = readDeclID();
3090}
3091
3093 VisitVarDecl(D);
3094}
3095
3096//===----------------------------------------------------------------------===//
3097// Attribute Reading
3098//===----------------------------------------------------------------------===//
3099
3100namespace {
3101class AttrReader {
3102 ASTRecordReader &Reader;
3103
3104public:
3105 AttrReader(ASTRecordReader &Reader) : Reader(Reader) {}
3106
3107 uint64_t readInt() {
3108 return Reader.readInt();
3109 }
3110
3111 bool readBool() { return Reader.readBool(); }
3112
3113 SourceRange readSourceRange() {
3114 return Reader.readSourceRange();
3115 }
3116
3117 SourceLocation readSourceLocation() {
3118 return Reader.readSourceLocation();
3119 }
3120
3121 Expr *readExpr() { return Reader.readExpr(); }
3122
3123 Attr *readAttr() { return Reader.readAttr(); }
3124
3125 std::string readString() {
3126 return Reader.readString();
3127 }
3128
3129 TypeSourceInfo *readTypeSourceInfo() {
3130 return Reader.readTypeSourceInfo();
3131 }
3132
3133 IdentifierInfo *readIdentifier() {
3134 return Reader.readIdentifier();
3135 }
3136
3137 VersionTuple readVersionTuple() {
3138 return Reader.readVersionTuple();
3139 }
3140
3141 OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); }
3142
3143 template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
3144 return Reader.GetLocalDeclAs<T>(LocalID);
3145 }
3146};
3147}
3148
3150 AttrReader Record(*this);
3151 auto V = Record.readInt();
3152 if (!V)
3153 return nullptr;
3154
3155 Attr *New = nullptr;
3156 // Kind is stored as a 1-based integer because 0 is used to indicate a null
3157 // Attr pointer.
3158 auto Kind = static_cast<attr::Kind>(V - 1);
3159 ASTContext &Context = getContext();
3160
3161 IdentifierInfo *AttrName = Record.readIdentifier();
3162 IdentifierInfo *ScopeName = Record.readIdentifier();
3163 SourceRange AttrRange = Record.readSourceRange();
3164 SourceLocation ScopeLoc = Record.readSourceLocation();
3165 unsigned ParsedKind = Record.readInt();
3166 unsigned Syntax = Record.readInt();
3167 unsigned SpellingIndex = Record.readInt();
3168 bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned &&
3170 SpellingIndex == AlignedAttr::Keyword_alignas);
3171 bool IsRegularKeywordAttribute = Record.readBool();
3172
3173 AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc,
3174 AttributeCommonInfo::Kind(ParsedKind),
3175 {AttributeCommonInfo::Syntax(Syntax), SpellingIndex,
3176 IsAlignas, IsRegularKeywordAttribute});
3177
3178#include "clang/Serialization/AttrPCHRead.inc"
3179
3180 assert(New && "Unable to decode attribute?");
3181 return New;
3182}
3183
3184/// Reads attributes from the current stream position.
3186 for (unsigned I = 0, E = readInt(); I != E; ++I)
3187 if (auto *A = readAttr())
3188 Attrs.push_back(A);
3189}
3190
3191//===----------------------------------------------------------------------===//
3192// ASTReader Implementation
3193//===----------------------------------------------------------------------===//
3194
3195/// Note that we have loaded the declaration with the given
3196/// Index.
3197///
3198/// This routine notes that this declaration has already been loaded,
3199/// so that future GetDecl calls will return this declaration rather
3200/// than trying to load a new declaration.
3201inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
3202 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
3203 DeclsLoaded[Index] = D;
3204}
3205
3206/// Determine whether the consumer will be interested in seeing
3207/// this declaration (via HandleTopLevelDecl).
3208///
3209/// This routine should return true for anything that might affect
3210/// code generation, e.g., inline function definitions, Objective-C
3211/// declarations with metadata, etc.
3212bool ASTReader::isConsumerInterestedIn(Decl *D) {
3213 // An ObjCMethodDecl is never considered as "interesting" because its
3214 // implementation container always is.
3215
3216 // An ImportDecl or VarDecl imported from a module map module will get
3217 // emitted when we import the relevant module.
3219 auto *M = D->getImportedOwningModule();
3220 if (M && M->Kind == Module::ModuleMapModule &&
3221 getContext().DeclMustBeEmitted(D))
3222 return false;
3223 }
3224
3227 return true;
3230 return !D->getDeclContext()->isFunctionOrMethod();
3231 if (const auto *Var = dyn_cast<VarDecl>(D))
3232 return Var->isFileVarDecl() &&
3233 (Var->isThisDeclarationADefinition() == VarDecl::Definition ||
3234 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
3235 if (const auto *Func = dyn_cast<FunctionDecl>(D))
3236 return Func->doesThisDeclarationHaveABody() || PendingBodies.count(D);
3237
3238 if (auto *ES = D->getASTContext().getExternalSource())
3239 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
3240 return true;
3241
3242 return false;
3243}
3244
3245/// Get the correct cursor and offset for loading a declaration.
3246ASTReader::RecordLocation
3247ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
3248 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
3249 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
3250 ModuleFile *M = I->second;
3251 const DeclOffset &DOffs =
3253 Loc = TranslateSourceLocation(*M, DOffs.getLocation());
3254 return RecordLocation(M, DOffs.getBitOffset(M->DeclsBlockStartOffset));
3255}
3256
3257ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
3258 auto I = GlobalBitOffsetsMap.find(GlobalOffset);
3259
3260 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
3261 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
3262}
3263
3264uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset) {
3265 return LocalOffset + M.GlobalBitOffset;
3266}
3267
3269ASTDeclReader::getOrFakePrimaryClassDefinition(ASTReader &Reader,
3270 CXXRecordDecl *RD) {
3271 // Try to dig out the definition.
3272 auto *DD = RD->DefinitionData;
3273 if (!DD)
3274 DD = RD->getCanonicalDecl()->DefinitionData;
3275
3276 // If there's no definition yet, then DC's definition is added by an update
3277 // record, but we've not yet loaded that update record. In this case, we
3278 // commit to DC being the canonical definition now, and will fix this when
3279 // we load the update record.
3280 if (!DD) {
3281 DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD);
3282 RD->setCompleteDefinition(true);
3283 RD->DefinitionData = DD;
3284 RD->getCanonicalDecl()->DefinitionData = DD;
3285
3286 // Track that we did this horrible thing so that we can fix it later.
3287 Reader.PendingFakeDefinitionData.insert(
3288 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
3289 }
3290
3291 return DD->Definition;
3292}
3293
3294/// Find the context in which we should search for previous declarations when
3295/// looking for declarations to merge.
3296DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
3297 DeclContext *DC) {
3298 if (auto *ND = dyn_cast<NamespaceDecl>(DC))
3299 return ND->getOriginalNamespace();
3300
3301 if (auto *RD = dyn_cast<CXXRecordDecl>(DC))
3302 return getOrFakePrimaryClassDefinition(Reader, RD);
3303
3304 if (auto *RD = dyn_cast<RecordDecl>(DC))
3305 return RD->getDefinition();
3306
3307 if (auto *ED = dyn_cast<EnumDecl>(DC))
3308 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
3309 : nullptr;
3310
3311 if (auto *OID = dyn_cast<ObjCInterfaceDecl>(DC))
3312 return OID->getDefinition();
3313
3314 // We can see the TU here only if we have no Sema object. It is possible
3315 // we're in clang-repl so we still need to get the primary context.
3316 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3317 return TU->getPrimaryContext();
3318
3319 return nullptr;
3320}
3321
3322ASTDeclReader::FindExistingResult::~FindExistingResult() {
3323 // Record that we had a typedef name for linkage whether or not we merge
3324 // with that declaration.
3325 if (TypedefNameForLinkage) {
3326 DeclContext *DC = New->getDeclContext()->getRedeclContext();
3327 Reader.ImportedTypedefNamesForLinkage.insert(
3328 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3329 return;
3330 }
3331
3332 if (!AddResult || Existing)
3333 return;
3334
3335 DeclarationName Name = New->getDeclName();
3336 DeclContext *DC = New->getDeclContext()->getRedeclContext();
3338 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3339 AnonymousDeclNumber, New);
3340 } else if (DC->isTranslationUnit() &&
3341 !Reader.getContext().getLangOpts().CPlusPlus) {
3342 if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
3343 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3344 .push_back(New);
3345 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3346 // Add the declaration to its redeclaration context so later merging
3347 // lookups will find it.
3348 MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true);
3349 }
3350}
3351
3352/// Find the declaration that should be merged into, given the declaration found
3353/// by name lookup. If we're merging an anonymous declaration within a typedef,
3354/// we need a matching typedef, and we merge with the type inside it.
3356 bool IsTypedefNameForLinkage) {
3357 if (!IsTypedefNameForLinkage)
3358 return Found;
3359
3360 // If we found a typedef declaration that gives a name to some other
3361 // declaration, then we want that inner declaration. Declarations from
3362 // AST files are handled via ImportedTypedefNamesForLinkage.
3363 if (Found->isFromASTFile())
3364 return nullptr;
3365
3366 if (auto *TND = dyn_cast<TypedefNameDecl>(Found))
3367 return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
3368
3369 return nullptr;
3370}
3371
3372/// Find the declaration to use to populate the anonymous declaration table
3373/// for the given lexical DeclContext. We only care about finding local
3374/// definitions of the context; we'll merge imported ones as we go.
3376ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) {
3377 // For classes, we track the definition as we merge.
3378 if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3379 auto *DD = RD->getCanonicalDecl()->DefinitionData;
3380 return DD ? DD->Definition : nullptr;
3381 } else if (auto *OID = dyn_cast<ObjCInterfaceDecl>(LexicalDC)) {
3382 return OID->getCanonicalDecl()->getDefinition();
3383 }
3384
3385 // For anything else, walk its merged redeclarations looking for a definition.
3386 // Note that we can't just call getDefinition here because the redeclaration
3387 // chain isn't wired up.
3388 for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) {
3389 if (auto *FD = dyn_cast<FunctionDecl>(D))
3390 if (FD->isThisDeclarationADefinition())
3391 return FD;
3392 if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
3393 if (MD->isThisDeclarationADefinition())
3394 return MD;
3395 if (auto *RD = dyn_cast<RecordDecl>(D))
3397 return RD;
3398 }
3399
3400 // No merged definition yet.
3401 return nullptr;
3402}
3403
3404NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
3405 DeclContext *DC,
3406 unsigned Index) {
3407 // If the lexical context has been merged, look into the now-canonical
3408 // definition.
3409 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3410
3411 // If we've seen this before, return the canonical declaration.
3412 auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3413 if (Index < Previous.size() && Previous[Index])
3414 return Previous[Index];
3415
3416 // If this is the first time, but we have parsed a declaration of the context,
3417 // build the anonymous declaration list from the parsed declaration.
3418 auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3419 if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
3420 numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) {
3421 if (Previous.size() == Number)
3422 Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));
3423 else
3424 Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl());
3425 });
3426 }
3427
3428 return Index < Previous.size() ? Previous[Index] : nullptr;
3429}
3430
3431void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader,
3432 DeclContext *DC, unsigned Index,
3433 NamedDecl *D) {
3434 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3435
3436 auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3437 if (Index >= Previous.size())
3438 Previous.resize(Index + 1);
3439 if (!Previous[Index])
3440 Previous[Index] = D;
3441}
3442
3443ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
3444 DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage
3445 : D->getDeclName();
3446
3447 if (!Name && !needsAnonymousDeclarationNumber(D)) {
3448 // Don't bother trying to find unnamed declarations that are in
3449 // unmergeable contexts.
3450 FindExistingResult Result(Reader, D, /*Existing=*/nullptr,
3451 AnonymousDeclNumber, TypedefNameForLinkage);
3452 Result.suppress();
3453 return Result;
3454 }
3455
3456 ASTContext &C = Reader.getContext();
3458 if (TypedefNameForLinkage) {
3459 auto It = Reader.ImportedTypedefNamesForLinkage.find(
3460 std::make_pair(DC, TypedefNameForLinkage));
3461 if (It != Reader.ImportedTypedefNamesForLinkage.end())
3462 if (C.isSameEntity(It->second, D))
3463 return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3464 TypedefNameForLinkage);
3465 // Go on to check in other places in case an existing typedef name
3466 // was not imported.
3467 }
3468
3470 // This is an anonymous declaration that we may need to merge. Look it up
3471 // in its context by number.
3472 if (auto *Existing = getAnonymousDeclForMerging(
3473 Reader, D->getLexicalDeclContext(), AnonymousDeclNumber))
3474 if (C.isSameEntity(Existing, D))
3475 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3476 TypedefNameForLinkage);
3477 } else if (DC->isTranslationUnit() &&
3478 !Reader.getContext().getLangOpts().CPlusPlus) {
3479 IdentifierResolver &IdResolver = Reader.getIdResolver();
3480
3481 // Temporarily consider the identifier to be up-to-date. We don't want to
3482 // cause additional lookups here.
3483 class UpToDateIdentifierRAII {
3484 IdentifierInfo *II;
3485 bool WasOutToDate = false;
3486
3487 public:
3488 explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) {
3489 if (II) {
3490 WasOutToDate = II->isOutOfDate();
3491 if (WasOutToDate)
3492 II->setOutOfDate(false);
3493 }
3494 }
3495
3496 ~UpToDateIdentifierRAII() {
3497 if (WasOutToDate)
3498 II->setOutOfDate(true);
3499 }
3500 } UpToDate(Name.getAsIdentifierInfo());
3501
3502 for (IdentifierResolver::iterator I = IdResolver.begin(Name),
3503 IEnd = IdResolver.end();
3504 I != IEnd; ++I) {
3505 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3506 if (C.isSameEntity(Existing, D))
3507 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3508 TypedefNameForLinkage);
3509 }
3510 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3511 DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
3512 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) {
3513 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3514 if (C.isSameEntity(Existing, D))
3515 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3516 TypedefNameForLinkage);
3517 }
3518 } else {
3519 // Not in a mergeable context.
3520 return FindExistingResult(Reader);
3521 }
3522
3523 // If this declaration is from a merged context, make a note that we need to
3524 // check that the canonical definition of that context contains the decl.
3525 //
3526 // Note that we don't perform ODR checks for decls from the global module
3527 // fragment.
3528 //
3529 // FIXME: We should do something similar if we merge two definitions of the
3530 // same template specialization into the same CXXRecordDecl.
3531 auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
3532 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3533 !shouldSkipCheckingODR(D) && MergedDCIt->second == D->getDeclContext())
3534 Reader.PendingOdrMergeChecks.push_back(D);
3535
3536 return FindExistingResult(Reader, D, /*Existing=*/nullptr,
3537 AnonymousDeclNumber, TypedefNameForLinkage);
3538}
3539
3540template<typename DeclT>
3542 return D->RedeclLink.getLatestNotUpdated();
3543}
3544
3546 llvm_unreachable("getMostRecentDecl on non-redeclarable declaration");
3547}
3548
3550 assert(D);
3551
3552 switch (D->getKind()) {
3553#define ABSTRACT_DECL(TYPE)
3554#define DECL(TYPE, BASE) \
3555 case Decl::TYPE: \
3556 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3557#include "clang/AST/DeclNodes.inc"
3558 }
3559 llvm_unreachable("unknown decl kind");
3560}
3561
3562Decl *ASTReader::getMostRecentExistingDecl(Decl *D) {
3564}
3565
3567 Decl *Previous) {
3568 InheritableAttr *NewAttr = nullptr;
3569 ASTContext &Context = Reader.getContext();
3570 const auto *IA = Previous->getAttr<MSInheritanceAttr>();
3571
3572 if (IA && !D->hasAttr<MSInheritanceAttr>()) {
3573 NewAttr = cast<InheritableAttr>(IA->clone(Context));
3574 NewAttr->setInherited(true);
3575 D->addAttr(NewAttr);
3576 }
3577
3578 const auto *AA = Previous->getAttr<AvailabilityAttr>();
3579 if (AA && !D->hasAttr<AvailabilityAttr>()) {
3580 NewAttr = AA->clone(Context);
3581 NewAttr->setInherited(true);
3582 D->addAttr(NewAttr);
3583 }
3584}
3585
3586template<typename DeclT>
3589 Decl *Previous, Decl *Canon) {
3590 D->RedeclLink.setPrevious(cast<DeclT>(Previous));
3591 D->First = cast<DeclT>(Previous)->First;
3592}
3593
3594namespace clang {
3595
3596template<>
3599 Decl *Previous, Decl *Canon) {
3600 auto *VD = static_cast<VarDecl *>(D);
3601 auto *PrevVD = cast<VarDecl>(Previous);
3602 D->RedeclLink.setPrevious(PrevVD);
3603 D->First = PrevVD->First;
3604
3605 // We should keep at most one definition on the chain.
3606 // FIXME: Cache the definition once we've found it. Building a chain with
3607 // N definitions currently takes O(N^2) time here.
3608 if (VD->isThisDeclarationADefinition() == VarDecl::Definition) {
3609 for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) {
3610 if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) {
3611 Reader.mergeDefinitionVisibility(CurD, VD);
3612 VD->demoteThisDefinitionToDeclaration();
3613 break;
3614 }
3615 }
3616 }
3617}
3618
3620 auto *DT = T->getContainedDeducedType();
3621 return DT && !DT->isDeduced();
3622}
3623
3624template<>
3627 Decl *Previous, Decl *Canon) {
3628 auto *FD = static_cast<FunctionDecl *>(D);
3629 auto *PrevFD = cast<FunctionDecl>(Previous);
3630
3631 FD->RedeclLink.setPrevious(PrevFD);
3632 FD->First = PrevFD->First;
3633
3634 // If the previous declaration is an inline function declaration, then this
3635 // declaration is too.
3636 if (PrevFD->isInlined() != FD->isInlined()) {
3637 // FIXME: [dcl.fct.spec]p4:
3638 // If a function with external linkage is declared inline in one
3639 // translation unit, it shall be declared inline in all translation
3640 // units in which it appears.
3641 //
3642 // Be careful of this case:
3643 //
3644 // module A:
3645 // template<typename T> struct X { void f(); };
3646 // template<typename T> inline void X<T>::f() {}
3647 //
3648 // module B instantiates the declaration of X<int>::f
3649 // module C instantiates the definition of X<int>::f
3650 //
3651 // If module B and C are merged, we do not have a violation of this rule.
3652 FD->setImplicitlyInline(true);
3653 }
3654
3655 auto *FPT = FD->getType()->getAs<FunctionProtoType>();
3656 auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>();
3657 if (FPT && PrevFPT) {
3658 // If we need to propagate an exception specification along the redecl
3659 // chain, make a note of that so that we can do so later.
3660 bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType());
3661 bool WasUnresolved =
3663 if (IsUnresolved != WasUnresolved)
3664 Reader.PendingExceptionSpecUpdates.insert(
3665 {Canon, IsUnresolved ? PrevFD : FD});
3666
3667 // If we need to propagate a deduced return type along the redecl chain,
3668 // make a note of that so that we can do it later.
3669 bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType());
3670 bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType());
3671 if (IsUndeduced != WasUndeduced)
3672 Reader.PendingDeducedTypeUpdates.insert(
3673 {cast<FunctionDecl>(Canon),
3674 (IsUndeduced ? PrevFPT : FPT)->getReturnType()});
3675 }
3676}
3677
3678} // namespace clang
3679
3681 llvm_unreachable("attachPreviousDecl on non-redeclarable declaration");
3682}
3683
3684/// Inherit the default template argument from \p From to \p To. Returns
3685/// \c false if there is no default template for \p From.
3686template <typename ParmDecl>
3687static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From,
3688 Decl *ToD) {
3689 auto *To = cast<ParmDecl>(ToD);
3690 if (!From->hasDefaultArgument())
3691 return false;
3692 To->setInheritedDefaultArgument(Context, From);
3693 return true;
3694}
3695
3697 TemplateDecl *From,
3698 TemplateDecl *To) {
3699 auto *FromTP = From->getTemplateParameters();
3700 auto *ToTP = To->getTemplateParameters();
3701 assert(FromTP->size() == ToTP->size() && "merged mismatched templates?");
3702
3703 for (unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3704 NamedDecl *FromParam = FromTP->getParam(I);
3705 NamedDecl *ToParam = ToTP->getParam(I);
3706
3707 if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam))
3708 inheritDefaultTemplateArgument(Context, FTTP, ToParam);
3709 else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam))
3710 inheritDefaultTemplateArgument(Context, FNTTP, ToParam);
3711 else
3713 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam);
3714 }
3715}
3716
3718 Decl *Previous, Decl *Canon) {
3719 assert(D && Previous);
3720
3721 switch (D->getKind()) {
3722#define ABSTRACT_DECL(TYPE)
3723#define DECL(TYPE, BASE) \
3724 case Decl::TYPE: \
3725 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
3726 break;
3727#include "clang/AST/DeclNodes.inc"
3728 }
3729
3730 // If the declaration was visible in one module, a redeclaration of it in
3731 // another module remains visible even if it wouldn't be visible by itself.
3732 //
3733 // FIXME: In this case, the declaration should only be visible if a module
3734 // that makes it visible has been imported.
3736 Previous->IdentifierNamespace &
3738
3739 // If the declaration declares a template, it may inherit default arguments
3740 // from the previous declaration.
3741 if (auto *TD = dyn_cast<TemplateDecl>(D))
3743 cast<TemplateDecl>(Previous), TD);
3744
3745 // If any of the declaration in the chain contains an Inheritable attribute,
3746 // it needs to be added to all the declarations in the redeclarable chain.
3747 // FIXME: Only the logic of merging MSInheritableAttr is present, it should
3748 // be extended for all inheritable attributes.
3750}
3751
3752template<typename DeclT>
3754 D->RedeclLink.setLatest(cast<DeclT>(Latest));
3755}
3756
3758 llvm_unreachable("attachLatestDecl on non-redeclarable declaration");
3759}
3760
3762 assert(D && Latest);
3763
3764 switch (D->getKind()) {
3765#define ABSTRACT_DECL(TYPE)
3766#define DECL(TYPE, BASE) \
3767 case Decl::TYPE: \
3768 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3769 break;
3770#include "clang/AST/DeclNodes.inc"
3771 }
3772}
3773
3774template<typename DeclT>
3777}
3778
3780 llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration");
3781}
3782
3783void ASTReader::markIncompleteDeclChain(Decl *D) {
3784 switch (D->getKind()) {
3785#define ABSTRACT_DECL(TYPE)
3786#define DECL(TYPE, BASE) \
3787 case Decl::TYPE: \
3788 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3789 break;
3790#include "clang/AST/DeclNodes.inc"
3791 }
3792}
3793
3794/// Read the declaration at the given offset from the AST file.
3795Decl *ASTReader::ReadDeclRecord(DeclID ID) {
3796 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
3797 SourceLocation DeclLoc;
3798 RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
3799 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
3800 // Keep track of where we are in the stream, then jump back there
3801 // after reading this declaration.
3802 SavedStreamPosition SavedPosition(DeclsCursor);
3803
3804 ReadingKindTracker ReadingKind(Read_Decl, *this);
3805
3806 // Note that we are loading a declaration record.
3807 Deserializing ADecl(this);
3808
3809 auto Fail = [](const char *what, llvm::Error &&Err) {
3810 llvm::report_fatal_error(Twine("ASTReader::readDeclRecord failed ") + what +
3811 ": " + toString(std::move(Err)));
3812 };
3813
3814 if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset))
3815 Fail("jumping", std::move(JumpFailed));
3816 ASTRecordReader Record(*this, *Loc.F);
3817 ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc);
3818 Expected<unsigned> MaybeCode = DeclsCursor.ReadCode();
3819 if (!MaybeCode)
3820 Fail("reading code", MaybeCode.takeError());
3821 unsigned Code = MaybeCode.get();
3822
3823 ASTContext &Context = getContext();
3824 Decl *D = nullptr;
3825 Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code);
3826 if (!MaybeDeclCode)
3827 llvm::report_fatal_error(
3828 Twine("ASTReader::readDeclRecord failed reading decl code: ") +
3829 toString(MaybeDeclCode.takeError()));
3830 switch ((DeclCode)MaybeDeclCode.get()) {
3833 llvm_unreachable("Record cannot be de-serialized with readDeclRecord");
3834 case DECL_TYPEDEF:
3835 D = TypedefDecl::CreateDeserialized(Context, ID);
3836 break;
3837 case DECL_TYPEALIAS:
3838 D = TypeAliasDecl::CreateDeserialized(Context, ID);
3839 break;
3840 case DECL_ENUM:
3841 D = EnumDecl::CreateDeserialized(Context, ID);
3842 break;
3843 case DECL_RECORD:
3844 D = RecordDecl::CreateDeserialized(Context, ID);
3845 break;
3846 case DECL_ENUM_CONSTANT:
3847 D = EnumConstantDecl::CreateDeserialized(Context, ID);
3848 break;
3849 case DECL_FUNCTION:
3850 D = FunctionDecl::CreateDeserialized(Context, ID);
3851 break;
3852 case DECL_LINKAGE_SPEC:
3853 D = LinkageSpecDecl::CreateDeserialized(Context, ID);
3854 break;
3855 case DECL_EXPORT:
3856 D = ExportDecl::CreateDeserialized(Context, ID);
3857 break;
3858 case DECL_LABEL:
3859 D = LabelDecl::CreateDeserialized(Context, ID);
3860 break;
3861 case DECL_NAMESPACE:
3862 D = NamespaceDecl::CreateDeserialized(Context, ID);
3863 break;
3866 break;
3867 case DECL_USING:
3868 D = UsingDecl::CreateDeserialized(Context, ID);
3869 break;
3870 case DECL_USING_PACK:
3871 D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt());
3872 break;
3873 case DECL_USING_SHADOW:
3874 D = UsingShadowDecl::CreateDeserialized(Context, ID);
3875 break;
3876 case DECL_USING_ENUM:
3877 D = UsingEnumDecl::CreateDeserialized(Context, ID);
3878 break;
3881 break;
3884 break;
3887 break;
3890 break;
3893 break;
3894 case DECL_CXX_RECORD:
3895 D = CXXRecordDecl::CreateDeserialized(Context, ID);
3896 break;
3899 break;
3900 case DECL_CXX_METHOD:
3901 D = CXXMethodDecl::CreateDeserialized(Context, ID);
3902 break;
3904 D = CXXConstructorDecl::CreateDeserialized(Context, ID, Record.readInt());
3905 break;
3908 break;
3911 break;
3912 case DECL_ACCESS_SPEC:
3913 D = AccessSpecDecl::CreateDeserialized(Context, ID);
3914 break;
3915 case DECL_FRIEND:
3916 D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt());
3917 break;
3920 break;
3923 break;
3926 break;
3929 break;
3930 case DECL_VAR_TEMPLATE:
3931 D = VarTemplateDecl::CreateDeserialized(Context, ID);
3932 break;
3935 break;
3938 break;
3941 break;
3943 bool HasTypeConstraint = Record.readInt();
3945 HasTypeConstraint);
3946 break;
3947 }
3949 bool HasTypeConstraint = Record.readInt();
3951 HasTypeConstraint);
3952 break;
3953 }
3955 bool HasTypeConstraint = Record.readInt();
3957 Record.readInt(),
3958 HasTypeConstraint);
3959 break;
3960 }
3963 break;
3966 Record.readInt());
3967 break;
3970 break;
3971 case DECL_CONCEPT:
3972 D = ConceptDecl::CreateDeserialized(Context, ID);
3973 break;
3976 break;
3977 case DECL_STATIC_ASSERT:
3978 D = StaticAssertDecl::CreateDeserialized(Context, ID);
3979 break;
3980 case DECL_OBJC_METHOD:
3981 D = ObjCMethodDecl::CreateDeserialized(Context, ID);
3982 break;
3985 break;
3986 case DECL_OBJC_IVAR:
3987 D = ObjCIvarDecl::CreateDeserialized(Context, ID);
3988 break;
3989 case DECL_OBJC_PROTOCOL:
3990 D = ObjCProtocolDecl::CreateDeserialized(Context, ID);
3991 break;
3994 break;
3995 case DECL_OBJC_CATEGORY:
3996 D = ObjCCategoryDecl::CreateDeserialized(Context, ID);
3997 break;
4000 break;
4003 break;
4006 break;
4007 case DECL_OBJC_PROPERTY:
4008 D = ObjCPropertyDecl::CreateDeserialized(Context, ID);
4009 break;
4012 break;
4013 case DECL_FIELD:
4014 D = FieldDecl::CreateDeserialized(Context, ID);
4015 break;
4016 case DECL_INDIRECTFIELD:
4018 break;
4019 case DECL_VAR:
4020 D = VarDecl::CreateDeserialized(Context, ID);
4021 break;
4024 break;
4025 case DECL_PARM_VAR:
4026 D = ParmVarDecl::CreateDeserialized(Context, ID);
4027 break;
4028 case DECL_DECOMPOSITION:
4029 D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt());
4030 break;
4031 case DECL_BINDING:
4032 D = BindingDecl::CreateDeserialized(Context, ID);
4033 break;
4035 D = FileScopeAsmDecl::CreateDeserialized(Context, ID);
4036 break;
4038 D = TopLevelStmtDecl::CreateDeserialized(Context, ID);
4039 break;
4040 case DECL_BLOCK:
4041 D = BlockDecl::CreateDeserialized(Context, ID);
4042 break;
4043 case DECL_MS_PROPERTY:
4044 D = MSPropertyDecl::CreateDeserialized(Context, ID);
4045 break;
4046 case DECL_MS_GUID:
4047 D = MSGuidDecl::CreateDeserialized(Context, ID);
4048 break;
4050 D = UnnamedGlobalConstantDecl::CreateDeserialized(Context, ID);
4051 break;
4053 D = TemplateParamObjectDecl::CreateDeserialized(Context, ID);
4054 break;
4055 case DECL_CAPTURED:
4056 D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt());
4057 break;
4059 Error("attempt to read a C++ base-specifier record as a declaration");
4060 return nullptr;
4062 Error("attempt to read a C++ ctor initializer record as a declaration");
4063 return nullptr;
4064 case DECL_IMPORT:
4065 // Note: last entry of the ImportDecl record is the number of stored source
4066 // locations.
4067 D = ImportDecl::CreateDeserialized(Context, ID, Record.back());
4068 break;
4070 Record.skipInts(1);
4071 unsigned NumChildren = Record.readInt();
4072 Record.skipInts(1);
4073 D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, NumChildren);
4074 break;
4075 }
4076 case DECL_OMP_ALLOCATE: {
4077 unsigned NumClauses = Record.readInt();
4078 unsigned NumVars = Record.readInt();
4079 Record.skipInts(1);
4080 D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses);
4081 break;
4082 }
4083 case DECL_OMP_REQUIRES: {
4084 unsigned NumClauses = Record.readInt();
4085 Record.skipInts(2);
4086 D = OMPRequiresDecl::CreateDeserialized(Context, ID, NumClauses);
4087 break;
4088 }
4091 break;
4093 unsigned NumClauses = Record.readInt();
4094 Record.skipInts(2);
4095 D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, NumClauses);
4096 break;
4097 }
4100 break;
4102 D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt());
4103 break;
4106 Record.readInt());
4107 break;
4108 case DECL_EMPTY:
4109 D = EmptyDecl::CreateDeserialized(Context, ID);
4110 break;
4113 break;
4116 break;
4117 case DECL_HLSL_BUFFER:
4118 D = HLSLBufferDecl::CreateDeserialized(Context, ID);
4119 break;
4122 Record.readInt());
4123 break;
4124 }
4125
4126 assert(D && "Unknown declaration reading AST file");
4127 LoadedDecl(Index, D);
4128 // Set the DeclContext before doing any deserialization, to make sure internal
4129 // calls to Decl::getASTContext() by Decl's methods will find the
4130 // TranslationUnitDecl without crashing.
4132 Reader.Visit(D);
4133
4134 // If this declaration is also a declaration context, get the
4135 // offsets for its tables of lexical and visible declarations.
4136 if (auto *DC = dyn_cast<DeclContext>(D)) {
4137 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
4138
4139 // Get the lexical and visible block for the delayed namespace.
4140 // It is sufficient to judge if ID is in DelayedNamespaceOffsetMap.
4141 // But it may be more efficient to filter the other cases.
4142 if (!Offsets.first && !Offsets.second && isa<NamespaceDecl>(D))
4143 if (auto Iter = DelayedNamespaceOffsetMap.find(ID);
4144 Iter != DelayedNamespaceOffsetMap.end())
4145 Offsets = Iter->second;
4146
4147 if (Offsets.first &&
4148 ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
4149 return nullptr;
4150 if (Offsets.second &&
4151 ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
4152 return nullptr;
4153 }
4154 assert(Record.getIdx() == Record.size());
4155
4156 // Load any relevant update records.
4157 PendingUpdateRecords.push_back(
4158 PendingUpdateRecord(ID, D, /*JustLoaded=*/true));
4159
4160 // Load the categories after recursive loading is finished.
4161 if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
4162 // If we already have a definition when deserializing the ObjCInterfaceDecl,
4163 // we put the Decl in PendingDefinitions so we can pull the categories here.
4164 if (Class->isThisDeclarationADefinition() ||
4165 PendingDefinitions.count(Class))
4166 loadObjCCategories(ID, Class);
4167
4168 // If we have deserialized a declaration that has a definition the
4169 // AST consumer might need to know about, queue it.
4170 // We don't pass it to the consumer immediately because we may be in recursive
4171 // loading, and some declarations may still be initializing.
4172 PotentiallyInterestingDecls.push_back(D);
4173
4174 return D;
4175}
4176
4177void ASTReader::PassInterestingDeclsToConsumer() {
4178 assert(Consumer);
4179
4180 if (PassingDeclsToConsumer)
4181 return;
4182
4183 // Guard variable to avoid recursively redoing the process of passing
4184 // decls to consumer.
4185 SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer, true);
4186
4187 // Ensure that we've loaded all potentially-interesting declarations
4188 // that need to be eagerly loaded.
4189 for (auto ID : EagerlyDeserializedDecls)
4190 GetDecl(ID);
4191 EagerlyDeserializedDecls.clear();
4192
4193 while (!PotentiallyInterestingDecls.empty()) {
4194 Decl *D = PotentiallyInterestingDecls.front();
4195 PotentiallyInterestingDecls.pop_front();
4196 if (isConsumerInterestedIn(D))
4197 PassInterestingDeclToConsumer(D);
4198 }
4199}
4200
4201void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
4202 // The declaration may have been modified by files later in the chain.
4203 // If this is the case, read the record containing the updates from each file
4204 // and pass it to ASTDeclReader to make the modifications.
4206 Decl *D = Record.D;
4207 ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
4208 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
4209
4210 SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs;
4211
4212 if (UpdI != DeclUpdateOffsets.end()) {
4213 auto UpdateOffsets = std::move(UpdI->second);
4214 DeclUpdateOffsets.erase(UpdI);
4215
4216 // Check if this decl was interesting to the consumer. If we just loaded
4217 // the declaration, then we know it was interesting and we skip the call
4218 // to isConsumerInterestedIn because it is unsafe to call in the
4219 // current ASTReader state.
4220 bool WasInteresting = Record.JustLoaded || isConsumerInterestedIn(D);
4221 for (auto &FileAndOffset : UpdateOffsets) {
4222 ModuleFile *F = FileAndOffset.first;
4223 uint64_t Offset = FileAndOffset.second;
4224 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
4225 SavedStreamPosition SavedPosition(Cursor);
4226 if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset))
4227 // FIXME don't do a fatal error.
4228 llvm::report_fatal_error(
4229 Twine("ASTReader::loadDeclUpdateRecords failed jumping: ") +
4230 toString(std::move(JumpFailed)));
4231 Expected<unsigned> MaybeCode = Cursor.ReadCode();
4232 if (!MaybeCode)
4233 llvm::report_fatal_error(
4234 Twine("ASTReader::loadDeclUpdateRecords failed reading code: ") +
4235 toString(MaybeCode.takeError()));
4236 unsigned Code = MaybeCode.get();
4237 ASTRecordReader Record(*this, *F);
4238 if (Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code))
4239 assert(MaybeRecCode.get() == DECL_UPDATES &&
4240 "Expected DECL_UPDATES record!");
4241 else
4242 llvm::report_fatal_error(
4243 Twine("ASTReader::loadDeclUpdateRecords failed reading rec code: ") +
4244 toString(MaybeCode.takeError()));
4245
4246 ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID,
4247 SourceLocation());
4248 Reader.UpdateDecl(D, PendingLazySpecializationIDs);
4249
4250 // We might have made this declaration interesting. If so, remember that
4251 // we need to hand it off to the consumer.
4252 if (!WasInteresting && isConsumerInterestedIn(D)) {
4253 PotentiallyInterestingDecls.push_back(D);
4254 WasInteresting = true;
4255 }
4256 }
4257 }
4258 // Add the lazy specializations to the template.
4259 assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||
4260 isa<FunctionTemplateDecl, VarTemplateDecl>(D)) &&
4261 "Must not have pending specializations");
4262 if (auto *CTD = dyn_cast<ClassTemplateDecl>(D))
4263 ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs);
4264 else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
4265 ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs);
4266 else if (auto *VTD = dyn_cast<VarTemplateDecl>(D))
4267 ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs);
4268 PendingLazySpecializationIDs.clear();
4269
4270 // Load the pending visible updates for this decl context, if it has any.
4271 auto I = PendingVisibleUpdates.find(ID);
4272 if (I != PendingVisibleUpdates.end()) {
4273 auto VisibleUpdates = std::move(I->second);
4274 PendingVisibleUpdates.erase(I);
4275
4276 auto *DC = cast<DeclContext>(D)->getPrimaryContext();
4277 for (const auto &Update : VisibleUpdates)
4278 Lookups[DC].Table.add(
4279 Update.Mod, Update.Data,
4282 }
4283}
4284
4285void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
4286 // Attach FirstLocal to the end of the decl chain.
4287 Decl *CanonDecl = FirstLocal->getCanonicalDecl();
4288 if (FirstLocal != CanonDecl) {
4289 Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl);
4291 *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
4292 CanonDecl);
4293 }
4294
4295 if (!LocalOffset) {
4296 ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal);
4297 return;
4298 }
4299
4300 // Load the list of other redeclarations from this module file.
4301 ModuleFile *M = getOwningModuleFile(FirstLocal);
4302 assert(M && "imported decl from no module file");
4303
4304 llvm::BitstreamCursor &Cursor = M->DeclsCursor;
4305 SavedStreamPosition SavedPosition(Cursor);
4306 if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset))
4307 llvm::report_fatal_error(
4308 Twine("ASTReader::loadPendingDeclChain failed jumping: ") +
4309 toString(std::move(JumpFailed)));
4310
4312 Expected<unsigned> MaybeCode = Cursor.ReadCode();
4313 if (!MaybeCode)
4314 llvm::report_fatal_error(
4315 Twine("ASTReader::loadPendingDeclChain failed reading code: ") +
4316 toString(MaybeCode.takeError()));
4317 unsigned Code = MaybeCode.get();
4318 if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record))
4319 assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS &&
4320 "expected LOCAL_REDECLARATIONS record!");
4321 else
4322 llvm::report_fatal_error(
4323 Twine("ASTReader::loadPendingDeclChain failed reading rec code: ") +
4324 toString(MaybeCode.takeError()));
4325
4326 // FIXME: We have several different dispatches on decl kind here; maybe
4327 // we should instead generate one loop per kind and dispatch up-front?
4328 Decl *MostRecent = FirstLocal;
4329 for (unsigned I = 0, N = Record.size(); I != N; ++I) {
4330 auto *D = GetLocalDecl(*M, Record[N - I - 1]);
4331 ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl);
4332 MostRecent = D;
4333 }
4334 ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);
4335}
4336
4337namespace {
4338
4339 /// Given an ObjC interface, goes through the modules and links to the
4340 /// interface all the categories for it.
4341 class ObjCCategoriesVisitor {
4342 ASTReader &Reader;
4344 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
4345 ObjCCategoryDecl *Tail = nullptr;
4346 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
4347 serialization::GlobalDeclID InterfaceID;
4348 unsigned PreviousGeneration;
4349
4350 void add(ObjCCategoryDecl *Cat) {
4351 // Only process each category once.
4352 if (!Deserialized.erase(Cat))
4353 return;
4354
4355 // Check for duplicate categories.
4356 if (Cat->getDeclName()) {
4357 ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()];
4358 if (Existing && Reader.getOwningModuleFile(Existing) !=
4359 Reader.getOwningModuleFile(Cat)) {
4360 llvm::DenseSet<std::pair<Decl *, Decl *>> NonEquivalentDecls;
4362 Cat->getASTContext(), Existing->getASTContext(),
4363 NonEquivalentDecls, StructuralEquivalenceKind::Default,
4364 /*StrictTypeSpelling =*/false,
4365 /*Complain =*/false,
4366 /*ErrorOnTagTypeMismatch =*/true);
4367 if (!Ctx.IsEquivalent(Cat, Existing)) {
4368 // Warn only if the categories with the same name are different.
4369 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
4370 << Interface->getDeclName() << Cat->getDeclName();
4371 Reader.Diag(Existing->getLocation(),
4372 diag::note_previous_definition);
4373 }
4374 } else if (!Existing) {
4375 // Record this category.
4376 Existing = Cat;
4377 }
4378 }
4379
4380 // Add this category to the end of the chain.
4381 if (Tail)
4383 else
4384 Interface->setCategoryListRaw(Cat);
4385 Tail = Cat;
4386 }
4387
4388 public:
4389 ObjCCategoriesVisitor(ASTReader &Reader,
4391 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
4392 serialization::GlobalDeclID InterfaceID,
4393 unsigned PreviousGeneration)
4394 : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
4395 InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) {
4396 // Populate the name -> category map with the set of known categories.
4397 for (auto *Cat : Interface->known_categories()) {
4398 if (Cat->getDeclName())
4399 NameCategoryMap[Cat->getDeclName()] = Cat;
4400
4401 // Keep track of the tail of the category list.
4402 Tail = Cat;
4403 }
4404 }
4405
4406 bool operator()(ModuleFile &M) {
4407 // If we've loaded all of the category information we care about from
4408 // this module file, we're done.
4409 if (M.Generation <= PreviousGeneration)
4410 return true;
4411
4412 // Map global ID of the definition down to the local ID used in this
4413 // module file. If there is no such mapping, we'll find nothing here
4414 // (or in any module it imports).
4415 DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID);
4416 if (!LocalID)
4417 return true;
4418
4419 // Perform a binary search to find the local redeclarations for this
4420 // declaration (if any).
4421 const ObjCCategoriesInfo Compare = { LocalID, 0 };
4422 const ObjCCategoriesInfo *Result
4423 = std::lower_bound(M.ObjCCategoriesMap,
4425 Compare);
4426 if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap ||
4427 Result->DefinitionID != LocalID) {
4428 // We didn't find anything. If the class definition is in this module
4429 // file, then the module files it depends on cannot have any categories,
4430 // so suppress further lookup.
4431 return Reader.isDeclIDFromModule(InterfaceID, M);
4432 }
4433
4434 // We found something. Dig out all of the categories.
4435 unsigned Offset = Result->Offset;
4436 unsigned N = M.ObjCCategories[Offset];
4437 M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again
4438 for (unsigned I = 0; I != N; ++I)
4439 add(cast_or_null<ObjCCategoryDecl>(
4440 Reader.GetLocalDecl(M, M.ObjCCategories[Offset++])));
4441 return true;
4442 }
4443 };
4444
4445} // namespace
4446
4447void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID,
4449 unsigned PreviousGeneration) {
4450 ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID,
4451 PreviousGeneration);
4452 ModuleMgr.visit(Visitor);
4453}
4454
4455template<typename DeclT, typename Fn>
4456static void forAllLaterRedecls(DeclT *D, Fn F) {
4457 F(D);
4458
4459 // Check whether we've already merged D into its redeclaration chain.
4460 // MostRecent may or may not be nullptr if D has not been merged. If
4461 // not, walk the merged redecl chain and see if it's there.
4462 auto *MostRecent = D->getMostRecentDecl();
4463 bool Found = false;
4464 for (auto *Redecl = MostRecent; Redecl && !Found;
4465 Redecl = Redecl->getPreviousDecl())
4466 Found = (Redecl == D);
4467
4468 // If this declaration is merged, apply the functor to all later decls.
4469 if (Found) {
4470 for (auto *Redecl = MostRecent; Redecl != D;
4471 Redecl = Redecl->getPreviousDecl())
4472 F(Redecl);
4473 }
4474}
4475
4477 llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) {
4478 while (Record.getIdx() < Record.size()) {
4479 switch ((DeclUpdateKind)Record.readInt()) {
4481 auto *RD = cast<CXXRecordDecl>(D);
4482 Decl *MD = Record.readDecl();
4483 assert(MD && "couldn't read decl from update record");
4484 Reader.PendingAddedClassMembers.push_back({RD, MD});
4485 break;
4486 }
4487
4489 // It will be added to the template's lazy specialization set.
4490 PendingLazySpecializationIDs.push_back(readDeclID());
4491 break;
4492
4494 auto *Anon = readDeclAs<NamespaceDecl>();
4495
4496 // Each module has its own anonymous namespace, which is disjoint from
4497 // any other module's anonymous namespaces, so don't attach the anonymous
4498 // namespace at all.
4499 if (!Record.isModule()) {
4500 if (auto *TU = dyn_cast<TranslationUnitDecl>(D))
4501 TU->setAnonymousNamespace(Anon);
4502 else
4503 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
4504 }
4505 break;
4506 }
4507
4509 auto *VD = cast<VarDecl>(D);
4510 VD->NonParmVarDeclBits.IsInline = Record.readInt();
4511 VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
4512 ReadVarDeclInit(VD);
4513 break;
4514 }
4515
4517 SourceLocation POI = Record.readSourceLocation();
4518 if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
4519 VTSD->setPointOfInstantiation(POI);
4520 } else if (auto *VD = dyn_cast<VarDecl>(D)) {
4521 MemberSpecializationInfo *MSInfo = VD->getMemberSpecializationInfo();
4522 assert(MSInfo && "No member specialization information");
4523 MSInfo->setPointOfInstantiation(POI);
4524 } else {
4525 auto *FD = cast<FunctionDecl>(D);
4526 if (auto *FTSInfo = FD->TemplateOrSpecialization
4528 FTSInfo->setPointOfInstantiation(POI);
4529 else
4530 FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>()
4531 ->setPointOfInstantiation(POI);
4532 }
4533 break;
4534 }
4535
4537 auto *Param = cast<ParmVarDecl>(D);
4538
4539 // We have to read the default argument regardless of whether we use it
4540 // so that hypothetical further update records aren't messed up.
4541 // TODO: Add a function to skip over the next expr record.
4542 auto *DefaultArg = Record.readExpr();
4543
4544 // Only apply the update if the parameter still has an uninstantiated
4545 // default argument.
4546 if (Param->hasUninstantiatedDefaultArg())
4547 Param->setDefaultArg(DefaultArg);
4548 break;
4549 }
4550
4552 auto *FD = cast<FieldDecl>(D);
4553 auto *DefaultInit = Record.readExpr();
4554
4555 // Only apply the update if the field still has an uninstantiated
4556 // default member initializer.
4557 if (FD->hasInClassInitializer() && !FD->hasNonNullInClassInitializer()) {
4558 if (DefaultInit)
4559 FD->setInClassInitializer(DefaultInit);
4560 else
4561 // Instantiation failed. We can get here if we serialized an AST for
4562 // an invalid program.
4563 FD->removeInClassInitializer();
4564 }
4565 break;
4566 }
4567
4569 auto *FD = cast<FunctionDecl>(D);
4570 if (Reader.PendingBodies[FD]) {
4571 // FIXME: Maybe check for ODR violations.
4572 // It's safe to stop now because this update record is always last.
4573 return;
4574 }
4575
4576 if (Record.readInt()) {
4577 // Maintain AST consistency: any later redeclarations of this function
4578 // are inline if this one is. (We might have merged another declaration
4579 // into this one.)
4580 forAllLaterRedecls(FD, [](FunctionDecl *FD) {
4581 FD->setImplicitlyInline();
4582 });
4583 }
4584 FD->setInnerLocStart(readSourceLocation());
4586 assert(Record.getIdx() == Record.size() && "lazy body must be last");
4587 break;
4588 }
4589
4591 auto *RD = cast<CXXRecordDecl>(D);
4592 auto *OldDD = RD->getCanonicalDecl()->DefinitionData;
4593 bool HadRealDefinition =
4594 OldDD && (OldDD->Definition != RD ||
4595 !Reader.PendingFakeDefinitionData.count(OldDD));
4596 RD->setParamDestroyedInCallee(Record.readInt());
4598 static_cast<RecordArgPassingKind>(Record.readInt()));
4599 ReadCXXRecordDefinition(RD, /*Update*/true);
4600
4601 // Visible update is handled separately.
4602 uint64_t LexicalOffset = ReadLocalOffset();
4603 if (!HadRealDefinition && LexicalOffset) {
4604 Record.readLexicalDeclContextStorage(LexicalOffset, RD);
4605 Reader.PendingFakeDefinitionData.erase(OldDD);
4606 }
4607
4608 auto TSK = (TemplateSpecializationKind)Record.readInt();
4609 SourceLocation POI = readSourceLocation();
4610 if (MemberSpecializationInfo *MSInfo =
4612 MSInfo->setTemplateSpecializationKind(TSK);
4613 MSInfo->setPointOfInstantiation(POI);
4614 } else {
4615 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
4616 Spec->setTemplateSpecializationKind(TSK);
4617 Spec->setPointOfInstantiation(POI);
4618
4619 if (Record.readInt()) {
4620 auto *PartialSpec =
4621 readDeclAs<ClassTemplatePartialSpecializationDecl>();
4623 Record.readTemplateArgumentList(TemplArgs);
4624 auto *TemplArgList = TemplateArgumentList::CreateCopy(
4625 Reader.getContext(), TemplArgs);
4626
4627 // FIXME: If we already have a partial specialization set,
4628 // check that it matches.
4629 if (!Spec->getSpecializedTemplateOrPartial()
4631 Spec->setInstantiationOf(PartialSpec, TemplArgList);
4632 }
4633 }
4634
4635 RD->setTagKind(static_cast<TagTypeKind>(Record.readInt()));
4636 RD->setLocation(readSourceLocation());
4637 RD->setLocStart(readSourceLocation());
4638 RD->setBraceRange(readSourceRange());
4639
4640 if (Record.readInt()) {
4641 AttrVec Attrs;
4642 Record.readAttributes(Attrs);
4643 // If the declaration already has attributes, we assume that some other
4644 // AST file already loaded them.
4645 if (!D->hasAttrs())
4646 D->setAttrsImpl(Attrs, Reader.getContext());
4647 }
4648 break;
4649 }
4650
4652 // Set the 'operator delete' directly to avoid emitting another update
4653 // record.
4654 auto *Del = readDeclAs<FunctionDecl>();
4655 auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl());
4656 auto *ThisArg = Record.readExpr();
4657 // FIXME: Check consistency if we have an old and new operator delete.
4658 if (!First->OperatorDelete) {
4659 First->OperatorDelete = Del;
4660 First->OperatorDeleteThisArg = ThisArg;
4661 }
4662 break;
4663 }
4664
4666 SmallVector<QualType, 8> ExceptionStorage;
4667 auto ESI = Record.readExceptionSpecInfo(ExceptionStorage);
4668
4669 // Update this declaration's exception specification, if needed.
4670 auto *FD = cast<FunctionDecl>(D);
4671 auto *FPT = FD->getType()->castAs<FunctionProtoType>();
4672 // FIXME: If the exception specification is already present, check that it
4673 // matches.
4674 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) {
4675 FD->setType(Reader.getContext().getFunctionType(
4676 FPT->getReturnType(), FPT->getParamTypes(),
4677 FPT->getExtProtoInfo().withExceptionSpec(ESI)));
4678
4679 // When we get to the end of deserializing, see if there are other decls
4680 // that we need to propagate this exception specification onto.
4681 Reader.PendingExceptionSpecUpdates.insert(
4682 std::make_pair(FD->getCanonicalDecl(), FD));
4683 }
4684 break;
4685 }
4686
4688 auto *FD = cast<FunctionDecl>(D);
4689 QualType DeducedResultType = Record.readType();
4690 Reader.PendingDeducedTypeUpdates.insert(
4691 {FD->getCanonicalDecl(), DeducedResultType});
4692 break;
4693 }
4694
4696 // Maintain AST consistency: any later redeclarations are used too.
4697 D->markUsed(Reader.getContext());
4698 break;
4699
4701 Reader.getContext().setManglingNumber(cast<NamedDecl>(D),
4702 Record.readInt());
4703 break;
4704
4706 Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D),
4707 Record.readInt());
4708 break;
4709
4711 D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(),
4712 readSourceRange()));
4713 break;
4714
4716 auto AllocatorKind =
4717 static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(Record.readInt());
4718 Expr *Allocator = Record.readExpr();
4719 Expr *Alignment = Record.readExpr();
4720 SourceRange SR = readSourceRange();
4721 D->addAttr(OMPAllocateDeclAttr::CreateImplicit(
4722 Reader.getContext(), AllocatorKind, Allocator, Alignment, SR));
4723 break;
4724 }
4725
4726 case UPD_DECL_EXPORTED: {
4727 unsigned SubmoduleID = readSubmoduleID();
4728 auto *Exported = cast<NamedDecl>(D);
4729 Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr;
4730 Reader.getContext().mergeDefinitionIntoModule(Exported, Owner);
4731 Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported);
4732 break;
4733 }
4734
4736 auto MapType = Record.readEnum<OMPDeclareTargetDeclAttr::MapTypeTy>();
4737 auto DevType = Record.readEnum<OMPDeclareTargetDeclAttr::DevTypeTy>();
4738 Expr *IndirectE = Record.readExpr();
4739 bool Indirect = Record.readBool();
4740 unsigned Level = Record.readInt();
4741 D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(
4742 Reader.getContext(), MapType, DevType, IndirectE, Indirect, Level,
4743 readSourceRange()));
4744 break;
4745 }
4746
4748 AttrVec Attrs;
4749 Record.readAttributes(Attrs);
4750 assert(Attrs.size() == 1);
4751 D->addAttr(Attrs[0]);
4752 break;
4753 }
4754 }
4755}
This file provides AST data structures related to concepts.
Defines the clang::ASTContext interface.
#define V(N, I)
Definition: ASTContext.h:3273
static T assert_cast(T t)
"Cast" to type T, asserting if we don't have an implicit conversion.
static bool allowODRLikeMergeInC(NamedDecl *ND)
ODR-like semantics for C/ObjC allow us to merge tag types and a structural check in Sema guarantees t...
static NamedDecl * getDeclForMerging(NamedDecl *Found, bool IsTypedefNameForLinkage)
Find the declaration that should be merged into, given the declaration found by name lookup.
static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, Decl *ToD)
Inherit the default template argument from From to To.
static void inheritDefaultTemplateArguments(ASTContext &Context, TemplateDecl *From, TemplateDecl *To)
static void forAllLaterRedecls(DeclT *D, Fn F)
static llvm::iterator_range< MergedRedeclIterator< DeclT > > merged_redecls(DeclT *D)
#define NO_MERGE(Field)
static char ID
Definition: Arena.cpp:183
Defines the clang::attr::Kind enum.
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition: CharUnits.h:225
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines OpenMP nodes for declarative directives.
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
unsigned Iter
Definition: HTMLLogger.cpp:154
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines several types used to describe C++ lambda expressions that are shared between the parser and ...
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:30
Defines the clang::Module class, which describes a module in the source code.
This file defines OpenMP AST classes for clauses.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
C Language Family Type Representation.
StateNode * Previous
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
bool needsCleanup() const
Returns whether the object performed allocations.
Definition: APValue.cpp:431
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1073
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
const LangOptions & getLangOpts() const
Definition: ASTContext.h:775
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
void addOverriddenMethod(const CXXMethodDecl *Method, const CXXMethodDecl *Overridden)
Note that the given C++ Method overrides the given Overridden method.
void setManglingNumber(const NamedDecl *ND, unsigned Number)
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:718
TypeSourceInfo * CreateTypeSourceInfo(QualType T, unsigned Size=0) const
Allocate an uninitialized TypeSourceInfo.
void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl, TemplateSpecializationKind TSK, SourceLocation PointOfInstantiation=SourceLocation())
Note that the static data member Inst is an instantiation of the static data member template Tmpl of ...
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1567
void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl)
void setBlockVarCopyInit(const VarDecl *VD, Expr *CopyExpr, bool CanThrow)
Set the copy initialization expression of a block var decl.
void addDestruction(T *Ptr) const
If T isn't trivially destructible, calls AddDeallocation to register it for destruction.
Definition: ASTContext.h:3100
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1187
void mergeDefinitionIntoModule(NamedDecl *ND, Module *M, bool NotifyListeners=true)
Note that the definition ND has been merged into module M, and should be visible whenever M is visibl...
void setPrimaryMergedDecl(Decl *D, Decl *Primary)
Definition: ASTContext.h:1039
void setObjCMethodRedeclaration(const ObjCMethodDecl *MD, const ObjCMethodDecl *Redecl)
void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D)
void VisitObjCImplementationDecl(ObjCImplementationDecl *D)
void mergeRedeclarableTemplate(RedeclarableTemplateDecl *D, RedeclarableResult &Redecl)
void VisitImportDecl(ImportDecl *D)
void VisitBindingDecl(BindingDecl *BD)
void VisitNamespaceDecl(NamespaceDecl *D)
void VisitTopLevelStmtDecl(TopLevelStmtDecl *D)
void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D)
void ReadFunctionDefinition(FunctionDecl *FD)
void VisitLabelDecl(LabelDecl *LD)
void VisitObjCCategoryDecl(ObjCCategoryDecl *D)
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
void VisitFunctionDecl(FunctionDecl *FD)
void VisitObjCMethodDecl(ObjCMethodDecl *D)
void VisitUsingShadowDecl(UsingShadowDecl *D)
void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
void VisitVarDecl(VarDecl *VD)
RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD)
void VisitMSGuidDecl(MSGuidDecl *D)
void VisitPragmaCommentDecl(PragmaCommentDecl *D)
void VisitRecordDecl(RecordDecl *RD)
void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D)
void ReadVarDeclInit(VarDecl *VD)
RedeclarableResult VisitClassTemplateSpecializationDeclImpl(ClassTemplateSpecializationDecl *D)
static Decl * getMostRecentDeclImpl(Redeclarable< DeclT > *D)
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
void VisitIndirectFieldDecl(IndirectFieldDecl *FD)
void VisitObjCContainerDecl(ObjCContainerDecl *D)
void VisitBlockDecl(BlockDecl *BD)
void VisitExportDecl(ExportDecl *D)
static void attachLatestDecl(Decl *D, Decl *latest)
void VisitStaticAssertDecl(StaticAssertDecl *D)
static void AddLazySpecializations(T *D, SmallVectorImpl< serialization::DeclID > &IDs)
void VisitEmptyDecl(EmptyDecl *D)
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D)
void VisitValueDecl(ValueDecl *VD)
RedeclarableResult VisitRedeclarable(Redeclarable< T > *D)
void VisitEnumDecl(EnumDecl *ED)
void mergeRedeclarable(Redeclarable< T > *D, RedeclarableResult &Redecl)
Attempts to merge the given declaration (D) with another declaration of the same entity.
void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
void VisitFriendTemplateDecl(FriendTemplateDecl *D)
void VisitObjCProtocolDecl(ObjCProtocolDecl *D)
void VisitClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl *D)
void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
void VisitDeclaratorDecl(DeclaratorDecl *DD)
RedeclarableResult VisitTagDecl(TagDecl *TD)
void UpdateDecl(Decl *D, SmallVectorImpl< serialization::DeclID > &)
void VisitFriendDecl(FriendDecl *D)
void VisitLinkageSpecDecl(LinkageSpecDecl *D)
void VisitCXXRecordDecl(CXXRecordDecl *D)
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD)
void VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
void VisitNamedDecl(NamedDecl *ND)
void mergeMergeable(Mergeable< T > *D)
Attempts to merge the given declaration (D) with another declaration of the same entity,...
void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
static Decl * getMostRecentDecl(Decl *D)
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D)
void VisitCXXConstructorDecl(CXXConstructorDecl *D)
void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D)
void VisitImplicitParamDecl(ImplicitParamDecl *PD)
void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
static void setNextObjCCategory(ObjCCategoryDecl *Cat, ObjCCategoryDecl *Next)
RedeclarableResult VisitVarDeclImpl(VarDecl *D)
void VisitMSPropertyDecl(MSPropertyDecl *FD)
void mergeTemplatePattern(RedeclarableTemplateDecl *D, RedeclarableTemplateDecl *Existing, bool IsKeyDecl)
Merge together the pattern declarations from two template declarations.
void VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
void VisitFieldDecl(FieldDecl *FD)
void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D)
void VisitCapturedDecl(CapturedDecl *CD)
void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D)
void VisitAccessSpecDecl(AccessSpecDecl *D)
void VisitCXXMethodDecl(CXXMethodDecl *D)
void VisitOMPAllocateDecl(OMPAllocateDecl *D)
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
static void attachLatestDeclImpl(Redeclarable< DeclT > *D, Decl *Latest)
static void markIncompleteDeclChainImpl(Redeclarable< DeclT > *D)
ObjCTypeParamList * ReadObjCTypeParamList()
void VisitHLSLBufferDecl(HLSLBufferDecl *D)
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D)
void VisitDecl(Decl *D)
void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD)
void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D)
RedeclarableResult VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D)
TODO: Unify with ClassTemplateSpecializationDecl version? May require unifying ClassTemplate(Partial)...
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
void VisitUsingEnumDecl(UsingEnumDecl *D)
void VisitObjCImplDecl(ObjCImplDecl *D)
void VisitTranslationUnitDecl(TranslationUnitDecl *TU)
RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D)
void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D)
void VisitTypeDecl(TypeDecl *TD)
RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD)
void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
void VisitEnumConstantDecl(EnumConstantDecl *ECD)