57#include "llvm/ADT/DenseMap.h"
58#include "llvm/ADT/FoldingSet.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/SmallPtrSet.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/ADT/iterator_range.h"
63#include "llvm/Bitstream/BitstreamReader.h"
64#include "llvm/Support/Casting.h"
65#include "llvm/Support/ErrorHandling.h"
66#include "llvm/Support/SaveAndRestore.h"
75using namespace serialization;
86 ASTReader::RecordLocation Loc;
93 unsigned AnonymousDeclNumber = 0;
97 bool HasPendingBody =
false;
102 bool IsDeclMarkedUsed =
false;
104 uint64_t GetCurrentCursorOffset();
106 uint64_t ReadLocalOffset() {
107 uint64_t LocalOffset = Record.readInt();
108 assert(LocalOffset < Loc.Offset &&
"offset point after current record");
109 return LocalOffset ? Loc.Offset - LocalOffset : 0;
112 uint64_t ReadGlobalOffset() {
113 uint64_t Local = ReadLocalOffset();
114 return Local ? Record.getGlobalBitOffset(Local) : 0;
118 return Record.readSourceLocation();
122 return Record.readSourceRange();
126 return Record.readTypeSourceInfo();
130 return Record.readDeclID();
133 std::string readString() {
134 return Record.readString();
138 for (
unsigned I = 0, Size = Record.readInt(); I != Size; ++I)
139 IDs.push_back(readDeclID());
143 return Record.readDecl();
148 return Record.readDeclAs<T>();
152 if (Record.getIdx() == Record.size())
155 return Record.getGlobalSubmoduleID(Record.readInt());
159 return Record.getSubmodule(readSubmoduleID());
163 Decl *LambdaContext =
nullptr,
164 unsigned IndexInLambdaContext = 0);
165 void ReadCXXDefinitionData(
struct CXXRecordDecl::DefinitionData &
Data,
167 unsigned IndexInLambdaContext);
169 struct CXXRecordDecl::DefinitionData &&NewDD);
170 void ReadObjCDefinitionData(
struct ObjCInterfaceDecl::DefinitionData &
Data);
172 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
173 void ReadObjCDefinitionData(
struct ObjCProtocolDecl::DefinitionData &
Data);
175 struct ObjCProtocolDecl::DefinitionData &&NewDD);
193 class RedeclarableResult {
200 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
206 bool isKeyDecl()
const {
return IsKeyDecl; }
210 Decl *getKnownMergeTarget()
const {
return MergeWith; }
218 class FindExistingResult {
222 bool AddResult =
false;
223 unsigned AnonymousDeclNumber = 0;
227 FindExistingResult(
ASTReader &Reader) : Reader(Reader) {}
230 unsigned AnonymousDeclNumber,
232 : Reader(Reader), New(New), Existing(Existing), AddResult(
true),
233 AnonymousDeclNumber(AnonymousDeclNumber),
234 TypedefNameForLinkage(TypedefNameForLinkage) {}
236 FindExistingResult(FindExistingResult &&Other)
237 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
238 AddResult(Other.AddResult),
239 AnonymousDeclNumber(Other.AnonymousDeclNumber),
240 TypedefNameForLinkage(Other.TypedefNameForLinkage) {
241 Other.AddResult =
false;
244 FindExistingResult &operator=(FindExistingResult &&) =
delete;
245 ~FindExistingResult();
249 void suppress() { AddResult =
false; }
251 operator NamedDecl*()
const {
return Existing; }
254 operator T*()
const {
return dyn_cast_or_null<T>(Existing); }
259 FindExistingResult findExisting(
NamedDecl *D);
263 ASTReader::RecordLocation Loc,
265 : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID),
266 ThisDeclLoc(ThisDeclLoc) {}
268 template <
typename T>
static
277 auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
279 if (
auto &Old = LazySpecializations) {
280 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
282 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
287 std::copy(IDs.begin(), IDs.end(),
Result + 1);
289 LazySpecializations =
Result;
292 template <
typename DeclT>
300 template <
typename DeclT>
308 template <
typename DeclT>
313 template <
typename DeclT>
327 Cat->NextClassCategory = Next;
434 template <
typename T>
438 Decl *Context,
unsigned Number);
441 RedeclarableResult &Redecl);
443 template <
typename T>
445 RedeclarableResult &Redecl);
487template <
typename DeclT>
class MergedRedeclIterator {
488 DeclT *Start =
nullptr;
489 DeclT *Canonical =
nullptr;
490 DeclT *Current =
nullptr;
493 MergedRedeclIterator() =
default;
494 MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
498 MergedRedeclIterator &operator++() {
499 if (Current->isFirstDecl()) {
501 Current = Current->getMostRecentDecl();
503 Current = Current->getPreviousDecl();
509 if (Current == Start || Current == Canonical)
514 friend bool operator!=(
const MergedRedeclIterator &A,
515 const MergedRedeclIterator &B) {
516 return A.Current != B.Current;
522template <
typename DeclT>
523static llvm::iterator_range<MergedRedeclIterator<DeclT>>
525 return llvm::make_range(MergedRedeclIterator<DeclT>(D),
526 MergedRedeclIterator<DeclT>());
529uint64_t ASTDeclReader::GetCurrentCursorOffset() {
530 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
535 Reader.DefinitionSource[FD] =
536 Loc.F->Kind == ModuleKind::MK_MainFile ||
539 if (
auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
540 CD->setNumCtorInitializers(Record.
readInt());
541 if (CD->getNumCtorInitializers())
542 CD->CtorInitializers = ReadGlobalOffset();
545 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
546 HasPendingBody =
true;
555 IsDeclMarkedUsed =
false;
557 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
558 if (
auto *TInfo = DD->getTypeSourceInfo())
562 if (
auto *TD = dyn_cast<TypeDecl>(D)) {
568 if (NamedDeclForTagDecl)
569 cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
570 cast<TypedefNameDecl>(Reader.
GetDecl(NamedDeclForTagDecl));
571 }
else if (
auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
574 }
else if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
578 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
580 }
else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
581 if (FD->hasInClassInitializer() && Record.
readInt()) {
582 FD->setLazyInClassInitializer(
LazyDeclStmtPtr(GetCurrentCursorOffset()));
589 isa<ParmVarDecl, ObjCTypeParamDecl>(D)) {
596 GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID();
597 GlobalDeclID LexicalDCIDForTemplateParmDecl = readDeclID();
598 if (!LexicalDCIDForTemplateParmDecl)
599 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
600 Reader.addPendingDeclContextInfo(D,
601 SemaDCIDForTemplateParmDecl,
602 LexicalDCIDForTemplateParmDecl);
605 auto *SemaDC = readDeclAs<DeclContext>();
606 auto *LexicalDC = readDeclAs<DeclContext>();
612 if (
auto *RD = dyn_cast<CXXRecordDecl>(SemaDC))
613 MergedSemaDC = getOrFakePrimaryClassDefinition(Reader, RD);
615 MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
618 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
622 D->InvalidDecl = Record.
readInt();
632 IsDeclMarkedUsed |= D->Used;
645 switch (ModuleOwnership) {
671 Reader.HiddenNamesMap[Owner].push_back(D);
673 }
else if (ModulePrivate) {
682 std::string Arg = readString();
683 memcpy(D->getTrailingObjects<
char>(), Arg.data(), Arg.size());
684 D->getTrailingObjects<
char>()[Arg.size()] =
'\0';
690 std::string Name = readString();
691 memcpy(D->getTrailingObjects<
char>(), Name.data(), Name.size());
692 D->getTrailingObjects<
char>()[Name.size()] =
'\0';
694 D->ValueStart = Name.size() + 1;
695 std::string
Value = readString();
696 memcpy(D->getTrailingObjects<
char>() + D->ValueStart,
Value.data(),
698 D->getTrailingObjects<
char>()[D->ValueStart +
Value.size()] =
'\0';
702 llvm_unreachable(
"Translation units are not serialized");
708 AnonymousDeclNumber = Record.
readInt();
718ASTDeclReader::RedeclarableResult
743 if (
auto *Template = readDeclAs<TypeAliasTemplateDecl>())
756 if (!isa<CXXRecordDecl>(TD))
769 TD->TypedefNameDeclOrQualifier = Info;
773 NamedDeclForTagDecl = readDeclID();
777 llvm_unreachable(
"unexpected tag info kind");
780 if (!isa<CXXRecordDecl>(TD))
792 ED->setNumPositiveBits(Record.
readInt());
793 ED->setNumNegativeBits(Record.
readInt());
798 ED->setHasODRHash(
true);
799 ED->ODRHash = Record.
readInt();
811 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
818 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
822 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
828 if (
auto *InstED = readDeclAs<EnumDecl>()) {
831 ED->setInstantiationOfMemberEnum(Reader.
getContext(), InstED, TSK);
836ASTDeclReader::RedeclarableResult
856 RD->setODRHash(Record.
readInt());
862 RecordDecl *&OldDef = Reader.RecordDefinitions[Canon];
867 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
874 Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef));
878 Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD);
890 if (isa<FunctionDecl, VarDecl>(VD))
908 auto *Info =
new (Reader.
getContext()) DeclaratorDecl::ExtInfo();
910 Info->TrailingRequiresClause = Record.
readExpr();
915 TSIType.
isNull() ? nullptr
931 auto *Template = readDeclAs<FunctionTemplateDecl>();
937 auto *InstFD = readDeclAs<FunctionDecl>();
940 FD->setInstantiationOfMemberFunction(Reader.
getContext(), InstFD, TSK);
945 auto *Template = readDeclAs<FunctionTemplateDecl>();
955 bool HasTemplateArgumentsAsWritten = Record.
readInt();
956 if (HasTemplateArgumentsAsWritten) {
957 unsigned NumTemplateArgLocs = Record.
readInt();
958 TemplArgLocs.reserve(NumTemplateArgLocs);
959 for (
unsigned i = 0; i != NumTemplateArgLocs; ++i)
962 LAngleLoc = readSourceLocation();
963 RAngleLoc = readSourceLocation();
972 for (
unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i)
977 auto *FD = readDeclAs<FunctionDecl>();
987 C, FD, Template, TSK, TemplArgList,
988 HasTemplateArgumentsAsWritten ? &TemplArgsInfo :
nullptr, POI,
990 FD->TemplateOrSpecialization = FTInfo;
995 auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>();
1001 llvm::FoldingSetNodeID ID;
1003 void *InsertPos =
nullptr;
1011 "already deserialized this template specialization");
1020 unsigned NumTemplates = Record.
readInt();
1021 while (NumTemplates--)
1022 TemplDecls.
addDecl(readDeclAs<NamedDecl>());
1026 unsigned NumArgs = Record.
readInt();
1033 TemplDecls, TemplArgs);
1052 Reader.PendingDeducedFunctionTypes.push_back({FD, DeferredTypeID});
1071 const bool Pure = Record.
readInt();
1089 FD->EndRangeLoc = readSourceLocation();
1092 FD->ODRHash = Record.
readInt();
1093 FD->setHasODRHash(
true);
1096 if (
unsigned NumLookups = Record.
readInt()) {
1098 for (
unsigned I = 0; I != NumLookups; ++I) {
1115 auto merge = [
this, &Redecl, FD](
auto &&F) {
1116 auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget());
1117 RedeclarableResult NewRedecl(Existing ? F(Existing) :
nullptr,
1118 Redecl.getFirstID(), Redecl.isKeyDecl());
1136 unsigned NumParams = Record.
readInt();
1138 Params.reserve(NumParams);
1139 for (
unsigned I = 0; I != NumParams; ++I)
1140 Params.push_back(readDeclAs<ParmVarDecl>());
1149 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1150 HasPendingBody =
true;
1153 MD->
setCmdDecl(readDeclAs<ImplicitParamDecl>());
1166 readDeclAs<ObjCMethodDecl>());
1173 MD->DeclEndLoc = readSourceLocation();
1174 unsigned NumParams = Record.
readInt();
1176 Params.reserve(NumParams);
1177 for (
unsigned I = 0; I != NumParams; ++I)
1178 Params.push_back(readDeclAs<ParmVarDecl>());
1181 unsigned NumStoredSelLocs = Record.
readInt();
1183 SelLocs.reserve(NumStoredSelLocs);
1184 for (
unsigned i = 0; i != NumStoredSelLocs; ++i)
1185 SelLocs.push_back(readSourceLocation());
1187 MD->setParamsAndSelLocs(Reader.
getContext(), Params, SelLocs);
1193 D->Variance = Record.
readInt();
1195 D->VarianceLoc = readSourceLocation();
1196 D->ColonLoc = readSourceLocation();
1206 unsigned numParams = Record.
readInt();
1211 typeParams.reserve(numParams);
1212 for (
unsigned i = 0; i != numParams; ++i) {
1213 auto *typeParam = readDeclAs<ObjCTypeParamDecl>();
1217 typeParams.push_back(typeParam);
1224 typeParams, rAngleLoc);
1227void ASTDeclReader::ReadObjCDefinitionData(
1228 struct ObjCInterfaceDecl::DefinitionData &
Data) {
1230 Data.SuperClassTInfo = readTypeSourceInfo();
1232 Data.EndLoc = readSourceLocation();
1233 Data.HasDesignatedInitializers = Record.
readInt();
1235 Data.HasODRHash =
true;
1238 unsigned NumProtocols = Record.
readInt();
1240 Protocols.reserve(NumProtocols);
1241 for (
unsigned I = 0; I != NumProtocols; ++I)
1242 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1244 ProtoLocs.reserve(NumProtocols);
1245 for (
unsigned I = 0; I != NumProtocols; ++I)
1246 ProtoLocs.push_back(readSourceLocation());
1247 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1251 NumProtocols = Record.
readInt();
1253 Protocols.reserve(NumProtocols);
1254 for (
unsigned I = 0; I != NumProtocols; ++I)
1255 Protocols.push_back(readDeclAs<ObjCProtocolDecl>());
1256 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1261 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1262 struct ObjCInterfaceDecl::DefinitionData &DD = D->data();
1263 if (DD.Definition == NewDD.Definition)
1266 Reader.MergedDeclContexts.insert(
1267 std::make_pair(NewDD.Definition, DD.Definition));
1271 Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back(
1272 {NewDD.Definition, &NewDD});
1284 ID->allocateDefinitionData();
1286 ReadObjCDefinitionData(
ID->data());
1288 if (Canon->Data.getPointer()) {
1291 MergeDefinitionData(Canon, std::move(
ID->data()));
1292 ID->Data = Canon->Data;
1296 ID->getCanonicalDecl()->Data =
ID->Data;
1299 ID->setIvarList(
nullptr);
1303 Reader.PendingDefinitions.insert(
ID);
1306 Reader.ObjCClassesLoaded.push_back(
ID);
1308 ID->Data =
ID->getCanonicalDecl()->Data;
1317 bool synth = Record.
readInt();
1332 if (PrevIvar && PrevIvar != IVD) {
1333 auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->
getDeclContext());
1334 auto *PrevParentExt =
1336 if (ParentExt && PrevParentExt) {
1340 .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt,
1342 .push_back(std::make_pair(IVD, PrevIvar));
1343 }
else if (ParentExt || PrevParentExt) {
1354void ASTDeclReader::ReadObjCDefinitionData(
1355 struct ObjCProtocolDecl::DefinitionData &
Data) {
1356 unsigned NumProtoRefs = Record.
readInt();
1358 ProtoRefs.reserve(NumProtoRefs);
1359 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1360 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1362 ProtoLocs.reserve(NumProtoRefs);
1363 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1364 ProtoLocs.push_back(readSourceLocation());
1365 Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1368 Data.HasODRHash =
true;
1371void ASTDeclReader::MergeDefinitionData(
1373 struct ObjCProtocolDecl::DefinitionData &DD = D->data();
1374 if (DD.Definition == NewDD.Definition)
1377 Reader.MergedDeclContexts.insert(
1378 std::make_pair(NewDD.Definition, DD.Definition));
1382 Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back(
1383 {NewDD.Definition, &NewDD});
1393 PD->allocateDefinitionData();
1395 ReadObjCDefinitionData(PD->data());
1398 if (Canon->Data.getPointer()) {
1401 MergeDefinitionData(Canon, std::move(PD->data()));
1402 PD->Data = Canon->Data;
1409 Reader.PendingDefinitions.insert(PD);
1428 Reader.CategoriesDeserialized.insert(CD);
1430 CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>();
1432 unsigned NumProtoRefs = Record.
readInt();
1434 ProtoRefs.reserve(NumProtoRefs);
1435 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1436 ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>());
1438 ProtoLocs.reserve(NumProtoRefs);
1439 for (
unsigned I = 0; I != NumProtoRefs; ++I)
1440 ProtoLocs.push_back(readSourceLocation());
1486 D->CategoryNameLoc = readSourceLocation();
1492 D->SuperLoc = readSourceLocation();
1497 D->NumIvarInitializers = Record.
readInt();
1498 if (D->NumIvarInitializers)
1499 D->IvarInitializers = ReadGlobalOffset();
1506 D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>();
1507 D->IvarLoc = readSourceLocation();
1516 FD->Mutable = Record.
readInt();
1518 unsigned Bits = Record.
readInt();
1519 FD->StorageKind = Bits >> 1;
1520 if (FD->StorageKind == FieldDecl::ISK_CapturedVLAType)
1527 if (
auto *Tmpl = readDeclAs<FieldDecl>())
1555 D->Value = Record.readAPValue();
1559 Reader.
getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D))
1565 D->Value = Record.readAPValue();
1570 Reader.
getContext().TemplateParamObjectDecls.GetOrInsertNode(D))
1577 FD->ChainingSize = Record.
readInt();
1578 assert(FD->ChainingSize >= 2 &&
"Anonymous chaining must be >= 2");
1581 for (
unsigned I = 0; I != FD->ChainingSize; ++I)
1582 FD->Chaining[I] = readDeclAs<NamedDecl>();
1595 bool HasDeducedType =
false;
1596 if (!isa<ParmVarDecl>(VD)) {
1610 HasDeducedType = Record.
readInt();
1617 Reader.PendingDeducedVarTypes.push_back({VD, DeferredTypeID});
1630 if (VD->
hasAttr<BlocksAttr>()) {
1637 Reader.DefinitionSource[VD] =
1638 Loc.F->Kind == ModuleKind::MK_MainFile ||
1643 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1645 switch ((VarKind)Record.
readInt()) {
1646 case VarNotTemplate:
1649 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1650 !isa<VarTemplateSpecializationDecl>(VD))
1657 case StaticDataMemberSpecialization: {
1658 auto *Tmpl = readDeclAs<VarDecl>();
1671 if (uint64_t Val = Record.
readInt()) {
1685 Eval->
Value = GetCurrentCursorOffset();
1695 unsigned isObjCMethodParam = Record.
readInt();
1696 unsigned scopeDepth = Record.
readInt();
1697 unsigned scopeIndex = Record.
readInt();
1698 unsigned declQualifier = Record.
readInt();
1699 if (isObjCMethodParam) {
1700 assert(scopeDepth == 0);
1717 auto **BDs = DD->getTrailingObjects<
BindingDecl *>();
1718 for (
unsigned I = 0; I != DD->NumBindings; ++I) {
1719 BDs[I] = readDeclAs<BindingDecl>();
1720 BDs[I]->setDecomposedDecl(DD);
1744 unsigned NumParams = Record.
readInt();
1746 Params.reserve(NumParams);
1747 for (
unsigned I = 0; I != NumParams; ++I)
1748 Params.push_back(readDeclAs<ParmVarDecl>());
1757 bool capturesCXXThis = Record.
readInt();
1758 unsigned numCaptures = Record.
readInt();
1760 captures.reserve(numCaptures);
1761 for (
unsigned i = 0; i != numCaptures; ++i) {
1762 auto *
decl = readDeclAs<VarDecl>();
1763 unsigned flags = Record.
readInt();
1764 bool byRef = (flags & 1);
1765 bool nested = (flags & 2);
1766 Expr *copyExpr = ((flags & 4) ? Record.
readExpr() :
nullptr);
1775 unsigned ContextParamPos = Record.
readInt();
1778 for (
unsigned I = 0; I < CD->NumParams; ++I) {
1779 if (I != ContextParamPos)
1780 CD->
setParam(I, readDeclAs<ImplicitParamDecl>());
1795 D->RBraceLoc = readSourceLocation();
1808 D->LocStart = readSourceLocation();
1809 D->RBraceLoc = readSourceLocation();
1816 if (Redecl.getFirstID() == ThisDeclID) {
1817 AnonNamespace = readDeclID();
1821 D->AnonOrFirstNamespaceAndFlags.setPointer(D->
getFirstDecl());
1826 if (AnonNamespace) {
1830 auto *Anon = cast<NamespaceDecl>(Reader.
GetDecl(AnonNamespace));
1840 D->KwLoc = readSourceLocation();
1841 D->LBraceLoc = readSourceLocation();
1842 D->RBraceLoc = readSourceLocation();
1848 D->NamespaceLoc = readSourceLocation();
1849 D->IdentLoc = readSourceLocation();
1851 D->Namespace = readDeclAs<NamedDecl>();
1860 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1862 if (
auto *Pattern = readDeclAs<NamedDecl>())
1872 D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>());
1873 if (
auto *Pattern = readDeclAs<UsingEnumDecl>())
1880 D->InstantiatedFrom = readDeclAs<NamedDecl>();
1881 auto **Expansions = D->getTrailingObjects<
NamedDecl *>();
1882 for (
unsigned I = 0; I != D->NumExpansions; ++I)
1883 Expansions[I] = readDeclAs<NamedDecl>();
1890 D->Underlying = readDeclAs<NamedDecl>();
1892 D->UsingOrNextShadow = readDeclAs<NamedDecl>();
1893 auto *Pattern = readDeclAs<UsingShadowDecl>();
1902 D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1903 D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>();
1904 D->IsVirtual = Record.
readInt();
1909 D->UsingLoc = readSourceLocation();
1910 D->NamespaceLoc = readSourceLocation();
1912 D->NominatedNamespace = readDeclAs<NamedDecl>();
1913 D->CommonAncestor = readDeclAs<DeclContext>();
1921 D->EllipsisLoc = readSourceLocation();
1928 D->TypenameLocation = readSourceLocation();
1930 D->EllipsisLoc = readSourceLocation();
1939void ASTDeclReader::ReadCXXDefinitionData(
1941 Decl *LambdaContext,
unsigned IndexInLambdaContext) {
1942#define FIELD(Name, Width, Merge) Data.Name = Record.readInt();
1943#include "clang/AST/CXXRecordDeclDefinitionBits.def"
1947 Data.HasODRHash =
true;
1950 Reader.DefinitionSource[D] =
1951 Loc.F->Kind == ModuleKind::MK_MainFile ||
1956 Data.ComputedVisibleConversions = Record.
readInt();
1957 if (
Data.ComputedVisibleConversions)
1959 assert(
Data.Definition &&
"Data.Definition should be already set!");
1961 if (!
Data.IsLambda) {
1962 assert(!LambdaContext && !IndexInLambdaContext &&
1963 "given lambda context for non-lambda");
1967 Data.Bases = ReadGlobalOffset();
1971 Data.VBases = ReadGlobalOffset();
1973 Data.FirstFriend = readDeclID();
1977 auto &Lambda =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(
Data);
1978 Lambda.DependencyKind = Record.
readInt();
1979 Lambda.IsGenericLambda = Record.
readInt();
1980 Lambda.CaptureDefault = Record.
readInt();
1981 Lambda.NumCaptures = Record.
readInt();
1982 Lambda.NumExplicitCaptures = Record.
readInt();
1983 Lambda.HasKnownInternalLinkage = Record.
readInt();
1984 Lambda.ManglingNumber = Record.
readInt();
1985 if (
unsigned DeviceManglingNumber = Record.
readInt())
1986 Reader.
getContext().DeviceLambdaManglingNumbers[D] = DeviceManglingNumber;
1987 Lambda.IndexInContext = IndexInLambdaContext;
1988 Lambda.ContextDecl = LambdaContext;
1990 if (Lambda.NumCaptures) {
1992 Lambda.NumCaptures);
1993 Lambda.AddCaptureList(Reader.
getContext(), ToCapture);
1995 Lambda.MethodTyInfo = readTypeSourceInfo();
1996 for (
unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
1998 bool IsImplicit = Record.
readInt();
2008 auto *Var = readDeclAs<VarDecl>();
2010 *ToCapture++ =
Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
2017void ASTDeclReader::MergeDefinitionData(
2018 CXXRecordDecl *D,
struct CXXRecordDecl::DefinitionData &&MergeDD) {
2019 assert(D->DefinitionData &&
2020 "merging class definition into non-definition");
2021 auto &DD = *D->DefinitionData;
2023 if (DD.Definition != MergeDD.Definition) {
2025 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
2027 Reader.PendingDefinitions.erase(MergeDD.Definition);
2028 MergeDD.Definition->setCompleteDefinition(
false);
2030 assert(!Reader.Lookups.contains(MergeDD.Definition) &&
2031 "already loaded pending lookups for merged definition");
2034 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
2035 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
2036 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
2039 assert(!DD.IsLambda && !MergeDD.IsLambda &&
"faked up lambda definition?");
2040 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
2044 auto *Def = DD.Definition;
2045 DD = std::move(MergeDD);
2046 DD.Definition = Def;
2050 bool DetectedOdrViolation =
false;
2052 #define FIELD(Name, Width, Merge) Merge(Name)
2053 #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
2054 #define NO_MERGE(Field) \
2055 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
2057 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2062 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
2063 DetectedOdrViolation =
true;
2069 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
2070 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
2071 DD.ComputedVisibleConversions =
true;
2078 auto &Lambda1 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(DD);
2079 auto &Lambda2 =
static_cast<CXXRecordDecl::LambdaDefinitionData &
>(MergeDD);
2080 DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind;
2081 DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda;
2082 DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault;
2083 DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures;
2084 DetectedOdrViolation |=
2085 Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures;
2086 DetectedOdrViolation |=
2087 Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage;
2088 DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber;
2090 if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) {
2091 for (
unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) {
2096 Lambda1.AddCaptureList(Reader.
getContext(), Lambda2.Captures.front());
2101 DetectedOdrViolation =
true;
2104 if (DetectedOdrViolation)
2105 Reader.PendingOdrMergeFailures[DD.Definition].push_back(
2106 {MergeDD.Definition, &MergeDD});
2109void ASTDeclReader::ReadCXXRecordDefinition(
CXXRecordDecl *D,
bool Update,
2110 Decl *LambdaContext,
2111 unsigned IndexInLambdaContext) {
2112 struct CXXRecordDecl::DefinitionData *DD;
2117 bool IsLambda = Record.
readInt();
2118 assert(!(IsLambda && Update) &&
2119 "lambda definition should not be added by update record");
2121 DD =
new (
C) CXXRecordDecl::LambdaDefinitionData(
2124 DD =
new (
C)
struct CXXRecordDecl::DefinitionData(D);
2130 if (!Canon->DefinitionData)
2131 Canon->DefinitionData = DD;
2132 D->DefinitionData = Canon->DefinitionData;
2133 ReadCXXDefinitionData(*DD, D, LambdaContext, IndexInLambdaContext);
2138 if (Canon->DefinitionData != DD) {
2139 MergeDefinitionData(Canon, std::move(*DD));
2149 if (Update || Canon != D)
2150 Reader.PendingDefinitions.insert(D);
2153ASTDeclReader::RedeclarableResult
2160 CXXRecNotTemplate = 0,
2162 CXXRecMemberSpecialization,
2166 Decl *LambdaContext =
nullptr;
2167 unsigned IndexInLambdaContext = 0;
2169 switch ((CXXRecKind)Record.
readInt()) {
2170 case CXXRecNotTemplate:
2172 if (!isa<ClassTemplateSpecializationDecl>(D))
2175 case CXXRecTemplate: {
2177 auto *Template = readDeclAs<ClassTemplateDecl>();
2178 D->TemplateOrInstantiation = Template;
2179 if (!Template->getTemplatedDecl()) {
2190 case CXXRecMemberSpecialization: {
2191 auto *RD = readDeclAs<CXXRecordDecl>();
2196 D->TemplateOrInstantiation = MSI;
2201 LambdaContext = readDecl();
2203 IndexInLambdaContext = Record.
readInt();
2204 mergeLambda(D, Redecl, LambdaContext, IndexInLambdaContext);
2209 bool WasDefinition = Record.
readInt();
2211 ReadCXXRecordDefinition(D,
false, LambdaContext,
2212 IndexInLambdaContext);
2219 if (WasDefinition) {
2220 DeclID KeyFn = readDeclID();
2225 C.KeyFunctions[D] = KeyFn;
2233 D->Ctor = readDeclAs<CXXConstructorDecl>();
2242 unsigned NumOverridenMethods = Record.
readInt();
2244 while (NumOverridenMethods--) {
2247 if (
auto *MD = readDeclAs<CXXMethodDecl>())
2253 Record.
skipInts(NumOverridenMethods);
2262 auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>();
2263 auto *Ctor = readDeclAs<CXXConstructorDecl>();
2274 if (
auto *OperatorDelete = readDeclAs<FunctionDecl>()) {
2278 if (!Canon->OperatorDelete) {
2279 Canon->OperatorDelete = OperatorDelete;
2280 Canon->OperatorDeleteThisArg = ThisArg;
2292 D->ImportedModule = readModule();
2293 D->setImportComplete(Record.
readInt());
2295 for (
unsigned I = 0, N = Record.
back(); I != N; ++I)
2296 StoredLocs[I] = readSourceLocation();
2308 D->Friend = readDeclAs<NamedDecl>();
2310 D->Friend = readTypeSourceInfo();
2311 for (
unsigned i = 0; i != D->NumTPLists; ++i)
2314 D->NextFriend = readDeclID();
2315 D->UnsupportedFriend = (Record.
readInt() != 0);
2316 D->FriendLoc = readSourceLocation();
2321 unsigned NumParams = Record.
readInt();
2322 D->NumParams = NumParams;
2324 for (
unsigned i = 0; i != NumParams; ++i)
2327 D->Friend = readDeclAs<NamedDecl>();
2329 D->Friend = readTypeSourceInfo();
2330 D->FriendLoc = readSourceLocation();
2338 D->
init(readDeclAs<NamedDecl>());
2353 for (
unsigned I = 0; I < D->NumTemplateArgs; ++I)
2361ASTDeclReader::RedeclarableResult
2370 Reader.PendingDefinitions.insert(CanonD);
2376 if (ThisDeclID == Redecl.getFirstID()) {
2377 if (
auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) {
2378 assert(RTD->getKind() == D->
getKind() &&
2379 "InstantiatedFromMemberTemplate kind mismatch");
2396 if (ThisDeclID == Redecl.getFirstID()) {
2400 readDeclIDList(SpecIDs);
2414 llvm_unreachable(
"BuiltinTemplates are not serialized");
2424 if (ThisDeclID == Redecl.getFirstID()) {
2428 readDeclIDList(SpecIDs);
2433ASTDeclReader::RedeclarableResult
2439 if (
Decl *InstD = readDecl()) {
2440 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2441 D->SpecializedTemplate = CTD;
2449 SpecializedPartialSpecialization();
2450 PS->PartialSpecialization
2451 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2452 PS->TemplateArgs = ArgList;
2453 D->SpecializedTemplate = PS;
2460 D->PointOfInstantiation = readSourceLocation();
2463 bool writtenAsCanonicalDecl = Record.
readInt();
2464 if (writtenAsCanonicalDecl) {
2465 auto *CanonPattern = readDeclAs<ClassTemplateDecl>();
2469 if (
auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
2470 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2471 .GetOrInsertNode(Partial);
2474 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2477 if (CanonSpec != D) {
2478 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2482 if (
auto *DDD = D->DefinitionData) {
2483 if (CanonSpec->DefinitionData)
2484 MergeDefinitionData(CanonSpec, std::move(*DDD));
2486 CanonSpec->DefinitionData = D->DefinitionData;
2488 D->DefinitionData = CanonSpec->DefinitionData;
2495 auto *ExplicitInfo =
2496 new (
C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2497 ExplicitInfo->TypeAsWritten = TyInfo;
2498 ExplicitInfo->ExternLoc = readSourceLocation();
2499 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2500 D->ExplicitInfo = ExplicitInfo;
2511 D->TemplateParams = Params;
2517 if (ThisDeclID == Redecl.getFirstID()) {
2518 D->InstantiatedFromMember.setPointer(
2519 readDeclAs<ClassTemplatePartialSpecializationDecl>());
2520 D->InstantiatedFromMember.setInt(Record.
readInt());
2527 D->Specialization = readDeclAs<CXXMethodDecl>();
2535 if (ThisDeclID == Redecl.getFirstID()) {
2538 readDeclIDList(SpecIDs);
2548ASTDeclReader::RedeclarableResult
2552 if (
Decl *InstD = readDecl()) {
2553 if (
auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2554 D->SpecializedTemplate = VTD;
2562 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2563 PS->PartialSpecialization =
2564 cast<VarTemplatePartialSpecializationDecl>(InstD);
2565 PS->TemplateArgs = ArgList;
2566 D->SpecializedTemplate = PS;
2572 auto *ExplicitInfo =
2573 new (
C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2574 ExplicitInfo->TypeAsWritten = TyInfo;
2575 ExplicitInfo->ExternLoc = readSourceLocation();
2576 ExplicitInfo->TemplateKeywordLoc = readSourceLocation();
2577 D->ExplicitInfo = ExplicitInfo;
2583 D->PointOfInstantiation = readSourceLocation();
2585 D->IsCompleteDefinition = Record.
readInt();
2589 bool writtenAsCanonicalDecl = Record.
readInt();
2590 if (writtenAsCanonicalDecl) {
2591 auto *CanonPattern = readDeclAs<VarTemplateDecl>();
2594 if (
auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
2595 CanonSpec = CanonPattern->getCommonPtr()
2596 ->PartialSpecializations.GetOrInsertNode(Partial);
2599 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2603 mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl);
2618 D->TemplateParams = Params;
2624 if (ThisDeclID == Redecl.getFirstID()) {
2625 D->InstantiatedFromMember.setPointer(
2626 readDeclAs<VarTemplatePartialSpecializationDecl>());
2627 D->InstantiatedFromMember.setInt(Record.
readInt());
2640 Expr *ImmediatelyDeclaredConstraint = Record.
readExpr();
2643 if ((D->ExpandedParameterPack = Record.
readInt()))
2644 D->NumExpanded = Record.
readInt();
2659 auto TypesAndInfos =
2660 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2663 TypesAndInfos[I].second = readTypeSourceInfo();
2667 D->ParameterPack = Record.
readInt();
2685 D->ParameterPack = Record.
readInt();
2699 D->AssertExprAndFailed.setPointer(Record.
readExpr());
2700 D->AssertExprAndFailed.setInt(Record.
readInt());
2701 D->Message = cast_or_null<StringLiteral>(Record.
readExpr());
2702 D->RParenLoc = readSourceLocation();
2712 D->ExtendingDecl = readDeclAs<ValueDecl>();
2713 D->ExprWithTemporary = Record.
readStmt();
2718 D->ManglingNumber = Record.
readInt();
2722std::pair<uint64_t, uint64_t>
2724 uint64_t LexicalOffset = ReadLocalOffset();
2725 uint64_t VisibleOffset = ReadLocalOffset();
2726 return std::make_pair(LexicalOffset, VisibleOffset);
2729template <
typename T>
2730ASTDeclReader::RedeclarableResult
2732 DeclID FirstDeclID = readDeclID();
2733 Decl *MergeWith =
nullptr;
2735 bool IsKeyDecl = ThisDeclID == FirstDeclID;
2736 bool IsFirstLocalDecl =
false;
2738 uint64_t RedeclOffset = 0;
2742 if (FirstDeclID == 0) {
2743 FirstDeclID = ThisDeclID;
2745 IsFirstLocalDecl =
true;
2746 }
else if (
unsigned N = Record.
readInt()) {
2750 IsFirstLocalDecl =
true;
2757 for (
unsigned I = 0; I != N - 1; ++I)
2758 MergeWith = readDecl();
2760 RedeclOffset = ReadLocalOffset();
2767 auto *FirstDecl = cast_or_null<T>(Reader.
GetDecl(FirstDeclID));
2768 if (FirstDecl != D) {
2774 D->
First = FirstDecl->getCanonicalDecl();
2777 auto *DAsT =
static_cast<T *
>(D);
2783 if (IsFirstLocalDecl)
2784 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2786 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2791template <
typename T>
2793 RedeclarableResult &Redecl) {
2802 auto *D =
static_cast<T *
>(DBase);
2804 if (
auto *Existing = Redecl.getKnownMergeTarget())
2807 else if (FindExistingResult ExistingRes = findExisting(D))
2808 if (T *Existing = ExistingRes)
2819 Decl *Context,
unsigned IndexInContext) {
2833 if (
auto *Existing = Redecl.getKnownMergeTarget())
2839 NamedDecl *&Slot = Reader.LambdaDeclarationsForMerging[{
2840 Context->getCanonicalDecl(), IndexInContext}];
2848 RedeclarableResult &Redecl) {
2861 llvm_unreachable(
"bad assert_cast");
2871 RedeclarableResult
Result( ExistingPattern,
2872 DPattern->getCanonicalDecl()->getGlobalID(),
2875 if (
auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2878 auto *ExistingClass =
2879 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2880 if (
auto *DDD = DClass->DefinitionData) {
2881 if (ExistingClass->DefinitionData) {
2882 MergeDefinitionData(ExistingClass, std::move(*DDD));
2884 ExistingClass->DefinitionData = DClass->DefinitionData;
2887 Reader.PendingDefinitions.insert(DClass);
2890 DClass->DefinitionData = ExistingClass->DefinitionData;
2895 if (
auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2898 if (
auto *DVar = dyn_cast<VarDecl>(DPattern))
2900 if (
auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2903 llvm_unreachable(
"merged an unknown kind of redeclarable template");
2908template <
typename T>
2910 RedeclarableResult &Redecl) {
2911 auto *D =
static_cast<T *
>(DBase);
2914 if (ExistingCanon != DCanon) {
2919 D->
First = ExistingCanon;
2920 ExistingCanon->Used |= D->Used;
2926 if (
auto *Namespace = dyn_cast<NamespaceDecl>(D))
2927 Namespace->AnonOrFirstNamespaceAndFlags.setPointer(
2928 assert_cast<NamespaceDecl *>(ExistingCanon));
2931 if (
auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2933 DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon),
2934 Redecl.isKeyDecl());
2937 if (Redecl.isKeyDecl())
2938 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2951 if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND))
2966 Reader.LETemporaryForMerging[std::make_pair(
2993 if (FindExistingResult ExistingRes = findExisting(
static_cast<T*
>(D)))
2994 if (T *Existing = ExistingRes)
2996 Existing->getCanonicalDecl());
3028 D->PrevDeclInScope = readDeclID();
3034 D->VarName = Record.readDeclarationName();
3035 D->PrevDeclInScope = readDeclID();
3053 uint64_t readInt() {
3057 bool readBool() {
return Reader.
readBool(); }
3069 std::string readString() {
3081 VersionTuple readVersionTuple() {
3087 template <
typename T> T *GetLocalDeclAs(uint32_t LocalID) {
3094 AttrReader Record(*
this);
3095 auto V = Record.readInt();
3099 Attr *New =
nullptr;
3109 unsigned ParsedKind = Record.readInt();
3110 unsigned Syntax = Record.readInt();
3111 unsigned SpellingIndex = Record.readInt();
3112 bool IsAlignas = (ParsedKind == AttributeCommonInfo::AT_Aligned &&
3114 SpellingIndex == AlignedAttr::Keyword_alignas);
3115 bool IsRegularKeywordAttribute = Record.readBool();
3120 IsAlignas, IsRegularKeywordAttribute});
3122#include "clang/Serialization/AttrPCHRead.inc"
3124 assert(New &&
"Unable to decode attribute?");
3130 for (
unsigned I = 0, E =
readInt(); I != E; ++I)
3145inline void ASTReader::LoadedDecl(
unsigned Index,
Decl *D) {
3146 assert(!DeclsLoaded[Index] &&
"Decl loaded twice?");
3147 DeclsLoaded[Index] = D;
3175 if (
const auto *Var = dyn_cast<VarDecl>(D))
3176 return Var->isFileVarDecl() &&
3178 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
3179 if (
const auto *Func = dyn_cast<FunctionDecl>(D))
3180 return Func->doesThisDeclarationHaveABody() || HasBody;
3190ASTReader::RecordLocation
3193 assert(I != GlobalDeclMap.
end() &&
"Corrupted global declaration map");
3201ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
3202 auto I = GlobalBitOffsetsMap.find(GlobalOffset);
3204 assert(I != GlobalBitOffsetsMap.end() &&
"Corrupted global bit offsets map");
3205 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
3213ASTDeclReader::getOrFakePrimaryClassDefinition(
ASTReader &Reader,
3216 auto *DD = RD->DefinitionData;
3225 DD =
new (Reader.
getContext())
struct CXXRecordDecl::DefinitionData(RD);
3227 RD->DefinitionData = DD;
3231 Reader.PendingFakeDefinitionData.insert(
3232 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
3235 return DD->Definition;
3242 if (
auto *ND = dyn_cast<NamespaceDecl>(DC))
3243 return ND->getOriginalNamespace();
3245 if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
3246 return getOrFakePrimaryClassDefinition(Reader, RD);
3248 if (
auto *RD = dyn_cast<RecordDecl>(DC))
3251 if (
auto *ED = dyn_cast<EnumDecl>(DC))
3255 if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(DC))
3256 return OID->getDefinition();
3260 if (
auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3266ASTDeclReader::FindExistingResult::~FindExistingResult() {
3269 if (TypedefNameForLinkage) {
3271 Reader.ImportedTypedefNamesForLinkage.insert(
3272 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3276 if (!AddResult || Existing)
3282 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3283 AnonymousDeclNumber, New);
3287 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3289 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3292 MergeDC->makeDeclVisibleInContextImpl(New,
true);
3300 bool IsTypedefNameForLinkage) {
3301 if (!IsTypedefNameForLinkage)
3310 if (
auto *TND = dyn_cast<TypedefNameDecl>(Found))
3311 return TND->getAnonDeclWithTypedefName(
true);
3320ASTDeclReader::getPrimaryDCForAnonymousDecl(
DeclContext *LexicalDC) {
3322 if (
auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3324 return DD ? DD->Definition :
nullptr;
3325 }
else if (
auto *OID = dyn_cast<ObjCInterfaceDecl>(LexicalDC)) {
3326 return OID->getCanonicalDecl()->getDefinition();
3333 if (
auto *FD = dyn_cast<FunctionDecl>(D))
3334 if (FD->isThisDeclarationADefinition())
3336 if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
3337 if (MD->isThisDeclarationADefinition())
3339 if (
auto *RD = dyn_cast<RecordDecl>(D))
3356 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3362 auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3363 if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
3375void ASTDeclReader::setAnonymousDeclForMerging(
ASTReader &Reader,
3378 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
3380 auto &
Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
3387ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(
NamedDecl *D) {
3394 FindExistingResult
Result(Reader, D,
nullptr,
3395 AnonymousDeclNumber, TypedefNameForLinkage);
3402 if (TypedefNameForLinkage) {
3403 auto It = Reader.ImportedTypedefNamesForLinkage.find(
3404 std::make_pair(DC, TypedefNameForLinkage));
3405 if (It != Reader.ImportedTypedefNamesForLinkage.end())
3406 if (
C.isSameEntity(It->second, D))
3407 return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3408 TypedefNameForLinkage);
3416 if (
auto *Existing = getAnonymousDeclForMerging(
3418 if (
C.isSameEntity(Existing, D))
3419 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3420 TypedefNameForLinkage);
3427 class UpToDateIdentifierRAII {
3429 bool WasOutToDate =
false;
3440 ~UpToDateIdentifierRAII() {
3444 } UpToDate(Name.getAsIdentifierInfo());
3447 IEnd = IdResolver.
end();
3450 if (
C.isSameEntity(Existing, D))
3451 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3452 TypedefNameForLinkage);
3454 }
else if (
DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3458 if (
C.isSameEntity(Existing, D))
3459 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3460 TypedefNameForLinkage);
3464 return FindExistingResult(Reader);
3473 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3475 Reader.PendingOdrMergeChecks.push_back(D);
3477 return FindExistingResult(Reader, D,
nullptr,
3478 AnonymousDeclNumber, TypedefNameForLinkage);
3481template<
typename DeclT>
3487 llvm_unreachable(
"getMostRecentDecl on non-redeclarable declaration");
3494#define ABSTRACT_DECL(TYPE)
3495#define DECL(TYPE, BASE) \
3497 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3498#include "clang/AST/DeclNodes.inc"
3500 llvm_unreachable(
"unknown decl kind");
3503Decl *ASTReader::getMostRecentExistingDecl(
Decl *D) {
3511 const auto *IA =
Previous->getAttr<MSInheritanceAttr>();
3513 if (IA && !D->
hasAttr<MSInheritanceAttr>()) {
3514 NewAttr = cast<InheritableAttr>(IA->clone(Context));
3519 const auto *AA =
Previous->getAttr<AvailabilityAttr>();
3520 if (AA && !D->
hasAttr<AvailabilityAttr>()) {
3521 NewAttr = AA->
clone(Context);
3527template<
typename DeclT>
3541 auto *VD =
static_cast<VarDecl *
>(D);
3542 auto *PrevVD = cast<VarDecl>(
Previous);
3544 D->
First = PrevVD->First;
3553 VD->demoteThisDefinitionToDeclaration();
3570 auto *PrevFD = cast<FunctionDecl>(
Previous);
3572 FD->RedeclLink.setPrevious(PrevFD);
3573 FD->First = PrevFD->First;
3577 if (PrevFD->isInlined() != FD->isInlined()) {
3593 FD->setImplicitlyInline(
true);
3598 if (FPT && PrevFPT) {
3602 bool WasUnresolved =
3604 if (IsUnresolved != WasUnresolved)
3605 Reader.PendingExceptionSpecUpdates.insert(
3606 {Canon, IsUnresolved ? PrevFD : FD});
3612 if (IsUndeduced != WasUndeduced)
3613 Reader.PendingDeducedTypeUpdates.insert(
3614 {cast<FunctionDecl>(Canon),
3615 (IsUndeduced ? PrevFPT : FPT)->getReturnType()});
3622 llvm_unreachable(
"attachPreviousDecl on non-redeclarable declaration");
3627template <
typename ParmDecl>
3630 auto *To = cast<ParmDecl>(ToD);
3631 if (!From->hasDefaultArgument())
3633 To->setInheritedDefaultArgument(Context, From);
3642 assert(FromTP->size() == ToTP->size() &&
"merged mismatched templates?");
3644 for (
unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3645 NamedDecl *FromParam = FromTP->getParam(I);
3648 if (
auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam))
3650 else if (
auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam))
3654 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam);
3663#define ABSTRACT_DECL(TYPE)
3664#define DECL(TYPE, BASE) \
3666 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
3668#include "clang/AST/DeclNodes.inc"
3682 if (
auto *TD = dyn_cast<TemplateDecl>(D))
3693template<
typename DeclT>
3699 llvm_unreachable(
"attachLatestDecl on non-redeclarable declaration");
3703 assert(D && Latest);
3706#define ABSTRACT_DECL(TYPE)
3707#define DECL(TYPE, BASE) \
3709 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3711#include "clang/AST/DeclNodes.inc"
3715template<
typename DeclT>
3721 llvm_unreachable(
"markIncompleteDeclChain on non-redeclarable declaration");
3724void ASTReader::markIncompleteDeclChain(
Decl *D) {
3726#define ABSTRACT_DECL(TYPE)
3727#define DECL(TYPE, BASE) \
3729 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3731#include "clang/AST/DeclNodes.inc"
3739 RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
3740 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
3745 ReadingKindTracker ReadingKind(Read_Decl, *
this);
3748 Deserializing ADecl(
this);
3750 auto Fail = [](
const char *what, llvm::Error &&Err) {
3751 llvm::report_fatal_error(Twine(
"ASTReader::readDeclRecord failed ") + what +
3755 if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset))
3756 Fail(
"jumping", std::move(JumpFailed));
3761 Fail(
"reading code", MaybeCode.takeError());
3762 unsigned Code = MaybeCode.get();
3768 llvm::report_fatal_error(
3769 Twine(
"ASTReader::readDeclRecord failed reading decl code: ") +
3770 toString(MaybeDeclCode.takeError()));
3771 switch ((
DeclCode)MaybeDeclCode.get()) {
3774 llvm_unreachable(
"Record cannot be de-serialized with readDeclRecord");
3887 bool HasTypeConstraint =
Record.readInt();
3893 bool HasTypeConstraint =
Record.readInt();
3899 bool HasTypeConstraint =
Record.readInt();
3991 D = MSGuidDecl::CreateDeserialized(Context, ID);
3994 D = UnnamedGlobalConstantDecl::CreateDeserialized(Context, ID);
3997 D = TemplateParamObjectDecl::CreateDeserialized(Context, ID);
4003 Error(
"attempt to read a C++ base-specifier record as a declaration");
4006 Error(
"attempt to read a C++ ctor initializer record as a declaration");
4015 unsigned NumChildren =
Record.readInt();
4021 unsigned NumClauses =
Record.readInt();
4022 unsigned NumVars =
Record.readInt();
4028 unsigned NumClauses =
Record.readInt();
4037 unsigned NumClauses =
Record.readInt();
4070 assert(D &&
"Unknown declaration reading AST file");
4071 LoadedDecl(Index, D);
4080 if (
auto *DC = dyn_cast<DeclContext>(D)) {
4081 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
4082 if (Offsets.first &&
4083 ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
4085 if (Offsets.second &&
4086 ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
4092 PendingUpdateRecords.push_back(
4093 PendingUpdateRecord(ID, D,
true));
4096 if (
auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
4099 if (
Class->isThisDeclarationADefinition() ||
4100 PendingDefinitions.count(Class))
4101 loadObjCCategories(ID, Class);
4107 PotentiallyInterestingDecls.push_back(
4108 InterestingDecl(D, Reader.hasPendingBody()));
4113void ASTReader::PassInterestingDeclsToConsumer() {
4116 if (PassingDeclsToConsumer)
4121 SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
true);
4125 for (
auto ID : EagerlyDeserializedDecls)
4127 EagerlyDeserializedDecls.clear();
4129 while (!PotentiallyInterestingDecls.empty()) {
4130 InterestingDecl D = PotentiallyInterestingDecls.front();
4131 PotentiallyInterestingDecls.pop_front();
4133 PassInterestingDeclToConsumer(D.getDecl());
4137void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
4143 ProcessingUpdatesRAIIObj ProcessingUpdates(*
this);
4144 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
4148 if (UpdI != DeclUpdateOffsets.end()) {
4149 auto UpdateOffsets = std::move(UpdI->second);
4150 DeclUpdateOffsets.erase(UpdI);
4156 bool WasInteresting =
4158 for (
auto &FileAndOffset : UpdateOffsets) {
4160 uint64_t Offset = FileAndOffset.second;
4163 if (llvm::Error JumpFailed =
Cursor.JumpToBit(Offset))
4165 llvm::report_fatal_error(
4166 Twine(
"ASTReader::loadDeclUpdateRecords failed jumping: ") +
4170 llvm::report_fatal_error(
4171 Twine(
"ASTReader::loadDeclUpdateRecords failed reading code: ") +
4173 unsigned Code = MaybeCode.get();
4177 "Expected DECL_UPDATES record!");
4179 llvm::report_fatal_error(
4180 Twine(
"ASTReader::loadDeclUpdateRecords failed reading rec code: ") +
4183 ASTDeclReader Reader(*
this, Record, RecordLocation(F, Offset), ID,
4185 Reader.UpdateDecl(D, PendingLazySpecializationIDs);
4189 if (!WasInteresting &&
4191 PotentiallyInterestingDecls.push_back(
4192 InterestingDecl(D, Reader.hasPendingBody()));
4193 WasInteresting =
true;
4198 assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||
4199 isa<FunctionTemplateDecl, VarTemplateDecl>(D)) &&
4200 "Must not have pending specializations");
4201 if (
auto *CTD = dyn_cast<ClassTemplateDecl>(D))
4203 else if (
auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
4205 else if (
auto *VTD = dyn_cast<VarTemplateDecl>(D))
4207 PendingLazySpecializationIDs.clear();
4210 auto I = PendingVisibleUpdates.find(ID);
4211 if (I != PendingVisibleUpdates.end()) {
4212 auto VisibleUpdates = std::move(I->second);
4213 PendingVisibleUpdates.erase(I);
4216 for (
const auto &Update : VisibleUpdates)
4217 Lookups[DC].Table.add(
4224void ASTReader::loadPendingDeclChain(
Decl *FirstLocal, uint64_t LocalOffset) {
4227 if (FirstLocal != CanonDecl) {
4230 *
this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
4241 assert(M &&
"imported decl from no module file");
4245 if (llvm::Error JumpFailed =
Cursor.JumpToBit(LocalOffset))
4246 llvm::report_fatal_error(
4247 Twine(
"ASTReader::loadPendingDeclChain failed jumping: ") +
4253 llvm::report_fatal_error(
4254 Twine(
"ASTReader::loadPendingDeclChain failed reading code: ") +
4256 unsigned Code = MaybeCode.get();
4259 "expected LOCAL_REDECLARATIONS record!");
4261 llvm::report_fatal_error(
4262 Twine(
"ASTReader::loadPendingDeclChain failed reading rec code: ") +
4267 Decl *MostRecent = FirstLocal;
4268 for (
unsigned I = 0, N =
Record.size(); I != N; ++I) {
4280 class ObjCCategoriesVisitor {
4283 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
4285 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
4287 unsigned PreviousGeneration;
4291 if (!Deserialized.erase(Cat))
4302 NonEquivalentDecls, StructuralEquivalenceKind::Default,
4306 if (!Ctx.IsEquivalent(Cat, Existing)) {
4311 diag::note_previous_definition);
4313 }
else if (!Existing) {
4328 ObjCCategoriesVisitor(
ASTReader &Reader,
4330 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
4332 unsigned PreviousGeneration)
4333 : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
4334 InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) {
4366 Result->DefinitionID != LocalID) {
4374 unsigned Offset = Result->Offset;
4377 for (
unsigned I = 0; I != N; ++I)
4378 add(cast_or_null<ObjCCategoryDecl>(
4388 unsigned PreviousGeneration) {
4389 ObjCCategoriesVisitor Visitor(*
this, D, CategoriesDeserialized, ID,
4390 PreviousGeneration);
4391 ModuleMgr.
visit(Visitor);
4394template<
typename DeclT,
typename Fn>
4403 for (
auto *Redecl = MostRecent; Redecl && !Found;
4405 Found = (Redecl == D);
4409 for (
auto *Redecl = MostRecent; Redecl != D;
4417 while (Record.getIdx() < Record.size()) {
4420 auto *RD = cast<CXXRecordDecl>(D);
4421 Decl *MD = Record.readDecl();
4422 assert(MD &&
"couldn't read decl from update record");
4423 Reader.PendingAddedClassMembers.push_back({RD, MD});
4429 PendingLazySpecializationIDs.push_back(readDeclID());
4433 auto *Anon = readDeclAs<NamespaceDecl>();
4438 if (!Record.isModule()) {
4439 if (
auto *TU = dyn_cast<TranslationUnitDecl>(D))
4440 TU->setAnonymousNamespace(Anon);
4442 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
4448 auto *VD = cast<VarDecl>(D);
4449 VD->NonParmVarDeclBits.IsInline = Record.readInt();
4450 VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
4457 if (
auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
4458 VTSD->setPointOfInstantiation(POI);
4459 }
else if (
auto *VD = dyn_cast<VarDecl>(D)) {
4461 assert(MSInfo &&
"No member specialization information");
4464 auto *FD = cast<FunctionDecl>(D);
4465 if (
auto *FTSInfo = FD->TemplateOrSpecialization
4467 FTSInfo->setPointOfInstantiation(POI);
4470 ->setPointOfInstantiation(POI);
4476 auto *Param = cast<ParmVarDecl>(D);
4481 auto *DefaultArg = Record.readExpr();
4485 if (Param->hasUninstantiatedDefaultArg())
4486 Param->setDefaultArg(DefaultArg);
4491 auto *FD = cast<FieldDecl>(D);
4492 auto *DefaultInit = Record.readExpr();
4496 if (FD->hasInClassInitializer() && !FD->hasNonNullInClassInitializer()) {
4498 FD->setInClassInitializer(DefaultInit);
4502 FD->removeInClassInitializer();
4508 auto *FD = cast<FunctionDecl>(D);
4509 if (Reader.PendingBodies[FD]) {
4515 if (Record.readInt()) {
4523 FD->setInnerLocStart(readSourceLocation());
4525 assert(Record.getIdx() == Record.size() &&
"lazy body must be last");
4530 auto *RD = cast<CXXRecordDecl>(D);
4532 bool HadRealDefinition =
4533 OldDD && (OldDD->Definition != RD ||
4534 !Reader.PendingFakeDefinitionData.count(OldDD));
4538 ReadCXXRecordDefinition(RD,
true);
4541 uint64_t LexicalOffset = ReadLocalOffset();
4542 if (!HadRealDefinition && LexicalOffset) {
4543 Record.readLexicalDeclContextStorage(LexicalOffset, RD);
4544 Reader.PendingFakeDefinitionData.erase(OldDD);
4551 MSInfo->setTemplateSpecializationKind(TSK);
4552 MSInfo->setPointOfInstantiation(POI);
4554 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
4555 Spec->setTemplateSpecializationKind(TSK);
4556 Spec->setPointOfInstantiation(POI);
4558 if (Record.readInt()) {
4560 readDeclAs<ClassTemplatePartialSpecializationDecl>();
4562 Record.readTemplateArgumentList(TemplArgs);
4568 if (!Spec->getSpecializedTemplateOrPartial()
4570 Spec->setInstantiationOf(PartialSpec, TemplArgList);
4579 if (Record.readInt()) {
4581 Record.readAttributes(Attrs);
4593 auto *Del = readDeclAs<FunctionDecl>();
4595 auto *ThisArg = Record.readExpr();
4597 if (!
First->OperatorDelete) {
4598 First->OperatorDelete = Del;
4599 First->OperatorDeleteThisArg = ThisArg;
4606 auto ESI = Record.readExceptionSpecInfo(ExceptionStorage);
4609 auto *FD = cast<FunctionDecl>(D);
4615 FPT->getReturnType(), FPT->getParamTypes(),
4616 FPT->getExtProtoInfo().withExceptionSpec(ESI)));
4620 Reader.PendingExceptionSpecUpdates.insert(
4621 std::make_pair(FD->getCanonicalDecl(), FD));
4627 auto *FD = cast<FunctionDecl>(D);
4628 QualType DeducedResultType = Record.readType();
4629 Reader.PendingDeducedTypeUpdates.insert(
4630 {FD->getCanonicalDecl(), DeducedResultType});
4651 readSourceRange()));
4655 auto AllocatorKind =
4656 static_cast<OMPAllocateDeclAttr::AllocatorTypeTy
>(Record.readInt());
4657 Expr *Allocator = Record.readExpr();
4658 Expr *Alignment = Record.readExpr();
4660 D->
addAttr(OMPAllocateDeclAttr::CreateImplicit(
4661 Reader.
getContext(), AllocatorKind, Allocator, Alignment, SR));
4667 auto *Exported = cast<NamedDecl>(D);
4670 Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported);
4675 auto MapType = Record.readEnum<OMPDeclareTargetDeclAttr::MapTypeTy>();
4676 auto DevType = Record.readEnum<OMPDeclareTargetDeclAttr::DevTypeTy>();
4677 Expr *IndirectE = Record.readExpr();
4678 bool Indirect = Record.readBool();
4679 unsigned Level = Record.readInt();
4680 D->
addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(
4681 Reader.
getContext(), MapType, DevType, IndirectE, Indirect, Level,
4682 readSourceRange()));
4688 Record.readAttributes(Attrs);
4689 assert(Attrs.size() == 1);
This file provides AST data structures related to concepts.
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],...
bool needsCleanup() const
Returns whether the object performed allocations.
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)
void ReadVarDeclInit(VarDecl *VD)
RedeclarableResult VisitClassTemplateSpecializationDeclImpl(ClassTemplateSpecializationDecl *D)
static Decl * getMostRecentDeclImpl(Redeclarable< DeclT > *D)
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
void VisitIndirectFieldDecl(IndirectFieldDecl *FD)
void VisitObjCContainerDecl(ObjCContainerDecl *D)
void VisitBlockDecl(BlockDecl *BD)
void VisitExportDecl(ExportDecl *D)
static void attachLatestDecl(Decl *D, Decl *latest)
void VisitStaticAssertDecl(StaticAssertDecl *D)
static void AddLazySpecializations(T *D, SmallVectorImpl< serialization::DeclID > &IDs)
void VisitEmptyDecl(EmptyDecl *D)
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D)
void VisitValueDecl(ValueDecl *VD)
RedeclarableResult VisitRedeclarable(Redeclarable< T > *D)
void VisitEnumDecl(EnumDecl *ED)
void mergeRedeclarable(Redeclarable< T > *D, RedeclarableResult &Redecl)
Attempts to merge the given declaration (D) with another declaration of the same entity.
void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
void VisitFriendTemplateDecl(FriendTemplateDecl *D)
void VisitObjCProtocolDecl(ObjCProtocolDecl *D)
void VisitClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl *D)
void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
void VisitDeclaratorDecl(DeclaratorDecl *DD)
RedeclarableResult VisitTagDecl(TagDecl *TD)
void UpdateDecl(Decl *D, SmallVectorImpl< serialization::DeclID > &)
void VisitFriendDecl(FriendDecl *D)
void VisitLinkageSpecDecl(LinkageSpecDecl *D)
void VisitCXXRecordDecl(CXXRecordDecl *D)
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD)
void VisitImplicitConceptSpecializationDecl(ImplicitConceptSpecializationDecl *D)
void VisitNamedDecl(NamedDecl *ND)
void mergeMergeable(Mergeable< T > *D)
Attempts to merge the given declaration (D) with another declaration of the same entity,...
void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
static Decl * getMostRecentDecl(Decl *D)
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D)
void VisitCXXConstructorDecl(CXXConstructorDecl *D)
void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D)
void VisitImplicitParamDecl(ImplicitParamDecl *PD)
void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
static void setNextObjCCategory(ObjCCategoryDecl *Cat, ObjCCategoryDecl *Next)
RedeclarableResult VisitVarDeclImpl(VarDecl *D)
void VisitMSPropertyDecl(MSPropertyDecl *FD)
void mergeTemplatePattern(RedeclarableTemplateDecl *D, RedeclarableTemplateDecl *Existing, bool IsKeyDecl)
Merge together the pattern declarations from two template declarations.
void VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
void VisitFieldDecl(FieldDecl *FD)
void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D)
void VisitCapturedDecl(CapturedDecl *CD)
void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D)
void VisitAccessSpecDecl(AccessSpecDecl *D)
void VisitCXXMethodDecl(CXXMethodDecl *D)
void VisitOMPAllocateDecl(OMPAllocateDecl *D)
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
static void attachLatestDeclImpl(Redeclarable< DeclT > *D, Decl *Latest)
static void markIncompleteDeclChainImpl(Redeclarable< DeclT > *D)
ObjCTypeParamList * ReadObjCTypeParamList()
void VisitHLSLBufferDecl(HLSLBufferDecl *D)
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D)
void 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 mergeLambda(CXXRecordDecl *D, RedeclarableResult &Redecl, Decl *Context, unsigned Number)
Attempt to merge D with a previous declaration of the same lambda, which is found by its index within...
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.