56#include "llvm/ADT/DenseMap.h"
57#include "llvm/ADT/FoldingSet.h"
58#include "llvm/ADT/STLExtras.h"
59#include "llvm/ADT/SmallPtrSet.h"
60#include "llvm/ADT/SmallVector.h"
61#include "llvm/ADT/iterator_range.h"
62#include "llvm/Bitstream/BitstreamReader.h"
63#include "llvm/Support/Casting.h"
64#include "llvm/Support/ErrorHandling.h"
65#include "llvm/Support/SaveAndRestore.h"
74using namespace serialization;
85 ASTReader::RecordLocation Loc;
92 unsigned AnonymousDeclNumber;
96 bool HasPendingBody =
false;
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();
129 return Record.readDeclID();
132 std::string readString() {
133 return Record.readString();
137 for (
unsigned I = 0, Size = Record.readInt(); I != Size; ++I)
138 IDs.push_back(readDeclID());
142 return Record.readDecl();
147 return Record.readDeclAs<T>();
151 if (Record.getIdx() == Record.size())
154 return Record.getGlobalSubmoduleID(Record.readInt());
158 return Record.getSubmodule(readSubmoduleID());
162 void ReadCXXDefinitionData(
struct CXXRecordDecl::DefinitionData &
Data,
165 struct CXXRecordDecl::DefinitionData &&NewDD);
166 void ReadObjCDefinitionData(
struct ObjCInterfaceDecl::DefinitionData &
Data);
168 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
169 void ReadObjCDefinitionData(
struct ObjCProtocolDecl::DefinitionData &
Data);
171 struct ObjCProtocolDecl::DefinitionData &&NewDD);
182 class RedeclarableResult {
189 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
195 bool isKeyDecl()
const {
return IsKeyDecl; }
199 Decl *getKnownMergeTarget()
const {
return MergeWith; }
207 class FindExistingResult {
211 bool AddResult =
false;
212 unsigned AnonymousDeclNumber = 0;
216 FindExistingResult(
ASTReader &Reader) : Reader(Reader) {}
219 unsigned AnonymousDeclNumber,
221 : Reader(Reader), New(New), Existing(Existing), AddResult(
true),
222 AnonymousDeclNumber(AnonymousDeclNumber),
223 TypedefNameForLinkage(TypedefNameForLinkage) {}
225 FindExistingResult(FindExistingResult &&Other)
226 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
227 AddResult(Other.AddResult),
228 AnonymousDeclNumber(Other.AnonymousDeclNumber),
229 TypedefNameForLinkage(Other.TypedefNameForLinkage) {
230 Other.AddResult =
false;
233 FindExistingResult &operator=(FindExistingResult &&) =
delete;
234 ~FindExistingResult();
238 void suppress() { AddResult =
false; }
240 operator NamedDecl*()
const {
return Existing; }
243 operator T*()
const {
return dyn_cast_or_null<T>(Existing); }
248 FindExistingResult findExisting(
NamedDecl *D);
252 ASTReader::RecordLocation Loc,
254 : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID),
255 ThisDeclLoc(ThisDeclLoc) {}
257 template <
typename T>
static
266 auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
268 if (
auto &Old = LazySpecializations) {
269 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
271 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
276 std::copy(IDs.begin(), IDs.end(),
Result + 1);
278 LazySpecializations =
Result;
281 template <
typename DeclT>
289 template <
typename DeclT>
297 template <
typename DeclT>
302 template <
typename DeclT>
316 Cat->NextClassCategory = Next;
422 template <
typename T>
426 RedeclarableResult &Redecl);
428 template <
typename T>
430 RedeclarableResult &Redecl);
472template<
typename DeclT>
473class MergedRedeclIterator {
475 DeclT *Canonical =
nullptr;
476 DeclT *Current =
nullptr;
479 MergedRedeclIterator() =
default;
480 MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
484 MergedRedeclIterator &operator++() {
485 if (Current->isFirstDecl()) {
487 Current = Current->getMostRecentDecl();
489 Current = Current->getPreviousDecl();
495 if (Current == Start || Current == Canonical)
500 friend bool operator!=(
const MergedRedeclIterator &A,
501 const MergedRedeclIterator &B) {
502 return A.Current != B.Current;
508template <
typename DeclT>
509static llvm::iterator_range<MergedRedeclIterator<DeclT>>
511 return llvm::make_range(MergedRedeclIterator<DeclT>(D),
512 MergedRedeclIterator<DeclT>());
515uint64_t ASTDeclReader::GetCurrentCursorOffset() {
516 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
521 Reader.DefinitionSource[FD] =
522 Loc.F->Kind == ModuleKind::MK_MainFile ||
525 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
526 CD->setNumCtorInitializers(Record.
readInt());
527 if (CD->getNumCtorInitializers())
528 CD->CtorInitializers = ReadGlobalOffset();
531 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
532 HasPendingBody =
true;
541 IsDeclMarkedUsed =
false;
543 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
544 if (
auto *TInfo = DD->getTypeSourceInfo())
548 if (
auto *TD = dyn_cast<TypeDecl>(D)) {
554 if (NamedDeclForTagDecl)
555 cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
556 cast<TypedefNameDecl>(Reader.
GetDecl(NamedDeclForTagDecl));
557 }
else if (
auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
560 }
else if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
572 isa<ParmVarDecl, ObjCTypeParamDecl>(D)) {
579 GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
580 GlobalDeclID LexicalDCIDForTemplateParmDecl = readDeclID();
581 if (!LexicalDCIDForTemplateParmDecl)
582 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
583 Reader.addPendingDeclContextInfo(D,
584 SemaDCIDForTemplateParmDecl,
585 LexicalDCIDForTemplateParmDecl);
588 auto *SemaDC = readDeclAs<DeclContext>();
589 auto *LexicalDC = readDeclAs<DeclContext>();
592 DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
595 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
599 D->InvalidDecl = Record.
readInt();
609 IsDeclMarkedUsed |= D->Used;
622 switch (ModuleOwnership) {
648 Reader.HiddenNamesMap[Owner].push_back(D);
650 }
else if (ModulePrivate) {
659 std::string Arg = readString();
660 memcpy(D->getTrailingObjects<
char>(), Arg.data(), Arg.size());
661 D->getTrailingObjects<
char>()[Arg.size()] =
'\0';
667 std::string Name = readString();
668 memcpy(D->getTrailingObjects<
char>(), Name.data(), Name.size());
669 D->getTrailingObjects<
char>()[Name.size()] =
'\0';
671 D->ValueStart = Name.size() + 1;
672 std::string
Value = readString();
673 memcpy(D->getTrailingObjects<
char>() + D->ValueStart,
Value.data(),
675 D->getTrailingObjects<
char>()[D->ValueStart +
Value.size()] =
'\0';
679 llvm_unreachable(
"Translation units are not serialized");
685 AnonymousDeclNumber = Record.
readInt();
695ASTDeclReader::RedeclarableResult
720 if (
auto *Template = readDeclAs<TypeAliasTemplateDecl>())
733 if (!isa<CXXRecordDecl>(TD))
746 TD->TypedefNameDeclOrQualifier = Info;
750 NamedDeclForTagDecl = readDeclID();
754 llvm_unreachable(
"unexpected tag info kind");
757 if (!isa<CXXRecordDecl>(TD))
769 ED->setNumPositiveBits(Record.
readInt());
770 ED->setNumNegativeBits(Record.
readInt());
775 ED->setHasODRHash(
true);
776 ED->ODRHash = Record.
readInt();
788 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
795 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
799 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
805 if (
auto *InstED = readDeclAs<EnumDecl>()) {
808 ED->setInstantiationOfMemberEnum(Reader.
getContext(), InstED, TSK);
813ASTDeclReader::RedeclarableResult
833 RD->setODRHash(Record.
readInt());
839 RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
844 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
851 Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
855 Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
867 if (isa<FunctionDecl>(VD))
885 auto *Info =
new (Reader.
getContext()) DeclaratorDecl::ExtInfo();
887 Info->TrailingRequiresClause = Record.
readExpr();
892 TSIType.
isNull() ? nullptr
908 auto *Template = readDeclAs<FunctionTemplateDecl>();
914 auto *InstFD = readDeclAs<FunctionDecl>();
917 FD->setInstantiationOfMemberFunction(Reader.
getContext(), InstFD, TSK);
922 auto *Template = readDeclAs<FunctionTemplateDecl>();
932 bool HasTemplateArgumentsAsWritten = Record.
readInt();
933 if (HasTemplateArgumentsAsWritten) {
934 unsigned NumTemplateArgLocs = Record.
readInt();
935 TemplArgLocs.reserve(NumTemplateArgLocs);
936 for (
unsigned i = 0; i != NumTemplateArgLocs; ++i)
939 LAngleLoc = readSourceLocation();
940 RAngleLoc = readSourceLocation();
949 for (
unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i)
954 auto *FD = readDeclAs<FunctionDecl>();
964 C, FD, Template, TSK, TemplArgList,
965 HasTemplateArgumentsAsWritten ? &TemplArgsInfo :
nullptr, POI,
967 FD->TemplateOrSpecialization = FTInfo;
972 auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>();
978 llvm::FoldingSetNodeID ID;
980 void *InsertPos =
nullptr;
988 "already deserialized this template specialization");
997 unsigned NumTemplates = Record.
readInt();
998 while (NumTemplates--)
999 TemplDecls.
addDecl(readDeclAs<NamedDecl>());
1003 unsigned NumArgs = Record.
readInt();
1010 TemplDecls, TemplArgs);
1029 Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID});
1048 const bool Pure = Record.
readInt();
1066 FD->EndRangeLoc = readSourceLocation();
1069 FD->ODRHash = Record.
readInt();
1070 FD->setHasODRHash(
true);
1073 if (
unsigned NumLookups = Record.
readInt()) {
1075 for (
unsigned I = 0; I != NumLookups; ++I) {
1092 auto merge = [
this, &Redecl, FD](
auto &&F) {
1093 auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1094 RedeclarableResult NewRedecl(Existing ? F(Existing) :
nullptr,
1095 Redecl.getFirstID(), Redecl.isKeyDecl());
1113 unsigned NumParams = Record.
readInt();
1115 Params.reserve(NumParams);
1116 for (
unsigned I = 0; I != NumParams; ++I)
1117 Params.push_back(readDeclAs<ParmVarDecl>());
1126 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1127 HasPendingBody =
true;
1130 MD->
setCmdDecl(readDeclAs<ImplicitParamDecl>());
1143 readDeclAs<ObjCMethodDecl>());
1150 MD->DeclEndLoc = readSourceLocation();
1151 unsigned NumParams = Record.
readInt();
1153 Params.reserve(NumParams);
1154 for (
unsigned I = 0; I != NumParams; ++I)
1155 Params.push_back(readDeclAs<ParmVarDecl>());
1158 unsigned NumStoredSelLocs = Record.
readInt();
1160 SelLocs.reserve(NumStoredSelLocs);
1161 for (
unsigned i = 0; i != NumStoredSelLocs; ++i)
1162 SelLocs.push_back(readSourceLocation());
1164 MD->setParamsAndSelLocs(Reader.
getContext(), Params, SelLocs);
1170 D->Variance = Record.
readInt();
1172 D->VarianceLoc = readSourceLocation();
1173 D->ColonLoc = readSourceLocation();
1183 unsigned numParams = Record.
readInt();
1188 typeParams.reserve(numParams);
1189 for (
unsigned i = 0; i != numParams; ++i) {
1190 auto *typeParam = readDeclAs<ObjCTypeParamDecl>();
1194 typeParams.push_back(typeParam);
1201 typeParams, rAngleLoc);
1204void ASTDeclReader::ReadObjCDefinitionData(
1205 struct ObjCInterfaceDecl::DefinitionData &
Data) {
1207 Data.SuperClassTInfo = readTypeSourceInfo();
1209 Data.EndLoc = readSourceLocation();
1210 Data.HasDesignatedInitializers = Record.
readInt();
1212 Data.HasODRHash =
true;
1215 unsigned NumProtocols = Record.
readInt();
1217 Protocols.reserve(NumProtocols);
1218 for (
unsigned I = 0; I != NumProtocols; ++I)
1219 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1221 ProtoLocs.reserve(NumProtocols);
1222 for (
unsigned I = 0; I != NumProtocols; ++I)
1223 ProtoLocs.push_back(readSourceLocation());
1224 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1228 NumProtocols = Record.
readInt();
1230 Protocols.reserve(NumProtocols);
1231 for (
unsigned I = 0; I != NumProtocols; ++I)
1232 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1233 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1238 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1239 struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1240 if (DD.Definition == NewDD.Definition)
1243 Reader.MergedDeclContexts.insert(
1244 std::make_pair(NewDD.Definition, DD.Definition));
1248 Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back(
1249 {NewDD.Definition, &NewDD});
1261 ID->allocateDefinitionData();
1263 ReadObjCDefinitionData(ID->data());
1265 if (Canon->Data.getPointer()) {
1268 MergeDefinitionData(Canon, std::move(ID->data()));
1269 ID->Data = Canon->Data;
1273 ID->getCanonicalDecl()->Data = ID->Data;
1276 ID->setIvarList(
nullptr);
1280 Reader.PendingDefinitions.insert(ID);
1283 Reader.ObjCClassesLoaded.push_back(ID);
1285 ID->Data = ID->getCanonicalDecl()->Data;
1294 bool synth = Record.
readInt();
1309 if (PrevIvar && PrevIvar != IVD) {
1310 auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->
getDeclContext());
1311 auto *PrevParentExt =
1313 if (ParentExt && PrevParentExt) {
1317 .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt,
1319 .push_back(std::make_pair(IVD, PrevIvar));
1320 }
else if (ParentExt || PrevParentExt) {
1331void ASTDeclReader::ReadObjCDefinitionData(
1332 struct ObjCProtocolDecl::DefinitionData &
Data) {
1333 unsigned NumProtoRefs = Record.
readInt();
1335 ProtoRefs.reserve(NumProtoRefs);
1336 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1337 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1339 ProtoLocs.reserve(NumProtoRefs);
1340 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1341 ProtoLocs.push_back(readSourceLocation());
1342 Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1345 Data.HasODRHash =
true;
1348void ASTDeclReader::MergeDefinitionData(
1350 struct ObjCProtocolDecl::DefinitionData &DD = D->data();
1351 if (DD.Definition == NewDD.Definition)
1354 Reader.MergedDeclContexts.insert(
1355 std::make_pair(NewDD.Definition, DD.Definition));
1359 Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back(
1360 {NewDD.Definition, &NewDD});
1370 PD->allocateDefinitionData();
1372 ReadObjCDefinitionData(PD->data());
1375 if (Canon->Data.getPointer()) {
1378 MergeDefinitionData(Canon, std::move(PD->data()));
1379 PD->Data = Canon->Data;
1386 Reader.PendingDefinitions.insert(PD);
1405 Reader.CategoriesDeserialized.insert(CD);
1407 CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>();
1409 unsigned NumProtoRefs = Record.
readInt();
1411 ProtoRefs.reserve(NumProtoRefs);
1412 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1413 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1415 ProtoLocs.reserve(NumProtoRefs);
1416 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1417 ProtoLocs.push_back(readSourceLocation());
1463 D->CategoryNameLoc = readSourceLocation();
1469 D->SuperLoc = readSourceLocation();
1474 D->NumIvarInitializers = Record.
readInt();
1475 if (D->NumIvarInitializers)
1476 D->IvarInitializers = ReadGlobalOffset();
1483 D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>();
1484 D->IvarLoc = readSourceLocation();
1493 FD->Mutable = Record.
readInt();
1495 if (
auto ISK =
static_cast<FieldDecl::InitStorageKind
>(Record.
readInt())) {
1496 FD->InitStorage.setInt(ISK);
1497 FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType
1506 if (
auto *Tmpl = readDeclAs<FieldDecl>())
1534 D->Value = Record.readAPValue();
1538 Reader.
getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D))
1544 D->Value = Record.readAPValue();
1549 Reader.
getContext().TemplateParamObjectDecls.GetOrInsertNode(D))
1556 FD->ChainingSize = Record.
readInt();
1557 assert(FD->ChainingSize >= 2 &&
"Anonymous chaining must be >= 2");
1560 for (
unsigned I = 0; I != FD->ChainingSize; ++I)
1561 FD->Chaining[I] = readDeclAs<NamedDecl>();
1574 if (!isa<ParmVarDecl>(VD)) {
1597 if (uint64_t Val = Record.
readInt()) {
1613 Reader.DefinitionSource[VD] =
1614 Loc.F->Kind == ModuleKind::MK_MainFile ||
1619 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1621 switch ((VarKind)Record.
readInt()) {
1622 case VarNotTemplate:
1625 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1626 !isa<VarTemplateSpecializationDecl>(VD))
1633 case StaticDataMemberSpecialization: {
1634 auto *Tmpl = readDeclAs<VarDecl>();
1652 unsigned isObjCMethodParam = Record.
readInt();
1653 unsigned scopeDepth = Record.
readInt();
1654 unsigned scopeIndex = Record.
readInt();
1655 unsigned declQualifier = Record.
readInt();
1656 if (isObjCMethodParam) {
1657 assert(scopeDepth == 0);
1674 auto **BDs = DD->getTrailingObjects<
BindingDecl *>();
1675 for (
unsigned I = 0; I != DD->NumBindings; ++I) {
1676 BDs[I] = readDeclAs<BindingDecl>();
1677 BDs[I]->setDecomposedDecl(DD);
1701 unsigned NumParams = Record.
readInt();
1703 Params.reserve(NumParams);
1704 for (
unsigned I = 0; I != NumParams; ++I)
1705 Params.push_back(readDeclAs<ParmVarDecl>());
1714 bool capturesCXXThis = Record.
readInt();
1715 unsigned numCaptures = Record.
readInt();
1717 captures.reserve(numCaptures);
1718 for (
unsigned i = 0; i != numCaptures; ++i) {
1719 auto *
decl = readDeclAs<VarDecl>();
1720 unsigned flags = Record.
readInt();
1721 bool byRef = (flags & 1);
1722 bool nested = (flags & 2);
1723 Expr *copyExpr = ((flags & 4) ? Record.
readExpr() :
nullptr);
1732 unsigned ContextParamPos = Record.
readInt();
1735 for (
unsigned I = 0; I < CD->NumParams; ++I) {
1736 if (I != ContextParamPos)
1737 CD->
setParam(I, readDeclAs<ImplicitParamDecl>());
1752 D->RBraceLoc = readSourceLocation();
1765 D->LocStart = readSourceLocation();
1766 D->RBraceLoc = readSourceLocation();
1773 if (Redecl.getFirstID() == ThisDeclID) {
1774 AnonNamespace = readDeclID();
1778 D->AnonOrFirstNamespaceAndFlags.setPointer(D->
getFirstDecl());
1783 if (AnonNamespace) {
1787 auto *Anon = cast<NamespaceDecl>(Reader.
GetDecl(AnonNamespace));
1797 D->KwLoc = readSourceLocation();
1798 D->LBraceLoc = readSourceLocation();
1799 D->RBraceLoc = readSourceLocation();
1805 D->NamespaceLoc = readSourceLocation();
1806 D->IdentLoc = readSourceLocation();
1808 D->Namespace = readDeclAs<NamedDecl>();
1817 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1819 if (
auto *Pattern = readDeclAs<NamedDecl>())
1829 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1830 if (
auto *Pattern = readDeclAs<UsingEnumDecl>())
1837 D->InstantiatedFrom = readDeclAs<NamedDecl>();
1838 auto **Expansions = D->getTrailingObjects<
NamedDecl *>();
1839 for (
unsigned I = 0; I != D->NumExpansions; ++I)
1840 Expansions[I] = readDeclAs<NamedDecl>();
1847 D->Underlying = readDeclAs<NamedDecl>();
1849 D->UsingOrNextShadow = readDeclAs<NamedDecl>();
1850 auto *Pattern = readDeclAs<UsingShadowDecl>();
1859 D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1860 D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1861 D->IsVirtual = Record.
readInt();
1866 D->UsingLoc = readSourceLocation();
1867 D->NamespaceLoc = readSourceLocation();
1869 D->NominatedNamespace = readDeclAs<NamedDecl>();
1870 D->CommonAncestor = readDeclAs<DeclContext>();
1878 D->EllipsisLoc = readSourceLocation();
1885 D->TypenameLocation = readSourceLocation();
1887 D->EllipsisLoc = readSourceLocation();
1896void ASTDeclReader::ReadCXXDefinitionData(
1898 #define FIELD(Name, Width, Merge) \
1899 Data.Name = Record.readInt();
1900 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
1904 Data.HasODRHash =
true;
1907 Reader.DefinitionSource[D] =
1908 Loc.F->Kind == ModuleKind::MK_MainFile ||
1914 Data.Bases = ReadGlobalOffset();
1917 Data.VBases = ReadGlobalOffset();
1920 Data.ComputedVisibleConversions = Record.
readInt();
1921 if (
Data.ComputedVisibleConversions)
1923 assert(
Data.Definition &&
"Data.Definition should be already set!");
1924 Data.FirstFriend = readDeclID();
1926 if (
Data.IsLambda) {
1929 auto &Lambda =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(
Data);
1930 Lambda.DependencyKind = Record.
readInt();
1931 Lambda.IsGenericLambda = Record.
readInt();
1932 Lambda.CaptureDefault = Record.
readInt();
1933 Lambda.NumCaptures = Record.
readInt();
1934 Lambda.NumExplicitCaptures = Record.
readInt();
1935 Lambda.HasKnownInternalLinkage = Record.
readInt();
1936 Lambda.ManglingNumber = Record.
readInt();
1938 Lambda.ContextDecl = readDeclID();
1940 if (Lambda.NumCaptures) {
1942 Lambda.NumCaptures);
1943 Lambda.AddCaptureList(Reader.
getContext(), ToCapture);
1945 Lambda.MethodTyInfo = readTypeSourceInfo();
1946 for (
unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
1948 bool IsImplicit = Record.
readInt();
1958 auto *Var = readDeclAs<VarDecl>();
1960 *ToCapture++ =
Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
1967void ASTDeclReader::MergeDefinitionData(
1968 CXXRecordDecl *D,
struct CXXRecordDecl::DefinitionData &&MergeDD) {
1969 assert(D->DefinitionData &&
1970 "merging class definition into non-definition");
1971 auto &DD = *D->DefinitionData;
1973 if (DD.Definition != MergeDD.Definition) {
1975 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
1977 Reader.PendingDefinitions.erase(MergeDD.Definition);
1978 MergeDD.Definition->setCompleteDefinition(
false);
1980 assert(!Reader.Lookups.contains(MergeDD.Definition) &&
1981 "already loaded pending lookups for merged definition");
1984 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
1985 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
1986 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
1989 assert(!DD.IsLambda && !MergeDD.IsLambda &&
"faked up lambda definition?");
1990 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
1994 auto *Def = DD.Definition;
1995 DD = std::move(MergeDD);
1996 DD.Definition = Def;
2000 bool DetectedOdrViolation =
false;
2002 #define FIELD(Name, Width, Merge) Merge(Name)
2003 #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
2004 #define NO_MERGE(Field) \
2005 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
2007 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2012 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
2013 DetectedOdrViolation =
true;
2019 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
2020 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
2021 DD.ComputedVisibleConversions =
true;
2028 auto &Lambda1 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(DD);
2029 auto &Lambda2 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(MergeDD);
2030 DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind;
2031 DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda;
2032 DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault;
2033 DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures;
2034 DetectedOdrViolation |=
2035 Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures;
2036 DetectedOdrViolation |=
2037 Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage;
2038 DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber;
2040 if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) {
2041 for (
unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) {
2046 Lambda1.AddCaptureList(Reader.
getContext(), Lambda2.Captures.front());
2051 DetectedOdrViolation =
true;
2054 if (DetectedOdrViolation)
2055 Reader.PendingOdrMergeFailures[DD.Definition].push_back(
2056 {MergeDD.Definition, &MergeDD});
2059void ASTDeclReader::ReadCXXRecordDefinition(
CXXRecordDecl *D,
bool Update) {
2060 struct CXXRecordDecl::DefinitionData *DD;
2065 bool IsLambda = Record.
readInt();
2067 DD =
new (
C) CXXRecordDecl::LambdaDefinitionData(
2070 DD =
new (
C)
struct CXXRecordDecl::DefinitionData(D);
2076 if (!Canon->DefinitionData)
2077 Canon->DefinitionData = DD;
2078 D->DefinitionData = Canon->DefinitionData;
2079 ReadCXXDefinitionData(*DD, D);
2084 if (Canon->DefinitionData != DD) {
2085 MergeDefinitionData(Canon, std::move(*DD));
2095 if (Update || Canon != D)
2096 Reader.PendingDefinitions.insert(D);
2099ASTDeclReader::RedeclarableResult
2106 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
2108 switch ((CXXRecKind)Record.
readInt()) {
2109 case CXXRecNotTemplate:
2111 if (!isa<ClassTemplateSpecializationDecl>(D))
2114 case CXXRecTemplate: {
2116 auto *Template = readDeclAs<ClassTemplateDecl>();
2117 D->TemplateOrInstantiation = Template;
2118 if (!Template->getTemplatedDecl()) {
2129 case CXXRecMemberSpecialization: {
2130 auto *RD = readDeclAs<CXXRecordDecl>();
2135 D->TemplateOrInstantiation = MSI;
2141 bool WasDefinition = Record.
readInt();
2143 ReadCXXRecordDefinition(D,
false);
2150 if (WasDefinition) {
2151 DeclID KeyFn = readDeclID();
2156 C.KeyFunctions[D] = KeyFn;
2164 D->Ctor = readDeclAs<CXXConstructorDecl>();
2172 unsigned NumOverridenMethods = Record.
readInt();
2174 while (NumOverridenMethods--) {
2177 if (
auto *MD = readDeclAs<CXXMethodDecl>())
2183 Record.
skipInts(NumOverridenMethods);
2192 auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>();
2193 auto *Ctor = readDeclAs<CXXConstructorDecl>();
2204 if (
auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
2208 if (!Canon->OperatorDelete) {
2209 Canon->OperatorDelete = OperatorDelete;
2210 Canon->OperatorDeleteThisArg = ThisArg;
2222 D->ImportedModule = readModule();
2223 D->setImportComplete(Record.
readInt());
2225 for (
unsigned I = 0, N = Record.
back(); I != N; ++I)
2226 StoredLocs[I] = readSourceLocation();
2238 D->Friend = readDeclAs<NamedDecl>();
2240 D->Friend = readTypeSourceInfo();
2241 for (
unsigned i = 0; i != D->NumTPLists; ++i)
2244 D->NextFriend = readDeclID();
2245 D->UnsupportedFriend = (Record.
readInt() != 0);
2246 D->FriendLoc = readSourceLocation();
2251 unsigned NumParams = Record.
readInt();
2252 D->NumParams = NumParams;
2254 for (
unsigned i = 0; i != NumParams; ++i)
2257 D->Friend = readDeclAs<NamedDecl>();
2259 D->Friend = readTypeSourceInfo();
2260 D->FriendLoc = readSourceLocation();
2268 D->
init(readDeclAs<NamedDecl>());
2283 for (
unsigned I = 0; I < D->NumTemplateArgs; ++I)
2291ASTDeclReader::RedeclarableResult
2300 Reader.PendingDefinitions.insert(CanonD);
2306 if (ThisDeclID == Redecl.getFirstID()) {
2307 if (
auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) {
2308 assert(RTD->getKind() == D->
getKind() &&
2309 "InstantiatedFromMemberTemplate kind mismatch");
2326 if (ThisDeclID == Redecl.getFirstID()) {
2330 readDeclIDList(SpecIDs);
2344 llvm_unreachable(
"BuiltinTemplates are not serialized");
2354 if (ThisDeclID == Redecl.getFirstID()) {
2358 readDeclIDList(SpecIDs);
2363ASTDeclReader::RedeclarableResult
2369 if (
Decl *InstD = readDecl()) {
2370 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2371 D->SpecializedTemplate = CTD;
2379 SpecializedPartialSpecialization();
2380 PS->PartialSpecialization
2381 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2382 PS->TemplateArgs = ArgList;
2383 D->SpecializedTemplate = PS;
2390 D->PointOfInstantiation = readSourceLocation();
2393 bool writtenAsCanonicalDecl = Record.
readInt();
2394 if (writtenAsCanonicalDecl) {
2395 auto *CanonPattern = readDeclAs<ClassTemplateDecl>();
2399 if (
auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
2400 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2401 .GetOrInsertNode(Partial);
2404 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2407 if (CanonSpec != D) {
2408 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2412 if (
auto *DDD = D->DefinitionData) {
2413 if (CanonSpec->DefinitionData)
2414 MergeDefinitionData(CanonSpec, std::move(*DDD));
2416 CanonSpec->DefinitionData = D->DefinitionData;
2418 D->DefinitionData = CanonSpec->DefinitionData;
2425 auto *ExplicitInfo =
2426 new (
C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2427 ExplicitInfo->TypeAsWritten = TyInfo;
2428 ExplicitInfo->ExternLoc = readSourceLocation();
2429 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2430 D->ExplicitInfo = ExplicitInfo;
2441 D->TemplateParams = Params;
2447 if (ThisDeclID == Redecl.getFirstID()) {
2448 D->InstantiatedFromMember.setPointer(
2449 readDeclAs<ClassTemplatePartialSpecializationDecl>());
2450 D->InstantiatedFromMember.setInt(Record.
readInt());
2457 D->Specialization = readDeclAs<CXXMethodDecl>();
2465 if (ThisDeclID == Redecl.getFirstID()) {
2468 readDeclIDList(SpecIDs);
2478ASTDeclReader::RedeclarableResult
2482 if (
Decl *InstD = readDecl()) {
2483 if (
auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2484 D->SpecializedTemplate = VTD;
2492 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2493 PS->PartialSpecialization =
2494 cast<VarTemplatePartialSpecializationDecl>(InstD);
2495 PS->TemplateArgs = ArgList;
2496 D->SpecializedTemplate = PS;
2502 auto *ExplicitInfo =
2503 new (
C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2504 ExplicitInfo->TypeAsWritten = TyInfo;
2505 ExplicitInfo->ExternLoc = readSourceLocation();
2506 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2507 D->ExplicitInfo = ExplicitInfo;
2513 D->PointOfInstantiation = readSourceLocation();
2515 D->IsCompleteDefinition = Record.
readInt();
2519 bool writtenAsCanonicalDecl = Record.
readInt();
2520 if (writtenAsCanonicalDecl) {
2521 auto *CanonPattern = readDeclAs<VarTemplateDecl>();
2524 if (
auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
2525 CanonSpec = CanonPattern->getCommonPtr()
2526 ->PartialSpecializations.GetOrInsertNode(Partial);
2529 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2533 mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl);
2548 D->TemplateParams = Params;
2554 if (ThisDeclID == Redecl.getFirstID()) {
2555 D->InstantiatedFromMember.setPointer(
2556 readDeclAs<VarTemplatePartialSpecializationDecl>());
2557 D->InstantiatedFromMember.setInt(Record.
readInt());
2573 Expr *ImmediatelyDeclaredConstraint = Record.
readExpr();
2575 ArgsAsWritten, ImmediatelyDeclaredConstraint);
2576 if ((D->ExpandedParameterPack = Record.
readInt()))
2577 D->NumExpanded = Record.
readInt();
2592 auto TypesAndInfos =
2593 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2596 TypesAndInfos[I].second = readTypeSourceInfo();
2600 D->ParameterPack = Record.
readInt();
2618 D->ParameterPack = Record.
readInt();
2632 D->AssertExprAndFailed.setPointer(Record.
readExpr());
2633 D->AssertExprAndFailed.setInt(Record.
readInt());
2634 D->Message = cast_or_null<StringLiteral>(Record.
readExpr());
2635 D->RParenLoc = readSourceLocation();
2645 D->ExtendingDecl = readDeclAs<ValueDecl>();
2646 D->ExprWithTemporary = Record.
readStmt();
2651 D->ManglingNumber = Record.
readInt();
2655std::pair<uint64_t, uint64_t>
2657 uint64_t LexicalOffset = ReadLocalOffset();
2658 uint64_t VisibleOffset = ReadLocalOffset();
2659 return std::make_pair(LexicalOffset, VisibleOffset);
2662template <
typename T>
2663ASTDeclReader::RedeclarableResult
2665 DeclID FirstDeclID = readDeclID();
2666 Decl *MergeWith =
nullptr;
2668 bool IsKeyDecl = ThisDeclID == FirstDeclID;
2669 bool IsFirstLocalDecl =
false;
2671 uint64_t RedeclOffset = 0;
2675 if (FirstDeclID == 0) {
2676 FirstDeclID = ThisDeclID;
2678 IsFirstLocalDecl =
true;
2679 }
else if (
unsigned N = Record.
readInt()) {
2683 IsFirstLocalDecl =
true;
2690 for (
unsigned I = 0; I != N - 1; ++I)
2691 MergeWith = readDecl();
2693 RedeclOffset = ReadLocalOffset();
2700 auto *FirstDecl = cast_or_null<T>(Reader.
GetDecl(FirstDeclID));
2701 if (FirstDecl != D) {
2707 D->
First = FirstDecl->getCanonicalDecl();
2710 auto *DAsT =
static_cast<T *
>(D);
2716 if (IsFirstLocalDecl)
2717 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2719 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2724template <
typename T>
2726 RedeclarableResult &Redecl) {
2735 auto *D =
static_cast<T *
>(DBase);
2737 if (
auto *Existing = Redecl.getKnownMergeTarget())
2740 else if (FindExistingResult ExistingRes = findExisting(D))
2741 if (T *Existing = ExistingRes)
2746 RedeclarableResult &Redecl) {
2759 llvm_unreachable(
"bad assert_cast");
2769 RedeclarableResult
Result( ExistingPattern,
2770 DPattern->getCanonicalDecl()->getGlobalID(),
2773 if (
auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2776 auto *ExistingClass =
2777 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2778 if (
auto *DDD = DClass->DefinitionData) {
2779 if (ExistingClass->DefinitionData) {
2780 MergeDefinitionData(ExistingClass, std::move(*DDD));
2782 ExistingClass->DefinitionData = DClass->DefinitionData;
2785 Reader.PendingDefinitions.insert(DClass);
2788 DClass->DefinitionData = ExistingClass->DefinitionData;
2793 if (
auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2796 if (
auto *DVar = dyn_cast<VarDecl>(DPattern))
2798 if (
auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2801 llvm_unreachable(
"merged an unknown kind of redeclarable template");
2806template <
typename T>
2808 RedeclarableResult &Redecl) {
2809 auto *D =
static_cast<T *
>(DBase);
2812 if (ExistingCanon != DCanon) {
2817 D->
First = ExistingCanon;
2818 ExistingCanon->Used |= D->Used;
2824 if (
auto *Namespace = dyn_cast<NamespaceDecl>(D))
2825 Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2826 assert_cast<NamespaceDecl *>(ExistingCanon));
2829 if (
auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2831 DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2832 Redecl.isKeyDecl());
2835 if (Redecl.isKeyDecl())
2836 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2849 if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
2864 Reader.LETemporaryForMerging[std::make_pair(
2891 if (FindExistingResult ExistingRes = findExisting(
static_cast<T*
>(D)))
2892 if (T *Existing = ExistingRes)
2894 Existing->getCanonicalDecl());
2926 D->PrevDeclInScope = readDeclID();
2932 D->VarName = Record.readDeclarationName();
2933 D->PrevDeclInScope = readDeclID();
2951 uint64_t readInt() {
2955 bool readBool() {
return Reader.
readBool(); }
2967 std::string readString() {
2979 VersionTuple readVersionTuple() {
2985 template <
typename T> T *GetLocalDeclAs(uint32_t LocalID) {
2992 AttrReader Record(*
this);
2993 auto V = Record.readInt();
2997 Attr *New =
nullptr;
3007 unsigned ParsedKind = Record.readInt();
3008 unsigned Syntax = Record.readInt();
3009 unsigned SpellingIndex = Record.readInt();
3015#include "clang/Serialization/AttrPCHRead.inc"
3017 assert(New &&
"Unable to decode attribute?");
3023 for (
unsigned I = 0, E =
readInt(); I != E; ++I)
3038inline void ASTReader::LoadedDecl(
unsigned Index,
Decl *D) {
3039 assert(!DeclsLoaded[Index] &&
"Decl loaded twice?");
3040 DeclsLoaded[Index] = D;
3068 if (
const auto *Var = dyn_cast<VarDecl>(D))
3069 return Var->isFileVarDecl() &&
3071 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
3072 if (
const auto *Func = dyn_cast<FunctionDecl>(D))
3073 return Func->doesThisDeclarationHaveABody() || HasBody;
3083ASTReader::RecordLocation
3086 assert(I != GlobalDeclMap.
end() &&
"Corrupted global declaration map");
3094ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
3095 auto I = GlobalBitOffsetsMap.find(GlobalOffset);
3097 assert(I != GlobalBitOffsetsMap.end() &&
"Corrupted global bit offsets map");
3098 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
3109 if (
auto *ND = dyn_cast<NamespaceDecl>(DC))
3110 return ND->getOriginalNamespace();
3112 if (
auto *RD = dyn_cast<CXXRecordDecl>(DC)) {
3114 auto *DD = RD->DefinitionData;
3116 DD = RD->getCanonicalDecl()->DefinitionData;
3123 DD =
new (Reader.
getContext())
struct CXXRecordDecl::DefinitionData(RD);
3124 RD->setCompleteDefinition(
true);
3125 RD->DefinitionData = DD;
3126 RD->getCanonicalDecl()->DefinitionData = DD;
3129 Reader.PendingFakeDefinitionData.insert(
3130 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
3133 return DD->Definition;
3136 if (
auto *RD = dyn_cast<RecordDecl>(DC))
3137 return RD->getDefinition();
3139 if (
auto *ED = dyn_cast<EnumDecl>(DC))
3140 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
3143 if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(DC))
3144 return OID->getDefinition();
3148 if (
auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3154ASTDeclReader::FindExistingResult::~FindExistingResult() {
3157 if (TypedefNameForLinkage) {
3159 Reader.ImportedTypedefNamesForLinkage.insert(
3160 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3164 if (!AddResult || Existing)
3170 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3171 AnonymousDeclNumber, New);
3175 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3177 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3180 MergeDC->makeDeclVisibleInContextImpl(New,
true);
3188 bool IsTypedefNameForLinkage) {
3189 if (!IsTypedefNameForLinkage)
3198 if (
auto *TND = dyn_cast<TypedefNameDecl>(Found))
3199 return TND->getAnonDeclWithTypedefName(
true);
3208ASTDeclReader::getPrimaryDCForAnonymousDecl(
DeclContext *LexicalDC) {
3210 if (
auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3211 auto *DD = RD->getCanonicalDecl()->DefinitionData;
3212 return DD ? DD->Definition :
nullptr;
3213 }
else if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(LexicalDC)) {
3214 return OID->getCanonicalDecl()->getDefinition();
3221 if (
auto *FD = dyn_cast<FunctionDecl>(D))
3222 if (FD->isThisDeclarationADefinition())
3224 if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
3225 if (MD->isThisDeclarationADefinition())
3227 if (
auto *RD = dyn_cast<RecordDecl>(D))
3228 if (RD->isThisDeclarationADefinition())
3244 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3250 auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3251 if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
3263void ASTDeclReader::setAnonymousDeclForMerging(
ASTReader &Reader,
3266 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3268 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3275ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(
NamedDecl *D) {
3282 FindExistingResult
Result(Reader, D,
nullptr,
3283 AnonymousDeclNumber, TypedefNameForLinkage);
3290 if (TypedefNameForLinkage) {
3291 auto It = Reader.ImportedTypedefNamesForLinkage.find(
3292 std::make_pair(DC, TypedefNameForLinkage));
3293 if (It != Reader.ImportedTypedefNamesForLinkage.end())
3294 if (
C.isSameEntity(It->second, D))
3295 return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3296 TypedefNameForLinkage);
3304 if (
auto *Existing = getAnonymousDeclForMerging(
3306 if (
C.isSameEntity(Existing, D))
3307 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3308 TypedefNameForLinkage);
3315 class UpToDateIdentifierRAII {
3317 bool WasOutToDate =
false;
3328 ~UpToDateIdentifierRAII() {
3332 } UpToDate(Name.getAsIdentifierInfo());
3335 IEnd = IdResolver.
end();
3338 if (
C.isSameEntity(Existing, D))
3339 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3340 TypedefNameForLinkage);
3342 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3346 if (
C.isSameEntity(Existing, D))
3347 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3348 TypedefNameForLinkage);
3352 return FindExistingResult(Reader);
3361 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3363 Reader.PendingOdrMergeChecks.push_back(D);
3365 return FindExistingResult(Reader, D,
nullptr,
3366 AnonymousDeclNumber, TypedefNameForLinkage);
3369template<
typename DeclT>
3375 llvm_unreachable(
"getMostRecentDecl on non-redeclarable declaration");
3382#define ABSTRACT_DECL(TYPE)
3383#define DECL(TYPE, BASE) \
3385 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3386#include "clang/AST/DeclNodes.inc"
3388 llvm_unreachable(
"unknown decl kind");
3391Decl *ASTReader::getMostRecentExistingDecl(
Decl *D) {
3399 const auto *IA =
Previous->getAttr<MSInheritanceAttr>();
3401 if (IA && !D->
hasAttr<MSInheritanceAttr>()) {
3402 NewAttr = cast<InheritableAttr>(IA->clone(Context));
3407 const auto *AA =
Previous->getAttr<AvailabilityAttr>();
3408 if (AA && !D->
hasAttr<AvailabilityAttr>()) {
3409 NewAttr = AA->
clone(Context);
3415template<
typename DeclT>
3429 auto *VD =
static_cast<VarDecl *
>(D);
3430 auto *PrevVD = cast<VarDecl>(
Previous);
3432 D->
First = PrevVD->First;
3441 VD->demoteThisDefinitionToDeclaration();
3458 auto *PrevFD = cast<FunctionDecl>(
Previous);
3460 FD->RedeclLink.setPrevious(PrevFD);
3461 FD->First = PrevFD->First;
3465 if (PrevFD->isInlined() != FD->isInlined()) {
3481 FD->setImplicitlyInline(
true);
3486 if (FPT && PrevFPT) {
3490 bool WasUnresolved =
3492 if (IsUnresolved != WasUnresolved)
3493 Reader.PendingExceptionSpecUpdates.insert(
3494 {Canon, IsUnresolved ? PrevFD : FD});
3500 if (IsUndeduced != WasUndeduced)
3501 Reader.PendingDeducedTypeUpdates.insert(
3502 {cast<FunctionDecl>(Canon),
3503 (IsUndeduced ? PrevFPT : FPT)->getReturnType()});
3510 llvm_unreachable(
"attachPreviousDecl on non-redeclarable declaration");
3515template <
typename ParmDecl>
3518 auto *To = cast<ParmDecl>(ToD);
3519 if (!From->hasDefaultArgument())
3521 To->setInheritedDefaultArgument(Context, From);
3530 assert(FromTP->size() == ToTP->size() &&
"merged mismatched templates?");
3532 for (
unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3533 NamedDecl *FromParam = FromTP->getParam(I);
3536 if (
auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam))
3538 else if (
auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam))
3542 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam);
3551#define ABSTRACT_DECL(TYPE)
3552#define DECL(TYPE, BASE) \
3554 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
3556#include "clang/AST/DeclNodes.inc"
3570 if (
auto *TD = dyn_cast<TemplateDecl>(D))
3581template<
typename DeclT>
3587 llvm_unreachable(
"attachLatestDecl on non-redeclarable declaration");
3591 assert(D && Latest);
3594#define ABSTRACT_DECL(TYPE)
3595#define DECL(TYPE, BASE) \
3597 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3599#include "clang/AST/DeclNodes.inc"
3603template<
typename DeclT>
3609 llvm_unreachable(
"markIncompleteDeclChain on non-redeclarable declaration");
3612void ASTReader::markIncompleteDeclChain(
Decl *D) {
3614#define ABSTRACT_DECL(TYPE)
3615#define DECL(TYPE, BASE) \
3617 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3619#include "clang/AST/DeclNodes.inc"
3627 RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
3628 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
3633 ReadingKindTracker ReadingKind(Read_Decl, *
this);
3636 Deserializing ADecl(
this);
3638 auto Fail = [](
const char *what, llvm::Error &&Err) {
3639 llvm::report_fatal_error(Twine(
"ASTReader::readDeclRecord failed ") + what +
3643 if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset))
3644 Fail(
"jumping", std::move(JumpFailed));
3649 Fail(
"reading code", MaybeCode.takeError());
3650 unsigned Code = MaybeCode.get();
3656 llvm::report_fatal_error(
3657 Twine(
"ASTReader::readDeclRecord failed reading decl code: ") +
3658 toString(MaybeDeclCode.takeError()));
3659 switch ((
DeclCode)MaybeDeclCode.get()) {
3662 llvm_unreachable(
"Record cannot be de-serialized with readDeclRecord");
3775 bool HasTypeConstraint =
Record.readInt();
3781 bool HasTypeConstraint =
Record.readInt();
3787 bool HasTypeConstraint =
Record.readInt();
3879 D = MSGuidDecl::CreateDeserialized(Context, ID);
3882 D = UnnamedGlobalConstantDecl::CreateDeserialized(Context, ID);
3885 D = TemplateParamObjectDecl::CreateDeserialized(Context, ID);
3891 Error(
"attempt to read a C++ base-specifier record as a declaration");
3894 Error(
"attempt to read a C++ ctor initializer record as a declaration");
3903 unsigned NumChildren =
Record.readInt();
3909 unsigned NumClauses =
Record.readInt();
3910 unsigned NumVars =
Record.readInt();
3916 unsigned NumClauses =
Record.readInt();
3925 unsigned NumClauses =
Record.readInt();
3958 assert(D &&
"Unknown declaration reading AST file");
3959 LoadedDecl(Index, D);
3968 if (
auto *DC = dyn_cast<DeclContext>(D)) {
3969 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
3970 if (Offsets.first &&
3971 ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
3973 if (Offsets.second &&
3974 ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
3980 PendingUpdateRecords.push_back(
3981 PendingUpdateRecord(ID, D,
true));
3984 if (
auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
3987 if (
Class->isThisDeclarationADefinition() ||
3988 PendingDefinitions.count(Class))
3989 loadObjCCategories(ID, Class);
3995 PotentiallyInterestingDecls.push_back(
3996 InterestingDecl(D, Reader.hasPendingBody()));
4001void ASTReader::PassInterestingDeclsToConsumer() {
4004 if (PassingDeclsToConsumer)
4009 SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
true);
4013 for (
auto ID : EagerlyDeserializedDecls)
4015 EagerlyDeserializedDecls.clear();
4017 while (!PotentiallyInterestingDecls.empty()) {
4018 InterestingDecl D = PotentiallyInterestingDecls.front();
4019 PotentiallyInterestingDecls.pop_front();
4021 PassInterestingDeclToConsumer(D.getDecl());
4025void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
4031 ProcessingUpdatesRAIIObj ProcessingUpdates(*
this);
4032 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
4036 if (UpdI != DeclUpdateOffsets.end()) {
4037 auto UpdateOffsets = std::move(UpdI->second);
4038 DeclUpdateOffsets.erase(UpdI);
4044 bool WasInteresting =
4046 for (
auto &FileAndOffset : UpdateOffsets) {
4053 llvm::report_fatal_error(
4054 Twine(
"ASTReader::loadDeclUpdateRecords failed jumping: ") +
4058 llvm::report_fatal_error(
4059 Twine(
"ASTReader::loadDeclUpdateRecords failed reading code: ") +
4061 unsigned Code = MaybeCode.get();
4065 "Expected DECL_UPDATES record!");
4067 llvm::report_fatal_error(
4068 Twine(
"ASTReader::loadDeclUpdateRecords failed reading rec code: ") +
4073 Reader.UpdateDecl(D, PendingLazySpecializationIDs);
4077 if (!WasInteresting &&
4079 PotentiallyInterestingDecls.push_back(
4080 InterestingDecl(D, Reader.hasPendingBody()));
4081 WasInteresting =
true;
4086 assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||
4087 isa<FunctionTemplateDecl, VarTemplateDecl>(D)) &&
4088 "Must not have pending specializations");
4089 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(D))
4091 else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
4093 else if (
auto *VTD = dyn_cast<VarTemplateDecl>(D))
4095 PendingLazySpecializationIDs.clear();
4098 auto I = PendingVisibleUpdates.find(ID);
4099 if (I != PendingVisibleUpdates.end()) {
4100 auto VisibleUpdates = std::move(I->second);
4101 PendingVisibleUpdates.erase(I);
4104 for (
const auto &Update : VisibleUpdates)
4105 Lookups[DC].Table.add(
4112void ASTReader::loadPendingDeclChain(
Decl *FirstLocal, uint64_t LocalOffset) {
4115 if (FirstLocal != CanonDecl) {
4118 *
this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
4129 assert(M &&
"imported decl from no module file");
4133 if (llvm::Error JumpFailed =
Cursor.JumpToBit(LocalOffset))
4134 llvm::report_fatal_error(
4135 Twine(
"ASTReader::loadPendingDeclChain failed jumping: ") +
4141 llvm::report_fatal_error(
4142 Twine(
"ASTReader::loadPendingDeclChain failed reading code: ") +
4144 unsigned Code = MaybeCode.get();
4147 "expected LOCAL_REDECLARATIONS record!");
4149 llvm::report_fatal_error(
4150 Twine(
"ASTReader::loadPendingDeclChain failed reading rec code: ") +
4155 Decl *MostRecent = FirstLocal;
4156 for (
unsigned I = 0, N =
Record.size(); I != N; ++I) {
4168 class ObjCCategoriesVisitor {
4171 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
4173 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
4175 unsigned PreviousGeneration;
4179 if (!Deserialized.erase(Cat))
4190 NonEquivalentDecls, StructuralEquivalenceKind::Default,
4194 if (!Ctx.IsEquivalent(Cat, Existing)) {
4199 diag::note_previous_definition);
4201 }
else if (!Existing) {
4216 ObjCCategoriesVisitor(
ASTReader &Reader,
4218 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
4220 unsigned PreviousGeneration)
4221 : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
4222 InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) {
4254 Result->DefinitionID != LocalID) {
4262 unsigned Offset = Result->Offset;
4265 for (
unsigned I = 0; I != N; ++I)
4266 add(cast_or_null<ObjCCategoryDecl>(
4276 unsigned PreviousGeneration) {
4277 ObjCCategoriesVisitor Visitor(*
this, D, CategoriesDeserialized, ID,
4278 PreviousGeneration);
4279 ModuleMgr.
visit(Visitor);
4282template<
typename DeclT,
typename Fn>
4291 for (
auto *Redecl = MostRecent; Redecl && !Found;
4293 Found = (Redecl == D);
4297 for (
auto *Redecl = MostRecent; Redecl != D;
4305 while (Record.getIdx() < Record.size()) {
4308 auto *RD = cast<CXXRecordDecl>(D);
4311 Decl *MD = Record.readDecl();
4312 assert(MD &&
"couldn't read decl from update record");
4315 RD->addedMember(MD);
4321 PendingLazySpecializationIDs.push_back(readDeclID());
4325 auto *Anon = readDeclAs<NamespaceDecl>();
4330 if (!Record.isModule()) {
4331 if (
auto *TU = dyn_cast<TranslationUnitDecl>(D))
4332 TU->setAnonymousNamespace(Anon);
4334 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
4340 auto *VD = cast<VarDecl>(D);
4341 VD->NonParmVarDeclBits.IsInline = Record.readInt();
4342 VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
4343 uint64_t Val = Record.readInt();
4344 if (Val && !VD->getInit()) {
4345 VD->setInit(Record.readExpr());
4357 if (
auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
4358 VTSD->setPointOfInstantiation(POI);
4359 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
4360 VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
4362 auto *FD = cast<FunctionDecl>(D);
4363 if (
auto *FTSInfo = FD->TemplateOrSpecialization
4365 FTSInfo->setPointOfInstantiation(POI);
4368 ->setPointOfInstantiation(POI);
4374 auto *Param = cast<ParmVarDecl>(D);
4379 auto *DefaultArg = Record.readExpr();
4383 if (Param->hasUninstantiatedDefaultArg())
4384 Param->setDefaultArg(DefaultArg);
4389 auto *FD = cast<FieldDecl>(D);
4390 auto *DefaultInit = Record.readExpr();
4394 if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) {
4396 FD->setInClassInitializer(DefaultInit);
4400 FD->removeInClassInitializer();
4406 auto *FD = cast<FunctionDecl>(D);
4407 if (Reader.PendingBodies[FD]) {
4413 if (Record.readInt()) {
4421 FD->setInnerLocStart(readSourceLocation());
4423 assert(Record.getIdx() == Record.size() &&
"lazy body must be last");
4428 auto *RD = cast<CXXRecordDecl>(D);
4429 auto *OldDD = RD->getCanonicalDecl()->DefinitionData;
4430 bool HadRealDefinition =
4431 OldDD && (OldDD->Definition != RD ||
4432 !Reader.PendingFakeDefinitionData.count(OldDD));
4433 RD->setParamDestroyedInCallee(Record.readInt());
4434 RD->setArgPassingRestrictions(
4436 ReadCXXRecordDefinition(RD,
true);
4439 uint64_t LexicalOffset = ReadLocalOffset();
4440 if (!HadRealDefinition && LexicalOffset) {
4441 Record.readLexicalDeclContextStorage(LexicalOffset, RD);
4442 Reader.PendingFakeDefinitionData.erase(OldDD);
4448 RD->getMemberSpecializationInfo()) {
4449 MSInfo->setTemplateSpecializationKind(TSK);
4450 MSInfo->setPointOfInstantiation(POI);
4452 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
4453 Spec->setTemplateSpecializationKind(TSK);
4454 Spec->setPointOfInstantiation(POI);
4456 if (Record.readInt()) {
4458 readDeclAs<ClassTemplatePartialSpecializationDecl>();
4460 Record.readTemplateArgumentList(TemplArgs);
4466 if (!Spec->getSpecializedTemplateOrPartial()
4468 Spec->setInstantiationOf(PartialSpec, TemplArgList);
4473 RD->setLocation(readSourceLocation());
4474 RD->setLocStart(readSourceLocation());
4475 RD->setBraceRange(readSourceRange());
4477 if (Record.readInt()) {
4479 Record.readAttributes(Attrs);
4491 auto *Del = readDeclAs<FunctionDecl>();
4493 auto *ThisArg = Record.readExpr();
4495 if (!
First->OperatorDelete) {
4496 First->OperatorDelete = Del;
4497 First->OperatorDeleteThisArg = ThisArg;
4504 auto ESI = Record.readExceptionSpecInfo(ExceptionStorage);
4507 auto *FD = cast<FunctionDecl>(D);
4513 FPT->getReturnType(), FPT->getParamTypes(),
4514 FPT->getExtProtoInfo().withExceptionSpec(ESI)));
4518 Reader.PendingExceptionSpecUpdates.insert(
4519 std::make_pair(FD->getCanonicalDecl(), FD));
4525 auto *FD = cast<FunctionDecl>(D);
4526 QualType DeducedResultType = Record.readType();
4527 Reader.PendingDeducedTypeUpdates.insert(
4528 {FD->getCanonicalDecl(), DeducedResultType});
4548 D->
addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(
4554 auto AllocatorKind =
4555 static_cast<OMPAllocateDeclAttr::AllocatorTypeTy
>(Record.readInt());
4556 Expr *Allocator = Record.readExpr();
4557 Expr *Alignment = Record.readExpr();
4559 D->
addAttr(OMPAllocateDeclAttr::CreateImplicit(
4560 Reader.
getContext(), AllocatorKind, Allocator, Alignment, SR,
4567 auto *Exported = cast<NamedDecl>(D);
4570 Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported);
4575 auto MapType = Record.readEnum<OMPDeclareTargetDeclAttr::MapTypeTy>();
4576 auto DevType = Record.readEnum<OMPDeclareTargetDeclAttr::DevTypeTy>();
4577 Expr *IndirectE = Record.readExpr();
4578 bool Indirect = Record.readBool();
4579 unsigned Level = Record.readInt();
4580 D->
addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(
4581 Reader.
getContext(), MapType, DevType, IndirectE, Indirect, Level,
4588 Record.readAttributes(Attrs);
4589 assert(Attrs.size() == 1);
Defines the clang::ASTContext interface.
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)
static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody)
Determine whether the consumer will be interested in seeing this declaration (via HandleTopLevelDecl)...
Defines the clang::attr::Kind enum.
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
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.
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.
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.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
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)
bool DeclMustBeEmitted(const Decl *D)
Determines if the decl can be CodeGen'ed or deserialized from PCH lazily, only when used; this is onl...
const LangOptions & getLangOpts() const
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
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.
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.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
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)
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 VisitClassScopeFunctionSpecializationDecl(ClassScopeFunctionSpecializationDecl *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)
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 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)
void VisitTypeAliasDecl(TypeAliasDecl *TD)
static void attachPreviousDeclImpl(ASTReader &Reader, Redeclarable< DeclT > *D, Decl *Previous, Decl *Canon)
void VisitConceptDecl(ConceptDecl *D)
void VisitObjCPropertyDecl(ObjCPropertyDecl *D)
void VisitObjCIvarDecl(ObjCIvarDecl *D)
void VisitUsingPackDecl(UsingPackDecl *D)
void VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
static void mergeInheritableAttributes(ASTReader &Reader, Decl *D, Decl *Previous)
void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D)
void VisitUsingDecl(UsingDecl *D)
void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D)
void VisitVarTemplatePartialSpecializationDecl(VarTemplatePartialSpecializationDecl *D)
TODO: Unify with ClassTemplatePartialSpecializationDecl version? May require unifying ClassTemplate(P...
void VisitParmVarDecl(ParmVarDecl *PD)
void VisitVarTemplateDecl(VarTemplateDecl *D)
TODO: Unify with ClassTemplateDecl version? May require unifying ClassTemplateDecl and VarTemplateDec...
static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, Decl *Canon)
std::pair< uint64_t, uint64_t > VisitDeclContext(DeclContext *DC)
ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, ASTReader::RecordLocation Loc, DeclID thisDeclID, SourceLocation ThisDeclLoc)
void VisitClassTemplateDecl(ClassTemplateDecl *D)
bool hasPendingBody() const
Determine whether this declaration has a pending body.
void VisitCXXDestructorDecl(CXXDestructorDecl *D)
void VisitTemplateDecl(TemplateDecl *D)
void VisitCXXConversionDecl(CXXConversionDecl *D)
void VisitTypedefDecl(TypedefDecl *TD)
void VisitOMPRequiresDecl(OMPRequiresDecl *D)
void VisitDecompositionDecl(DecompositionDecl *DD)
Reads an AST files chain containing the contents of a translation unit.
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Decl * GetDecl(serialization::DeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Decl * GetLocalDecl(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, SourceLocation Loc) const
Translate a source location from another module file's source location space into ours.
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope.
ModuleFile * getOwningModuleFile(const Decl *D)
Retrieve the module file that owns the given declaration, or NULL if the declaration is not from a mo...
serialization::DeclID mapGlobalIDToModuleFileGlobalID(ModuleFile &M, serialization::DeclID GlobalID)
Map a global declaration ID into the declaration ID used to refer to this declaration within the give...
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef)
Note that MergedDef is a redefinition of the canonical definition Def, so Def should be visible whene...
SmallVector< uint64_t, 64 > RecordData
An object for streaming information from a record.
bool readBool()
Read a boolean value, advancing Idx.
std::string readString()
Read a string, advancing Idx.
TemplateArgumentLoc readTemplateArgumentLoc()
Reads a TemplateArgumentLoc, advancing Idx.
void readTypeLoc(TypeLoc TL, LocSeq *Seq=nullptr)
Reads the location information for a type.
ExplicitSpecifier readExplicitSpec()
void readUnresolvedSet(LazyASTUnresolvedSet &Set)
Read a UnresolvedSet structure, advancing Idx.
void readTemplateArgumentList(SmallVectorImpl< TemplateArgument > &TemplArgs, bool Canonicalize=false)
Read a template argument array, advancing Idx.
void readAttributes(AttrVec &Attrs)
Reads attributes from the current stream position, advancing Idx.
void readQualifierInfo(QualifierInfo &Info)
DeclarationNameLoc readDeclarationNameLoc(DeclarationName Name)
Read a declaration name, advancing Idx.
QualType readType()
Read a type from the current position in the record.
T * GetLocalDeclAs(uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
bool isModule() const
Is this a module file for a module (rather than a PCH or similar).
T * readDeclAs()
Reads a declaration from the given position in the record, advancing Idx.
DeclarationNameInfo readDeclarationNameInfo()
IdentifierInfo * readIdentifier()
TemplateArgument readTemplateArgument(bool Canonicalize)
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
TypeSourceInfo * readTypeSourceInfo()
Reads a declarator info from the given record, advancing Idx.
void skipInts(unsigned N)
Skips the specified number of values.
SourceRange readSourceRange(LocSeq *Seq=nullptr)
Read a source range, advancing Idx.
serialization::TypeID getGlobalTypeID(unsigned LocalID) const
Map a local type ID within a given AST file to a global type ID.
NestedNameSpecifierLoc readNestedNameSpecifierLoc()
Return a nested name specifier, advancing Idx.
void readOMPChildren(OMPChildren *Data)
Read an OpenMP children, advancing Idx.
OMPTraitInfo * readOMPTraitInfo()
Read an OMPTraitInfo object, advancing Idx.
TemplateParameterList * readTemplateParameterList()
Read a template parameter list, advancing Idx.
VersionTuple readVersionTuple()
Read a version tuple, advancing Idx.
uint64_t back()
Returns the last value in this record.
Stmt * readStmt()
Reads a statement.
const ASTTemplateArgumentListInfo * readASTTemplateArgumentListInfo()
uint64_t readInt()
Returns the current value in this record, and advances to the next value.
Attr * readAttr()
Reads one attribute from the current stream position, advancing Idx.