58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/FoldingSet.h"
60#include "llvm/ADT/STLExtras.h"
61#include "llvm/ADT/SmallPtrSet.h"
62#include "llvm/ADT/SmallVector.h"
63#include "llvm/ADT/iterator_range.h"
64#include "llvm/Bitstream/BitstreamReader.h"
65#include "llvm/Support/Casting.h"
66#include "llvm/Support/ErrorHandling.h"
67#include "llvm/Support/SaveAndRestore.h"
76using namespace serialization;
87 ASTReader::RecordLocation Loc;
94 unsigned AnonymousDeclNumber = 0;
101 bool IsDeclMarkedUsed =
false;
103 uint64_t GetCurrentCursorOffset();
105 uint64_t ReadLocalOffset() {
106 uint64_t LocalOffset =
Record.readInt();
107 assert(LocalOffset <
Loc.Offset &&
"offset point after current record");
108 return LocalOffset ?
Loc.Offset - LocalOffset : 0;
111 uint64_t ReadGlobalOffset() {
112 uint64_t Local = ReadLocalOffset();
113 return Local ?
Record.getGlobalBitOffset(Local) : 0;
117 return Record.readSourceLocation();
121 return Record.readSourceRange();
125 return Record.readTypeSourceInfo();
130 std::string readString() {
131 return Record.readString();
135 for (
unsigned I = 0, Size =
Record.readInt(); I != Size; ++I)
136 IDs.push_back(readDeclID());
156 return Record.getSubmodule(readSubmoduleID());
160 Decl *LambdaContext =
nullptr,
161 unsigned IndexInLambdaContext = 0);
162 void ReadCXXDefinitionData(
struct CXXRecordDecl::DefinitionData &
Data,
164 unsigned IndexInLambdaContext);
166 struct CXXRecordDecl::DefinitionData &&NewDD);
167 void ReadObjCDefinitionData(
struct ObjCInterfaceDecl::DefinitionData &
Data);
169 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
170 void ReadObjCDefinitionData(
struct ObjCProtocolDecl::DefinitionData &
Data);
172 struct ObjCProtocolDecl::DefinitionData &&NewDD);
190 class RedeclarableResult {
197 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
203 bool isKeyDecl()
const {
return IsKeyDecl; }
207 Decl *getKnownMergeTarget()
const {
return MergeWith; }
215 class FindExistingResult {
219 bool AddResult =
false;
220 unsigned AnonymousDeclNumber = 0;
224 FindExistingResult(
ASTReader &Reader) : Reader(Reader) {}
227 unsigned AnonymousDeclNumber,
229 : Reader(Reader), New(New), Existing(Existing), AddResult(
true),
230 AnonymousDeclNumber(AnonymousDeclNumber),
231 TypedefNameForLinkage(TypedefNameForLinkage) {}
233 FindExistingResult(FindExistingResult &&
Other)
235 AddResult(
Other.AddResult),
236 AnonymousDeclNumber(
Other.AnonymousDeclNumber),
237 TypedefNameForLinkage(
Other.TypedefNameForLinkage) {
238 Other.AddResult =
false;
241 FindExistingResult &operator=(FindExistingResult &&) =
delete;
242 ~FindExistingResult();
246 void suppress() { AddResult =
false; }
248 operator NamedDecl*()
const {
return Existing; }
251 operator T*()
const {
return dyn_cast_or_null<T>(Existing); }
256 FindExistingResult findExisting(
NamedDecl *
D);
263 ThisDeclLoc(ThisDeclLoc) {}
265 template <
typename T>
274 auto *&LazySpecializations =
D->getCommonPtr()->LazySpecializations;
276 if (
auto &Old = LazySpecializations) {
277 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0].getRawValue());
279 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
285 std::copy(IDs.begin(), IDs.end(),
Result + 1);
287 LazySpecializations =
Result;
290 template <
typename DeclT>
298 template <
typename DeclT>
306 template <
typename DeclT>
311 template <
typename DeclT>
322 Cat->NextClassCategory = Next;
427 template <
typename T>
431 Decl *Context,
unsigned Number);
434 RedeclarableResult &Redecl);
436 template <
typename T>
438 RedeclarableResult &Redecl);
480template <
typename DeclT>
class MergedRedeclIterator {
481 DeclT *Start =
nullptr;
482 DeclT *Canonical =
nullptr;
483 DeclT *Current =
nullptr;
486 MergedRedeclIterator() =
default;
487 MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
491 MergedRedeclIterator &operator++() {
492 if (Current->isFirstDecl()) {
494 Current = Current->getMostRecentDecl();
496 Current = Current->getPreviousDecl();
502 if (Current == Start || Current == Canonical)
507 friend bool operator!=(
const MergedRedeclIterator &A,
508 const MergedRedeclIterator &B) {
509 return A.Current != B.Current;
515template <
typename DeclT>
516static llvm::iterator_range<MergedRedeclIterator<DeclT>>
518 return llvm::make_range(MergedRedeclIterator<DeclT>(
D),
519 MergedRedeclIterator<DeclT>());
522uint64_t ASTDeclReader::GetCurrentCursorOffset() {
523 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
528 Reader.DefinitionSource[FD] =
529 Loc.F->Kind == ModuleKind::MK_MainFile ||
532 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
533 CD->setNumCtorInitializers(
Record.readInt());
534 if (CD->getNumCtorInitializers())
535 CD->CtorInitializers = ReadGlobalOffset();
538 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
547 IsDeclMarkedUsed =
false;
549 if (
auto *DD = dyn_cast<DeclaratorDecl>(
D)) {
550 if (
auto *TInfo = DD->getTypeSourceInfo())
551 Record.readTypeLoc(TInfo->getTypeLoc());
554 if (
auto *TD = dyn_cast<TypeDecl>(
D)) {
560 if (NamedDeclForTagDecl.
isValid())
561 cast<TagDecl>(
D)->TypedefNameDeclOrQualifier =
562 cast<TypedefNameDecl>(Reader.
GetDecl(NamedDeclForTagDecl));
563 }
else if (
auto *ID = dyn_cast<ObjCInterfaceDecl>(
D)) {
566 }
else if (
auto *FD = dyn_cast<FunctionDecl>(
D)) {
570 }
else if (
auto *VD = dyn_cast<VarDecl>(
D)) {
572 }
else if (
auto *FD = dyn_cast<FieldDecl>(
D)) {
573 if (FD->hasInClassInitializer() &&
Record.readInt()) {
574 FD->setLazyInClassInitializer(
LazyDeclStmtPtr(GetCurrentCursorOffset()));
581 auto ModuleOwnership =
585 IsDeclMarkedUsed |=
D->Used;
588 bool HasStandaloneLexicalDC = DeclBits.
getNextBit();
595 isa<ParmVarDecl, ObjCTypeParamDecl>(
D)) {
602 GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
605 if (LexicalDCIDForTemplateParmDecl.
isInvalid())
606 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
607 Reader.addPendingDeclContextInfo(
D,
608 SemaDCIDForTemplateParmDecl,
609 LexicalDCIDForTemplateParmDecl);
612 auto *SemaDC = readDeclAs<DeclContext>();
614 HasStandaloneLexicalDC ? readDeclAs<DeclContext>() :
nullptr;
620 if (
auto *RD = dyn_cast<CXXRecordDecl>(SemaDC))
621 MergedSemaDC = getOrFakePrimaryClassDefinition(Reader, RD);
623 MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
626 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
633 Record.readAttributes(Attrs);
644 switch (ModuleOwnership) {
670 Reader.HiddenNamesMap[Owner].push_back(
D);
672 }
else if (ModulePrivate) {
681 std::string Arg = readString();
682 memcpy(
D->getTrailingObjects<
char>(), Arg.data(), Arg.size());
683 D->getTrailingObjects<
char>()[Arg.size()] =
'\0';
689 std::string Name = readString();
690 memcpy(
D->getTrailingObjects<
char>(), Name.data(), Name.size());
691 D->getTrailingObjects<
char>()[Name.size()] =
'\0';
693 D->ValueStart = Name.size() + 1;
694 std::string
Value = readString();
695 memcpy(
D->getTrailingObjects<
char>() +
D->ValueStart,
Value.data(),
697 D->getTrailingObjects<
char>()[
D->ValueStart +
Value.size()] =
'\0';
701 llvm_unreachable(
"Translation units are not serialized");
707 AnonymousDeclNumber =
Record.readInt();
714 DeferredTypeID =
Record.getGlobalTypeID(
Record.readInt());
717ASTDeclReader::RedeclarableResult
742 if (
auto *Template = readDeclAs<TypeAliasTemplateDecl>())
769 Record.readQualifierInfo(*Info);
770 TD->TypedefNameDeclOrQualifier = Info;
774 NamedDeclForTagDecl = readDeclID();
775 TypedefNameForLinkage =
Record.readIdentifier();
778 llvm_unreachable(
"unexpected tag info kind");
781 if (!isa<CXXRecordDecl>(TD))
795 ED->setNumPositiveBits(EnumDeclBits.
getNextBits(8));
796 ED->setNumNegativeBits(EnumDeclBits.
getNextBits(8));
801 ED->setHasODRHash(
true);
802 ED->ODRHash =
Record.readInt();
819 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
826 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
832 if (
auto *InstED = readDeclAs<EnumDecl>()) {
835 ED->setInstantiationOfMemberEnum(Reader.
getContext(), InstED, TSK);
840ASTDeclReader::RedeclarableResult
864 RD->setODRHash(
Record.readInt());
870 RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
882 Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
886 Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
898 if (isa<FunctionDecl, VarDecl>(VD))
899 DeferredTypeID =
Record.getGlobalTypeID(
Record.readInt());
916 auto *Info =
new (Reader.
getContext()) DeclaratorDecl::ExtInfo();
917 Record.readQualifierInfo(*Info);
918 Info->TrailingRequiresClause =
Record.readExpr();
923 TSIType.
isNull() ? nullptr
939 auto *Template = readDeclAs<FunctionTemplateDecl>();
945 auto *InstFD = readDeclAs<FunctionDecl>();
948 FD->setInstantiationOfMemberFunction(Reader.
getContext(), InstFD, TSK);
953 auto *Template = readDeclAs<FunctionTemplateDecl>();
958 Record.readTemplateArgumentList(TemplArgs,
true);
962 bool HasTemplateArgumentsAsWritten =
Record.readBool();
963 if (HasTemplateArgumentsAsWritten)
964 Record.readTemplateArgumentListInfo(TemplArgsWritten);
974 auto *FD = readDeclAs<FunctionDecl>();
984 C, FD, Template, TSK, TemplArgList,
985 HasTemplateArgumentsAsWritten ? &TemplArgsWritten :
nullptr, POI,
987 FD->TemplateOrSpecialization = FTInfo;
992 auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>();
998 llvm::FoldingSetNodeID ID;
1000 void *InsertPos =
nullptr;
1008 "already deserialized this template specialization");
1017 unsigned NumCandidates =
Record.readInt();
1018 while (NumCandidates--)
1019 Candidates.
addDecl(readDeclAs<NamedDecl>());
1023 bool HasTemplateArgumentsAsWritten =
Record.readBool();
1024 if (HasTemplateArgumentsAsWritten)
1025 Record.readTemplateArgumentListInfo(TemplArgsWritten);
1029 HasTemplateArgumentsAsWritten ? &TemplArgsWritten :
nullptr);
1048 Reader.PendingDeducedFunctionTypes.push_back({FD, DeferredTypeID});
1070 const bool Pure = FunctionDeclBits.
getNextBit();
1088 FD->EndRangeLoc = readSourceLocation();
1092 FD->ODRHash =
Record.readInt();
1093 FD->setHasODRHash(
true);
1099 if (
auto Info =
Record.readInt()) {
1100 bool HasMessage = Info & 2;
1102 HasMessage ? cast<StringLiteral>(
Record.readExpr()) :
nullptr;
1104 unsigned NumLookups =
Record.readInt();
1106 for (
unsigned I = 0; I != NumLookups; ++I) {
1114 Reader.
getContext(), Lookups, DeletedMessage));
1125 auto merge = [
this, &Redecl, FD](
auto &&F) {
1126 auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1127 RedeclarableResult NewRedecl(Existing ? F(Existing) :
nullptr,
1128 Redecl.getFirstID(), Redecl.isKeyDecl());
1146 unsigned NumParams =
Record.readInt();
1148 Params.reserve(NumParams);
1149 for (
unsigned I = 0; I != NumParams; ++I)
1150 Params.push_back(readDeclAs<ParmVarDecl>());
1159 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1162 MD->
setCmdDecl(readDeclAs<ImplicitParamDecl>());
1175 readDeclAs<ObjCMethodDecl>());
1183 MD->DeclEndLoc = readSourceLocation();
1184 unsigned NumParams =
Record.readInt();
1186 Params.reserve(NumParams);
1187 for (
unsigned I = 0; I != NumParams; ++I)
1188 Params.push_back(readDeclAs<ParmVarDecl>());
1191 unsigned NumStoredSelLocs =
Record.readInt();
1193 SelLocs.reserve(NumStoredSelLocs);
1194 for (
unsigned i = 0; i != NumStoredSelLocs; ++i)
1195 SelLocs.push_back(readSourceLocation());
1197 MD->setParamsAndSelLocs(Reader.
getContext(), Params, SelLocs);
1203 D->Variance =
Record.readInt();
1205 D->VarianceLoc = readSourceLocation();
1206 D->ColonLoc = readSourceLocation();
1216 unsigned numParams =
Record.readInt();
1221 typeParams.reserve(numParams);
1222 for (
unsigned i = 0; i != numParams; ++i) {
1223 auto *typeParam = readDeclAs<ObjCTypeParamDecl>();
1227 typeParams.push_back(typeParam);
1234 typeParams, rAngleLoc);
1237void ASTDeclReader::ReadObjCDefinitionData(
1238 struct ObjCInterfaceDecl::DefinitionData &
Data) {
1240 Data.SuperClassTInfo = readTypeSourceInfo();
1242 Data.EndLoc = readSourceLocation();
1243 Data.HasDesignatedInitializers =
Record.readInt();
1245 Data.HasODRHash =
true;
1248 unsigned NumProtocols =
Record.readInt();
1250 Protocols.reserve(NumProtocols);
1251 for (
unsigned I = 0; I != NumProtocols; ++I)
1252 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1254 ProtoLocs.reserve(NumProtocols);
1255 for (
unsigned I = 0; I != NumProtocols; ++I)
1256 ProtoLocs.push_back(readSourceLocation());
1257 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1261 NumProtocols =
Record.readInt();
1263 Protocols.reserve(NumProtocols);
1264 for (
unsigned I = 0; I != NumProtocols; ++I)
1265 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1266 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1271 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1272 struct ObjCInterfaceDecl::DefinitionData &DD =
D->data();
1273 if (DD.Definition == NewDD.Definition)
1276 Reader.MergedDeclContexts.insert(
1277 std::make_pair(NewDD.Definition, DD.Definition));
1280 if (
D->getODRHash() != NewDD.ODRHash)
1281 Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back(
1282 {NewDD.Definition, &NewDD});
1288 DeferredTypeID =
Record.getGlobalTypeID(
Record.readInt());
1294 ID->allocateDefinitionData();
1296 ReadObjCDefinitionData(
ID->data());
1298 if (Canon->Data.getPointer()) {
1301 MergeDefinitionData(Canon, std::move(
ID->data()));
1302 ID->Data = Canon->Data;
1306 ID->getCanonicalDecl()->Data =
ID->Data;
1309 ID->setIvarList(
nullptr);
1313 Reader.PendingDefinitions.insert(
ID);
1316 Reader.ObjCClassesLoaded.push_back(
ID);
1318 ID->Data =
ID->getCanonicalDecl()->Data;
1327 bool synth =
Record.readInt();
1342 if (PrevIvar && PrevIvar != IVD) {
1343 auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->
getDeclContext());
1344 auto *PrevParentExt =
1346 if (ParentExt && PrevParentExt) {
1350 .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt,
1352 .push_back(std::make_pair(IVD, PrevIvar));
1353 }
else if (ParentExt || PrevParentExt) {
1364void ASTDeclReader::ReadObjCDefinitionData(
1365 struct ObjCProtocolDecl::DefinitionData &
Data) {
1366 unsigned NumProtoRefs =
Record.readInt();
1368 ProtoRefs.reserve(NumProtoRefs);
1369 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1370 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1372 ProtoLocs.reserve(NumProtoRefs);
1373 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1374 ProtoLocs.push_back(readSourceLocation());
1375 Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1378 Data.HasODRHash =
true;
1381void ASTDeclReader::MergeDefinitionData(
1383 struct ObjCProtocolDecl::DefinitionData &DD =
D->data();
1384 if (DD.Definition == NewDD.Definition)
1387 Reader.MergedDeclContexts.insert(
1388 std::make_pair(NewDD.Definition, DD.Definition));
1391 if (
D->getODRHash() != NewDD.ODRHash)
1392 Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back(
1393 {NewDD.Definition, &NewDD});
1403 PD->allocateDefinitionData();
1405 ReadObjCDefinitionData(PD->data());
1408 if (Canon->Data.getPointer()) {
1411 MergeDefinitionData(Canon, std::move(PD->data()));
1412 PD->Data = Canon->Data;
1419 Reader.PendingDefinitions.insert(PD);
1438 Reader.CategoriesDeserialized.insert(CD);
1440 CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>();
1442 unsigned NumProtoRefs =
Record.readInt();
1444 ProtoRefs.reserve(NumProtoRefs);
1445 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1446 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1448 ProtoLocs.reserve(NumProtoRefs);
1449 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1450 ProtoLocs.push_back(readSourceLocation());
1468 D->setAtLoc(readSourceLocation());
1469 D->setLParenLoc(readSourceLocation());
1474 D->setPropertyAttributesAsWritten(
1476 D->setPropertyImplementation(
1484 D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1485 D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1486 D->setPropertyIvarDecl(readDeclAs<ObjCIvarDecl>());
1491 D->setClassInterface(readDeclAs<ObjCInterfaceDecl>());
1496 D->CategoryNameLoc = readSourceLocation();
1501 D->setSuperClass(readDeclAs<ObjCInterfaceDecl>());
1502 D->SuperLoc = readSourceLocation();
1503 D->setIvarLBraceLoc(readSourceLocation());
1504 D->setIvarRBraceLoc(readSourceLocation());
1505 D->setHasNonZeroConstructors(
Record.readInt());
1506 D->setHasDestructors(
Record.readInt());
1507 D->NumIvarInitializers =
Record.readInt();
1508 if (
D->NumIvarInitializers)
1509 D->IvarInitializers = ReadGlobalOffset();
1514 D->setAtLoc(readSourceLocation());
1515 D->setPropertyDecl(readDeclAs<ObjCPropertyDecl>());
1516 D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>();
1517 D->IvarLoc = readSourceLocation();
1518 D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1519 D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>());
1520 D->setGetterCXXConstructor(
Record.readExpr());
1521 D->setSetterCXXAssignment(
Record.readExpr());
1526 FD->Mutable =
Record.readInt();
1528 unsigned Bits =
Record.readInt();
1529 FD->StorageKind = Bits >> 1;
1530 if (FD->StorageKind == FieldDecl::ISK_CapturedVLAType)
1532 cast<VariableArrayType>(
Record.readType().getTypePtr());
1537 if (
auto *Tmpl = readDeclAs<FieldDecl>())
1545 PD->GetterId =
Record.readIdentifier();
1546 PD->SetterId =
Record.readIdentifier();
1551 D->PartVal.Part1 =
Record.readInt();
1552 D->PartVal.Part2 =
Record.readInt();
1553 D->PartVal.Part3 =
Record.readInt();
1554 for (
auto &
C :
D->PartVal.Part4And5)
1565 D->Value =
Record.readAPValue();
1569 Reader.
getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(
D))
1575 D->Value =
Record.readAPValue();
1580 Reader.
getContext().TemplateParamObjectDecls.GetOrInsertNode(
D))
1587 FD->ChainingSize =
Record.readInt();
1588 assert(FD->ChainingSize >= 2 &&
"Anonymous chaining must be >= 2");
1591 for (
unsigned I = 0; I != FD->ChainingSize; ++I)
1592 FD->Chaining[I] = readDeclAs<NamedDecl>();
1603 bool DefGeneratedInModule = VarDeclBits.
getNextBit();
1608 bool HasDeducedType =
false;
1609 if (!isa<ParmVarDecl>(VD)) {
1635 Reader.PendingDeducedVarTypes.push_back({VD, DeferredTypeID});
1647 if (DefGeneratedInModule) {
1648 Reader.DefinitionSource[VD] =
1649 Loc.F->Kind == ModuleKind::MK_MainFile ||
1653 if (VD->
hasAttr<BlocksAttr>()) {
1660 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1662 switch ((VarKind)
Record.readInt()) {
1663 case VarNotTemplate:
1666 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1667 !isa<VarTemplateSpecializationDecl>(VD))
1674 case StaticDataMemberSpecialization: {
1675 auto *Tmpl = readDeclAs<VarDecl>();
1688 if (uint64_t Val =
Record.readInt()) {
1702 Eval->
Value = GetCurrentCursorOffset();
1713 unsigned scopeIndex =
Record.readInt();
1715 unsigned isObjCMethodParam = ParmVarDeclBits.
getNextBit();
1716 unsigned scopeDepth = ParmVarDeclBits.
getNextBits(7);
1717 unsigned declQualifier = ParmVarDeclBits.
getNextBits(7);
1718 if (isObjCMethodParam) {
1719 assert(scopeDepth == 0);
1732 PD->ExplicitObjectParameterIntroducerLoc =
Record.readSourceLocation();
1740 auto **BDs = DD->getTrailingObjects<
BindingDecl *>();
1741 for (
unsigned I = 0; I != DD->NumBindings; ++I) {
1742 BDs[I] = readDeclAs<BindingDecl>();
1743 BDs[I]->setDecomposedDecl(DD);
1749 BD->Binding =
Record.readExpr();
1760 D->Statement =
Record.readStmt();
1767 unsigned NumParams =
Record.readInt();
1769 Params.reserve(NumParams);
1770 for (
unsigned I = 0; I != NumParams; ++I)
1771 Params.push_back(readDeclAs<ParmVarDecl>());
1780 bool capturesCXXThis =
Record.readInt();
1781 unsigned numCaptures =
Record.readInt();
1783 captures.reserve(numCaptures);
1784 for (
unsigned i = 0; i != numCaptures; ++i) {
1785 auto *
decl = readDeclAs<VarDecl>();
1786 unsigned flags =
Record.readInt();
1787 bool byRef = (flags & 1);
1788 bool nested = (flags & 2);
1789 Expr *copyExpr = ((flags & 4) ?
Record.readExpr() :
nullptr);
1798 unsigned ContextParamPos =
Record.readInt();
1801 for (
unsigned I = 0; I < CD->NumParams; ++I) {
1802 if (I != ContextParamPos)
1803 CD->
setParam(I, readDeclAs<ImplicitParamDecl>());
1812 D->setExternLoc(readSourceLocation());
1813 D->setRBraceLoc(readSourceLocation());
1818 D->RBraceLoc = readSourceLocation();
1823 D->setLocStart(readSourceLocation());
1833 D->LocStart = readSourceLocation();
1834 D->RBraceLoc = readSourceLocation();
1841 if (Redecl.getFirstID() == ThisDeclID)
1842 AnonNamespace = readDeclID();
1846 if (AnonNamespace.
isValid()) {
1850 auto *Anon = cast<NamespaceDecl>(Reader.
GetDecl(AnonNamespace));
1852 D->setAnonymousNamespace(Anon);
1859 D->IsCBuffer =
Record.readBool();
1860 D->KwLoc = readSourceLocation();
1861 D->LBraceLoc = readSourceLocation();
1862 D->RBraceLoc = readSourceLocation();
1868 D->NamespaceLoc = readSourceLocation();
1869 D->IdentLoc = readSourceLocation();
1870 D->QualifierLoc =
Record.readNestedNameSpecifierLoc();
1871 D->Namespace = readDeclAs<NamedDecl>();
1877 D->setUsingLoc(readSourceLocation());
1878 D->QualifierLoc =
Record.readNestedNameSpecifierLoc();
1879 D->DNLoc =
Record.readDeclarationNameLoc(
D->getDeclName());
1880 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1881 D->setTypename(
Record.readInt());
1882 if (
auto *Pattern = readDeclAs<NamedDecl>())
1889 D->setUsingLoc(readSourceLocation());
1890 D->setEnumLoc(readSourceLocation());
1891 D->setEnumType(
Record.readTypeSourceInfo());
1892 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1893 if (
auto *Pattern = readDeclAs<UsingEnumDecl>())
1900 D->InstantiatedFrom = readDeclAs<NamedDecl>();
1901 auto **Expansions =
D->getTrailingObjects<
NamedDecl *>();
1902 for (
unsigned I = 0; I !=
D->NumExpansions; ++I)
1903 Expansions[I] = readDeclAs<NamedDecl>();
1910 D->Underlying = readDeclAs<NamedDecl>();
1912 D->UsingOrNextShadow = readDeclAs<NamedDecl>();
1913 auto *Pattern = readDeclAs<UsingShadowDecl>();
1922 D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1923 D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1924 D->IsVirtual =
Record.readInt();
1929 D->UsingLoc = readSourceLocation();
1930 D->NamespaceLoc = readSourceLocation();
1931 D->QualifierLoc =
Record.readNestedNameSpecifierLoc();
1932 D->NominatedNamespace = readDeclAs<NamedDecl>();
1933 D->CommonAncestor = readDeclAs<DeclContext>();
1938 D->setUsingLoc(readSourceLocation());
1939 D->QualifierLoc =
Record.readNestedNameSpecifierLoc();
1940 D->DNLoc =
Record.readDeclarationNameLoc(
D->getDeclName());
1941 D->EllipsisLoc = readSourceLocation();
1948 D->TypenameLocation = readSourceLocation();
1949 D->QualifierLoc =
Record.readNestedNameSpecifierLoc();
1950 D->EllipsisLoc = readSourceLocation();
1959void ASTDeclReader::ReadCXXDefinitionData(
1961 Decl *LambdaContext,
unsigned IndexInLambdaContext) {
1965#define FIELD(Name, Width, Merge) \
1966 if (!CXXRecordDeclBits.canGetNextNBits(Width)) \
1967 CXXRecordDeclBits.updateValue(Record.readInt()); \
1968 Data.Name = CXXRecordDeclBits.getNextBits(Width);
1970#include "clang/AST/CXXRecordDeclDefinitionBits.def"
1975 Data.HasODRHash =
true;
1978 Reader.DefinitionSource[
D] =
1979 Loc.F->Kind == ModuleKind::MK_MainFile ||
1984 Data.ComputedVisibleConversions =
Record.readInt();
1985 if (
Data.ComputedVisibleConversions)
1986 Record.readUnresolvedSet(
Data.VisibleConversions);
1987 assert(
Data.Definition &&
"Data.Definition should be already set!");
1989 if (!
Data.IsLambda) {
1990 assert(!LambdaContext && !IndexInLambdaContext &&
1991 "given lambda context for non-lambda");
1995 Data.Bases = ReadGlobalOffset();
1999 Data.VBases = ReadGlobalOffset();
2005 auto &Lambda =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(
Data);
2008 Lambda.DependencyKind = LambdaBits.getNextBits(2);
2009 Lambda.IsGenericLambda = LambdaBits.getNextBit();
2010 Lambda.CaptureDefault = LambdaBits.getNextBits(2);
2011 Lambda.NumCaptures = LambdaBits.getNextBits(15);
2012 Lambda.HasKnownInternalLinkage = LambdaBits.getNextBit();
2014 Lambda.NumExplicitCaptures =
Record.readInt();
2015 Lambda.ManglingNumber =
Record.readInt();
2016 if (
unsigned DeviceManglingNumber =
Record.readInt())
2017 Reader.
getContext().DeviceLambdaManglingNumbers[
D] = DeviceManglingNumber;
2018 Lambda.IndexInContext = IndexInLambdaContext;
2019 Lambda.ContextDecl = LambdaContext;
2021 if (Lambda.NumCaptures) {
2023 Lambda.NumCaptures);
2024 Lambda.AddCaptureList(Reader.
getContext(), ToCapture);
2026 Lambda.MethodTyInfo = readTypeSourceInfo();
2027 for (
unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
2030 bool IsImplicit = CaptureBits.getNextBit();
2043 auto *Var = readDeclAs<ValueDecl>();
2045 new (ToCapture)
Capture(
Loc, IsImplicit,
Kind, Var, EllipsisLoc);
2053void ASTDeclReader::MergeDefinitionData(
2054 CXXRecordDecl *
D,
struct CXXRecordDecl::DefinitionData &&MergeDD) {
2055 assert(
D->DefinitionData &&
2056 "merging class definition into non-definition");
2057 auto &DD = *
D->DefinitionData;
2059 if (DD.Definition != MergeDD.Definition) {
2061 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
2063 Reader.PendingDefinitions.erase(MergeDD.Definition);
2064 MergeDD.Definition->setCompleteDefinition(
false);
2066 assert(!Reader.Lookups.contains(MergeDD.Definition) &&
2067 "already loaded pending lookups for merged definition");
2070 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
2071 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
2072 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
2075 assert(!DD.IsLambda && !MergeDD.IsLambda &&
"faked up lambda definition?");
2076 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
2080 auto *Def = DD.Definition;
2081 DD = std::move(MergeDD);
2082 DD.Definition = Def;
2086 bool DetectedOdrViolation =
false;
2088 #define FIELD(Name, Width, Merge) Merge(Name)
2089 #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
2090 #define NO_MERGE(Field) \
2091 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
2093 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2098 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
2099 DetectedOdrViolation =
true;
2105 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
2106 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
2107 DD.ComputedVisibleConversions =
true;
2114 auto &Lambda1 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(DD);
2115 auto &Lambda2 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(MergeDD);
2116 DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind;
2117 DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda;
2118 DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault;
2119 DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures;
2120 DetectedOdrViolation |=
2121 Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures;
2122 DetectedOdrViolation |=
2123 Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage;
2124 DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber;
2126 if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) {
2127 for (
unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) {
2132 Lambda1.AddCaptureList(Reader.
getContext(), Lambda2.Captures.front());
2140 if (
D->getODRHash() != MergeDD.ODRHash) {
2141 DetectedOdrViolation =
true;
2144 if (DetectedOdrViolation)
2145 Reader.PendingOdrMergeFailures[DD.Definition].push_back(
2146 {MergeDD.Definition, &MergeDD});
2150 Decl *LambdaContext,
2151 unsigned IndexInLambdaContext) {
2152 struct CXXRecordDecl::DefinitionData *DD;
2157 bool IsLambda =
Record.readInt();
2158 assert(!(IsLambda &&
Update) &&
2159 "lambda definition should not be added by update record");
2161 DD =
new (
C) CXXRecordDecl::LambdaDefinitionData(
2164 DD =
new (
C)
struct CXXRecordDecl::DefinitionData(
D);
2170 if (!Canon->DefinitionData)
2171 Canon->DefinitionData = DD;
2172 D->DefinitionData = Canon->DefinitionData;
2173 ReadCXXDefinitionData(*DD,
D, LambdaContext, IndexInLambdaContext);
2178 if (Canon->DefinitionData != DD) {
2179 MergeDefinitionData(Canon, std::move(*DD));
2184 D->setCompleteDefinition(
true);
2190 Reader.PendingDefinitions.insert(
D);
2193ASTDeclReader::RedeclarableResult
2200 CXXRecNotTemplate = 0,
2202 CXXRecMemberSpecialization,
2206 Decl *LambdaContext =
nullptr;
2207 unsigned IndexInLambdaContext = 0;
2209 switch ((CXXRecKind)
Record.readInt()) {
2210 case CXXRecNotTemplate:
2212 if (!isa<ClassTemplateSpecializationDecl>(
D))
2215 case CXXRecTemplate: {
2217 auto *Template = readDeclAs<ClassTemplateDecl>();
2218 D->TemplateOrInstantiation = Template;
2219 if (!Template->getTemplatedDecl()) {
2230 case CXXRecMemberSpecialization: {
2231 auto *RD = readDeclAs<CXXRecordDecl>();
2236 D->TemplateOrInstantiation = MSI;
2241 LambdaContext = readDecl();
2243 IndexInLambdaContext =
Record.readInt();
2244 mergeLambda(
D, Redecl, LambdaContext, IndexInLambdaContext);
2249 bool WasDefinition =
Record.readInt();
2251 ReadCXXRecordDefinition(
D,
false, LambdaContext,
2252 IndexInLambdaContext);
2259 if (WasDefinition) {
2261 if (KeyFn.
isValid() &&
D->isCompleteDefinition())
2272 D->setExplicitSpecifier(
Record.readExplicitSpec());
2273 D->Ctor = readDeclAs<CXXConstructorDecl>();
2275 D->setDeductionCandidateKind(
2282 unsigned NumOverridenMethods =
Record.readInt();
2284 while (NumOverridenMethods--) {
2287 if (
auto *MD = readDeclAs<CXXMethodDecl>())
2293 Record.skipInts(NumOverridenMethods);
2300 D->setExplicitSpecifier(
Record.readExplicitSpec());
2301 if (
D->isInheritingConstructor()) {
2302 auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>();
2303 auto *Ctor = readDeclAs<CXXConstructorDecl>();
2314 if (
auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
2316 auto *ThisArg =
Record.readExpr();
2318 if (!Canon->OperatorDelete) {
2319 Canon->OperatorDelete = OperatorDelete;
2320 Canon->OperatorDeleteThisArg = ThisArg;
2326 D->setExplicitSpecifier(
Record.readExplicitSpec());
2332 D->ImportedModule = readModule();
2333 D->setImportComplete(
Record.readInt());
2335 for (
unsigned I = 0, N =
Record.back(); I != N; ++I)
2336 StoredLocs[I] = readSourceLocation();
2342 D->setColonLoc(readSourceLocation());
2348 D->Friend = readDeclAs<NamedDecl>();
2350 D->Friend = readTypeSourceInfo();
2351 for (
unsigned i = 0; i !=
D->NumTPLists; ++i)
2353 Record.readTemplateParameterList();
2355 D->UnsupportedFriend = (
Record.readInt() != 0);
2356 D->FriendLoc = readSourceLocation();
2361 unsigned NumParams =
Record.readInt();
2362 D->NumParams = NumParams;
2364 for (
unsigned i = 0; i != NumParams; ++i)
2365 D->Params[i] =
Record.readTemplateParameterList();
2367 D->Friend = readDeclAs<NamedDecl>();
2369 D->Friend = readTypeSourceInfo();
2370 D->FriendLoc = readSourceLocation();
2376 assert(!
D->TemplateParams &&
"TemplateParams already set!");
2377 D->TemplateParams =
Record.readTemplateParameterList();
2378 D->init(readDeclAs<NamedDecl>());
2383 D->ConstraintExpr =
Record.readExpr();
2393 for (
unsigned I = 0; I <
D->NumTemplateArgs; ++I)
2394 Args.push_back(
Record.readTemplateArgument(
true));
2395 D->setTemplateArguments(Args);
2401ASTDeclReader::RedeclarableResult
2410 Reader.PendingDefinitions.insert(CanonD);
2416 if (ThisDeclID == Redecl.getFirstID()) {
2417 if (
auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) {
2418 assert(RTD->getKind() ==
D->
getKind() &&
2419 "InstantiatedFromMemberTemplate kind mismatch");
2420 D->setInstantiatedFromMemberTemplate(RTD);
2422 D->setMemberSpecialization();
2436 if (ThisDeclID == Redecl.getFirstID()) {
2440 readDeclIDList(SpecIDs);
2444 if (
D->getTemplatedDecl()->TemplateOrInstantiation) {
2449 D->getTemplatedDecl(),
D->getInjectedClassNameSpecialization());
2454 llvm_unreachable(
"BuiltinTemplates are not serialized");
2464 if (ThisDeclID == Redecl.getFirstID()) {
2468 readDeclIDList(SpecIDs);
2473ASTDeclReader::RedeclarableResult
2479 if (
Decl *InstD = readDecl()) {
2480 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2481 D->SpecializedTemplate = CTD;
2484 Record.readTemplateArgumentList(TemplArgs);
2489 SpecializedPartialSpecialization();
2490 PS->PartialSpecialization
2491 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2492 PS->TemplateArgs = ArgList;
2493 D->SpecializedTemplate = PS;
2498 Record.readTemplateArgumentList(TemplArgs,
true);
2500 D->PointOfInstantiation = readSourceLocation();
2503 bool writtenAsCanonicalDecl =
Record.readInt();
2504 if (writtenAsCanonicalDecl) {
2505 auto *CanonPattern = readDeclAs<ClassTemplateDecl>();
2509 if (
auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(
D)) {
2510 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2511 .GetOrInsertNode(Partial);
2514 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(
D);
2517 if (CanonSpec !=
D) {
2518 mergeRedeclarable<TagDecl>(
D, CanonSpec, Redecl);
2522 if (
auto *DDD =
D->DefinitionData) {
2523 if (CanonSpec->DefinitionData)
2524 MergeDefinitionData(CanonSpec, std::move(*DDD));
2526 CanonSpec->DefinitionData =
D->DefinitionData;
2528 D->DefinitionData = CanonSpec->DefinitionData;
2537 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2538 D->ExplicitInfo = ExplicitInfo;
2542 D->setTemplateArgsAsWritten(
Record.readASTTemplateArgumentListInfo());
2552 D->TemplateParams = Params;
2557 if (ThisDeclID == Redecl.getFirstID()) {
2558 D->InstantiatedFromMember.setPointer(
2559 readDeclAs<ClassTemplatePartialSpecializationDecl>());
2560 D->InstantiatedFromMember.setInt(
Record.readInt());
2567 if (ThisDeclID == Redecl.getFirstID()) {
2570 readDeclIDList(SpecIDs);
2580ASTDeclReader::RedeclarableResult
2584 if (
Decl *InstD = readDecl()) {
2585 if (
auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2586 D->SpecializedTemplate = VTD;
2589 Record.readTemplateArgumentList(TemplArgs);
2594 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2595 PS->PartialSpecialization =
2596 cast<VarTemplatePartialSpecializationDecl>(InstD);
2597 PS->TemplateArgs = ArgList;
2598 D->SpecializedTemplate = PS;
2606 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2607 D->ExplicitInfo = ExplicitInfo;
2611 D->setTemplateArgsAsWritten(
Record.readASTTemplateArgumentListInfo());
2614 Record.readTemplateArgumentList(TemplArgs,
true);
2616 D->PointOfInstantiation = readSourceLocation();
2618 D->IsCompleteDefinition =
Record.readInt();
2622 bool writtenAsCanonicalDecl =
Record.readInt();
2623 if (writtenAsCanonicalDecl) {
2624 auto *CanonPattern = readDeclAs<VarTemplateDecl>();
2627 if (
auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(
D)) {
2628 CanonSpec = CanonPattern->getCommonPtr()
2629 ->PartialSpecializations.GetOrInsertNode(Partial);
2632 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(
D);
2636 mergeRedeclarable<VarDecl>(
D, CanonSpec, Redecl);
2651 D->TemplateParams = Params;
2656 if (ThisDeclID == Redecl.getFirstID()) {
2657 D->InstantiatedFromMember.setPointer(
2658 readDeclAs<VarTemplatePartialSpecializationDecl>());
2659 D->InstantiatedFromMember.setInt(
Record.readInt());
2666 D->setDeclaredWithTypename(
Record.readInt());
2668 if (
D->hasTypeConstraint()) {
2671 CR =
Record.readConceptReference();
2672 Expr *ImmediatelyDeclaredConstraint =
Record.readExpr();
2674 D->setTypeConstraint(CR, ImmediatelyDeclaredConstraint);
2675 if ((
D->ExpandedParameterPack =
Record.readInt()))
2676 D->NumExpanded =
Record.readInt();
2681 Record.readTemplateArgumentLoc());
2687 D->setDepth(
Record.readInt());
2688 D->setPosition(
Record.readInt());
2689 if (
D->hasPlaceholderTypeConstraint())
2690 D->setPlaceholderTypeConstraint(
Record.readExpr());
2691 if (
D->isExpandedParameterPack()) {
2692 auto TypesAndInfos =
2693 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2694 for (
unsigned I = 0, N =
D->getNumExpansionTypes(); I != N; ++I) {
2696 TypesAndInfos[I].second = readTypeSourceInfo();
2700 D->ParameterPack =
Record.readInt();
2703 Record.readTemplateArgumentLoc());
2709 D->setDeclaredWithTypename(
Record.readBool());
2711 D->setDepth(
Record.readInt());
2712 D->setPosition(
Record.readInt());
2713 if (
D->isExpandedParameterPack()) {
2715 for (
unsigned I = 0, N =
D->getNumExpansionTemplateParameters();
2717 Data[I] =
Record.readTemplateParameterList();
2720 D->ParameterPack =
Record.readInt();
2723 Record.readTemplateArgumentLoc());
2734 D->AssertExprAndFailed.setPointer(
Record.readExpr());
2735 D->AssertExprAndFailed.setInt(
Record.readInt());
2736 D->Message = cast_or_null<StringLiteral>(
Record.readExpr());
2737 D->RParenLoc = readSourceLocation();
2747 D->ExtendingDecl = readDeclAs<ValueDecl>();
2748 D->ExprWithTemporary =
Record.readStmt();
2753 D->ManglingNumber =
Record.readInt();
2757std::pair<uint64_t, uint64_t>
2759 uint64_t LexicalOffset = ReadLocalOffset();
2760 uint64_t VisibleOffset = ReadLocalOffset();
2761 return std::make_pair(LexicalOffset, VisibleOffset);
2764template <
typename T>
2765ASTDeclReader::RedeclarableResult
2768 Decl *MergeWith =
nullptr;
2770 bool IsKeyDecl = ThisDeclID == FirstDeclID;
2771 bool IsFirstLocalDecl =
false;
2773 uint64_t RedeclOffset = 0;
2778 FirstDeclID = ThisDeclID;
2780 IsFirstLocalDecl =
true;
2781 }
else if (
unsigned N =
Record.readInt()) {
2785 IsFirstLocalDecl =
true;
2792 for (
unsigned I = 0; I != N - 1; ++I)
2793 MergeWith = readDecl();
2795 RedeclOffset = ReadLocalOffset();
2802 auto *FirstDecl = cast_or_null<T>(Reader.
GetDecl(FirstDeclID));
2803 if (FirstDecl !=
D) {
2812 auto *DAsT =
static_cast<T *
>(
D);
2818 if (IsFirstLocalDecl)
2819 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2821 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2826template <
typename T>
2828 RedeclarableResult &Redecl) {
2837 auto *
D =
static_cast<T *
>(DBase);
2839 if (
auto *Existing = Redecl.getKnownMergeTarget())
2842 else if (FindExistingResult ExistingRes = findExisting(
D))
2843 if (
T *Existing = ExistingRes)
2854 Decl *Context,
unsigned IndexInContext) {
2868 if (
auto *Existing = Redecl.getKnownMergeTarget())
2874 NamedDecl *&Slot = Reader.LambdaDeclarationsForMerging[{
2875 Context->getCanonicalDecl(), IndexInContext}];
2883 RedeclarableResult &Redecl) {
2896 llvm_unreachable(
"bad assert_cast");
2904 auto *DPattern =
D->getTemplatedDecl();
2906 RedeclarableResult
Result(
2908 DPattern->getCanonicalDecl()->getGlobalID(), IsKeyDecl);
2910 if (
auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2913 auto *ExistingClass =
2914 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2915 if (
auto *DDD = DClass->DefinitionData) {
2916 if (ExistingClass->DefinitionData) {
2917 MergeDefinitionData(ExistingClass, std::move(*DDD));
2919 ExistingClass->DefinitionData = DClass->DefinitionData;
2922 Reader.PendingDefinitions.insert(DClass);
2925 DClass->DefinitionData = ExistingClass->DefinitionData;
2930 if (
auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2933 if (
auto *DVar = dyn_cast<VarDecl>(DPattern))
2935 if (
auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2938 llvm_unreachable(
"merged an unknown kind of redeclarable template");
2943template <
typename T>
2945 RedeclarableResult &Redecl) {
2946 auto *
D =
static_cast<T *
>(DBase);
2947 T *ExistingCanon = Existing->getCanonicalDecl();
2949 if (ExistingCanon != DCanon) {
2954 D->First = ExistingCanon;
2955 ExistingCanon->Used |=
D->Used;
2959 if (
auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(
D))
2961 DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2962 Redecl.isKeyDecl());
2965 if (Redecl.isKeyDecl())
2966 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2979 if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
2994 Reader.LETemporaryForMerging[std::make_pair(
3021 if (FindExistingResult ExistingRes = findExisting(
static_cast<T*
>(
D)))
3022 if (
T *Existing = ExistingRes)
3024 Existing->getCanonicalDecl());
3028 Record.readOMPChildren(
D->Data);
3033 Record.readOMPChildren(
D->Data);
3038 Record.readOMPChildren(
D->Data);
3047 D->setCombinerData(In, Out);
3049 D->setCombiner(Combiner);
3052 D->setInitializerData(Orig, Priv);
3055 D->setInitializer(
Init, IK);
3060 Record.readOMPChildren(
D->Data);
3062 D->VarName =
Record.readDeclarationName();
3081 uint64_t readInt() {
3085 bool readBool() {
return Reader.
readBool(); }
3099 std::string readString() {
3111 VersionTuple readVersionTuple() {
3117 template <
typename T>
T *readDeclAs() {
return Reader.
readDeclAs<
T>(); }
3122 AttrReader
Record(*
this);
3127 Attr *New =
nullptr;
3137 unsigned ParsedKind =
Record.readInt();
3138 unsigned Syntax =
Record.readInt();
3139 unsigned SpellingIndex =
Record.readInt();
3140 bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned &&
3142 SpellingIndex == AlignedAttr::Keyword_alignas);
3143 bool IsRegularKeywordAttribute =
Record.readBool();
3148 IsAlignas, IsRegularKeywordAttribute});
3150#include "clang/Serialization/AttrPCHRead.inc"
3152 assert(New &&
"Unable to decode attribute?");
3158 for (
unsigned I = 0,
E =
readInt(); I !=
E; ++I)
3173inline void ASTReader::LoadedDecl(
unsigned Index,
Decl *
D) {
3174 assert(!DeclsLoaded[Index] &&
"Decl loaded twice?");
3175 DeclsLoaded[Index] =
D;
3184bool ASTReader::isConsumerInterestedIn(
Decl *
D) {
3203 if (
const auto *Var = dyn_cast<VarDecl>(
D))
3204 return Var->isFileVarDecl() &&
3206 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
3207 if (
const auto *
Func = dyn_cast<FunctionDecl>(
D))
3208 return Func->doesThisDeclarationHaveABody() || PendingBodies.count(
D);
3218ASTReader::RecordLocation ASTReader::DeclCursorForID(
GlobalDeclID ID,
3222 unsigned LocalDeclIndex =
ID.getLocalDeclIndex();
3228ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
3229 auto I = GlobalBitOffsetsMap.find(GlobalOffset);
3231 assert(I != GlobalBitOffsetsMap.end() &&
"Corrupted global bit offsets map");
3232 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
3240ASTDeclReader::getOrFakePrimaryClassDefinition(
ASTReader &Reader,
3243 auto *DD = RD->DefinitionData;
3252 DD =
new (Reader.
getContext())
struct CXXRecordDecl::DefinitionData(RD);
3254 RD->DefinitionData = DD;
3258 Reader.PendingFakeDefinitionData.insert(
3259 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
3262 return DD->Definition;
3269 if (
auto *ND = dyn_cast<NamespaceDecl>(DC))
3270 return ND->getFirstDecl();
3272 if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
3273 return getOrFakePrimaryClassDefinition(Reader, RD);
3275 if (
auto *RD = dyn_cast<RecordDecl>(DC))
3278 if (
auto *ED = dyn_cast<EnumDecl>(DC))
3281 if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(DC))
3286 if (
auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3292ASTDeclReader::FindExistingResult::~FindExistingResult() {
3295 if (TypedefNameForLinkage) {
3297 Reader.ImportedTypedefNamesForLinkage.insert(
3298 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3302 if (!AddResult || Existing)
3308 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3309 AnonymousDeclNumber, New);
3313 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3315 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3318 MergeDC->makeDeclVisibleInContextImpl(New,
true);
3326 bool IsTypedefNameForLinkage) {
3327 if (!IsTypedefNameForLinkage)
3333 if (
Found->isFromASTFile())
3336 if (
auto *TND = dyn_cast<TypedefNameDecl>(
Found))
3337 return TND->getAnonDeclWithTypedefName(
true);
3346ASTDeclReader::getPrimaryDCForAnonymousDecl(
DeclContext *LexicalDC) {
3348 if (
auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3350 return DD ? DD->Definition :
nullptr;
3351 }
else if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(LexicalDC)) {
3352 return OID->getCanonicalDecl()->getDefinition();
3359 if (
auto *FD = dyn_cast<FunctionDecl>(
D))
3360 if (FD->isThisDeclarationADefinition())
3362 if (
auto *MD = dyn_cast<ObjCMethodDecl>(
D))
3363 if (MD->isThisDeclarationADefinition())
3365 if (
auto *RD = dyn_cast<RecordDecl>(
D))
3382 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3388 auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3389 if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
3401void ASTDeclReader::setAnonymousDeclForMerging(
ASTReader &Reader,
3404 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3406 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3413ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(
NamedDecl *
D) {
3420 FindExistingResult
Result(Reader,
D,
nullptr,
3421 AnonymousDeclNumber, TypedefNameForLinkage);
3428 if (TypedefNameForLinkage) {
3429 auto It = Reader.ImportedTypedefNamesForLinkage.find(
3430 std::make_pair(DC, TypedefNameForLinkage));
3431 if (It != Reader.ImportedTypedefNamesForLinkage.end())
3432 if (
C.isSameEntity(It->second,
D))
3433 return FindExistingResult(Reader,
D, It->second, AnonymousDeclNumber,
3434 TypedefNameForLinkage);
3442 if (
auto *Existing = getAnonymousDeclForMerging(
3444 if (
C.isSameEntity(Existing,
D))
3445 return FindExistingResult(Reader,
D, Existing, AnonymousDeclNumber,
3446 TypedefNameForLinkage);
3453 class UpToDateIdentifierRAII {
3455 bool WasOutToDate =
false;
3466 ~UpToDateIdentifierRAII() {
3470 } UpToDate(Name.getAsIdentifierInfo());
3473 IEnd = IdResolver.
end();
3476 if (
C.isSameEntity(Existing,
D))
3477 return FindExistingResult(Reader,
D, Existing, AnonymousDeclNumber,
3478 TypedefNameForLinkage);
3480 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3484 if (
C.isSameEntity(Existing,
D))
3485 return FindExistingResult(Reader,
D, Existing, AnonymousDeclNumber,
3486 TypedefNameForLinkage);
3490 return FindExistingResult(Reader);
3502 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3504 Reader.PendingOdrMergeChecks.push_back(
D);
3506 return FindExistingResult(Reader,
D,
nullptr,
3507 AnonymousDeclNumber, TypedefNameForLinkage);
3510template<
typename DeclT>
3512 return D->RedeclLink.getLatestNotUpdated();
3516 llvm_unreachable(
"getMostRecentDecl on non-redeclarable declaration");
3523#define ABSTRACT_DECL(TYPE)
3524#define DECL(TYPE, BASE) \
3526 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3527#include "clang/AST/DeclNodes.inc"
3529 llvm_unreachable(
"unknown decl kind");
3532Decl *ASTReader::getMostRecentExistingDecl(
Decl *
D) {
3540 const auto *IA =
Previous->getAttr<MSInheritanceAttr>();
3542 if (IA && !
D->
hasAttr<MSInheritanceAttr>()) {
3543 NewAttr = cast<InheritableAttr>(IA->clone(Context));
3548 const auto *AA =
Previous->getAttr<AvailabilityAttr>();
3549 if (AA && !
D->
hasAttr<AvailabilityAttr>()) {
3550 NewAttr = AA->
clone(Context);
3556template<
typename DeclT>
3560 D->RedeclLink.setPrevious(cast<DeclT>(
Previous));
3561 D->First = cast<DeclT>(
Previous)->First;
3570 auto *VD =
static_cast<VarDecl *
>(
D);
3571 auto *PrevVD = cast<VarDecl>(
Previous);
3572 D->RedeclLink.setPrevious(PrevVD);
3573 D->First = PrevVD->First;
3582 VD->demoteThisDefinitionToDeclaration();
3599 auto *PrevFD = cast<FunctionDecl>(
Previous);
3601 FD->RedeclLink.setPrevious(PrevFD);
3602 FD->First = PrevFD->First;
3606 if (PrevFD->isInlined() != FD->isInlined()) {
3622 FD->setImplicitlyInline(
true);
3627 if (FPT && PrevFPT) {
3631 bool WasUnresolved =
3633 if (IsUnresolved != WasUnresolved)
3634 Reader.PendingExceptionSpecUpdates.insert(
3635 {Canon, IsUnresolved ? PrevFD : FD});
3641 if (IsUndeduced != WasUndeduced)
3642 Reader.PendingDeducedTypeUpdates.insert(
3643 {cast<FunctionDecl>(Canon),
3644 (IsUndeduced ? PrevFPT : FPT)->getReturnType()});
3651 llvm_unreachable(
"attachPreviousDecl on non-redeclarable declaration");
3656template <
typename ParmDecl>
3659 auto *To = cast<ParmDecl>(ToD);
3660 if (!From->hasDefaultArgument())
3662 To->setInheritedDefaultArgument(Context, From);
3671 assert(FromTP->size() == ToTP->size() &&
"merged mismatched templates?");
3673 for (
unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3674 NamedDecl *FromParam = FromTP->getParam(I);
3677 if (
auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam))
3679 else if (
auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam))
3683 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam);
3706 if (!isa<VarDecl, FunctionDecl, TagDecl, RedeclarableTemplateDecl>(
Previous))
3714 if (
auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(
Previous);
3715 VTSD && !VTSD->isExplicitSpecialization())
3717 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(
Previous);
3718 CTSD && !CTSD->isExplicitSpecialization())
3721 if (
auto *FTSI =
Func->getTemplateSpecializationInfo();
3722 FTSI && !FTSI->isExplicitSpecialization())
3730 diag::err_multiple_decl_in_different_modules)
3740#define ABSTRACT_DECL(TYPE)
3741#define DECL(TYPE, BASE) \
3743 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
3745#include "clang/AST/DeclNodes.inc"
3761 if (
auto *TD = dyn_cast<TemplateDecl>(
D))
3772template<
typename DeclT>
3774 D->RedeclLink.setLatest(cast<DeclT>(Latest));
3778 llvm_unreachable(
"attachLatestDecl on non-redeclarable declaration");
3782 assert(
D && Latest);
3785#define ABSTRACT_DECL(TYPE)
3786#define DECL(TYPE, BASE) \
3788 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3790#include "clang/AST/DeclNodes.inc"
3794template<
typename DeclT>
3796 D->RedeclLink.markIncomplete();
3800 llvm_unreachable(
"markIncompleteDeclChain on non-redeclarable declaration");
3803void ASTReader::markIncompleteDeclChain(
Decl *
D) {
3805#define ABSTRACT_DECL(TYPE)
3806#define DECL(TYPE, BASE) \
3808 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3810#include "clang/AST/DeclNodes.inc"
3817 RecordLocation
Loc = DeclCursorForID(ID, DeclLoc);
3818 llvm::BitstreamCursor &DeclsCursor =
Loc.F->DeclsCursor;
3823 ReadingKindTracker ReadingKind(Read_Decl, *
this);
3826 Deserializing ADecl(
this);
3828 auto Fail = [](
const char *what, llvm::Error &&Err) {
3829 llvm::report_fatal_error(Twine(
"ASTReader::readDeclRecord failed ") + what +
3833 if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(
Loc.Offset))
3834 Fail(
"jumping", std::move(JumpFailed));
3839 Fail(
"reading code", MaybeCode.takeError());
3840 unsigned Code = MaybeCode.get();
3846 llvm::report_fatal_error(
3847 Twine(
"ASTReader::readDeclRecord failed reading decl code: ") +
3848 toString(MaybeDeclCode.takeError()));
3850 switch ((
DeclCode)MaybeDeclCode.get()) {
3853 llvm_unreachable(
"Record cannot be de-serialized with readDeclRecord");
3963 bool HasTypeConstraint =
Record.readInt();
3969 bool HasTypeConstraint =
Record.readInt();
3975 bool HasTypeConstraint =
Record.readInt();
3977 Context, ID,
Record.readInt(), HasTypeConstraint);
4066 D = MSGuidDecl::CreateDeserialized(Context, ID);
4069 D = UnnamedGlobalConstantDecl::CreateDeserialized(Context, ID);
4072 D = TemplateParamObjectDecl::CreateDeserialized(Context, ID);
4078 Error(
"attempt to read a C++ base-specifier record as a declaration");
4081 Error(
"attempt to read a C++ ctor initializer record as a declaration");
4090 unsigned NumChildren =
Record.readInt();
4096 unsigned NumClauses =
Record.readInt();
4097 unsigned NumVars =
Record.readInt();
4103 unsigned NumClauses =
Record.readInt();
4112 unsigned NumClauses =
Record.readInt();
4145 assert(
D &&
"Unknown declaration reading AST file");
4146 LoadedDecl(translateGlobalDeclIDToIndex(ID),
D);
4154 [&] { Reader.Visit(
D); });
4158 if (
auto *DC = dyn_cast<DeclContext>(
D)) {
4159 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
4164 if (!Offsets.first && !Offsets.second && isa<NamespaceDecl>(
D))
4165 if (
auto Iter = DelayedNamespaceOffsetMap.find(ID);
4166 Iter != DelayedNamespaceOffsetMap.end())
4167 Offsets =
Iter->second;
4169 if (Offsets.first &&
4170 ReadLexicalDeclContextStorage(*
Loc.F, DeclsCursor, Offsets.first, DC))
4172 if (Offsets.second &&
4173 ReadVisibleDeclContextStorage(*
Loc.F, DeclsCursor, Offsets.second, ID))
4179 PendingUpdateRecords.push_back(
4180 PendingUpdateRecord(ID,
D,
true));
4183 if (
auto *
Class = dyn_cast<ObjCInterfaceDecl>(
D))
4186 if (
Class->isThisDeclarationADefinition() ||
4187 PendingDefinitions.count(
Class))
4188 loadObjCCategories(ID,
Class);
4194 PotentiallyInterestingDecls.push_back(
D);
4199void ASTReader::PassInterestingDeclsToConsumer() {
4202 if (PassingDeclsToConsumer)
4207 SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
true);
4211 for (
auto ID : EagerlyDeserializedDecls)
4213 EagerlyDeserializedDecls.clear();
4215 auto ConsumingPotentialInterestingDecls = [
this]() {
4216 while (!PotentiallyInterestingDecls.empty()) {
4217 Decl *
D = PotentiallyInterestingDecls.front();
4218 PotentiallyInterestingDecls.pop_front();
4219 if (isConsumerInterestedIn(
D))
4220 PassInterestingDeclToConsumer(
D);
4223 std::deque<Decl *> MaybeInterestingDecls =
4224 std::move(PotentiallyInterestingDecls);
4225 PotentiallyInterestingDecls.clear();
4226 assert(PotentiallyInterestingDecls.empty());
4227 while (!MaybeInterestingDecls.empty()) {
4228 Decl *
D = MaybeInterestingDecls.front();
4229 MaybeInterestingDecls.pop_front();
4235 if (
auto *VD = dyn_cast<VarDecl>(
D);
4236 VD && VD->isFileVarDecl() && !VD->isExternallyVisible())
4238 ConsumingPotentialInterestingDecls();
4239 if (isConsumerInterestedIn(
D))
4240 PassInterestingDeclToConsumer(
D);
4244 ConsumingPotentialInterestingDecls();
4247 auto *RD = cast<CXXRecordDecl>(
GetDecl(ID));
4249 PassVTableToConsumer(RD);
4251 VTablesToEmit.clear();
4254void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &
Record) {
4260 ProcessingUpdatesRAIIObj ProcessingUpdates(*
this);
4261 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
4265 if (UpdI != DeclUpdateOffsets.end()) {
4266 auto UpdateOffsets = std::move(UpdI->second);
4267 DeclUpdateOffsets.erase(UpdI);
4273 bool WasInteresting =
Record.JustLoaded || isConsumerInterestedIn(
D);
4274 for (
auto &FileAndOffset : UpdateOffsets) {
4276 uint64_t Offset = FileAndOffset.second;
4279 if (llvm::Error JumpFailed =
Cursor.JumpToBit(Offset))
4281 llvm::report_fatal_error(
4282 Twine(
"ASTReader::loadDeclUpdateRecords failed jumping: ") +
4286 llvm::report_fatal_error(
4287 Twine(
"ASTReader::loadDeclUpdateRecords failed reading code: ") +
4289 unsigned Code = MaybeCode.get();
4293 "Expected DECL_UPDATES record!");
4295 llvm::report_fatal_error(
4296 Twine(
"ASTReader::loadDeclUpdateRecords failed reading rec code: ") +
4301 Reader.UpdateDecl(
D, PendingLazySpecializationIDs);
4305 if (!WasInteresting && isConsumerInterestedIn(
D)) {
4306 PotentiallyInterestingDecls.push_back(
D);
4307 WasInteresting =
true;
4312 assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(
D) ||
4313 isa<FunctionTemplateDecl, VarTemplateDecl>(
D)) &&
4314 "Must not have pending specializations");
4315 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(
D))
4317 else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(
D))
4319 else if (
auto *VTD = dyn_cast<VarTemplateDecl>(
D))
4321 PendingLazySpecializationIDs.clear();
4324 auto I = PendingVisibleUpdates.find(ID);
4325 if (I != PendingVisibleUpdates.end()) {
4326 auto VisibleUpdates = std::move(I->second);
4327 PendingVisibleUpdates.erase(I);
4330 for (
const auto &
Update : VisibleUpdates)
4331 Lookups[DC].Table.add(
4338void ASTReader::loadPendingDeclChain(
Decl *FirstLocal, uint64_t LocalOffset) {
4341 if (FirstLocal != CanonDecl) {
4344 *
this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
4355 assert(M &&
"imported decl from no module file");
4359 if (llvm::Error JumpFailed =
Cursor.JumpToBit(LocalOffset))
4360 llvm::report_fatal_error(
4361 Twine(
"ASTReader::loadPendingDeclChain failed jumping: ") +
4367 llvm::report_fatal_error(
4368 Twine(
"ASTReader::loadPendingDeclChain failed reading code: ") +
4370 unsigned Code = MaybeCode.get();
4373 "expected LOCAL_REDECLARATIONS record!");
4375 llvm::report_fatal_error(
4376 Twine(
"ASTReader::loadPendingDeclChain failed reading rec code: ") +
4381 Decl *MostRecent = FirstLocal;
4382 for (
unsigned I = 0, N =
Record.size(); I != N; ++I) {
4383 unsigned Idx = N - I - 1;
4395 class ObjCCategoriesVisitor {
4398 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
4400 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
4402 unsigned PreviousGeneration;
4406 if (!Deserialized.erase(Cat))
4417 NonEquivalentDecls, StructuralEquivalenceKind::Default,
4421 if (!Ctx.IsEquivalent(Cat, Existing)) {
4426 diag::note_previous_definition);
4428 }
else if (!Existing) {
4443 ObjCCategoriesVisitor(
4445 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
4448 InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) {
4450 for (
auto *Cat :
Interface->known_categories()) {
4481 LocalID != Result->getDefinitionID()) {
4489 unsigned Offset = Result->Offset;
4492 for (
unsigned I = 0; I != N; ++I)
4501 unsigned PreviousGeneration) {
4502 ObjCCategoriesVisitor Visitor(*
this,
D, CategoriesDeserialized, ID,
4503 PreviousGeneration);
4504 ModuleMgr.
visit(Visitor);
4507template<
typename DeclT,
typename Fn>
4516 for (
auto *Redecl = MostRecent; Redecl && !
Found;
4517 Redecl = Redecl->getPreviousDecl())
4522 for (
auto *Redecl = MostRecent; Redecl !=
D;
4534 auto *RD = cast<CXXRecordDecl>(
D);
4536 assert(MD &&
"couldn't read decl from update record");
4537 Reader.PendingAddedClassMembers.push_back({RD, MD});
4543 PendingLazySpecializationIDs.push_back(readDeclID());
4547 auto *Anon = readDeclAs<NamespaceDecl>();
4552 if (!
Record.isModule()) {
4553 if (
auto *TU = dyn_cast<TranslationUnitDecl>(
D))
4554 TU->setAnonymousNamespace(Anon);
4556 cast<NamespaceDecl>(
D)->setAnonymousNamespace(Anon);
4562 auto *VD = cast<VarDecl>(
D);
4563 VD->NonParmVarDeclBits.IsInline =
Record.readInt();
4564 VD->NonParmVarDeclBits.IsInlineSpecified =
Record.readInt();
4571 if (
auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(
D)) {
4572 VTSD->setPointOfInstantiation(POI);
4573 }
else if (
auto *VD = dyn_cast<VarDecl>(
D)) {
4575 assert(MSInfo &&
"No member specialization information");
4578 auto *FD = cast<FunctionDecl>(
D);
4579 if (
auto *FTSInfo = FD->TemplateOrSpecialization
4581 FTSInfo->setPointOfInstantiation(POI);
4584 ->setPointOfInstantiation(POI);
4590 auto *Param = cast<ParmVarDecl>(
D);
4595 auto *DefaultArg =
Record.readExpr();
4599 if (Param->hasUninstantiatedDefaultArg())
4600 Param->setDefaultArg(DefaultArg);
4605 auto *FD = cast<FieldDecl>(
D);
4606 auto *DefaultInit =
Record.readExpr();
4610 if (FD->hasInClassInitializer() && !FD->hasNonNullInClassInitializer()) {
4612 FD->setInClassInitializer(DefaultInit);
4616 FD->removeInClassInitializer();
4622 auto *FD = cast<FunctionDecl>(
D);
4623 if (Reader.PendingBodies[FD]) {
4637 FD->setInnerLocStart(readSourceLocation());
4639 assert(
Record.getIdx() ==
Record.size() &&
"lazy body must be last");
4644 auto *RD = cast<CXXRecordDecl>(
D);
4646 bool HadRealDefinition =
4647 OldDD && (OldDD->Definition != RD ||
4648 !Reader.PendingFakeDefinitionData.count(OldDD));
4652 ReadCXXRecordDefinition(RD,
true);
4655 uint64_t LexicalOffset = ReadLocalOffset();
4656 if (!HadRealDefinition && LexicalOffset) {
4657 Record.readLexicalDeclContextStorage(LexicalOffset, RD);
4658 Reader.PendingFakeDefinitionData.erase(OldDD);
4665 MSInfo->setTemplateSpecializationKind(TSK);
4666 MSInfo->setPointOfInstantiation(POI);
4668 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
4669 Spec->setTemplateSpecializationKind(TSK);
4670 Spec->setPointOfInstantiation(POI);
4674 readDeclAs<ClassTemplatePartialSpecializationDecl>();
4676 Record.readTemplateArgumentList(TemplArgs);
4682 if (!Spec->getSpecializedTemplateOrPartial()
4684 Spec->setInstantiationOf(PartialSpec, TemplArgList);
4695 Record.readAttributes(Attrs);
4707 auto *Del = readDeclAs<FunctionDecl>();
4709 auto *ThisArg =
Record.readExpr();
4711 if (!
First->OperatorDelete) {
4712 First->OperatorDelete = Del;
4713 First->OperatorDeleteThisArg = ThisArg;
4720 auto ESI =
Record.readExceptionSpecInfo(ExceptionStorage);
4723 auto *FD = cast<FunctionDecl>(
D);
4729 FPT->getReturnType(), FPT->getParamTypes(),
4730 FPT->getExtProtoInfo().withExceptionSpec(ESI)));