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