clang  6.0.0svn
ASTReaderDecl.cpp
Go to the documentation of this file.
1 //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the ASTReader::ReadDeclRecord method, which is the
11 // entrypoint for loading a decl.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "ASTCommon.h"
16 #include "ASTReaderInternals.h"
17 #include "clang/AST/ASTContext.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/DeclGroup.h"
20 #include "clang/AST/DeclTemplate.h"
21 #include "clang/AST/DeclVisitor.h"
22 #include "clang/AST/Expr.h"
26 #include "llvm/Support/SaveAndRestore.h"
27 
28 using namespace clang;
29 using namespace clang::serialization;
30 
31 //===----------------------------------------------------------------------===//
32 // Declaration deserialization
33 //===----------------------------------------------------------------------===//
34 
35 namespace clang {
36  class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
37  ASTReader &Reader;
38  ASTRecordReader &Record;
39  ASTReader::RecordLocation Loc;
40  const DeclID ThisDeclID;
41  const SourceLocation ThisDeclLoc;
43  TypeID TypeIDForTypeDecl;
44  unsigned AnonymousDeclNumber;
45  GlobalDeclID NamedDeclForTagDecl;
46  IdentifierInfo *TypedefNameForLinkage;
47 
48  bool HasPendingBody;
49 
50  ///\brief A flag to carry the information for a decl from the entity is
51  /// used. We use it to delay the marking of the canonical decl as used until
52  /// the entire declaration is deserialized and merged.
53  bool IsDeclMarkedUsed;
54 
55  uint64_t GetCurrentCursorOffset();
56 
57  uint64_t ReadLocalOffset() {
58  uint64_t LocalOffset = Record.readInt();
59  assert(LocalOffset < Loc.Offset && "offset point after current record");
60  return LocalOffset ? Loc.Offset - LocalOffset : 0;
61  }
62 
63  uint64_t ReadGlobalOffset() {
64  uint64_t Local = ReadLocalOffset();
65  return Local ? Record.getGlobalBitOffset(Local) : 0;
66  }
67 
68  SourceLocation ReadSourceLocation() {
69  return Record.readSourceLocation();
70  }
71 
72  SourceRange ReadSourceRange() {
73  return Record.readSourceRange();
74  }
75 
76  TypeSourceInfo *GetTypeSourceInfo() {
77  return Record.getTypeSourceInfo();
78  }
79 
80  serialization::DeclID ReadDeclID() {
81  return Record.readDeclID();
82  }
83 
84  std::string ReadString() {
85  return Record.readString();
86  }
87 
88  void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) {
89  for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I)
90  IDs.push_back(ReadDeclID());
91  }
92 
93  Decl *ReadDecl() {
94  return Record.readDecl();
95  }
96 
97  template<typename T>
98  T *ReadDeclAs() {
99  return Record.readDeclAs<T>();
100  }
101 
102  void ReadQualifierInfo(QualifierInfo &Info) {
103  Record.readQualifierInfo(Info);
104  }
105 
106  void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
107  Record.readDeclarationNameLoc(DNLoc, Name);
108  }
109 
110  serialization::SubmoduleID readSubmoduleID() {
111  if (Record.getIdx() == Record.size())
112  return 0;
113 
114  return Record.getGlobalSubmoduleID(Record.readInt());
115  }
116 
117  Module *readModule() {
118  return Record.getSubmodule(readSubmoduleID());
119  }
120 
121  void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update);
122  void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
123  const CXXRecordDecl *D);
124  void MergeDefinitionData(CXXRecordDecl *D,
125  struct CXXRecordDecl::DefinitionData &&NewDD);
126  void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data);
127  void MergeDefinitionData(ObjCInterfaceDecl *D,
128  struct ObjCInterfaceDecl::DefinitionData &&NewDD);
129  void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data);
130  void MergeDefinitionData(ObjCProtocolDecl *D,
131  struct ObjCProtocolDecl::DefinitionData &&NewDD);
132 
133  static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader,
134  DeclContext *DC,
135  unsigned Index);
136  static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC,
137  unsigned Index, NamedDecl *D);
138 
139  /// Results from loading a RedeclarableDecl.
140  class RedeclarableResult {
141  Decl *MergeWith;
142  GlobalDeclID FirstID;
143  bool IsKeyDecl;
144 
145  public:
146  RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl)
147  : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
148 
149  /// \brief Retrieve the first ID.
150  GlobalDeclID getFirstID() const { return FirstID; }
151 
152  /// \brief Is this declaration a key declaration?
153  bool isKeyDecl() const { return IsKeyDecl; }
154 
155  /// \brief Get a known declaration that this should be merged with, if
156  /// any.
157  Decl *getKnownMergeTarget() const { return MergeWith; }
158  };
159 
160  /// \brief Class used to capture the result of searching for an existing
161  /// declaration of a specific kind and name, along with the ability
162  /// to update the place where this result was found (the declaration
163  /// chain hanging off an identifier or the DeclContext we searched in)
164  /// if requested.
165  class FindExistingResult {
166  ASTReader &Reader;
167  NamedDecl *New;
168  NamedDecl *Existing;
169  bool AddResult;
170 
171  unsigned AnonymousDeclNumber;
172  IdentifierInfo *TypedefNameForLinkage;
173 
174  void operator=(FindExistingResult &&) = delete;
175 
176  public:
177  FindExistingResult(ASTReader &Reader)
178  : Reader(Reader), New(nullptr), Existing(nullptr), AddResult(false),
179  AnonymousDeclNumber(0), TypedefNameForLinkage(nullptr) {}
180 
181  FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing,
182  unsigned AnonymousDeclNumber,
183  IdentifierInfo *TypedefNameForLinkage)
184  : Reader(Reader), New(New), Existing(Existing), AddResult(true),
185  AnonymousDeclNumber(AnonymousDeclNumber),
186  TypedefNameForLinkage(TypedefNameForLinkage) {}
187 
188  FindExistingResult(FindExistingResult &&Other)
189  : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
190  AddResult(Other.AddResult),
191  AnonymousDeclNumber(Other.AnonymousDeclNumber),
192  TypedefNameForLinkage(Other.TypedefNameForLinkage) {
193  Other.AddResult = false;
194  }
195 
196  ~FindExistingResult();
197 
198  /// \brief Suppress the addition of this result into the known set of
199  /// names.
200  void suppress() { AddResult = false; }
201 
202  operator NamedDecl*() const { return Existing; }
203 
204  template<typename T>
205  operator T*() const { return dyn_cast_or_null<T>(Existing); }
206  };
207 
208  static DeclContext *getPrimaryContextForMerging(ASTReader &Reader,
209  DeclContext *DC);
210  FindExistingResult findExisting(NamedDecl *D);
211 
212  public:
214  ASTReader::RecordLocation Loc,
215  DeclID thisDeclID, SourceLocation ThisDeclLoc)
216  : Reader(Reader), Record(Record), Loc(Loc),
217  ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc),
218  TypeIDForTypeDecl(0), NamedDeclForTagDecl(0),
219  TypedefNameForLinkage(nullptr), HasPendingBody(false),
220  IsDeclMarkedUsed(false) {}
221 
222  template <typename T> static
225  if (IDs.empty())
226  return;
227 
228  // FIXME: We should avoid this pattern of getting the ASTContext.
229  ASTContext &C = D->getASTContext();
230 
231  auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
232 
233  if (auto &Old = LazySpecializations) {
234  IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
235  std::sort(IDs.begin(), IDs.end());
236  IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
237  }
238 
239  auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
240  *Result = IDs.size();
241  std::copy(IDs.begin(), IDs.end(), Result + 1);
242 
243  LazySpecializations = Result;
244  }
245 
246  template <typename DeclT>
247  static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D);
248  static Decl *getMostRecentDeclImpl(...);
249  static Decl *getMostRecentDecl(Decl *D);
250 
251  template <typename DeclT>
252  static void attachPreviousDeclImpl(ASTReader &Reader,
254  Decl *Canon);
255  static void attachPreviousDeclImpl(ASTReader &Reader, ...);
256  static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous,
257  Decl *Canon);
258 
259  template <typename DeclT>
260  static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest);
261  static void attachLatestDeclImpl(...);
262  static void attachLatestDecl(Decl *D, Decl *latest);
263 
264  template <typename DeclT>
265  static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D);
266  static void markIncompleteDeclChainImpl(...);
267 
268  /// \brief Determine whether this declaration has a pending body.
269  bool hasPendingBody() const { return HasPendingBody; }
270 
271  void ReadFunctionDefinition(FunctionDecl *FD);
272  void Visit(Decl *D);
273 
275 
277  ObjCCategoryDecl *Next) {
278  Cat->NextClassCategory = Next;
279  }
280 
281  void VisitDecl(Decl *D);
282  void VisitPragmaCommentDecl(PragmaCommentDecl *D);
283  void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
284  void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
285  void VisitNamedDecl(NamedDecl *ND);
286  void VisitLabelDecl(LabelDecl *LD);
287  void VisitNamespaceDecl(NamespaceDecl *D);
288  void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
289  void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
290  void VisitTypeDecl(TypeDecl *TD);
291  RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD);
292  void VisitTypedefDecl(TypedefDecl *TD);
293  void VisitTypeAliasDecl(TypeAliasDecl *TD);
294  void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
295  RedeclarableResult VisitTagDecl(TagDecl *TD);
296  void VisitEnumDecl(EnumDecl *ED);
297  RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
298  void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); }
299  RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
300  void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); }
301  RedeclarableResult VisitClassTemplateSpecializationDeclImpl(
305  VisitClassTemplateSpecializationDeclImpl(D);
306  }
307  void VisitClassTemplatePartialSpecializationDecl(
309  void VisitClassScopeFunctionSpecializationDecl(
311  RedeclarableResult
312  VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D);
314  VisitVarTemplateSpecializationDeclImpl(D);
315  }
316  void VisitVarTemplatePartialSpecializationDecl(
318  void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
319  void VisitValueDecl(ValueDecl *VD);
320  void VisitEnumConstantDecl(EnumConstantDecl *ECD);
321  void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
322  void VisitDeclaratorDecl(DeclaratorDecl *DD);
323  void VisitFunctionDecl(FunctionDecl *FD);
324  void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD);
325  void VisitCXXMethodDecl(CXXMethodDecl *D);
326  void VisitCXXConstructorDecl(CXXConstructorDecl *D);
327  void VisitCXXDestructorDecl(CXXDestructorDecl *D);
328  void VisitCXXConversionDecl(CXXConversionDecl *D);
329  void VisitFieldDecl(FieldDecl *FD);
330  void VisitMSPropertyDecl(MSPropertyDecl *FD);
331  void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
332  RedeclarableResult VisitVarDeclImpl(VarDecl *D);
333  void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
334  void VisitImplicitParamDecl(ImplicitParamDecl *PD);
335  void VisitParmVarDecl(ParmVarDecl *PD);
336  void VisitDecompositionDecl(DecompositionDecl *DD);
337  void VisitBindingDecl(BindingDecl *BD);
338  void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
339  DeclID VisitTemplateDecl(TemplateDecl *D);
340  RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
341  void VisitClassTemplateDecl(ClassTemplateDecl *D);
342  void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
343  void VisitVarTemplateDecl(VarTemplateDecl *D);
344  void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
345  void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
346  void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
347  void VisitUsingDecl(UsingDecl *D);
348  void VisitUsingPackDecl(UsingPackDecl *D);
349  void VisitUsingShadowDecl(UsingShadowDecl *D);
350  void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
351  void VisitLinkageSpecDecl(LinkageSpecDecl *D);
352  void VisitExportDecl(ExportDecl *D);
353  void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
354  void VisitImportDecl(ImportDecl *D);
355  void VisitAccessSpecDecl(AccessSpecDecl *D);
356  void VisitFriendDecl(FriendDecl *D);
357  void VisitFriendTemplateDecl(FriendTemplateDecl *D);
358  void VisitStaticAssertDecl(StaticAssertDecl *D);
359  void VisitBlockDecl(BlockDecl *BD);
360  void VisitCapturedDecl(CapturedDecl *CD);
361  void VisitEmptyDecl(EmptyDecl *D);
362 
363  std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
364 
365  template<typename T>
366  RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
367 
368  template<typename T>
369  void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl,
370  DeclID TemplatePatternID = 0);
371 
372  template<typename T>
373  void mergeRedeclarable(Redeclarable<T> *D, T *Existing,
374  RedeclarableResult &Redecl,
375  DeclID TemplatePatternID = 0);
376 
377  template<typename T>
378  void mergeMergeable(Mergeable<T> *D);
379 
380  void mergeTemplatePattern(RedeclarableTemplateDecl *D,
381  RedeclarableTemplateDecl *Existing,
382  DeclID DsID, bool IsKeyDecl);
383 
384  ObjCTypeParamList *ReadObjCTypeParamList();
385 
386  // FIXME: Reorder according to DeclNodes.td?
387  void VisitObjCMethodDecl(ObjCMethodDecl *D);
388  void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
389  void VisitObjCContainerDecl(ObjCContainerDecl *D);
390  void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
391  void VisitObjCIvarDecl(ObjCIvarDecl *D);
392  void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
393  void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
394  void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
395  void VisitObjCImplDecl(ObjCImplDecl *D);
396  void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
397  void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
398  void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
399  void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
400  void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
401  void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
402  void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
403  void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
404  };
405 } // end namespace clang
406 
407 namespace {
408 /// Iterator over the redeclarations of a declaration that have already
409 /// been merged into the same redeclaration chain.
410 template<typename DeclT>
411 class MergedRedeclIterator {
412  DeclT *Start, *Canonical, *Current;
413 public:
414  MergedRedeclIterator() : Current(nullptr) {}
415  MergedRedeclIterator(DeclT *Start)
416  : Start(Start), Canonical(nullptr), Current(Start) {}
417 
418  DeclT *operator*() { return Current; }
419 
420  MergedRedeclIterator &operator++() {
421  if (Current->isFirstDecl()) {
422  Canonical = Current;
423  Current = Current->getMostRecentDecl();
424  } else
425  Current = Current->getPreviousDecl();
426 
427  // If we started in the merged portion, we'll reach our start position
428  // eventually. Otherwise, we'll never reach it, but the second declaration
429  // we reached was the canonical declaration, so stop when we see that one
430  // again.
431  if (Current == Start || Current == Canonical)
432  Current = nullptr;
433  return *this;
434  }
435 
436  friend bool operator!=(const MergedRedeclIterator &A,
437  const MergedRedeclIterator &B) {
438  return A.Current != B.Current;
439  }
440 };
441 } // end anonymous namespace
442 
443 template <typename DeclT>
444 static llvm::iterator_range<MergedRedeclIterator<DeclT>>
445 merged_redecls(DeclT *D) {
446  return llvm::make_range(MergedRedeclIterator<DeclT>(D),
447  MergedRedeclIterator<DeclT>());
448 }
449 
450 uint64_t ASTDeclReader::GetCurrentCursorOffset() {
451  return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
452 }
453 
455  if (Record.readInt())
456  Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile;
457  if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
458  CD->NumCtorInitializers = Record.readInt();
459  if (CD->NumCtorInitializers)
460  CD->CtorInitializers = ReadGlobalOffset();
461  }
462  // Store the offset of the body so we can lazily load it later.
463  Reader.PendingBodies[FD] = GetCurrentCursorOffset();
464  HasPendingBody = true;
465 }
466 
469 
470  // At this point we have deserialized and merged the decl and it is safe to
471  // update its canonical decl to signal that the entire entity is used.
472  D->getCanonicalDecl()->Used |= IsDeclMarkedUsed;
473  IsDeclMarkedUsed = false;
474 
475  if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
476  if (DD->DeclInfo) {
477  DeclaratorDecl::ExtInfo *Info =
478  DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
479  Info->TInfo = GetTypeSourceInfo();
480  }
481  else {
482  DD->DeclInfo = GetTypeSourceInfo();
483  }
484  }
485 
486  if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
487  // We have a fully initialized TypeDecl. Read its type now.
488  TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
489 
490  // If this is a tag declaration with a typedef name for linkage, it's safe
491  // to load that typedef now.
492  if (NamedDeclForTagDecl)
493  cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
494  cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl));
495  } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
496  // if we have a fully initialized TypeDecl, we can safely read its type now.
497  ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
498  } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
499  // FunctionDecl's body was written last after all other Stmts/Exprs.
500  // We only read it if FD doesn't already have a body (e.g., from another
501  // module).
502  // FIXME: Can we diagnose ODR violations somehow?
503  if (Record.readInt())
504  ReadFunctionDefinition(FD);
505  }
506 }
507 
509  if (D->isTemplateParameter() || D->isTemplateParameterPack() ||
510  isa<ParmVarDecl>(D)) {
511  // We don't want to deserialize the DeclContext of a template
512  // parameter or of a parameter of a function template immediately. These
513  // entities might be used in the formulation of its DeclContext (for
514  // example, a function parameter can be used in decltype() in trailing
515  // return type of the function). Use the translation unit DeclContext as a
516  // placeholder.
517  GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID();
518  GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID();
519  if (!LexicalDCIDForTemplateParmDecl)
520  LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
521  Reader.addPendingDeclContextInfo(D,
522  SemaDCIDForTemplateParmDecl,
523  LexicalDCIDForTemplateParmDecl);
524  D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
525  } else {
526  DeclContext *SemaDC = ReadDeclAs<DeclContext>();
527  DeclContext *LexicalDC = ReadDeclAs<DeclContext>();
528  if (!LexicalDC)
529  LexicalDC = SemaDC;
530  DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
531  // Avoid calling setLexicalDeclContext() directly because it uses
532  // Decl::getASTContext() internally which is unsafe during derialization.
533  D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
534  Reader.getContext());
535  }
536  D->setLocation(ThisDeclLoc);
537  D->setInvalidDecl(Record.readInt());
538  if (Record.readInt()) { // hasAttrs
539  AttrVec Attrs;
540  Record.readAttributes(Attrs);
541  // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
542  // internally which is unsafe during derialization.
543  D->setAttrsImpl(Attrs, Reader.getContext());
544  }
545  D->setImplicit(Record.readInt());
546  D->Used = Record.readInt();
547  IsDeclMarkedUsed |= D->Used;
548  D->setReferenced(Record.readInt());
549  D->setTopLevelDeclInObjCContainer(Record.readInt());
550  D->setAccess((AccessSpecifier)Record.readInt());
551  D->FromASTFile = true;
552  bool ModulePrivate = Record.readInt();
553 
554  // Determine whether this declaration is part of a (sub)module. If so, it
555  // may not yet be visible.
556  if (unsigned SubmoduleID = readSubmoduleID()) {
557  // Store the owning submodule ID in the declaration.
562 
563  if (ModulePrivate) {
564  // Module-private declarations are never visible, so there is no work to
565  // do.
566  } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
567  // If local visibility is being tracked, this declaration will become
568  // hidden and visible as the owning module does.
569  } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
570  // Mark the declaration as visible when its owning module becomes visible.
571  if (Owner->NameVisibility == Module::AllVisible)
573  else
574  Reader.HiddenNamesMap[Owner].push_back(D);
575  }
576  } else if (ModulePrivate) {
578  }
579 }
580 
582  VisitDecl(D);
583  D->setLocation(ReadSourceLocation());
584  D->CommentKind = (PragmaMSCommentKind)Record.readInt();
585  std::string Arg = ReadString();
586  memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size());
587  D->getTrailingObjects<char>()[Arg.size()] = '\0';
588 }
589 
591  VisitDecl(D);
592  D->setLocation(ReadSourceLocation());
593  std::string Name = ReadString();
594  memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size());
595  D->getTrailingObjects<char>()[Name.size()] = '\0';
596 
597  D->ValueStart = Name.size() + 1;
598  std::string Value = ReadString();
599  memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(),
600  Value.size());
601  D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0';
602 }
603 
605  llvm_unreachable("Translation units are not serialized");
606 }
607 
609  VisitDecl(ND);
610  ND->setDeclName(Record.readDeclarationName());
611  AnonymousDeclNumber = Record.readInt();
612 }
613 
615  VisitNamedDecl(TD);
616  TD->setLocStart(ReadSourceLocation());
617  // Delay type reading until after we have fully initialized the decl.
618  TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt());
619 }
620 
621 ASTDeclReader::RedeclarableResult
623  RedeclarableResult Redecl = VisitRedeclarable(TD);
624  VisitTypeDecl(TD);
625  TypeSourceInfo *TInfo = GetTypeSourceInfo();
626  if (Record.readInt()) { // isModed
627  QualType modedT = Record.readType();
628  TD->setModedTypeSourceInfo(TInfo, modedT);
629  } else
630  TD->setTypeSourceInfo(TInfo);
631  // Read and discard the declaration for which this is a typedef name for
632  // linkage, if it exists. We cannot rely on our type to pull in this decl,
633  // because it might have been merged with a type from another module and
634  // thus might not refer to our version of the declaration.
635  ReadDecl();
636  return Redecl;
637 }
638 
640  RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
641  mergeRedeclarable(TD, Redecl);
642 }
643 
645  RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
646  if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>())
647  // Merged when we merge the template.
648  TD->setDescribedAliasTemplate(Template);
649  else
650  mergeRedeclarable(TD, Redecl);
651 }
652 
653 ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) {
654  RedeclarableResult Redecl = VisitRedeclarable(TD);
655  VisitTypeDecl(TD);
656 
657  TD->IdentifierNamespace = Record.readInt();
658  TD->setTagKind((TagDecl::TagKind)Record.readInt());
659  if (!isa<CXXRecordDecl>(TD))
660  TD->setCompleteDefinition(Record.readInt());
661  TD->setEmbeddedInDeclarator(Record.readInt());
662  TD->setFreeStanding(Record.readInt());
663  TD->setCompleteDefinitionRequired(Record.readInt());
664  TD->setBraceRange(ReadSourceRange());
665 
666  switch (Record.readInt()) {
667  case 0:
668  break;
669  case 1: { // ExtInfo
670  TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
671  ReadQualifierInfo(*Info);
672  TD->TypedefNameDeclOrQualifier = Info;
673  break;
674  }
675  case 2: // TypedefNameForAnonDecl
676  NamedDeclForTagDecl = ReadDeclID();
677  TypedefNameForLinkage = Record.getIdentifierInfo();
678  break;
679  default:
680  llvm_unreachable("unexpected tag info kind");
681  }
682 
683  if (!isa<CXXRecordDecl>(TD))
684  mergeRedeclarable(TD, Redecl);
685  return Redecl;
686 }
687 
689  VisitTagDecl(ED);
690  if (TypeSourceInfo *TI = GetTypeSourceInfo())
691  ED->setIntegerTypeSourceInfo(TI);
692  else
693  ED->setIntegerType(Record.readType());
694  ED->setPromotionType(Record.readType());
695  ED->setNumPositiveBits(Record.readInt());
696  ED->setNumNegativeBits(Record.readInt());
697  ED->IsScoped = Record.readInt();
698  ED->IsScopedUsingClassTag = Record.readInt();
699  ED->IsFixed = Record.readInt();
700 
701  // If this is a definition subject to the ODR, and we already have a
702  // definition, merge this one into it.
703  if (ED->IsCompleteDefinition &&
704  Reader.getContext().getLangOpts().Modules &&
705  Reader.getContext().getLangOpts().CPlusPlus) {
706  EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
707  if (!OldDef) {
708  // This is the first time we've seen an imported definition. Look for a
709  // local definition before deciding that we are the first definition.
710  for (auto *D : merged_redecls(ED->getCanonicalDecl())) {
711  if (!D->isFromASTFile() && D->isCompleteDefinition()) {
712  OldDef = D;
713  break;
714  }
715  }
716  }
717  if (OldDef) {
718  Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
719  ED->IsCompleteDefinition = false;
720  Reader.mergeDefinitionVisibility(OldDef, ED);
721  } else {
722  OldDef = ED;
723  }
724  }
725 
726  if (EnumDecl *InstED = ReadDeclAs<EnumDecl>()) {
728  (TemplateSpecializationKind)Record.readInt();
729  SourceLocation POI = ReadSourceLocation();
730  ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK);
732  }
733 }
734 
735 ASTDeclReader::RedeclarableResult
737  RedeclarableResult Redecl = VisitTagDecl(RD);
738  RD->setHasFlexibleArrayMember(Record.readInt());
739  RD->setAnonymousStructOrUnion(Record.readInt());
740  RD->setHasObjectMember(Record.readInt());
741  RD->setHasVolatileMember(Record.readInt());
742  return Redecl;
743 }
744 
746  VisitNamedDecl(VD);
747  VD->setType(Record.readType());
748 }
749 
751  VisitValueDecl(ECD);
752  if (Record.readInt())
753  ECD->setInitExpr(Record.readExpr());
754  ECD->setInitVal(Record.readAPSInt());
755  mergeMergeable(ECD);
756 }
757 
759  VisitValueDecl(DD);
760  DD->setInnerLocStart(ReadSourceLocation());
761  if (Record.readInt()) { // hasExtInfo
762  DeclaratorDecl::ExtInfo *Info
763  = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
764  ReadQualifierInfo(*Info);
765  DD->DeclInfo = Info;
766  }
767 }
768 
770  RedeclarableResult Redecl = VisitRedeclarable(FD);
771  VisitDeclaratorDecl(FD);
772 
773  ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName());
774  FD->IdentifierNamespace = Record.readInt();
775 
776  // FunctionDecl's body is handled last at ASTDeclReader::Visit,
777  // after everything else is read.
778 
779  FD->SClass = (StorageClass)Record.readInt();
780  FD->IsInline = Record.readInt();
781  FD->IsInlineSpecified = Record.readInt();
782  FD->IsExplicitSpecified = Record.readInt();
783  FD->IsVirtualAsWritten = Record.readInt();
784  FD->IsPure = Record.readInt();
785  FD->HasInheritedPrototype = Record.readInt();
786  FD->HasWrittenPrototype = Record.readInt();
787  FD->IsDeleted = Record.readInt();
788  FD->IsTrivial = Record.readInt();
789  FD->IsDefaulted = Record.readInt();
790  FD->IsExplicitlyDefaulted = Record.readInt();
791  FD->HasImplicitReturnZero = Record.readInt();
792  FD->IsConstexpr = Record.readInt();
793  FD->UsesSEHTry = Record.readInt();
794  FD->HasSkippedBody = Record.readInt();
795  FD->IsLateTemplateParsed = Record.readInt();
796  FD->setCachedLinkage(Linkage(Record.readInt()));
797  FD->EndRangeLoc = ReadSourceLocation();
798 
799  switch ((FunctionDecl::TemplatedKind)Record.readInt()) {
801  mergeRedeclarable(FD, Redecl);
802  break;
804  // Merged when we merge the template.
805  FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>());
806  break;
808  FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>();
810  (TemplateSpecializationKind)Record.readInt();
811  SourceLocation POI = ReadSourceLocation();
812  FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
814  mergeRedeclarable(FD, Redecl);
815  break;
816  }
818  FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>();
820  (TemplateSpecializationKind)Record.readInt();
821 
822  // Template arguments.
824  Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
825 
826  // Template args as written.
828  SourceLocation LAngleLoc, RAngleLoc;
829  bool HasTemplateArgumentsAsWritten = Record.readInt();
830  if (HasTemplateArgumentsAsWritten) {
831  unsigned NumTemplateArgLocs = Record.readInt();
832  TemplArgLocs.reserve(NumTemplateArgLocs);
833  for (unsigned i=0; i != NumTemplateArgLocs; ++i)
834  TemplArgLocs.push_back(Record.readTemplateArgumentLoc());
835 
836  LAngleLoc = ReadSourceLocation();
837  RAngleLoc = ReadSourceLocation();
838  }
839 
840  SourceLocation POI = ReadSourceLocation();
841 
842  ASTContext &C = Reader.getContext();
843  TemplateArgumentList *TemplArgList
844  = TemplateArgumentList::CreateCopy(C, TemplArgs);
845  TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
846  for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
847  TemplArgsInfo.addArgument(TemplArgLocs[i]);
849  = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
850  TemplArgList,
851  HasTemplateArgumentsAsWritten ? &TemplArgsInfo
852  : nullptr,
853  POI);
854  FD->TemplateOrSpecialization = FTInfo;
855 
856  if (FD->isCanonicalDecl()) { // if canonical add to template's set.
857  // The template that contains the specializations set. It's not safe to
858  // use getCanonicalDecl on Template since it may still be initializing.
859  FunctionTemplateDecl *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>();
860  // Get the InsertPos by FindNodeOrInsertPos() instead of calling
861  // InsertNode(FTInfo) directly to avoid the getASTContext() call in
862  // FunctionTemplateSpecializationInfo's Profile().
863  // We avoid getASTContext because a decl in the parent hierarchy may
864  // be initializing.
865  llvm::FoldingSetNodeID ID;
867  void *InsertPos = nullptr;
868  FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr();
869  FunctionTemplateSpecializationInfo *ExistingInfo =
870  CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos);
871  if (InsertPos)
872  CommonPtr->Specializations.InsertNode(FTInfo, InsertPos);
873  else {
874  assert(Reader.getContext().getLangOpts().Modules &&
875  "already deserialized this template specialization");
876  mergeRedeclarable(FD, ExistingInfo->Function, Redecl);
877  }
878  }
879  break;
880  }
882  // Templates.
883  UnresolvedSet<8> TemplDecls;
884  unsigned NumTemplates = Record.readInt();
885  while (NumTemplates--)
886  TemplDecls.addDecl(ReadDeclAs<NamedDecl>());
887 
888  // Templates args.
889  TemplateArgumentListInfo TemplArgs;
890  unsigned NumArgs = Record.readInt();
891  while (NumArgs--)
892  TemplArgs.addArgument(Record.readTemplateArgumentLoc());
893  TemplArgs.setLAngleLoc(ReadSourceLocation());
894  TemplArgs.setRAngleLoc(ReadSourceLocation());
895 
896  FD->setDependentTemplateSpecialization(Reader.getContext(),
897  TemplDecls, TemplArgs);
898  // These are not merged; we don't need to merge redeclarations of dependent
899  // template friends.
900  break;
901  }
902  }
903 
904  // Read in the parameters.
905  unsigned NumParams = Record.readInt();
907  Params.reserve(NumParams);
908  for (unsigned I = 0; I != NumParams; ++I)
909  Params.push_back(ReadDeclAs<ParmVarDecl>());
910  FD->setParams(Reader.getContext(), Params);
911 }
912 
914  VisitNamedDecl(MD);
915  if (Record.readInt()) {
916  // Load the body on-demand. Most clients won't care, because method
917  // definitions rarely show up in headers.
918  Reader.PendingBodies[MD] = GetCurrentCursorOffset();
919  HasPendingBody = true;
920  MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>());
921  MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>());
922  }
923  MD->setInstanceMethod(Record.readInt());
924  MD->setVariadic(Record.readInt());
925  MD->setPropertyAccessor(Record.readInt());
926  MD->setDefined(Record.readInt());
927  MD->IsOverriding = Record.readInt();
928  MD->HasSkippedBody = Record.readInt();
929 
930  MD->IsRedeclaration = Record.readInt();
931  MD->HasRedeclaration = Record.readInt();
932  if (MD->HasRedeclaration)
933  Reader.getContext().setObjCMethodRedeclaration(MD,
934  ReadDeclAs<ObjCMethodDecl>());
935 
937  MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt());
938  MD->SetRelatedResultType(Record.readInt());
939  MD->setReturnType(Record.readType());
940  MD->setReturnTypeSourceInfo(GetTypeSourceInfo());
941  MD->DeclEndLoc = ReadSourceLocation();
942  unsigned NumParams = Record.readInt();
944  Params.reserve(NumParams);
945  for (unsigned I = 0; I != NumParams; ++I)
946  Params.push_back(ReadDeclAs<ParmVarDecl>());
947 
948  MD->SelLocsKind = Record.readInt();
949  unsigned NumStoredSelLocs = Record.readInt();
951  SelLocs.reserve(NumStoredSelLocs);
952  for (unsigned i = 0; i != NumStoredSelLocs; ++i)
953  SelLocs.push_back(ReadSourceLocation());
954 
955  MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
956 }
957 
959  VisitTypedefNameDecl(D);
960 
961  D->Variance = Record.readInt();
962  D->Index = Record.readInt();
963  D->VarianceLoc = ReadSourceLocation();
964  D->ColonLoc = ReadSourceLocation();
965 }
966 
968  VisitNamedDecl(CD);
969  CD->setAtStartLoc(ReadSourceLocation());
970  CD->setAtEndRange(ReadSourceRange());
971 }
972 
974  unsigned numParams = Record.readInt();
975  if (numParams == 0)
976  return nullptr;
977 
979  typeParams.reserve(numParams);
980  for (unsigned i = 0; i != numParams; ++i) {
981  auto typeParam = ReadDeclAs<ObjCTypeParamDecl>();
982  if (!typeParam)
983  return nullptr;
984 
985  typeParams.push_back(typeParam);
986  }
987 
988  SourceLocation lAngleLoc = ReadSourceLocation();
989  SourceLocation rAngleLoc = ReadSourceLocation();
990 
991  return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc,
992  typeParams, rAngleLoc);
993 }
994 
995 void ASTDeclReader::ReadObjCDefinitionData(
996  struct ObjCInterfaceDecl::DefinitionData &Data) {
997  // Read the superclass.
998  Data.SuperClassTInfo = GetTypeSourceInfo();
999 
1000  Data.EndLoc = ReadSourceLocation();
1001  Data.HasDesignatedInitializers = Record.readInt();
1002 
1003  // Read the directly referenced protocols and their SourceLocations.
1004  unsigned NumProtocols = Record.readInt();
1006  Protocols.reserve(NumProtocols);
1007  for (unsigned I = 0; I != NumProtocols; ++I)
1008  Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
1010  ProtoLocs.reserve(NumProtocols);
1011  for (unsigned I = 0; I != NumProtocols; ++I)
1012  ProtoLocs.push_back(ReadSourceLocation());
1013  Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1014  Reader.getContext());
1015 
1016  // Read the transitive closure of protocols referenced by this class.
1017  NumProtocols = Record.readInt();
1018  Protocols.clear();
1019  Protocols.reserve(NumProtocols);
1020  for (unsigned I = 0; I != NumProtocols; ++I)
1021  Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
1022  Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1023  Reader.getContext());
1024 }
1025 
1026 void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
1027  struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1028  // FIXME: odr checking?
1029 }
1030 
1032  RedeclarableResult Redecl = VisitRedeclarable(ID);
1033  VisitObjCContainerDecl(ID);
1034  TypeIDForTypeDecl = Record.getGlobalTypeID(Record.readInt());
1035  mergeRedeclarable(ID, Redecl);
1036 
1037  ID->TypeParamList = ReadObjCTypeParamList();
1038  if (Record.readInt()) {
1039  // Read the definition.
1040  ID->allocateDefinitionData();
1041 
1042  ReadObjCDefinitionData(ID->data());
1043  ObjCInterfaceDecl *Canon = ID->getCanonicalDecl();
1044  if (Canon->Data.getPointer()) {
1045  // If we already have a definition, keep the definition invariant and
1046  // merge the data.
1047  MergeDefinitionData(Canon, std::move(ID->data()));
1048  ID->Data = Canon->Data;
1049  } else {
1050  // Set the definition data of the canonical declaration, so other
1051  // redeclarations will see it.
1052  ID->getCanonicalDecl()->Data = ID->Data;
1053 
1054  // We will rebuild this list lazily.
1055  ID->setIvarList(nullptr);
1056  }
1057 
1058  // Note that we have deserialized a definition.
1059  Reader.PendingDefinitions.insert(ID);
1060 
1061  // Note that we've loaded this Objective-C class.
1062  Reader.ObjCClassesLoaded.push_back(ID);
1063  } else {
1064  ID->Data = ID->getCanonicalDecl()->Data;
1065  }
1066 }
1067 
1069  VisitFieldDecl(IVD);
1070  IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt());
1071  // This field will be built lazily.
1072  IVD->setNextIvar(nullptr);
1073  bool synth = Record.readInt();
1074  IVD->setSynthesize(synth);
1075 }
1076 
1077 void ASTDeclReader::ReadObjCDefinitionData(
1078  struct ObjCProtocolDecl::DefinitionData &Data) {
1079 
1080  unsigned NumProtoRefs = Record.readInt();
1082  ProtoRefs.reserve(NumProtoRefs);
1083  for (unsigned I = 0; I != NumProtoRefs; ++I)
1084  ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
1086  ProtoLocs.reserve(NumProtoRefs);
1087  for (unsigned I = 0; I != NumProtoRefs; ++I)
1088  ProtoLocs.push_back(ReadSourceLocation());
1089  Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1090  ProtoLocs.data(), Reader.getContext());
1091 }
1092 
1093 void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D,
1094  struct ObjCProtocolDecl::DefinitionData &&NewDD) {
1095  // FIXME: odr checking?
1096 }
1097 
1099  RedeclarableResult Redecl = VisitRedeclarable(PD);
1100  VisitObjCContainerDecl(PD);
1101  mergeRedeclarable(PD, Redecl);
1102 
1103  if (Record.readInt()) {
1104  // Read the definition.
1105  PD->allocateDefinitionData();
1106 
1107  ReadObjCDefinitionData(PD->data());
1108 
1109  ObjCProtocolDecl *Canon = PD->getCanonicalDecl();
1110  if (Canon->Data.getPointer()) {
1111  // If we already have a definition, keep the definition invariant and
1112  // merge the data.
1113  MergeDefinitionData(Canon, std::move(PD->data()));
1114  PD->Data = Canon->Data;
1115  } else {
1116  // Set the definition data of the canonical declaration, so other
1117  // redeclarations will see it.
1118  PD->getCanonicalDecl()->Data = PD->Data;
1119  }
1120  // Note that we have deserialized a definition.
1121  Reader.PendingDefinitions.insert(PD);
1122  } else {
1123  PD->Data = PD->getCanonicalDecl()->Data;
1124  }
1125 }
1126 
1128  VisitFieldDecl(FD);
1129 }
1130 
1132  VisitObjCContainerDecl(CD);
1133  CD->setCategoryNameLoc(ReadSourceLocation());
1134  CD->setIvarLBraceLoc(ReadSourceLocation());
1135  CD->setIvarRBraceLoc(ReadSourceLocation());
1136 
1137  // Note that this category has been deserialized. We do this before
1138  // deserializing the interface declaration, so that it will consider this
1139  /// category.
1140  Reader.CategoriesDeserialized.insert(CD);
1141 
1142  CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>();
1143  CD->TypeParamList = ReadObjCTypeParamList();
1144  unsigned NumProtoRefs = Record.readInt();
1146  ProtoRefs.reserve(NumProtoRefs);
1147  for (unsigned I = 0; I != NumProtoRefs; ++I)
1148  ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
1150  ProtoLocs.reserve(NumProtoRefs);
1151  for (unsigned I = 0; I != NumProtoRefs; ++I)
1152  ProtoLocs.push_back(ReadSourceLocation());
1153  CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
1154  Reader.getContext());
1155 }
1156 
1158  VisitNamedDecl(CAD);
1159  CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
1160 }
1161 
1163  VisitNamedDecl(D);
1164  D->setAtLoc(ReadSourceLocation());
1165  D->setLParenLoc(ReadSourceLocation());
1166  QualType T = Record.readType();
1167  TypeSourceInfo *TSI = GetTypeSourceInfo();
1168  D->setType(T, TSI);
1170  (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt());
1172  (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt());
1174  (ObjCPropertyDecl::PropertyControl)Record.readInt());
1175  DeclarationName GetterName = Record.readDeclarationName();
1176  SourceLocation GetterLoc = ReadSourceLocation();
1177  D->setGetterName(GetterName.getObjCSelector(), GetterLoc);
1178  DeclarationName SetterName = Record.readDeclarationName();
1179  SourceLocation SetterLoc = ReadSourceLocation();
1180  D->setSetterName(SetterName.getObjCSelector(), SetterLoc);
1181  D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1182  D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1183  D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>());
1184 }
1185 
1187  VisitObjCContainerDecl(D);
1188  D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
1189 }
1190 
1192  VisitObjCImplDecl(D);
1193  D->CategoryNameLoc = ReadSourceLocation();
1194 }
1195 
1197  VisitObjCImplDecl(D);
1198  D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>());
1199  D->SuperLoc = ReadSourceLocation();
1200  D->setIvarLBraceLoc(ReadSourceLocation());
1201  D->setIvarRBraceLoc(ReadSourceLocation());
1202  D->setHasNonZeroConstructors(Record.readInt());
1203  D->setHasDestructors(Record.readInt());
1204  D->NumIvarInitializers = Record.readInt();
1205  if (D->NumIvarInitializers)
1206  D->IvarInitializers = ReadGlobalOffset();
1207 }
1208 
1210  VisitDecl(D);
1211  D->setAtLoc(ReadSourceLocation());
1212  D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>());
1213  D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>();
1214  D->IvarLoc = ReadSourceLocation();
1215  D->setGetterCXXConstructor(Record.readExpr());
1216  D->setSetterCXXAssignment(Record.readExpr());
1217 }
1218 
1220  VisitDeclaratorDecl(FD);
1221  FD->Mutable = Record.readInt();
1222 
1223  if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) {
1224  FD->InitStorage.setInt(ISK);
1225  FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType
1226  ? Record.readType().getAsOpaquePtr()
1227  : Record.readExpr());
1228  }
1229 
1230  if (auto *BW = Record.readExpr())
1231  FD->setBitWidth(BW);
1232 
1233  if (!FD->getDeclName()) {
1234  if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>())
1235  Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
1236  }
1237  mergeMergeable(FD);
1238 }
1239 
1241  VisitDeclaratorDecl(PD);
1242  PD->GetterId = Record.getIdentifierInfo();
1243  PD->SetterId = Record.getIdentifierInfo();
1244 }
1245 
1247  VisitValueDecl(FD);
1248 
1249  FD->ChainingSize = Record.readInt();
1250  assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
1251  FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
1252 
1253  for (unsigned I = 0; I != FD->ChainingSize; ++I)
1254  FD->Chaining[I] = ReadDeclAs<NamedDecl>();
1255 
1256  mergeMergeable(FD);
1257 }
1258 
1259 ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
1260  RedeclarableResult Redecl = VisitRedeclarable(VD);
1261  VisitDeclaratorDecl(VD);
1262 
1263  VD->VarDeclBits.SClass = (StorageClass)Record.readInt();
1264  VD->VarDeclBits.TSCSpec = Record.readInt();
1265  VD->VarDeclBits.InitStyle = Record.readInt();
1266  if (!isa<ParmVarDecl>(VD)) {
1267  VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =
1268  Record.readInt();
1269  VD->NonParmVarDeclBits.ExceptionVar = Record.readInt();
1270  VD->NonParmVarDeclBits.NRVOVariable = Record.readInt();
1271  VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt();
1272  VD->NonParmVarDeclBits.ARCPseudoStrong = Record.readInt();
1273  VD->NonParmVarDeclBits.IsInline = Record.readInt();
1274  VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
1275  VD->NonParmVarDeclBits.IsConstexpr = Record.readInt();
1276  VD->NonParmVarDeclBits.IsInitCapture = Record.readInt();
1277  VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt();
1278  VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt();
1279  }
1280  Linkage VarLinkage = Linkage(Record.readInt());
1281  VD->setCachedLinkage(VarLinkage);
1282 
1283  // Reconstruct the one piece of the IdentifierNamespace that we need.
1284  if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage &&
1286  VD->setLocalExternDecl();
1287 
1288  if (uint64_t Val = Record.readInt()) {
1289  VD->setInit(Record.readExpr());
1290  if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
1291  EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
1292  Eval->CheckedICE = true;
1293  Eval->IsICE = Val == 3;
1294  }
1295  }
1296 
1297  if (VD->getStorageDuration() == SD_Static && Record.readInt())
1298  Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile;
1299 
1300  enum VarKind {
1301  VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1302  };
1303  switch ((VarKind)Record.readInt()) {
1304  case VarNotTemplate:
1305  // Only true variables (not parameters or implicit parameters) can be
1306  // merged; the other kinds are not really redeclarable at all.
1307  if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1308  !isa<VarTemplateSpecializationDecl>(VD))
1309  mergeRedeclarable(VD, Redecl);
1310  break;
1311  case VarTemplate:
1312  // Merged when we merge the template.
1313  VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>());
1314  break;
1315  case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo.
1316  VarDecl *Tmpl = ReadDeclAs<VarDecl>();
1318  (TemplateSpecializationKind)Record.readInt();
1319  SourceLocation POI = ReadSourceLocation();
1320  Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
1321  mergeRedeclarable(VD, Redecl);
1322  break;
1323  }
1324  }
1325 
1326  return Redecl;
1327 }
1328 
1330  VisitVarDecl(PD);
1331 }
1332 
1334  VisitVarDecl(PD);
1335  unsigned isObjCMethodParam = Record.readInt();
1336  unsigned scopeDepth = Record.readInt();
1337  unsigned scopeIndex = Record.readInt();
1338  unsigned declQualifier = Record.readInt();
1339  if (isObjCMethodParam) {
1340  assert(scopeDepth == 0);
1341  PD->setObjCMethodScopeInfo(scopeIndex);
1342  PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
1343  } else {
1344  PD->setScopeInfo(scopeDepth, scopeIndex);
1345  }
1346  PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt();
1347  PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt();
1348  if (Record.readInt()) // hasUninstantiatedDefaultArg.
1349  PD->setUninstantiatedDefaultArg(Record.readExpr());
1350 
1351  // FIXME: If this is a redeclaration of a function from another module, handle
1352  // inheritance of default arguments.
1353 }
1354 
1356  VisitVarDecl(DD);
1357  BindingDecl **BDs = DD->getTrailingObjects<BindingDecl*>();
1358  for (unsigned I = 0; I != DD->NumBindings; ++I)
1359  BDs[I] = ReadDeclAs<BindingDecl>();
1360 }
1361 
1363  VisitValueDecl(BD);
1364  BD->Binding = Record.readExpr();
1365 }
1366 
1368  VisitDecl(AD);
1369  AD->setAsmString(cast<StringLiteral>(Record.readExpr()));
1370  AD->setRParenLoc(ReadSourceLocation());
1371 }
1372 
1374  VisitDecl(BD);
1375  BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt()));
1376  BD->setSignatureAsWritten(GetTypeSourceInfo());
1377  unsigned NumParams = Record.readInt();
1379  Params.reserve(NumParams);
1380  for (unsigned I = 0; I != NumParams; ++I)
1381  Params.push_back(ReadDeclAs<ParmVarDecl>());
1382  BD->setParams(Params);
1383 
1384  BD->setIsVariadic(Record.readInt());
1385  BD->setBlockMissingReturnType(Record.readInt());
1386  BD->setIsConversionFromLambda(Record.readInt());
1387 
1388  bool capturesCXXThis = Record.readInt();
1389  unsigned numCaptures = Record.readInt();
1391  captures.reserve(numCaptures);
1392  for (unsigned i = 0; i != numCaptures; ++i) {
1393  VarDecl *decl = ReadDeclAs<VarDecl>();
1394  unsigned flags = Record.readInt();
1395  bool byRef = (flags & 1);
1396  bool nested = (flags & 2);
1397  Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr);
1398 
1399  captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1400  }
1401  BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
1402 }
1403 
1405  VisitDecl(CD);
1406  unsigned ContextParamPos = Record.readInt();
1407  CD->setNothrow(Record.readInt() != 0);
1408  // Body is set by VisitCapturedStmt.
1409  for (unsigned I = 0; I < CD->NumParams; ++I) {
1410  if (I != ContextParamPos)
1411  CD->setParam(I, ReadDeclAs<ImplicitParamDecl>());
1412  else
1413  CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>());
1414  }
1415 }
1416 
1418  VisitDecl(D);
1419  D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt());
1420  D->setExternLoc(ReadSourceLocation());
1421  D->setRBraceLoc(ReadSourceLocation());
1422 }
1423 
1425  VisitDecl(D);
1426  D->RBraceLoc = ReadSourceLocation();
1427 }
1428 
1430  VisitNamedDecl(D);
1431  D->setLocStart(ReadSourceLocation());
1432 }
1433 
1435  RedeclarableResult Redecl = VisitRedeclarable(D);
1436  VisitNamedDecl(D);
1437  D->setInline(Record.readInt());
1438  D->LocStart = ReadSourceLocation();
1439  D->RBraceLoc = ReadSourceLocation();
1440 
1441  // Defer loading the anonymous namespace until we've finished merging
1442  // this namespace; loading it might load a later declaration of the
1443  // same namespace, and we have an invariant that older declarations
1444  // get merged before newer ones try to merge.
1445  GlobalDeclID AnonNamespace = 0;
1446  if (Redecl.getFirstID() == ThisDeclID) {
1447  AnonNamespace = ReadDeclID();
1448  } else {
1449  // Link this namespace back to the first declaration, which has already
1450  // been deserialized.
1451  D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl());
1452  }
1453 
1454  mergeRedeclarable(D, Redecl);
1455 
1456  if (AnonNamespace) {
1457  // Each module has its own anonymous namespace, which is disjoint from
1458  // any other module's anonymous namespaces, so don't attach the anonymous
1459  // namespace at all.
1460  NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace));
1461  if (!Record.isModule())
1462  D->setAnonymousNamespace(Anon);
1463  }
1464 }
1465 
1467  RedeclarableResult Redecl = VisitRedeclarable(D);
1468  VisitNamedDecl(D);
1469  D->NamespaceLoc = ReadSourceLocation();
1470  D->IdentLoc = ReadSourceLocation();
1471  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1472  D->Namespace = ReadDeclAs<NamedDecl>();
1473  mergeRedeclarable(D, Redecl);
1474 }
1475 
1477  VisitNamedDecl(D);
1478  D->setUsingLoc(ReadSourceLocation());
1479  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1480  ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
1481  D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>());
1482  D->setTypename(Record.readInt());
1483  if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>())
1484  Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
1485  mergeMergeable(D);
1486 }
1487 
1489  VisitNamedDecl(D);
1490  D->InstantiatedFrom = ReadDeclAs<NamedDecl>();
1491  NamedDecl **Expansions = D->getTrailingObjects<NamedDecl*>();
1492  for (unsigned I = 0; I != D->NumExpansions; ++I)
1493  Expansions[I] = ReadDeclAs<NamedDecl>();
1494  mergeMergeable(D);
1495 }
1496 
1498  RedeclarableResult Redecl = VisitRedeclarable(D);
1499  VisitNamedDecl(D);
1500  D->setTargetDecl(ReadDeclAs<NamedDecl>());
1501  D->UsingOrNextShadow = ReadDeclAs<NamedDecl>();
1502  UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>();
1503  if (Pattern)
1504  Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
1505  mergeRedeclarable(D, Redecl);
1506 }
1507 
1510  VisitUsingShadowDecl(D);
1511  D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
1512  D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
1513  D->IsVirtual = Record.readInt();
1514 }
1515 
1517  VisitNamedDecl(D);
1518  D->UsingLoc = ReadSourceLocation();
1519  D->NamespaceLoc = ReadSourceLocation();
1520  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1521  D->NominatedNamespace = ReadDeclAs<NamedDecl>();
1522  D->CommonAncestor = ReadDeclAs<DeclContext>();
1523 }
1524 
1526  VisitValueDecl(D);
1527  D->setUsingLoc(ReadSourceLocation());
1528  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1529  ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
1530  D->EllipsisLoc = ReadSourceLocation();
1531  mergeMergeable(D);
1532 }
1533 
1536  VisitTypeDecl(D);
1537  D->TypenameLocation = ReadSourceLocation();
1538  D->QualifierLoc = Record.readNestedNameSpecifierLoc();
1539  D->EllipsisLoc = ReadSourceLocation();
1540  mergeMergeable(D);
1541 }
1542 
1543 void ASTDeclReader::ReadCXXDefinitionData(
1544  struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) {
1545  // Note: the caller has deserialized the IsLambda bit already.
1546  Data.UserDeclaredConstructor = Record.readInt();
1547  Data.UserDeclaredSpecialMembers = Record.readInt();
1548  Data.Aggregate = Record.readInt();
1549  Data.PlainOldData = Record.readInt();
1550  Data.Empty = Record.readInt();
1551  Data.Polymorphic = Record.readInt();
1552  Data.Abstract = Record.readInt();
1553  Data.IsStandardLayout = Record.readInt();
1554  Data.HasNoNonEmptyBases = Record.readInt();
1555  Data.HasPrivateFields = Record.readInt();
1556  Data.HasProtectedFields = Record.readInt();
1557  Data.HasPublicFields = Record.readInt();
1558  Data.HasMutableFields = Record.readInt();
1559  Data.HasVariantMembers = Record.readInt();
1560  Data.HasOnlyCMembers = Record.readInt();
1561  Data.HasInClassInitializer = Record.readInt();
1562  Data.HasUninitializedReferenceMember = Record.readInt();
1563  Data.HasUninitializedFields = Record.readInt();
1564  Data.HasInheritedConstructor = Record.readInt();
1565  Data.HasInheritedAssignment = Record.readInt();
1566  Data.NeedOverloadResolutionForCopyConstructor = Record.readInt();
1567  Data.NeedOverloadResolutionForMoveConstructor = Record.readInt();
1568  Data.NeedOverloadResolutionForMoveAssignment = Record.readInt();
1569  Data.NeedOverloadResolutionForDestructor = Record.readInt();
1570  Data.DefaultedCopyConstructorIsDeleted = Record.readInt();
1571  Data.DefaultedMoveConstructorIsDeleted = Record.readInt();
1572  Data.DefaultedMoveAssignmentIsDeleted = Record.readInt();
1573  Data.DefaultedDestructorIsDeleted = Record.readInt();
1574  Data.HasTrivialSpecialMembers = Record.readInt();
1575  Data.DeclaredNonTrivialSpecialMembers = Record.readInt();
1576  Data.HasIrrelevantDestructor = Record.readInt();
1577  Data.HasConstexprNonCopyMoveConstructor = Record.readInt();
1578  Data.HasDefaultedDefaultConstructor = Record.readInt();
1579  Data.CanPassInRegisters = Record.readInt();
1580  Data.DefaultedDefaultConstructorIsConstexpr = Record.readInt();
1581  Data.HasConstexprDefaultConstructor = Record.readInt();
1582  Data.HasNonLiteralTypeFieldsOrBases = Record.readInt();
1583  Data.ComputedVisibleConversions = Record.readInt();
1584  Data.UserProvidedDefaultConstructor = Record.readInt();
1585  Data.DeclaredSpecialMembers = Record.readInt();
1586  Data.ImplicitCopyConstructorCanHaveConstParamForVBase = Record.readInt();
1587  Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase = Record.readInt();
1588  Data.ImplicitCopyAssignmentHasConstParam = Record.readInt();
1589  Data.HasDeclaredCopyConstructorWithConstParam = Record.readInt();
1590  Data.HasDeclaredCopyAssignmentWithConstParam = Record.readInt();
1591  Data.ODRHash = Record.readInt();
1592  Data.HasODRHash = true;
1593 
1594  if (Record.readInt())
1595  Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile;
1596 
1597  Data.NumBases = Record.readInt();
1598  if (Data.NumBases)
1599  Data.Bases = ReadGlobalOffset();
1600  Data.NumVBases = Record.readInt();
1601  if (Data.NumVBases)
1602  Data.VBases = ReadGlobalOffset();
1603 
1604  Record.readUnresolvedSet(Data.Conversions);
1605  Record.readUnresolvedSet(Data.VisibleConversions);
1606  assert(Data.Definition && "Data.Definition should be already set!");
1607  Data.FirstFriend = ReadDeclID();
1608 
1609  if (Data.IsLambda) {
1610  typedef LambdaCapture Capture;
1611  CXXRecordDecl::LambdaDefinitionData &Lambda
1612  = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data);
1613  Lambda.Dependent = Record.readInt();
1614  Lambda.IsGenericLambda = Record.readInt();
1615  Lambda.CaptureDefault = Record.readInt();
1616  Lambda.NumCaptures = Record.readInt();
1617  Lambda.NumExplicitCaptures = Record.readInt();
1618  Lambda.ManglingNumber = Record.readInt();
1619  Lambda.ContextDecl = ReadDeclID();
1620  Lambda.Captures = (Capture *)Reader.getContext().Allocate(
1621  sizeof(Capture) * Lambda.NumCaptures);
1622  Capture *ToCapture = Lambda.Captures;
1623  Lambda.MethodTyInfo = GetTypeSourceInfo();
1624  for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
1625  SourceLocation Loc = ReadSourceLocation();
1626  bool IsImplicit = Record.readInt();
1627  LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record.readInt());
1628  switch (Kind) {
1629  case LCK_StarThis:
1630  case LCK_This:
1631  case LCK_VLAType:
1632  *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation());
1633  break;
1634  case LCK_ByCopy:
1635  case LCK_ByRef:
1636  VarDecl *Var = ReadDeclAs<VarDecl>();
1637  SourceLocation EllipsisLoc = ReadSourceLocation();
1638  *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
1639  break;
1640  }
1641  }
1642  }
1643 }
1644 
1645 void ASTDeclReader::MergeDefinitionData(
1646  CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) {
1647  assert(D->DefinitionData &&
1648  "merging class definition into non-definition");
1649  auto &DD = *D->DefinitionData;
1650 
1651  if (DD.Definition != MergeDD.Definition) {
1652  // Track that we merged the definitions.
1653  Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
1654  DD.Definition));
1655  Reader.PendingDefinitions.erase(MergeDD.Definition);
1656  MergeDD.Definition->IsCompleteDefinition = false;
1657  Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
1658  assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
1659  "already loaded pending lookups for merged definition");
1660  }
1661 
1662  auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
1663  if (PFDI != Reader.PendingFakeDefinitionData.end() &&
1664  PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
1665  // We faked up this definition data because we found a class for which we'd
1666  // not yet loaded the definition. Replace it with the real thing now.
1667  assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
1668  PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
1669 
1670  // Don't change which declaration is the definition; that is required
1671  // to be invariant once we select it.
1672  auto *Def = DD.Definition;
1673  DD = std::move(MergeDD);
1674  DD.Definition = Def;
1675  return;
1676  }
1677 
1678  // FIXME: Move this out into a .def file?
1679  bool DetectedOdrViolation = false;
1680 #define OR_FIELD(Field) DD.Field |= MergeDD.Field;
1681 #define MATCH_FIELD(Field) \
1682  DetectedOdrViolation |= DD.Field != MergeDD.Field; \
1683  OR_FIELD(Field)
1684  MATCH_FIELD(UserDeclaredConstructor)
1685  MATCH_FIELD(UserDeclaredSpecialMembers)
1686  MATCH_FIELD(Aggregate)
1687  MATCH_FIELD(PlainOldData)
1688  MATCH_FIELD(Empty)
1689  MATCH_FIELD(Polymorphic)
1690  MATCH_FIELD(Abstract)
1691  MATCH_FIELD(IsStandardLayout)
1692  MATCH_FIELD(HasNoNonEmptyBases)
1693  MATCH_FIELD(HasPrivateFields)
1694  MATCH_FIELD(HasProtectedFields)
1695  MATCH_FIELD(HasPublicFields)
1696  MATCH_FIELD(HasMutableFields)
1697  MATCH_FIELD(HasVariantMembers)
1698  MATCH_FIELD(HasOnlyCMembers)
1699  MATCH_FIELD(HasInClassInitializer)
1700  MATCH_FIELD(HasUninitializedReferenceMember)
1701  MATCH_FIELD(HasUninitializedFields)
1702  MATCH_FIELD(HasInheritedConstructor)
1703  MATCH_FIELD(HasInheritedAssignment)
1704  MATCH_FIELD(NeedOverloadResolutionForCopyConstructor)
1705  MATCH_FIELD(NeedOverloadResolutionForMoveConstructor)
1706  MATCH_FIELD(NeedOverloadResolutionForMoveAssignment)
1707  MATCH_FIELD(NeedOverloadResolutionForDestructor)
1708  MATCH_FIELD(DefaultedCopyConstructorIsDeleted)
1709  MATCH_FIELD(DefaultedMoveConstructorIsDeleted)
1710  MATCH_FIELD(DefaultedMoveAssignmentIsDeleted)
1711  MATCH_FIELD(DefaultedDestructorIsDeleted)
1712  OR_FIELD(HasTrivialSpecialMembers)
1713  OR_FIELD(DeclaredNonTrivialSpecialMembers)
1714  MATCH_FIELD(HasIrrelevantDestructor)
1715  OR_FIELD(HasConstexprNonCopyMoveConstructor)
1716  OR_FIELD(HasDefaultedDefaultConstructor)
1717  MATCH_FIELD(CanPassInRegisters)
1718  MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr)
1719  OR_FIELD(HasConstexprDefaultConstructor)
1720  MATCH_FIELD(HasNonLiteralTypeFieldsOrBases)
1721  // ComputedVisibleConversions is handled below.
1722  MATCH_FIELD(UserProvidedDefaultConstructor)
1723  OR_FIELD(DeclaredSpecialMembers)
1724  MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForVBase)
1725  MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForNonVBase)
1726  MATCH_FIELD(ImplicitCopyAssignmentHasConstParam)
1727  OR_FIELD(HasDeclaredCopyConstructorWithConstParam)
1728  OR_FIELD(HasDeclaredCopyAssignmentWithConstParam)
1729  MATCH_FIELD(IsLambda)
1730 #undef OR_FIELD
1731 #undef MATCH_FIELD
1732 
1733  if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
1734  DetectedOdrViolation = true;
1735  // FIXME: Issue a diagnostic if the base classes don't match when we come
1736  // to lazily load them.
1737 
1738  // FIXME: Issue a diagnostic if the list of conversion functions doesn't
1739  // match when we come to lazily load them.
1740  if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
1741  DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
1742  DD.ComputedVisibleConversions = true;
1743  }
1744 
1745  // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
1746  // lazily load it.
1747 
1748  if (DD.IsLambda) {
1749  // FIXME: ODR-checking for merging lambdas (this happens, for instance,
1750  // when they occur within the body of a function template specialization).
1751  }
1752 
1753  if (D->getODRHash() != MergeDD.ODRHash) {
1754  DetectedOdrViolation = true;
1755  }
1756 
1757  if (DetectedOdrViolation)
1758  Reader.PendingOdrMergeFailures[DD.Definition].push_back(
1759  {MergeDD.Definition, &MergeDD});
1760 }
1761 
1762 void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) {
1763  struct CXXRecordDecl::DefinitionData *DD;
1764  ASTContext &C = Reader.getContext();
1765 
1766  // Determine whether this is a lambda closure type, so that we can
1767  // allocate the appropriate DefinitionData structure.
1768  bool IsLambda = Record.readInt();
1769  if (IsLambda)
1770  DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false,
1771  LCD_None);
1772  else
1773  DD = new (C) struct CXXRecordDecl::DefinitionData(D);
1774 
1775  ReadCXXDefinitionData(*DD, D);
1776 
1777  // We might already have a definition for this record. This can happen either
1778  // because we're reading an update record, or because we've already done some
1779  // merging. Either way, just merge into it.
1780  CXXRecordDecl *Canon = D->getCanonicalDecl();
1781  if (Canon->DefinitionData) {
1782  MergeDefinitionData(Canon, std::move(*DD));
1783  D->DefinitionData = Canon->DefinitionData;
1784  return;
1785  }
1786 
1787  // Mark this declaration as being a definition.
1788  D->IsCompleteDefinition = true;
1789  D->DefinitionData = DD;
1790 
1791  // If this is not the first declaration or is an update record, we can have
1792  // other redeclarations already. Make a note that we need to propagate the
1793  // DefinitionData pointer onto them.
1794  if (Update || Canon != D) {
1795  Canon->DefinitionData = D->DefinitionData;
1796  Reader.PendingDefinitions.insert(D);
1797  }
1798 }
1799 
1800 ASTDeclReader::RedeclarableResult
1802  RedeclarableResult Redecl = VisitRecordDeclImpl(D);
1803 
1804  ASTContext &C = Reader.getContext();
1805 
1806  enum CXXRecKind {
1807  CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1808  };
1809  switch ((CXXRecKind)Record.readInt()) {
1810  case CXXRecNotTemplate:
1811  // Merged when we merge the folding set entry in the primary template.
1812  if (!isa<ClassTemplateSpecializationDecl>(D))
1813  mergeRedeclarable(D, Redecl);
1814  break;
1815  case CXXRecTemplate: {
1816  // Merged when we merge the template.
1817  ClassTemplateDecl *Template = ReadDeclAs<ClassTemplateDecl>();
1818  D->TemplateOrInstantiation = Template;
1819  if (!Template->getTemplatedDecl()) {
1820  // We've not actually loaded the ClassTemplateDecl yet, because we're
1821  // currently being loaded as its pattern. Rely on it to set up our
1822  // TypeForDecl (see VisitClassTemplateDecl).
1823  //
1824  // Beware: we do not yet know our canonical declaration, and may still
1825  // get merged once the surrounding class template has got off the ground.
1826  TypeIDForTypeDecl = 0;
1827  }
1828  break;
1829  }
1830  case CXXRecMemberSpecialization: {
1831  CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>();
1833  (TemplateSpecializationKind)Record.readInt();
1834  SourceLocation POI = ReadSourceLocation();
1835  MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1836  MSI->setPointOfInstantiation(POI);
1837  D->TemplateOrInstantiation = MSI;
1838  mergeRedeclarable(D, Redecl);
1839  break;
1840  }
1841  }
1842 
1843  bool WasDefinition = Record.readInt();
1844  if (WasDefinition)
1845  ReadCXXRecordDefinition(D, /*Update*/false);
1846  else
1847  // Propagate DefinitionData pointer from the canonical declaration.
1848  D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
1849 
1850  // Lazily load the key function to avoid deserializing every method so we can
1851  // compute it.
1852  if (WasDefinition) {
1853  DeclID KeyFn = ReadDeclID();
1854  if (KeyFn && D->IsCompleteDefinition)
1855  // FIXME: This is wrong for the ARM ABI, where some other module may have
1856  // made this function no longer be a key function. We need an update
1857  // record or similar for that case.
1858  C.KeyFunctions[D] = KeyFn;
1859  }
1860 
1861  return Redecl;
1862 }
1863 
1865  VisitFunctionDecl(D);
1866  D->IsCopyDeductionCandidate = Record.readInt();
1867 }
1868 
1870  VisitFunctionDecl(D);
1871 
1872  unsigned NumOverridenMethods = Record.readInt();
1873  if (D->isCanonicalDecl()) {
1874  while (NumOverridenMethods--) {
1875  // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1876  // MD may be initializing.
1877  if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>())
1878  Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl());
1879  }
1880  } else {
1881  // We don't care about which declarations this used to override; we get
1882  // the relevant information from the canonical declaration.
1883  Record.skipInts(NumOverridenMethods);
1884  }
1885 }
1886 
1888  // We need the inherited constructor information to merge the declaration,
1889  // so we have to read it before we call VisitCXXMethodDecl.
1890  if (D->isInheritingConstructor()) {
1891  auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>();
1892  auto *Ctor = ReadDeclAs<CXXConstructorDecl>();
1893  *D->getTrailingObjects<InheritedConstructor>() =
1894  InheritedConstructor(Shadow, Ctor);
1895  }
1896 
1897  VisitCXXMethodDecl(D);
1898 }
1899 
1901  VisitCXXMethodDecl(D);
1902 
1903  if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) {
1904  auto *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl());
1905  auto *ThisArg = Record.readExpr();
1906  // FIXME: Check consistency if we have an old and new operator delete.
1907  if (!Canon->OperatorDelete) {
1908  Canon->OperatorDelete = OperatorDelete;
1909  Canon->OperatorDeleteThisArg = ThisArg;
1910  }
1911  }
1912 }
1913 
1915  VisitCXXMethodDecl(D);
1916 }
1917 
1919  VisitDecl(D);
1920  D->ImportedAndComplete.setPointer(readModule());
1921  D->ImportedAndComplete.setInt(Record.readInt());
1922  SourceLocation *StoredLocs = D->getTrailingObjects<SourceLocation>();
1923  for (unsigned I = 0, N = Record.back(); I != N; ++I)
1924  StoredLocs[I] = ReadSourceLocation();
1925  Record.skipInts(1); // The number of stored source locations.
1926 }
1927 
1929  VisitDecl(D);
1930  D->setColonLoc(ReadSourceLocation());
1931 }
1932 
1934  VisitDecl(D);
1935  if (Record.readInt()) // hasFriendDecl
1936  D->Friend = ReadDeclAs<NamedDecl>();
1937  else
1938  D->Friend = GetTypeSourceInfo();
1939  for (unsigned i = 0; i != D->NumTPLists; ++i)
1940  D->getTrailingObjects<TemplateParameterList *>()[i] =
1941  Record.readTemplateParameterList();
1942  D->NextFriend = ReadDeclID();
1943  D->UnsupportedFriend = (Record.readInt() != 0);
1944  D->FriendLoc = ReadSourceLocation();
1945 }
1946 
1948  VisitDecl(D);
1949  unsigned NumParams = Record.readInt();
1950  D->NumParams = NumParams;
1951  D->Params = new TemplateParameterList*[NumParams];
1952  for (unsigned i = 0; i != NumParams; ++i)
1953  D->Params[i] = Record.readTemplateParameterList();
1954  if (Record.readInt()) // HasFriendDecl
1955  D->Friend = ReadDeclAs<NamedDecl>();
1956  else
1957  D->Friend = GetTypeSourceInfo();
1958  D->FriendLoc = ReadSourceLocation();
1959 }
1960 
1962  VisitNamedDecl(D);
1963 
1964  DeclID PatternID = ReadDeclID();
1965  NamedDecl *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID));
1966  TemplateParameterList *TemplateParams = Record.readTemplateParameterList();
1967  // FIXME handle associated constraints
1968  D->init(TemplatedDecl, TemplateParams);
1969 
1970  return PatternID;
1971 }
1972 
1973 ASTDeclReader::RedeclarableResult
1975  RedeclarableResult Redecl = VisitRedeclarable(D);
1976 
1977  // Make sure we've allocated the Common pointer first. We do this before
1978  // VisitTemplateDecl so that getCommonPtr() can be used during initialization.
1980  if (!CanonD->Common) {
1981  CanonD->Common = CanonD->newCommon(Reader.getContext());
1982  Reader.PendingDefinitions.insert(CanonD);
1983  }
1984  D->Common = CanonD->Common;
1985 
1986  // If this is the first declaration of the template, fill in the information
1987  // for the 'common' pointer.
1988  if (ThisDeclID == Redecl.getFirstID()) {
1989  if (RedeclarableTemplateDecl *RTD
1990  = ReadDeclAs<RedeclarableTemplateDecl>()) {
1991  assert(RTD->getKind() == D->getKind() &&
1992  "InstantiatedFromMemberTemplate kind mismatch");
1994  if (Record.readInt())
1996  }
1997  }
1998 
1999  DeclID PatternID = VisitTemplateDecl(D);
2000  D->IdentifierNamespace = Record.readInt();
2001 
2002  mergeRedeclarable(D, Redecl, PatternID);
2003 
2004  // If we merged the template with a prior declaration chain, merge the common
2005  // pointer.
2006  // FIXME: Actually merge here, don't just overwrite.
2007  D->Common = D->getCanonicalDecl()->Common;
2008 
2009  return Redecl;
2010 }
2011 
2013  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2014 
2015  if (ThisDeclID == Redecl.getFirstID()) {
2016  // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
2017  // the specializations.
2019  ReadDeclIDList(SpecIDs);
2021  }
2022 
2023  if (D->getTemplatedDecl()->TemplateOrInstantiation) {
2024  // We were loaded before our templated declaration was. We've not set up
2025  // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct
2026  // it now.
2027  Reader.getContext().getInjectedClassNameType(
2029  }
2030 }
2031 
2033  llvm_unreachable("BuiltinTemplates are not serialized");
2034 }
2035 
2036 /// TODO: Unify with ClassTemplateDecl version?
2037 /// May require unifying ClassTemplateDecl and
2038 /// VarTemplateDecl beyond TemplateDecl...
2040  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2041 
2042  if (ThisDeclID == Redecl.getFirstID()) {
2043  // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of
2044  // the specializations.
2046  ReadDeclIDList(SpecIDs);
2048  }
2049 }
2050 
2051 ASTDeclReader::RedeclarableResult
2054  RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D);
2055 
2056  ASTContext &C = Reader.getContext();
2057  if (Decl *InstD = ReadDecl()) {
2058  if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
2059  D->SpecializedTemplate = CTD;
2060  } else {
2062  Record.readTemplateArgumentList(TemplArgs);
2063  TemplateArgumentList *ArgList
2064  = TemplateArgumentList::CreateCopy(C, TemplArgs);
2065  ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
2067  SpecializedPartialSpecialization();
2068  PS->PartialSpecialization
2069  = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2070  PS->TemplateArgs = ArgList;
2071  D->SpecializedTemplate = PS;
2072  }
2073  }
2074 
2076  Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2077  D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2078  D->PointOfInstantiation = ReadSourceLocation();
2079  D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2080 
2081  bool writtenAsCanonicalDecl = Record.readInt();
2082  if (writtenAsCanonicalDecl) {
2083  ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>();
2084  if (D->isCanonicalDecl()) { // It's kept in the folding set.
2085  // Set this as, or find, the canonical declaration for this specialization
2088  dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
2089  CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
2090  .GetOrInsertNode(Partial);
2091  } else {
2092  CanonSpec =
2093  CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2094  }
2095  // If there was already a canonical specialization, merge into it.
2096  if (CanonSpec != D) {
2097  mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2098 
2099  // This declaration might be a definition. Merge with any existing
2100  // definition.
2101  if (auto *DDD = D->DefinitionData) {
2102  if (CanonSpec->DefinitionData)
2103  MergeDefinitionData(CanonSpec, std::move(*DDD));
2104  else
2105  CanonSpec->DefinitionData = D->DefinitionData;
2106  }
2107  D->DefinitionData = CanonSpec->DefinitionData;
2108  }
2109  }
2110  }
2111 
2112  // Explicit info.
2113  if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
2114  ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
2115  = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2116  ExplicitInfo->TypeAsWritten = TyInfo;
2117  ExplicitInfo->ExternLoc = ReadSourceLocation();
2118  ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
2119  D->ExplicitInfo = ExplicitInfo;
2120  }
2121 
2122  return Redecl;
2123 }
2124 
2127  RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D);
2128 
2129  D->TemplateParams = Record.readTemplateParameterList();
2130  D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2131 
2132  // These are read/set from/to the first declaration.
2133  if (ThisDeclID == Redecl.getFirstID()) {
2134  D->InstantiatedFromMember.setPointer(
2135  ReadDeclAs<ClassTemplatePartialSpecializationDecl>());
2136  D->InstantiatedFromMember.setInt(Record.readInt());
2137  }
2138 }
2139 
2142  VisitDecl(D);
2143  D->Specialization = ReadDeclAs<CXXMethodDecl>();
2144 }
2145 
2147  RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2148 
2149  if (ThisDeclID == Redecl.getFirstID()) {
2150  // This FunctionTemplateDecl owns a CommonPtr; read it.
2152  ReadDeclIDList(SpecIDs);
2154  }
2155 }
2156 
2157 /// TODO: Unify with ClassTemplateSpecializationDecl version?
2158 /// May require unifying ClassTemplate(Partial)SpecializationDecl and
2159 /// VarTemplate(Partial)SpecializationDecl with a new data
2160 /// structure Template(Partial)SpecializationDecl, and
2161 /// using Template(Partial)SpecializationDecl as input type.
2162 ASTDeclReader::RedeclarableResult
2165  RedeclarableResult Redecl = VisitVarDeclImpl(D);
2166 
2167  ASTContext &C = Reader.getContext();
2168  if (Decl *InstD = ReadDecl()) {
2169  if (VarTemplateDecl *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2170  D->SpecializedTemplate = VTD;
2171  } else {
2173  Record.readTemplateArgumentList(TemplArgs);
2175  C, TemplArgs);
2176  VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS =
2177  new (C)
2178  VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2179  PS->PartialSpecialization =
2180  cast<VarTemplatePartialSpecializationDecl>(InstD);
2181  PS->TemplateArgs = ArgList;
2182  D->SpecializedTemplate = PS;
2183  }
2184  }
2185 
2186  // Explicit info.
2187  if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
2188  VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo =
2189  new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2190  ExplicitInfo->TypeAsWritten = TyInfo;
2191  ExplicitInfo->ExternLoc = ReadSourceLocation();
2192  ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
2193  D->ExplicitInfo = ExplicitInfo;
2194  }
2195 
2197  Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
2198  D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
2199  D->PointOfInstantiation = ReadSourceLocation();
2200  D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
2201  D->IsCompleteDefinition = Record.readInt();
2202 
2203  bool writtenAsCanonicalDecl = Record.readInt();
2204  if (writtenAsCanonicalDecl) {
2205  VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>();
2206  if (D->isCanonicalDecl()) { // It's kept in the folding set.
2207  // FIXME: If it's already present, merge it.
2209  dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
2210  CanonPattern->getCommonPtr()->PartialSpecializations
2211  .GetOrInsertNode(Partial);
2212  } else {
2213  CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2214  }
2215  }
2216  }
2217 
2218  return Redecl;
2219 }
2220 
2221 /// TODO: Unify with ClassTemplatePartialSpecializationDecl version?
2222 /// May require unifying ClassTemplate(Partial)SpecializationDecl and
2223 /// VarTemplate(Partial)SpecializationDecl with a new data
2224 /// structure Template(Partial)SpecializationDecl, and
2225 /// using Template(Partial)SpecializationDecl as input type.
2228  RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D);
2229 
2230  D->TemplateParams = Record.readTemplateParameterList();
2231  D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
2232 
2233  // These are read/set from/to the first declaration.
2234  if (ThisDeclID == Redecl.getFirstID()) {
2235  D->InstantiatedFromMember.setPointer(
2236  ReadDeclAs<VarTemplatePartialSpecializationDecl>());
2237  D->InstantiatedFromMember.setInt(Record.readInt());
2238  }
2239 }
2240 
2242  VisitTypeDecl(D);
2243 
2244  D->setDeclaredWithTypename(Record.readInt());
2245 
2246  if (Record.readInt())
2247  D->setDefaultArgument(GetTypeSourceInfo());
2248 }
2249 
2251  VisitDeclaratorDecl(D);
2252  // TemplateParmPosition.
2253  D->setDepth(Record.readInt());
2254  D->setPosition(Record.readInt());
2255  if (D->isExpandedParameterPack()) {
2256  auto TypesAndInfos =
2257  D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
2258  for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
2259  new (&TypesAndInfos[I].first) QualType(Record.readType());
2260  TypesAndInfos[I].second = GetTypeSourceInfo();
2261  }
2262  } else {
2263  // Rest of NonTypeTemplateParmDecl.
2264  D->ParameterPack = Record.readInt();
2265  if (Record.readInt())
2266  D->setDefaultArgument(Record.readExpr());
2267  }
2268 }
2269 
2271  VisitTemplateDecl(D);
2272  // TemplateParmPosition.
2273  D->setDepth(Record.readInt());
2274  D->setPosition(Record.readInt());
2275  if (D->isExpandedParameterPack()) {
2276  TemplateParameterList **Data =
2277  D->getTrailingObjects<TemplateParameterList *>();
2278  for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2279  I != N; ++I)
2280  Data[I] = Record.readTemplateParameterList();
2281  } else {
2282  // Rest of TemplateTemplateParmDecl.
2283  D->ParameterPack = Record.readInt();
2284  if (Record.readInt())
2285  D->setDefaultArgument(Reader.getContext(),
2286  Record.readTemplateArgumentLoc());
2287  }
2288 }
2289 
2291  VisitRedeclarableTemplateDecl(D);
2292 }
2293 
2295  VisitDecl(D);
2296  D->AssertExprAndFailed.setPointer(Record.readExpr());
2297  D->AssertExprAndFailed.setInt(Record.readInt());
2298  D->Message = cast_or_null<StringLiteral>(Record.readExpr());
2299  D->RParenLoc = ReadSourceLocation();
2300 }
2301 
2303  VisitDecl(D);
2304 }
2305 
2306 std::pair<uint64_t, uint64_t>
2308  uint64_t LexicalOffset = ReadLocalOffset();
2309  uint64_t VisibleOffset = ReadLocalOffset();
2310  return std::make_pair(LexicalOffset, VisibleOffset);
2311 }
2312 
2313 template <typename T>
2314 ASTDeclReader::RedeclarableResult
2316  DeclID FirstDeclID = ReadDeclID();
2317  Decl *MergeWith = nullptr;
2318 
2319  bool IsKeyDecl = ThisDeclID == FirstDeclID;
2320  bool IsFirstLocalDecl = false;
2321 
2322  uint64_t RedeclOffset = 0;
2323 
2324  // 0 indicates that this declaration was the only declaration of its entity,
2325  // and is used for space optimization.
2326  if (FirstDeclID == 0) {
2327  FirstDeclID = ThisDeclID;
2328  IsKeyDecl = true;
2329  IsFirstLocalDecl = true;
2330  } else if (unsigned N = Record.readInt()) {
2331  // This declaration was the first local declaration, but may have imported
2332  // other declarations.
2333  IsKeyDecl = N == 1;
2334  IsFirstLocalDecl = true;
2335 
2336  // We have some declarations that must be before us in our redeclaration
2337  // chain. Read them now, and remember that we ought to merge with one of
2338  // them.
2339  // FIXME: Provide a known merge target to the second and subsequent such
2340  // declaration.
2341  for (unsigned I = 0; I != N - 1; ++I)
2342  MergeWith = ReadDecl();
2343 
2344  RedeclOffset = ReadLocalOffset();
2345  } else {
2346  // This declaration was not the first local declaration. Read the first
2347  // local declaration now, to trigger the import of other redeclarations.
2348  (void)ReadDecl();
2349  }
2350 
2351  T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2352  if (FirstDecl != D) {
2353  // We delay loading of the redeclaration chain to avoid deeply nested calls.
2354  // We temporarily set the first (canonical) declaration as the previous one
2355  // which is the one that matters and mark the real previous DeclID to be
2356  // loaded & attached later on.
2358  D->First = FirstDecl->getCanonicalDecl();
2359  }
2360 
2361  T *DAsT = static_cast<T*>(D);
2362 
2363  // Note that we need to load local redeclarations of this decl and build a
2364  // decl chain for them. This must happen *after* we perform the preloading
2365  // above; this ensures that the redeclaration chain is built in the correct
2366  // order.
2367  if (IsFirstLocalDecl)
2368  Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
2369 
2370  return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
2371 }
2372 
2373 /// \brief Attempts to merge the given declaration (D) with another declaration
2374 /// of the same entity.
2375 template<typename T>
2377  RedeclarableResult &Redecl,
2378  DeclID TemplatePatternID) {
2379  // If modules are not available, there is no reason to perform this merge.
2380  if (!Reader.getContext().getLangOpts().Modules)
2381  return;
2382 
2383  // If we're not the canonical declaration, we don't need to merge.
2384  if (!DBase->isFirstDecl())
2385  return;
2386 
2387  T *D = static_cast<T*>(DBase);
2388 
2389  if (auto *Existing = Redecl.getKnownMergeTarget())
2390  // We already know of an existing declaration we should merge with.
2391  mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID);
2392  else if (FindExistingResult ExistingRes = findExisting(D))
2393  if (T *Existing = ExistingRes)
2394  mergeRedeclarable(D, Existing, Redecl, TemplatePatternID);
2395 }
2396 
2397 /// \brief "Cast" to type T, asserting if we don't have an implicit conversion.
2398 /// We use this to put code in a template that will only be valid for certain
2399 /// instantiations.
2400 template<typename T> static T assert_cast(T t) { return t; }
2401 template<typename T> static T assert_cast(...) {
2402  llvm_unreachable("bad assert_cast");
2403 }
2404 
2405 /// \brief Merge together the pattern declarations from two template
2406 /// declarations.
2408  RedeclarableTemplateDecl *Existing,
2409  DeclID DsID, bool IsKeyDecl) {
2410  auto *DPattern = D->getTemplatedDecl();
2411  auto *ExistingPattern = Existing->getTemplatedDecl();
2412  RedeclarableResult Result(/*MergeWith*/ ExistingPattern,
2413  DPattern->getCanonicalDecl()->getGlobalID(),
2414  IsKeyDecl);
2415 
2416  if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2417  // Merge with any existing definition.
2418  // FIXME: This is duplicated in several places. Refactor.
2419  auto *ExistingClass =
2420  cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
2421  if (auto *DDD = DClass->DefinitionData) {
2422  if (ExistingClass->DefinitionData) {
2423  MergeDefinitionData(ExistingClass, std::move(*DDD));
2424  } else {
2425  ExistingClass->DefinitionData = DClass->DefinitionData;
2426  // We may have skipped this before because we thought that DClass
2427  // was the canonical declaration.
2428  Reader.PendingDefinitions.insert(DClass);
2429  }
2430  }
2431  DClass->DefinitionData = ExistingClass->DefinitionData;
2432 
2433  return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern),
2434  Result);
2435  }
2436  if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2437  return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern),
2438  Result);
2439  if (auto *DVar = dyn_cast<VarDecl>(DPattern))
2440  return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result);
2441  if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2442  return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern),
2443  Result);
2444  llvm_unreachable("merged an unknown kind of redeclarable template");
2445 }
2446 
2447 /// \brief Attempts to merge the given declaration (D) with another declaration
2448 /// of the same entity.
2449 template<typename T>
2451  RedeclarableResult &Redecl,
2452  DeclID TemplatePatternID) {
2453  T *D = static_cast<T*>(DBase);
2454  T *ExistingCanon = Existing->getCanonicalDecl();
2455  T *DCanon = D->getCanonicalDecl();
2456  if (ExistingCanon != DCanon) {
2457  assert(DCanon->getGlobalID() == Redecl.getFirstID() &&
2458  "already merged this declaration");
2459 
2460  // Have our redeclaration link point back at the canonical declaration
2461  // of the existing declaration, so that this declaration has the
2462  // appropriate canonical declaration.
2463  D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
2464  D->First = ExistingCanon;
2465  ExistingCanon->Used |= D->Used;
2466  D->Used = false;
2467 
2468  // When we merge a namespace, update its pointer to the first namespace.
2469  // We cannot have loaded any redeclarations of this declaration yet, so
2470  // there's nothing else that needs to be updated.
2471  if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
2472  Namespace->AnonOrFirstNamespaceAndInline.setPointer(
2473  assert_cast<NamespaceDecl*>(ExistingCanon));
2474 
2475  // When we merge a template, merge its pattern.
2476  if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2477  mergeTemplatePattern(
2478  DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon),
2479  TemplatePatternID, Redecl.isKeyDecl());
2480 
2481  // If this declaration is a key declaration, make a note of that.
2482  if (Redecl.isKeyDecl())
2483  Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
2484  }
2485 }
2486 
2487 /// \brief Attempts to merge the given declaration (D) with another declaration
2488 /// of the same entity, for the case where the entity is not actually
2489 /// redeclarable. This happens, for instance, when merging the fields of
2490 /// identical class definitions from two different modules.
2491 template<typename T>
2493  // If modules are not available, there is no reason to perform this merge.
2494  if (!Reader.getContext().getLangOpts().Modules)
2495  return;
2496 
2497  // ODR-based merging is only performed in C++. In C, identically-named things
2498  // in different translation units are not redeclarations (but may still have
2499  // compatible types).
2500  if (!Reader.getContext().getLangOpts().CPlusPlus)
2501  return;
2502 
2503  if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2504  if (T *Existing = ExistingRes)
2505  Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2506  Existing->getCanonicalDecl());
2507 }
2508 
2510  VisitDecl(D);
2511  unsigned NumVars = D->varlist_size();
2513  Vars.reserve(NumVars);
2514  for (unsigned i = 0; i != NumVars; ++i) {
2515  Vars.push_back(Record.readExpr());
2516  }
2517  D->setVars(Vars);
2518 }
2519 
2521  VisitValueDecl(D);
2522  D->setLocation(ReadSourceLocation());
2523  D->setCombiner(Record.readExpr());
2524  D->setInitializer(
2525  Record.readExpr(),
2526  static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()));
2527  D->PrevDeclInScope = ReadDeclID();
2528 }
2529 
2531  VisitVarDecl(D);
2532 }
2533 
2534 //===----------------------------------------------------------------------===//
2535 // Attribute Reading
2536 //===----------------------------------------------------------------------===//
2537 
2538 /// \brief Reads attributes from the current stream position.
2540  for (unsigned i = 0, e = Record.readInt(); i != e; ++i) {
2541  Attr *New = nullptr;
2542  attr::Kind Kind = (attr::Kind)Record.readInt();
2543  SourceRange Range = Record.readSourceRange();
2544  ASTContext &Context = getContext();
2545 
2546 #include "clang/Serialization/AttrPCHRead.inc"
2547 
2548  assert(New && "Unable to decode attribute?");
2549  Attrs.push_back(New);
2550  }
2551 }
2552 
2553 //===----------------------------------------------------------------------===//
2554 // ASTReader Implementation
2555 //===----------------------------------------------------------------------===//
2556 
2557 /// \brief Note that we have loaded the declaration with the given
2558 /// Index.
2559 ///
2560 /// This routine notes that this declaration has already been loaded,
2561 /// so that future GetDecl calls will return this declaration rather
2562 /// than trying to load a new declaration.
2563 inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
2564  assert(!DeclsLoaded[Index] && "Decl loaded twice?");
2565  DeclsLoaded[Index] = D;
2566 }
2567 
2568 
2569 /// \brief Determine whether the consumer will be interested in seeing
2570 /// this declaration (via HandleTopLevelDecl).
2571 ///
2572 /// This routine should return true for anything that might affect
2573 /// code generation, e.g., inline function definitions, Objective-C
2574 /// declarations with metadata, etc.
2575 static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
2576  // An ObjCMethodDecl is never considered as "interesting" because its
2577  // implementation container always is.
2578 
2579  // An ImportDecl or VarDecl imported from a module map module will get
2580  // emitted when we import the relevant module.
2581  if (isa<ImportDecl>(D) || isa<VarDecl>(D)) {
2582  auto *M = D->getImportedOwningModule();
2583  if (M && M->Kind == Module::ModuleMapModule &&
2584  Ctx.DeclMustBeEmitted(D))
2585  return false;
2586  }
2587 
2588  if (isa<FileScopeAsmDecl>(D) ||
2589  isa<ObjCProtocolDecl>(D) ||
2590  isa<ObjCImplDecl>(D) ||
2591  isa<ImportDecl>(D) ||
2592  isa<PragmaCommentDecl>(D) ||
2593  isa<PragmaDetectMismatchDecl>(D))
2594  return true;
2595  if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D))
2596  return !D->getDeclContext()->isFunctionOrMethod();
2597  if (VarDecl *Var = dyn_cast<VarDecl>(D))
2598  return Var->isFileVarDecl() &&
2599  Var->isThisDeclarationADefinition() == VarDecl::Definition;
2600  if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
2601  return Func->doesThisDeclarationHaveABody() || HasBody;
2602 
2603  if (auto *ES = D->getASTContext().getExternalSource())
2604  if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
2605  return true;
2606 
2607  return false;
2608 }
2609 
2610 /// \brief Get the correct cursor and offset for loading a declaration.
2611 ASTReader::RecordLocation
2612 ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
2613  GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
2614  assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
2615  ModuleFile *M = I->second;
2616  const DeclOffset &DOffs =
2617  M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
2618  Loc = TranslateSourceLocation(*M, DOffs.getLocation());
2619  return RecordLocation(M, DOffs.BitOffset);
2620 }
2621 
2622 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
2624  = GlobalBitOffsetsMap.find(GlobalOffset);
2625 
2626  assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
2627  return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
2628 }
2629 
2630 uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
2631  return LocalOffset + M.GlobalBitOffset;
2632 }
2633 
2635  const TemplateParameterList *Y);
2636 
2637 /// \brief Determine whether two template parameters are similar enough
2638 /// that they may be used in declarations of the same template.
2639 static bool isSameTemplateParameter(const NamedDecl *X,
2640  const NamedDecl *Y) {
2641  if (X->getKind() != Y->getKind())
2642  return false;
2643 
2644  if (const TemplateTypeParmDecl *TX = dyn_cast<TemplateTypeParmDecl>(X)) {
2645  const TemplateTypeParmDecl *TY = cast<TemplateTypeParmDecl>(Y);
2646  return TX->isParameterPack() == TY->isParameterPack();
2647  }
2648 
2649  if (const NonTypeTemplateParmDecl *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) {
2650  const NonTypeTemplateParmDecl *TY = cast<NonTypeTemplateParmDecl>(Y);
2651  return TX->isParameterPack() == TY->isParameterPack() &&
2652  TX->getASTContext().hasSameType(TX->getType(), TY->getType());
2653  }
2654 
2655  const TemplateTemplateParmDecl *TX = cast<TemplateTemplateParmDecl>(X);
2656  const TemplateTemplateParmDecl *TY = cast<TemplateTemplateParmDecl>(Y);
2657  return TX->isParameterPack() == TY->isParameterPack() &&
2659  TY->getTemplateParameters());
2660 }
2661 
2663  if (auto *NS = X->getAsNamespace())
2664  return NS;
2665  if (auto *NAS = X->getAsNamespaceAlias())
2666  return NAS->getNamespace();
2667  return nullptr;
2668 }
2669 
2671  const NestedNameSpecifier *Y) {
2672  if (auto *NSX = getNamespace(X)) {
2673  auto *NSY = getNamespace(Y);
2674  if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl())
2675  return false;
2676  } else if (X->getKind() != Y->getKind())
2677  return false;
2678 
2679  // FIXME: For namespaces and types, we're permitted to check that the entity
2680  // is named via the same tokens. We should probably do so.
2681  switch (X->getKind()) {
2683  if (X->getAsIdentifier() != Y->getAsIdentifier())
2684  return false;
2685  break;
2688  // We've already checked that we named the same namespace.
2689  break;
2692  if (X->getAsType()->getCanonicalTypeInternal() !=
2694  return false;
2695  break;
2698  return true;
2699  }
2700 
2701  // Recurse into earlier portion of NNS, if any.
2702  auto *PX = X->getPrefix();
2703  auto *PY = Y->getPrefix();
2704  if (PX && PY)
2705  return isSameQualifier(PX, PY);
2706  return !PX && !PY;
2707 }
2708 
2709 /// \brief Determine whether two template parameter lists are similar enough
2710 /// that they may be used in declarations of the same template.
2712  const TemplateParameterList *Y) {
2713  if (X->size() != Y->size())
2714  return false;
2715 
2716  for (unsigned I = 0, N = X->size(); I != N; ++I)
2717  if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
2718  return false;
2719 
2720  return true;
2721 }
2722 
2723 /// Determine whether the attributes we can overload on are identical for A and
2724 /// B. Will ignore any overloadable attrs represented in the type of A and B.
2726  const FunctionDecl *B) {
2727  // Note that pass_object_size attributes are represented in the function's
2728  // ExtParameterInfo, so we don't need to check them here.
2729 
2731  // Since this is an equality check, we can ignore that enable_if attrs show up
2732  // in reverse order.
2733  for (const auto *EIA : A->specific_attrs<EnableIfAttr>())
2734  AEnableIfs.push_back(EIA);
2735 
2737  for (const auto *EIA : B->specific_attrs<EnableIfAttr>())
2738  BEnableIfs.push_back(EIA);
2739 
2740  // Two very common cases: either we have 0 enable_if attrs, or we have an
2741  // unequal number of enable_if attrs.
2742  if (AEnableIfs.empty() && BEnableIfs.empty())
2743  return true;
2744 
2745  if (AEnableIfs.size() != BEnableIfs.size())
2746  return false;
2747 
2748  llvm::FoldingSetNodeID Cand1ID, Cand2ID;
2749  for (unsigned I = 0, E = AEnableIfs.size(); I != E; ++I) {
2750  Cand1ID.clear();
2751  Cand2ID.clear();
2752 
2753  AEnableIfs[I]->getCond()->Profile(Cand1ID, A->getASTContext(), true);
2754  BEnableIfs[I]->getCond()->Profile(Cand2ID, B->getASTContext(), true);
2755  if (Cand1ID != Cand2ID)
2756  return false;
2757  }
2758 
2759  return true;
2760 }
2761 
2762 /// \brief Determine whether the two declarations refer to the same entity.
2763 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
2764  assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
2765 
2766  if (X == Y)
2767  return true;
2768 
2769  // Must be in the same context.
2770  if (!X->getDeclContext()->getRedeclContext()->Equals(
2772  return false;
2773 
2774  // Two typedefs refer to the same entity if they have the same underlying
2775  // type.
2776  if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X))
2777  if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y))
2778  return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(),
2779  TypedefY->getUnderlyingType());
2780 
2781  // Must have the same kind.
2782  if (X->getKind() != Y->getKind())
2783  return false;
2784 
2785  // Objective-C classes and protocols with the same name always match.
2786  if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X))
2787  return true;
2788 
2789  if (isa<ClassTemplateSpecializationDecl>(X)) {
2790  // No need to handle these here: we merge them when adding them to the
2791  // template.
2792  return false;
2793  }
2794 
2795  // Compatible tags match.
2796  if (TagDecl *TagX = dyn_cast<TagDecl>(X)) {
2797  TagDecl *TagY = cast<TagDecl>(Y);
2798  return (TagX->getTagKind() == TagY->getTagKind()) ||
2799  ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class ||
2800  TagX->getTagKind() == TTK_Interface) &&
2801  (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class ||
2802  TagY->getTagKind() == TTK_Interface));
2803  }
2804 
2805  // Functions with the same type and linkage match.
2806  // FIXME: This needs to cope with merging of prototyped/non-prototyped
2807  // functions, etc.
2808  if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) {
2809  FunctionDecl *FuncY = cast<FunctionDecl>(Y);
2810  if (CXXConstructorDecl *CtorX = dyn_cast<CXXConstructorDecl>(X)) {
2811  CXXConstructorDecl *CtorY = cast<CXXConstructorDecl>(Y);
2812  if (CtorX->getInheritedConstructor() &&
2813  !isSameEntity(CtorX->getInheritedConstructor().getConstructor(),
2815  return false;
2816  }
2817  ASTContext &C = FuncX->getASTContext();
2818  if (!C.hasSameType(FuncX->getType(), FuncY->getType())) {
2819  // We can get functions with different types on the redecl chain in C++17
2820  // if they have differing exception specifications and at least one of
2821  // the excpetion specs is unresolved.
2822  // FIXME: Do we need to check for C++14 deduced return types here too?
2823  auto *XFPT = FuncX->getType()->getAs<FunctionProtoType>();
2824  auto *YFPT = FuncY->getType()->getAs<FunctionProtoType>();
2825  if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT &&
2826  (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) ||
2828  C.hasSameFunctionTypeIgnoringExceptionSpec(FuncX->getType(),
2829  FuncY->getType()))
2830  return true;
2831  return false;
2832  }
2833  return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() &&
2834  hasSameOverloadableAttrs(FuncX, FuncY);
2835  }
2836 
2837  // Variables with the same type and linkage match.
2838  if (VarDecl *VarX = dyn_cast<VarDecl>(X)) {
2839  VarDecl *VarY = cast<VarDecl>(Y);
2840  if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) {
2841  ASTContext &C = VarX->getASTContext();
2842  if (C.hasSameType(VarX->getType(), VarY->getType()))
2843  return true;
2844 
2845  // We can get decls with different types on the redecl chain. Eg.
2846  // template <typename T> struct S { static T Var[]; }; // #1
2847  // template <typename T> T S<T>::Var[sizeof(T)]; // #2
2848  // Only? happens when completing an incomplete array type. In this case
2849  // when comparing #1 and #2 we should go through their element type.
2850  const ArrayType *VarXTy = C.getAsArrayType(VarX->getType());
2851  const ArrayType *VarYTy = C.getAsArrayType(VarY->getType());
2852  if (!VarXTy || !VarYTy)
2853  return false;
2854  if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType())
2855  return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType());
2856  }
2857  return false;
2858  }
2859 
2860  // Namespaces with the same name and inlinedness match.
2861  if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) {
2862  NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y);
2863  return NamespaceX->isInline() == NamespaceY->isInline();
2864  }
2865 
2866  // Identical template names and kinds match if their template parameter lists
2867  // and patterns match.
2868  if (TemplateDecl *TemplateX = dyn_cast<TemplateDecl>(X)) {
2869  TemplateDecl *TemplateY = cast<TemplateDecl>(Y);
2870  return isSameEntity(TemplateX->getTemplatedDecl(),
2871  TemplateY->getTemplatedDecl()) &&
2872  isSameTemplateParameterList(TemplateX->getTemplateParameters(),
2873  TemplateY->getTemplateParameters());
2874  }
2875 
2876  // Fields with the same name and the same type match.
2877  if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) {
2878  FieldDecl *FDY = cast<FieldDecl>(Y);
2879  // FIXME: Also check the bitwidth is odr-equivalent, if any.
2880  return X->getASTContext().hasSameType(FDX->getType(), FDY->getType());
2881  }
2882 
2883  // Indirect fields with the same target field match.
2884  if (auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) {
2885  auto *IFDY = cast<IndirectFieldDecl>(Y);
2886  return IFDX->getAnonField()->getCanonicalDecl() ==
2887  IFDY->getAnonField()->getCanonicalDecl();
2888  }
2889 
2890  // Enumerators with the same name match.
2891  if (isa<EnumConstantDecl>(X))
2892  // FIXME: Also check the value is odr-equivalent.
2893  return true;
2894 
2895  // Using shadow declarations with the same target match.
2896  if (UsingShadowDecl *USX = dyn_cast<UsingShadowDecl>(X)) {
2897  UsingShadowDecl *USY = cast<UsingShadowDecl>(Y);
2898  return USX->getTargetDecl() == USY->getTargetDecl();
2899  }
2900 
2901  // Using declarations with the same qualifier match. (We already know that
2902  // the name matches.)
2903  if (auto *UX = dyn_cast<UsingDecl>(X)) {
2904  auto *UY = cast<UsingDecl>(Y);
2905  return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
2906  UX->hasTypename() == UY->hasTypename() &&
2907  UX->isAccessDeclaration() == UY->isAccessDeclaration();
2908  }
2909  if (auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) {
2910  auto *UY = cast<UnresolvedUsingValueDecl>(Y);
2911  return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
2912  UX->isAccessDeclaration() == UY->isAccessDeclaration();
2913  }
2914  if (auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X))
2915  return isSameQualifier(
2916  UX->getQualifier(),
2917  cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier());
2918 
2919  // Namespace alias definitions with the same target match.
2920  if (auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) {
2921  auto *NAY = cast<NamespaceAliasDecl>(Y);
2922  return NAX->getNamespace()->Equals(NAY->getNamespace());
2923  }
2924 
2925  return false;
2926 }
2927 
2928 /// Find the context in which we should search for previous declarations when
2929 /// looking for declarations to merge.
2930 DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
2931  DeclContext *DC) {
2932  if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC))
2933  return ND->getOriginalNamespace();
2934 
2935  if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
2936  // Try to dig out the definition.
2937  auto *DD = RD->DefinitionData;
2938  if (!DD)
2939  DD = RD->getCanonicalDecl()->DefinitionData;
2940 
2941  // If there's no definition yet, then DC's definition is added by an update
2942  // record, but we've not yet loaded that update record. In this case, we
2943  // commit to DC being the canonical definition now, and will fix this when
2944  // we load the update record.
2945  if (!DD) {
2946  DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD);
2947  RD->IsCompleteDefinition = true;
2948  RD->DefinitionData = DD;
2949  RD->getCanonicalDecl()->DefinitionData = DD;
2950 
2951  // Track that we did this horrible thing so that we can fix it later.
2952  Reader.PendingFakeDefinitionData.insert(
2953  std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
2954  }
2955 
2956  return DD->Definition;
2957  }
2958 
2959  if (EnumDecl *ED = dyn_cast<EnumDecl>(DC))
2960  return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
2961  : nullptr;
2962 
2963  // We can see the TU here only if we have no Sema object. In that case,
2964  // there's no TU scope to look in, so using the DC alone is sufficient.
2965  if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2966  return TU;
2967 
2968  return nullptr;
2969 }
2970 
2971 ASTDeclReader::FindExistingResult::~FindExistingResult() {
2972  // Record that we had a typedef name for linkage whether or not we merge
2973  // with that declaration.
2974  if (TypedefNameForLinkage) {
2975  DeclContext *DC = New->getDeclContext()->getRedeclContext();
2976  Reader.ImportedTypedefNamesForLinkage.insert(
2977  std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
2978  return;
2979  }
2980 
2981  if (!AddResult || Existing)
2982  return;
2983 
2984  DeclarationName Name = New->getDeclName();
2985  DeclContext *DC = New->getDeclContext()->getRedeclContext();
2987  setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
2988  AnonymousDeclNumber, New);
2989  } else if (DC->isTranslationUnit() &&
2990  !Reader.getContext().getLangOpts().CPlusPlus) {
2991  if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
2992  Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
2993  .push_back(New);
2994  } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
2995  // Add the declaration to its redeclaration context so later merging
2996  // lookups will find it.
2997  MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true);
2998  }
2999 }
3000 
3001 /// Find the declaration that should be merged into, given the declaration found
3002 /// by name lookup. If we're merging an anonymous declaration within a typedef,
3003 /// we need a matching typedef, and we merge with the type inside it.
3005  bool IsTypedefNameForLinkage) {
3006  if (!IsTypedefNameForLinkage)
3007  return Found;
3008 
3009  // If we found a typedef declaration that gives a name to some other
3010  // declaration, then we want that inner declaration. Declarations from
3011  // AST files are handled via ImportedTypedefNamesForLinkage.
3012  if (Found->isFromASTFile())
3013  return nullptr;
3014 
3015  if (auto *TND = dyn_cast<TypedefNameDecl>(Found))
3016  return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
3017 
3018  return nullptr;
3019 }
3020 
3021 NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
3022  DeclContext *DC,
3023  unsigned Index) {
3024  // If the lexical context has been merged, look into the now-canonical
3025  // definition.
3026  if (auto *Merged = Reader.MergedDeclContexts.lookup(DC))
3027  DC = Merged;
3028 
3029  // If we've seen this before, return the canonical declaration.
3030  auto &Previous = Reader.AnonymousDeclarationsForMerging[DC];
3031  if (Index < Previous.size() && Previous[Index])
3032  return Previous[Index];
3033 
3034  // If this is the first time, but we have parsed a declaration of the context,
3035  // build the anonymous declaration list from the parsed declaration.
3036  if (!cast<Decl>(DC)->isFromASTFile()) {
3037  numberAnonymousDeclsWithin(DC, [&](NamedDecl *ND, unsigned Number) {
3038  if (Previous.size() == Number)
3039  Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));
3040  else
3041  Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl());
3042  });
3043  }
3044 
3045  return Index < Previous.size() ? Previous[Index] : nullptr;
3046 }
3047 
3048 void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader,
3049  DeclContext *DC, unsigned Index,
3050  NamedDecl *D) {
3051  if (auto *Merged = Reader.MergedDeclContexts.lookup(DC))
3052  DC = Merged;
3053 
3054  auto &Previous = Reader.AnonymousDeclarationsForMerging[DC];
3055  if (Index >= Previous.size())
3056  Previous.resize(Index + 1);
3057  if (!Previous[Index])
3058  Previous[Index] = D;
3059 }
3060 
3061 ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
3062  DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage
3063  : D->getDeclName();
3064 
3065  if (!Name && !needsAnonymousDeclarationNumber(D)) {
3066  // Don't bother trying to find unnamed declarations that are in
3067  // unmergeable contexts.
3068  FindExistingResult Result(Reader, D, /*Existing=*/nullptr,
3069  AnonymousDeclNumber, TypedefNameForLinkage);
3070  Result.suppress();
3071  return Result;
3072  }
3073 
3075  if (TypedefNameForLinkage) {
3076  auto It = Reader.ImportedTypedefNamesForLinkage.find(
3077  std::make_pair(DC, TypedefNameForLinkage));
3078  if (It != Reader.ImportedTypedefNamesForLinkage.end())
3079  if (isSameEntity(It->second, D))
3080  return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3081  TypedefNameForLinkage);
3082  // Go on to check in other places in case an existing typedef name
3083  // was not imported.
3084  }
3085 
3087  // This is an anonymous declaration that we may need to merge. Look it up
3088  // in its context by number.
3089  if (auto *Existing = getAnonymousDeclForMerging(
3090  Reader, D->getLexicalDeclContext(), AnonymousDeclNumber))
3091  if (isSameEntity(Existing, D))
3092  return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3093  TypedefNameForLinkage);
3094  } else if (DC->isTranslationUnit() &&
3095  !Reader.getContext().getLangOpts().CPlusPlus) {
3096  IdentifierResolver &IdResolver = Reader.getIdResolver();
3097 
3098  // Temporarily consider the identifier to be up-to-date. We don't want to
3099  // cause additional lookups here.
3100  class UpToDateIdentifierRAII {
3101  IdentifierInfo *II;
3102  bool WasOutToDate;
3103 
3104  public:
3105  explicit UpToDateIdentifierRAII(IdentifierInfo *II)
3106  : II(II), WasOutToDate(false)
3107  {
3108  if (II) {
3109  WasOutToDate = II->isOutOfDate();
3110  if (WasOutToDate)
3111  II->setOutOfDate(false);
3112  }
3113  }
3114 
3115  ~UpToDateIdentifierRAII() {
3116  if (WasOutToDate)
3117  II->setOutOfDate(true);
3118  }
3119  } UpToDate(Name.getAsIdentifierInfo());
3120 
3121  for (IdentifierResolver::iterator I = IdResolver.begin(Name),
3122  IEnd = IdResolver.end();
3123  I != IEnd; ++I) {
3124  if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3125  if (isSameEntity(Existing, D))
3126  return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3127  TypedefNameForLinkage);
3128  }
3129  } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
3130  DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
3131  for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) {
3132  if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
3133  if (isSameEntity(Existing, D))
3134  return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3135  TypedefNameForLinkage);
3136  }
3137  } else {
3138  // Not in a mergeable context.
3139  return FindExistingResult(Reader);
3140  }
3141 
3142  // If this declaration is from a merged context, make a note that we need to
3143  // check that the canonical definition of that context contains the decl.
3144  //
3145  // FIXME: We should do something similar if we merge two definitions of the
3146  // same template specialization into the same CXXRecordDecl.
3147  auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
3148  if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3149  MergedDCIt->second == D->getDeclContext())
3150  Reader.PendingOdrMergeChecks.push_back(D);
3151 
3152  return FindExistingResult(Reader, D, /*Existing=*/nullptr,
3153  AnonymousDeclNumber, TypedefNameForLinkage);
3154 }
3155 
3156 template<typename DeclT>
3158  return D->RedeclLink.getLatestNotUpdated();
3159 }
3161  llvm_unreachable("getMostRecentDecl on non-redeclarable declaration");
3162 }
3163 
3165  assert(D);
3166 
3167  switch (D->getKind()) {
3168 #define ABSTRACT_DECL(TYPE)
3169 #define DECL(TYPE, BASE) \
3170  case Decl::TYPE: \
3171  return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3172 #include "clang/AST/DeclNodes.inc"
3173  }
3174  llvm_unreachable("unknown decl kind");
3175 }
3176 
3177 Decl *ASTReader::getMostRecentExistingDecl(Decl *D) {
3179 }
3180 
3181 template<typename DeclT>
3184  Decl *Previous, Decl *Canon) {
3185  D->RedeclLink.setPrevious(cast<DeclT>(Previous));
3186  D->First = cast<DeclT>(Previous)->First;
3187 }
3188 
3189 namespace clang {
3190 template<>
3193  Decl *Previous, Decl *Canon) {
3194  VarDecl *VD = static_cast<VarDecl*>(D);
3195  VarDecl *PrevVD = cast<VarDecl>(Previous);
3196  D->RedeclLink.setPrevious(PrevVD);
3197  D->First = PrevVD->First;
3198 
3199  // We should keep at most one definition on the chain.
3200  // FIXME: Cache the definition once we've found it. Building a chain with
3201  // N definitions currently takes O(N^2) time here.
3203  for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) {
3204  if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) {
3205  Reader.mergeDefinitionVisibility(CurD, VD);
3207  break;
3208  }
3209  }
3210  }
3211 }
3212 
3213 template<>
3216  Decl *Previous, Decl *Canon) {
3217  FunctionDecl *FD = static_cast<FunctionDecl*>(D);
3218  FunctionDecl *PrevFD = cast<FunctionDecl>(Previous);
3219 
3220  FD->RedeclLink.setPrevious(PrevFD);
3221  FD->First = PrevFD->First;
3222 
3223  // If the previous declaration is an inline function declaration, then this
3224  // declaration is too.
3225  if (PrevFD->IsInline != FD->IsInline) {
3226  // FIXME: [dcl.fct.spec]p4:
3227  // If a function with external linkage is declared inline in one
3228  // translation unit, it shall be declared inline in all translation
3229  // units in which it appears.
3230  //
3231  // Be careful of this case:
3232  //
3233  // module A:
3234  // template<typename T> struct X { void f(); };
3235  // template<typename T> inline void X<T>::f() {}
3236  //
3237  // module B instantiates the declaration of X<int>::f
3238  // module C instantiates the definition of X<int>::f
3239  //
3240  // If module B and C are merged, we do not have a violation of this rule.
3241  FD->IsInline = true;
3242  }
3243 
3244  // If we need to propagate an exception specification along the redecl
3245  // chain, make a note of that so that we can do so later.
3246  auto *FPT = FD->getType()->getAs<FunctionProtoType>();
3247  auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>();
3248  if (FPT && PrevFPT) {
3249  bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType());
3250  bool WasUnresolved =
3252  if (IsUnresolved != WasUnresolved)
3253  Reader.PendingExceptionSpecUpdates.insert(
3254  std::make_pair(Canon, IsUnresolved ? PrevFD : FD));
3255  }
3256 }
3257 } // end namespace clang
3258 
3260  llvm_unreachable("attachPreviousDecl on non-redeclarable declaration");
3261 }
3262 
3263 /// Inherit the default template argument from \p From to \p To. Returns
3264 /// \c false if there is no default template for \p From.
3265 template <typename ParmDecl>
3266 static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From,
3267  Decl *ToD) {
3268  auto *To = cast<ParmDecl>(ToD);
3269  if (!From->hasDefaultArgument())
3270  return false;
3271  To->setInheritedDefaultArgument(Context, From);
3272  return true;
3273 }
3274 
3276  TemplateDecl *From,
3277  TemplateDecl *To) {
3278  auto *FromTP = From->getTemplateParameters();
3279  auto *ToTP = To->getTemplateParameters();
3280  assert(FromTP->size() == ToTP->size() && "merged mismatched templates?");
3281 
3282  for (unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3283  NamedDecl *FromParam = FromTP->getParam(N - I - 1);
3284  if (FromParam->isParameterPack())
3285  continue;
3286  NamedDecl *ToParam = ToTP->getParam(N - I - 1);
3287 
3288  if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) {
3289  if (!inheritDefaultTemplateArgument(Context, FTTP, ToParam))
3290  break;
3291  } else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) {
3292  if (!inheritDefaultTemplateArgument(Context, FNTTP, ToParam))
3293  break;
3294  } else {
3296  Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam))
3297  break;
3298  }
3299  }
3300 }
3301 
3303  Decl *Previous, Decl *Canon) {
3304  assert(D && Previous);
3305 
3306  switch (D->getKind()) {
3307 #define ABSTRACT_DECL(TYPE)
3308 #define DECL(TYPE, BASE) \
3309  case Decl::TYPE: \
3310  attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
3311  break;
3312 #include "clang/AST/DeclNodes.inc"
3313  }
3314 
3315  // If the declaration was visible in one module, a redeclaration of it in
3316  // another module remains visible even if it wouldn't be visible by itself.
3317  //
3318  // FIXME: In this case, the declaration should only be visible if a module
3319  // that makes it visible has been imported.
3320  D->IdentifierNamespace |=
3321  Previous->IdentifierNamespace &
3323 
3324  // If the declaration declares a template, it may inherit default arguments
3325  // from the previous declaration.
3326  if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
3328  cast<TemplateDecl>(Previous), TD);
3329 }
3330 
3331 template<typename DeclT>
3333  D->RedeclLink.setLatest(cast<DeclT>(Latest));
3334 }
3336  llvm_unreachable("attachLatestDecl on non-redeclarable declaration");
3337 }
3338 
3340  assert(D && Latest);
3341 
3342  switch (D->getKind()) {
3343 #define ABSTRACT_DECL(TYPE)
3344 #define DECL(TYPE, BASE) \
3345  case Decl::TYPE: \
3346  attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3347  break;
3348 #include "clang/AST/DeclNodes.inc"
3349  }
3350 }
3351 
3352 template<typename DeclT>
3354  D->RedeclLink.markIncomplete();
3355 }
3357  llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration");
3358 }
3359 
3360 void ASTReader::markIncompleteDeclChain(Decl *D) {
3361  switch (D->getKind()) {
3362 #define ABSTRACT_DECL(TYPE)
3363 #define DECL(TYPE, BASE) \
3364  case Decl::TYPE: \
3365  ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3366  break;
3367 #include "clang/AST/DeclNodes.inc"
3368  }
3369 }
3370 
3371 /// \brief Read the declaration at the given offset from the AST file.
3372 Decl *ASTReader::ReadDeclRecord(DeclID ID) {
3373  unsigned Index = ID - NUM_PREDEF_DECL_IDS;
3374  SourceLocation DeclLoc;
3375  RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
3376  llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
3377  // Keep track of where we are in the stream, then jump back there
3378  // after reading this declaration.
3379  SavedStreamPosition SavedPosition(DeclsCursor);
3380 
3381  ReadingKindTracker ReadingKind(Read_Decl, *this);
3382 
3383  // Note that we are loading a declaration record.
3384  Deserializing ADecl(this);
3385 
3386  DeclsCursor.JumpToBit(Loc.Offset);
3387  ASTRecordReader Record(*this, *Loc.F);
3388  ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc);
3389  unsigned Code = DeclsCursor.ReadCode();
3390 
3391  ASTContext &Context = getContext();
3392  Decl *D = nullptr;
3393  switch ((DeclCode)Record.readRecord(DeclsCursor, Code)) {
3394  case DECL_CONTEXT_LEXICAL:
3395  case DECL_CONTEXT_VISIBLE:
3396  llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
3397  case DECL_TYPEDEF:
3398  D = TypedefDecl::CreateDeserialized(Context, ID);
3399  break;
3400  case DECL_TYPEALIAS:
3401  D = TypeAliasDecl::CreateDeserialized(Context, ID);
3402  break;
3403  case DECL_ENUM:
3404  D = EnumDecl::CreateDeserialized(Context, ID);
3405  break;
3406  case DECL_RECORD:
3407  D = RecordDecl::CreateDeserialized(Context, ID);
3408  break;
3409  case DECL_ENUM_CONSTANT:
3410  D = EnumConstantDecl::CreateDeserialized(Context, ID);
3411  break;
3412  case DECL_FUNCTION:
3413  D = FunctionDecl::CreateDeserialized(Context, ID);
3414  break;
3415  case DECL_LINKAGE_SPEC:
3416  D = LinkageSpecDecl::CreateDeserialized(Context, ID);
3417  break;
3418  case DECL_EXPORT:
3419  D = ExportDecl::CreateDeserialized(Context, ID);
3420  break;
3421  case DECL_LABEL:
3422  D = LabelDecl::CreateDeserialized(Context, ID);
3423  break;
3424  case DECL_NAMESPACE:
3425  D = NamespaceDecl::CreateDeserialized(Context, ID);
3426  break;
3427  case DECL_NAMESPACE_ALIAS:
3428  D = NamespaceAliasDecl::CreateDeserialized(Context, ID);
3429  break;
3430  case DECL_USING:
3431  D = UsingDecl::CreateDeserialized(Context, ID);
3432  break;
3433  case DECL_USING_PACK:
3434  D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt());
3435  break;
3436  case DECL_USING_SHADOW:
3437  D = UsingShadowDecl::CreateDeserialized(Context, ID);
3438  break;
3441  break;
3442  case DECL_USING_DIRECTIVE:
3443  D = UsingDirectiveDecl::CreateDeserialized(Context, ID);
3444  break;
3447  break;
3450  break;
3451  case DECL_CXX_RECORD:
3452  D = CXXRecordDecl::CreateDeserialized(Context, ID);
3453  break;
3456  break;
3457  case DECL_CXX_METHOD:
3458  D = CXXMethodDecl::CreateDeserialized(Context, ID);
3459  break;
3460  case DECL_CXX_CONSTRUCTOR:
3461  D = CXXConstructorDecl::CreateDeserialized(Context, ID, false);
3462  break;
3464  D = CXXConstructorDecl::CreateDeserialized(Context, ID, true);
3465  break;
3466  case DECL_CXX_DESTRUCTOR:
3467  D = CXXDestructorDecl::CreateDeserialized(Context, ID);
3468  break;
3469  case DECL_CXX_CONVERSION:
3470  D = CXXConversionDecl::CreateDeserialized(Context, ID);
3471  break;
3472  case DECL_ACCESS_SPEC:
3473  D = AccessSpecDecl::CreateDeserialized(Context, ID);
3474  break;
3475  case DECL_FRIEND:
3476  D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt());
3477  break;
3478  case DECL_FRIEND_TEMPLATE:
3479  D = FriendTemplateDecl::CreateDeserialized(Context, ID);
3480  break;
3481  case DECL_CLASS_TEMPLATE:
3482  D = ClassTemplateDecl::CreateDeserialized(Context, ID);
3483  break;
3486  break;
3489  break;
3490  case DECL_VAR_TEMPLATE:
3491  D = VarTemplateDecl::CreateDeserialized(Context, ID);
3492  break;
3495  break;
3498  break;
3501  break;
3504  break;
3507  break;
3510  break;
3513  Record.readInt());
3514  break;
3517  break;
3520  Record.readInt());
3521  break;
3524  break;
3525  case DECL_STATIC_ASSERT:
3526  D = StaticAssertDecl::CreateDeserialized(Context, ID);
3527  break;
3528  case DECL_OBJC_METHOD:
3529  D = ObjCMethodDecl::CreateDeserialized(Context, ID);
3530  break;
3531  case DECL_OBJC_INTERFACE:
3532  D = ObjCInterfaceDecl::CreateDeserialized(Context, ID);
3533  break;
3534  case DECL_OBJC_IVAR:
3535  D = ObjCIvarDecl::CreateDeserialized(Context, ID);
3536  break;
3537  case DECL_OBJC_PROTOCOL:
3538  D = ObjCProtocolDecl::CreateDeserialized(Context, ID);
3539  break;
3541  D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID);
3542  break;
3543  case DECL_OBJC_CATEGORY:
3544  D = ObjCCategoryDecl::CreateDeserialized(Context, ID);
3545  break;
3548  break;
3551  break;
3554  break;
3555  case DECL_OBJC_PROPERTY:
3556  D = ObjCPropertyDecl::CreateDeserialized(Context, ID);
3557  break;
3560  break;
3561  case DECL_FIELD:
3562  D = FieldDecl::CreateDeserialized(Context, ID);
3563  break;
3564  case DECL_INDIRECTFIELD:
3565  D = IndirectFieldDecl::CreateDeserialized(Context, ID);
3566  break;
3567  case DECL_VAR:
3568  D = VarDecl::CreateDeserialized(Context, ID);
3569  break;
3570  case DECL_IMPLICIT_PARAM:
3571  D = ImplicitParamDecl::CreateDeserialized(Context, ID);
3572  break;
3573  case DECL_PARM_VAR:
3574  D = ParmVarDecl::CreateDeserialized(Context, ID);
3575  break;
3576  case DECL_DECOMPOSITION:
3577  D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt());
3578  break;
3579  case DECL_BINDING:
3580  D = BindingDecl::CreateDeserialized(Context, ID);
3581  break;
3582  case DECL_FILE_SCOPE_ASM:
3583  D = FileScopeAsmDecl::CreateDeserialized(Context, ID);
3584  break;
3585  case DECL_BLOCK:
3586  D = BlockDecl::CreateDeserialized(Context, ID);
3587  break;
3588  case DECL_MS_PROPERTY:
3589  D = MSPropertyDecl::CreateDeserialized(Context, ID);
3590  break;
3591  case DECL_CAPTURED:
3592  D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt());
3593  break;
3595  Error("attempt to read a C++ base-specifier record as a declaration");
3596  return nullptr;
3598  Error("attempt to read a C++ ctor initializer record as a declaration");
3599  return nullptr;
3600  case DECL_IMPORT:
3601  // Note: last entry of the ImportDecl record is the number of stored source
3602  // locations.
3603  D = ImportDecl::CreateDeserialized(Context, ID, Record.back());
3604  break;
3606  D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt());
3607  break;
3610  break;
3611  case DECL_OMP_CAPTUREDEXPR:
3612  D = OMPCapturedExprDecl::CreateDeserialized(Context, ID);
3613  break;
3614  case DECL_PRAGMA_COMMENT:
3615  D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt());
3616  break;
3619  Record.readInt());
3620  break;
3621  case DECL_EMPTY:
3622  D = EmptyDecl::CreateDeserialized(Context, ID);
3623  break;
3624  case DECL_OBJC_TYPE_PARAM:
3625  D = ObjCTypeParamDecl::CreateDeserialized(Context, ID);
3626  break;
3627  }
3628 
3629  assert(D && "Unknown declaration reading AST file");
3630  LoadedDecl(Index, D);
3631  // Set the DeclContext before doing any deserialization, to make sure internal
3632  // calls to Decl::getASTContext() by Decl's methods will find the
3633  // TranslationUnitDecl without crashing.
3634  D->setDeclContext(Context.getTranslationUnitDecl());
3635  Reader.Visit(D);
3636 
3637  // If this declaration is also a declaration context, get the
3638  // offsets for its tables of lexical and visible declarations.
3639  if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
3640  std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
3641  if (Offsets.first &&
3642  ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
3643  return nullptr;
3644  if (Offsets.second &&
3645  ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
3646  return nullptr;
3647  }
3648  assert(Record.getIdx() == Record.size());
3649 
3650  // Load any relevant update records.
3651  PendingUpdateRecords.push_back(
3652  PendingUpdateRecord(ID, D, /*JustLoaded=*/true));
3653 
3654  // Load the categories after recursive loading is finished.
3655  if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D))
3656  // If we already have a definition when deserializing the ObjCInterfaceDecl,
3657  // we put the Decl in PendingDefinitions so we can pull the categories here.
3658  if (Class->isThisDeclarationADefinition() ||
3659  PendingDefinitions.count(Class))
3660  loadObjCCategories(ID, Class);
3661 
3662  // If we have deserialized a declaration that has a definition the
3663  // AST consumer might need to know about, queue it.
3664  // We don't pass it to the consumer immediately because we may be in recursive
3665  // loading, and some declarations may still be initializing.
3666  PotentiallyInterestingDecls.push_back(
3667  InterestingDecl(D, Reader.hasPendingBody()));
3668 
3669  return D;
3670 }
3671 
3672 void ASTReader::PassInterestingDeclsToConsumer() {
3673  assert(Consumer);
3674 
3675  if (PassingDeclsToConsumer)
3676  return;
3677 
3678  // Guard variable to avoid recursively redoing the process of passing
3679  // decls to consumer.
3680  SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
3681  true);
3682 
3683  // Ensure that we've loaded all potentially-interesting declarations
3684  // that need to be eagerly loaded.
3685  for (auto ID : EagerlyDeserializedDecls)
3686  GetDecl(ID);
3687  EagerlyDeserializedDecls.clear();
3688 
3689  while (!PotentiallyInterestingDecls.empty()) {
3690  InterestingDecl D = PotentiallyInterestingDecls.front();
3691  PotentiallyInterestingDecls.pop_front();
3692  if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody()))
3693  PassInterestingDeclToConsumer(D.getDecl());
3694  }
3695 }
3696 
3697 void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
3698  // The declaration may have been modified by files later in the chain.
3699  // If this is the case, read the record containing the updates from each file
3700  // and pass it to ASTDeclReader to make the modifications.
3701  serialization::GlobalDeclID ID = Record.ID;
3702  Decl *D = Record.D;
3703  ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
3704  DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
3705 
3706  llvm::SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs;
3707 
3708  if (UpdI != DeclUpdateOffsets.end()) {
3709  auto UpdateOffsets = std::move(UpdI->second);
3710  DeclUpdateOffsets.erase(UpdI);
3711 
3712  // Check if this decl was interesting to the consumer. If we just loaded
3713  // the declaration, then we know it was interesting and we skip the call
3714  // to isConsumerInterestedIn because it is unsafe to call in the
3715  // current ASTReader state.
3716  bool WasInteresting =
3717  Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false);
3718  for (auto &FileAndOffset : UpdateOffsets) {
3719  ModuleFile *F = FileAndOffset.first;
3720  uint64_t Offset = FileAndOffset.second;
3721  llvm::BitstreamCursor &Cursor = F->DeclsCursor;
3722  SavedStreamPosition SavedPosition(Cursor);
3723  Cursor.JumpToBit(Offset);
3724  unsigned Code = Cursor.ReadCode();
3725  ASTRecordReader Record(*this, *F);
3726  unsigned RecCode = Record.readRecord(Cursor, Code);
3727  (void)RecCode;
3728  assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
3729 
3730  ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID,
3731  SourceLocation());
3732  Reader.UpdateDecl(D, PendingLazySpecializationIDs);
3733 
3734  // We might have made this declaration interesting. If so, remember that
3735  // we need to hand it off to the consumer.
3736  if (!WasInteresting &&
3737  isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) {
3738  PotentiallyInterestingDecls.push_back(
3739  InterestingDecl(D, Reader.hasPendingBody()));
3740  WasInteresting = true;
3741  }
3742  }
3743  }
3744  // Add the lazy specializations to the template.
3745  assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||
3746  isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) &&
3747  "Must not have pending specializations");
3748  if (auto *CTD = dyn_cast<ClassTemplateDecl>(D))
3749  ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs);
3750  else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
3751  ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs);
3752  else if (auto *VTD = dyn_cast<VarTemplateDecl>(D))
3753  ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs);
3754  PendingLazySpecializationIDs.clear();
3755 
3756  // Load the pending visible updates for this decl context, if it has any.
3757  auto I = PendingVisibleUpdates.find(ID);
3758  if (I != PendingVisibleUpdates.end()) {
3759  auto VisibleUpdates = std::move(I->second);
3760  PendingVisibleUpdates.erase(I);
3761 
3762  auto *DC = cast<DeclContext>(D)->getPrimaryContext();
3763  for (const PendingVisibleUpdate &Update : VisibleUpdates)
3764  Lookups[DC].Table.add(
3765  Update.Mod, Update.Data,
3767  DC->setHasExternalVisibleStorage(true);
3768  }
3769 }
3770 
3771 void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
3772  // Attach FirstLocal to the end of the decl chain.
3773  Decl *CanonDecl = FirstLocal->getCanonicalDecl();
3774  if (FirstLocal != CanonDecl) {
3775  Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl);
3777  *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
3778  CanonDecl);
3779  }
3780 
3781  if (!LocalOffset) {
3782  ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal);
3783  return;
3784  }
3785 
3786  // Load the list of other redeclarations from this module file.
3787  ModuleFile *M = getOwningModuleFile(FirstLocal);
3788  assert(M && "imported decl from no module file");
3789 
3790  llvm::BitstreamCursor &Cursor = M->DeclsCursor;
3791  SavedStreamPosition SavedPosition(Cursor);
3792  Cursor.JumpToBit(LocalOffset);
3793 
3794  RecordData Record;
3795  unsigned Code = Cursor.ReadCode();
3796  unsigned RecCode = Cursor.readRecord(Code, Record);
3797  (void)RecCode;
3798  assert(RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!");
3799 
3800  // FIXME: We have several different dispatches on decl kind here; maybe
3801  // we should instead generate one loop per kind and dispatch up-front?
3802  Decl *MostRecent = FirstLocal;
3803  for (unsigned I = 0, N = Record.size(); I != N; ++I) {
3804  auto *D = GetLocalDecl(*M, Record[N - I - 1]);
3805  ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl);
3806  MostRecent = D;
3807  }
3808  ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);
3809 }
3810 
3811 namespace {
3812  /// \brief Given an ObjC interface, goes through the modules and links to the
3813  /// interface all the categories for it.
3814  class ObjCCategoriesVisitor {
3815  ASTReader &Reader;
3816  ObjCInterfaceDecl *Interface;
3817  llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
3818  ObjCCategoryDecl *Tail;
3819  llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
3820  serialization::GlobalDeclID InterfaceID;
3821  unsigned PreviousGeneration;
3822 
3823  void add(ObjCCategoryDecl *Cat) {
3824  // Only process each category once.
3825  if (!Deserialized.erase(Cat))
3826  return;
3827 
3828  // Check for duplicate categories.
3829  if (Cat->getDeclName()) {
3830  ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()];
3831  if (Existing &&
3832  Reader.getOwningModuleFile(Existing)
3833  != Reader.getOwningModuleFile(Cat)) {
3834  // FIXME: We should not warn for duplicates in diamond:
3835  //
3836  // MT //
3837  // / \ //
3838  // ML MR //
3839  // \ / //
3840  // MB //
3841  //
3842  // If there are duplicates in ML/MR, there will be warning when
3843  // creating MB *and* when importing MB. We should not warn when
3844  // importing.
3845  Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
3846  << Interface->getDeclName() << Cat->getDeclName();
3847  Reader.Diag(Existing->getLocation(), diag::note_previous_definition);
3848  } else if (!Existing) {
3849  // Record this category.
3850  Existing = Cat;
3851  }
3852  }
3853 
3854  // Add this category to the end of the chain.
3855  if (Tail)
3857  else
3858  Interface->setCategoryListRaw(Cat);
3859  Tail = Cat;
3860  }
3861 
3862  public:
3863  ObjCCategoriesVisitor(ASTReader &Reader,
3864  ObjCInterfaceDecl *Interface,
3865  llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
3866  serialization::GlobalDeclID InterfaceID,
3867  unsigned PreviousGeneration)
3868  : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
3869  Tail(nullptr), InterfaceID(InterfaceID),
3870  PreviousGeneration(PreviousGeneration)
3871  {
3872  // Populate the name -> category map with the set of known categories.
3873  for (auto *Cat : Interface->known_categories()) {
3874  if (Cat->getDeclName())
3875  NameCategoryMap[Cat->getDeclName()] = Cat;
3876 
3877  // Keep track of the tail of the category list.
3878  Tail = Cat;
3879  }
3880  }
3881 
3882  bool operator()(ModuleFile &M) {
3883  // If we've loaded all of the category information we care about from
3884  // this module file, we're done.
3885  if (M.Generation <= PreviousGeneration)
3886  return true;
3887 
3888  // Map global ID of the definition down to the local ID used in this
3889  // module file. If there is no such mapping, we'll find nothing here
3890  // (or in any module it imports).
3891  DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID);
3892  if (!LocalID)
3893  return true;
3894 
3895  // Perform a binary search to find the local redeclarations for this
3896  // declaration (if any).
3897  const ObjCCategoriesInfo Compare = { LocalID, 0 };
3898  const ObjCCategoriesInfo *Result
3899  = std::lower_bound(M.ObjCCategoriesMap,
3901  Compare);
3902  if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap ||
3903  Result->DefinitionID != LocalID) {
3904  // We didn't find anything. If the class definition is in this module
3905  // file, then the module files it depends on cannot have any categories,
3906  // so suppress further lookup.
3907  return Reader.isDeclIDFromModule(InterfaceID, M);
3908  }
3909 
3910  // We found something. Dig out all of the categories.
3911  unsigned Offset = Result->Offset;
3912  unsigned N = M.ObjCCategories[Offset];
3913  M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again
3914  for (unsigned I = 0; I != N; ++I)
3915  add(cast_or_null<ObjCCategoryDecl>(
3916  Reader.GetLocalDecl(M, M.ObjCCategories[Offset++])));
3917  return true;
3918  }
3919  };
3920 } // end anonymous namespace
3921 
3922 void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID,
3923  ObjCInterfaceDecl *D,
3924  unsigned PreviousGeneration) {
3925  ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID,
3926  PreviousGeneration);
3927  ModuleMgr.visit(Visitor);
3928 }
3929 
3930 template<typename DeclT, typename Fn>
3931 static void forAllLaterRedecls(DeclT *D, Fn F) {
3932  F(D);
3933 
3934  // Check whether we've already merged D into its redeclaration chain.
3935  // MostRecent may or may not be nullptr if D has not been merged. If
3936  // not, walk the merged redecl chain and see if it's there.
3937  auto *MostRecent = D->getMostRecentDecl();
3938  bool Found = false;
3939  for (auto *Redecl = MostRecent; Redecl && !Found;
3940  Redecl = Redecl->getPreviousDecl())
3941  Found = (Redecl == D);
3942 
3943  // If this declaration is merged, apply the functor to all later decls.
3944  if (Found) {
3945  for (auto *Redecl = MostRecent; Redecl != D;
3946  Redecl = Redecl->getPreviousDecl())
3947  F(Redecl);
3948  }
3949 }
3950 
3952  llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) {
3953  while (Record.getIdx() < Record.size()) {
3954  switch ((DeclUpdateKind)Record.readInt()) {
3956  auto *RD = cast<CXXRecordDecl>(D);
3957  // FIXME: If we also have an update record for instantiating the
3958  // definition of D, we need that to happen before we get here.
3959  Decl *MD = Record.readDecl();
3960  assert(MD && "couldn't read decl from update record");
3961  // FIXME: We should call addHiddenDecl instead, to add the member
3962  // to its DeclContext.
3963  RD->addedMember(MD);
3964  break;
3965  }
3966 
3968  // It will be added to the template's lazy specialization set.
3969  PendingLazySpecializationIDs.push_back(ReadDeclID());
3970  break;
3971 
3973  NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>();
3974 
3975  // Each module has its own anonymous namespace, which is disjoint from
3976  // any other module's anonymous namespaces, so don't attach the anonymous
3977  // namespace at all.
3978  if (!Record.isModule()) {
3979  if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
3980  TU->setAnonymousNamespace(Anon);
3981  else
3982  cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
3983  }
3984  break;
3985  }
3986 
3988  VarDecl *VD = cast<VarDecl>(D);
3989  VD->NonParmVarDeclBits.IsInline = Record.readInt();
3990  VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
3991  uint64_t Val = Record.readInt();
3992  if (Val && !VD->getInit()) {
3993  VD->setInit(Record.readExpr());
3994  if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
3995  EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
3996  Eval->CheckedICE = true;
3997  Eval->IsICE = Val == 3;
3998  }
3999  }
4000  break;
4001  }
4002 
4004  SourceLocation POI = Record.readSourceLocation();
4005  if (VarTemplateSpecializationDecl *VTSD =
4006  dyn_cast<VarTemplateSpecializationDecl>(D)) {
4007  VTSD->setPointOfInstantiation(POI);
4008  } else if (auto *VD = dyn_cast<VarDecl>(D)) {
4009  VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
4010  } else {
4011  auto *FD = cast<FunctionDecl>(D);
4012  if (auto *FTSInfo = FD->TemplateOrSpecialization
4013  .dyn_cast<FunctionTemplateSpecializationInfo *>())
4014  FTSInfo->setPointOfInstantiation(POI);
4015  else
4016  FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>()
4017  ->setPointOfInstantiation(POI);
4018  }
4019  break;
4020  }
4021 
4023  auto Param = cast<ParmVarDecl>(D);
4024 
4025  // We have to read the default argument regardless of whether we use it
4026  // so that hypothetical further update records aren't messed up.
4027  // TODO: Add a function to skip over the next expr record.
4028  auto DefaultArg = Record.readExpr();
4029 
4030  // Only apply the update if the parameter still has an uninstantiated
4031  // default argument.
4032  if (Param->hasUninstantiatedDefaultArg())
4033  Param->setDefaultArg(DefaultArg);
4034  break;
4035  }
4036 
4038  auto FD = cast<FieldDecl>(D);
4039  auto DefaultInit = Record.readExpr();
4040 
4041  // Only apply the update if the field still has an uninstantiated
4042  // default member initializer.
4043  if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) {
4044  if (DefaultInit)
4045  FD->setInClassInitializer(DefaultInit);
4046  else
4047  // Instantiation failed. We can get here if we serialized an AST for
4048  // an invalid program.
4049  FD->removeInClassInitializer();
4050  }
4051  break;
4052  }
4053 
4055  FunctionDecl *FD = cast<FunctionDecl>(D);
4056  if (Reader.PendingBodies[FD]) {
4057  // FIXME: Maybe check for ODR violations.
4058  // It's safe to stop now because this update record is always last.
4059  return;
4060  }
4061 
4062  if (Record.readInt()) {
4063  // Maintain AST consistency: any later redeclarations of this function
4064  // are inline if this one is. (We might have merged another declaration
4065  // into this one.)
4066  forAllLaterRedecls(FD, [](FunctionDecl *FD) {
4067  FD->setImplicitlyInline();
4068  });
4069  }
4070  FD->setInnerLocStart(ReadSourceLocation());
4071  ReadFunctionDefinition(FD);
4072  assert(Record.getIdx() == Record.size() && "lazy body must be last");
4073  break;
4074  }
4075 
4077  auto *RD = cast<CXXRecordDecl>(D);
4078  auto *OldDD = RD->getCanonicalDecl()->DefinitionData;
4079  bool HadRealDefinition =
4080  OldDD && (OldDD->Definition != RD ||
4081  !Reader.PendingFakeDefinitionData.count(OldDD));
4082  ReadCXXRecordDefinition(RD, /*Update*/true);
4083 
4084  // Visible update is handled separately.
4085  uint64_t LexicalOffset = ReadLocalOffset();
4086  if (!HadRealDefinition && LexicalOffset) {
4087  Record.readLexicalDeclContextStorage(LexicalOffset, RD);
4088  Reader.PendingFakeDefinitionData.erase(OldDD);
4089  }
4090 
4091  auto TSK = (TemplateSpecializationKind)Record.readInt();
4092  SourceLocation POI = ReadSourceLocation();
4093  if (MemberSpecializationInfo *MSInfo =
4094  RD->getMemberSpecializationInfo()) {
4095  MSInfo->setTemplateSpecializationKind(TSK);
4096  MSInfo->setPointOfInstantiation(POI);
4097  } else {
4099  cast<ClassTemplateSpecializationDecl>(RD);
4100  Spec->setTemplateSpecializationKind(TSK);
4101  Spec->setPointOfInstantiation(POI);
4102 
4103  if (Record.readInt()) {
4104  auto PartialSpec =
4105  ReadDeclAs<ClassTemplatePartialSpecializationDecl>();
4107  Record.readTemplateArgumentList(TemplArgs);
4108  auto *TemplArgList = TemplateArgumentList::CreateCopy(
4109  Reader.getContext(), TemplArgs);
4110 
4111  // FIXME: If we already have a partial specialization set,
4112  // check that it matches.
4113  if (!Spec->getSpecializedTemplateOrPartial()
4115  Spec->setInstantiationOf(PartialSpec, TemplArgList);
4116  }
4117  }
4118 
4119  RD->setTagKind((TagTypeKind)Record.readInt());
4120  RD->setLocation(ReadSourceLocation());
4121  RD->setLocStart(ReadSourceLocation());
4122  RD->setBraceRange(ReadSourceRange());
4123 
4124  if (Record.readInt()) {
4125  AttrVec Attrs;
4126  Record.readAttributes(Attrs);
4127  // If the declaration already has attributes, we assume that some other
4128  // AST file already loaded them.
4129  if (!D->hasAttrs())
4130  D->setAttrsImpl(Attrs, Reader.getContext());
4131  }
4132  break;
4133  }
4134 
4136  // Set the 'operator delete' directly to avoid emitting another update
4137  // record.
4138  auto *Del = ReadDeclAs<FunctionDecl>();
4139  auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl());
4140  auto *ThisArg = Record.readExpr();
4141  // FIXME: Check consistency if we have an old and new operator delete.
4142  if (!First->OperatorDelete) {
4143  First->OperatorDelete = Del;
4144  First->OperatorDeleteThisArg = ThisArg;
4145  }
4146  break;
4147  }
4148 
4151  SmallVector<QualType, 8> ExceptionStorage;
4152  Record.readExceptionSpec(ExceptionStorage, ESI);
4153 
4154  // Update this declaration's exception specification, if needed.
4155  auto *FD = cast<FunctionDecl>(D);
4156  auto *FPT = FD->getType()->castAs<FunctionProtoType>();
4157  // FIXME: If the exception specification is already present, check that it
4158  // matches.
4159  if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) {
4160  FD->setType(Reader.getContext().getFunctionType(
4161  FPT->getReturnType(), FPT->getParamTypes(),
4162  FPT->getExtProtoInfo().withExceptionSpec(ESI)));
4163 
4164  // When we get to the end of deserializing, see if there are other decls
4165  // that we need to propagate this exception specification onto.
4166  Reader.PendingExceptionSpecUpdates.insert(
4167  std::make_pair(FD->getCanonicalDecl(), FD));
4168  }
4169  break;
4170  }
4171 
4173  // FIXME: Also do this when merging redecls.
4174  QualType DeducedResultType = Record.readType();
4175  for (auto *Redecl : merged_redecls(D)) {
4176  // FIXME: If the return type is already deduced, check that it matches.
4177  FunctionDecl *FD = cast<FunctionDecl>(Redecl);
4179  DeducedResultType);
4180  }
4181  break;
4182  }
4183 
4184  case UPD_DECL_MARKED_USED: {
4185  // Maintain AST consistency: any later redeclarations are used too.
4186  D->markUsed(Reader.getContext());
4187  break;
4188  }
4189 
4190  case UPD_MANGLING_NUMBER:
4191  Reader.getContext().setManglingNumber(cast<NamedDecl>(D),
4192  Record.readInt());
4193  break;
4194 
4196  Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D),
4197  Record.readInt());
4198  break;
4199 
4201  D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(),
4202  ReadSourceRange()));
4203  break;
4204 
4205  case UPD_DECL_EXPORTED: {
4206  unsigned SubmoduleID = readSubmoduleID();
4207  auto *Exported = cast<NamedDecl>(D);
4208  if (auto *TD = dyn_cast<TagDecl>(Exported))
4209  Exported = TD->getDefinition();
4210  Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr;
4211  if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
4212  Reader.getContext().mergeDefinitionIntoModule(cast<NamedDecl>(Exported),
4213  Owner);
4214  Reader.PendingMergedDefinitionsToDeduplicate.insert(
4215  cast<NamedDecl>(Exported));
4216  } else if (Owner && Owner->NameVisibility != Module::AllVisible) {
4217  // If Owner is made visible at some later point, make this declaration
4218  // visible too.
4219  Reader.HiddenNamesMap[Owner].push_back(Exported);
4220  } else {
4221  // The declaration is now visible.
4222  Exported->setVisibleDespiteOwningModule();
4223  }
4224  break;
4225  }
4226 
4229  AttrVec Attrs;
4230  Record.readAttributes(Attrs);
4231  assert(Attrs.size() == 1);
4232  D->addAttr(Attrs[0]);
4233  break;
4234  }
4235  }
4236 }
const uint64_t & readInt()
Returns the current value in this record, and advances to the next value.
Definition: ASTReader.h:2362
RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD)
void VisitTypeDecl(TypeDecl *TD)
void setCategoryNameLoc(SourceLocation Loc)
Definition: DeclObjC.h:2433
A FriendTemplateDecl record.
Definition: ASTBitCodes.h:1354
Defines the clang::ASTContext interface.
A NonTypeTemplateParmDecl record.
Definition: ASTBitCodes.h:1381
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1547
Decl * GetLocalDecl(ModuleFile &F, uint32_t LocalID)
Reads a declaration with the given local ID in the given module.
Definition: ASTReader.h:1808
SourceLocation readSourceLocation()
Read a source location, advancing Idx.
Definition: ASTReader.h:2554
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3128
void VisitClassScopeFunctionSpecializationDecl(ClassScopeFunctionSpecializationDecl *D)
static const Decl * getCanonicalDecl(const Decl *D)
void setImplicit(bool I=true)
Definition: DeclBase.h:552
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1698
void VisitVarDecl(VarDecl *VD)
#define MATCH_FIELD(Field)
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:3551
A class which contains all the information about a particular captured value.
Definition: Decl.h:3693
static ImportDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumLocations)
Create a new, deserialized module import declaration.
Definition: Decl.cpp:4458
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
void VisitImportDecl(ImportDecl *D)
A (possibly-)qualified type.
Definition: Type.h:653
void mergeMergeable(Mergeable< T > *D)
Attempts to merge the given declaration (D) with another declaration of the same entity, for the case where the entity is not actually redeclarable.
static ObjCIvarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1748
FunctionDecl * Function
The function template specialization that this structure describes.
Definition: DeclTemplate.h:529
Static storage duration.
Definition: Specifiers.h:277
void setDefaultArgument(TypeSourceInfo *DefArg)
Set the default argument for this template parameter.
void VisitUsingDecl(UsingDecl *D)
static UnresolvedUsingValueDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2521
static VarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:1872
void setLParenLoc(SourceLocation L)
Definition: DeclObjC.h:842
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&#39;t alre...
void VisitFieldDecl(FieldDecl *FD)
void VisitImplicitParamDecl(ImplicitParamDecl *PD)
This declaration has an owning module, but is only visible to lookups that occur within that module...
An OMPThreadPrivateDecl record.
Definition: ASTBitCodes.h:1417
void VisitObjCIvarDecl(ObjCIvarDecl *D)
#define OR_FIELD(Field)
void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D)
static void setNextObjCCategory(ObjCCategoryDecl *Cat, ObjCCategoryDecl *Next)
bool IsICE
Whether this statement is an integral constant expression, or in C++11, whether the statement is a co...
Definition: Decl.h:795
RedeclarableResult VisitClassTemplateSpecializationDeclImpl(ClassTemplateSpecializationDecl *D)
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Definition: Decl.h:2665
void setEmbeddedInDeclarator(bool isInDeclarator)
Definition: Decl.h:3109
No linkage, which means that the entity is unique and can only be referred to from within its scope...
Definition: Linkage.h:28
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1010
unsigned Generation
The generation of which this module file is a part.
Definition: Module.h:164
static AccessSpecDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:59
TypedefDecl - Represents the declaration of a typedef-name via the &#39;typedef&#39; type specifier...
Definition: Decl.h:2892
void setParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:3911
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
An OMPDeclareReductionDecl record.
Definition: ASTBitCodes.h:1435
void VisitEnumConstantDecl(EnumConstantDecl *ECD)
static PragmaCommentDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned ArgSize)
Definition: Decl.cpp:4110
static void attachLatestDeclImpl(Redeclarable< DeclT > *D, Decl *Latest)
unsigned getNumExpansionTypes() const
Retrieves the number of expansion types in an expanded parameter pack.
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
Definition: ASTReader.cpp:8313
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
static NamedDecl * getDeclForMerging(NamedDecl *Found, bool IsTypedefNameForLinkage)
Find the declaration that should be merged into, given the declaration found by name lookup...
A VarTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1372
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Defines the C++ template declaration subclasses.
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
Definition: DeclTemplate.h:453
static Decl * getMostRecentDecl(Decl *D)
known_categories_range known_categories() const
Definition: DeclObjC.h:1706
void VisitCXXDestructorDecl(CXXDestructorDecl *D)
void VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
A record that stores the set of declarations that are lexically stored within a given DeclContext...
Definition: ASTBitCodes.h:1279
void VisitObjCCategoryDecl(ObjCCategoryDecl *D)
bool isExpandedParameterPack() const
Whether this parameter is a template template parameter pack that has a known list of different templ...
Represents an empty-declaration.
Definition: Decl.h:4075
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
Definition: Decl.cpp:4048
unsigned LocalNumObjCCategoriesInMap
The number of redeclaration info entries in ObjCCategoriesMap.
Definition: Module.h:420
Class that performs name lookup into a DeclContext stored in an AST file.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:2560
Declaration of a variable template.
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:506
A ObjCPropertyDecl record.
Definition: ASTBitCodes.h:1236
void setPropertyImplementation(PropertyControl pc)
Definition: DeclObjC.h:946
static bool hasSameOverloadableAttrs(const FunctionDecl *A, const FunctionDecl *B)
Determine whether the attributes we can overload on are identical for A and B.
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:133
static FriendDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned FriendTypeNumTPLists)
Definition: DeclFriend.cpp:66
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:95
A container of type source information.
Definition: Decl.h:86
uint64_t GlobalBitOffset
The global bit offset (or base) of this module.
Definition: Module.h:174
void readQualifierInfo(QualifierInfo &Info)
Definition: ASTReader.h:2500
void setPropertyAccessor(bool isAccessor)
Definition: DeclObjC.h:460
static void inheritDefaultTemplateArguments(ASTContext &Context, TemplateDecl *From, TemplateDecl *To)
ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, ASTReader::RecordLocation Loc, DeclID thisDeclID, SourceLocation ThisDeclLoc)
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:26
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2397
This is a module that was defined by a module map and built out of header files.
Definition: Module.h:76
static CapturedDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumParams)
Definition: Decl.cpp:4243
QualType getElementType() const
Definition: Type.h:2595
Represents a #pragma comment line.
Definition: Decl.h:139
A ClassTemplateDecl record.
Definition: ASTBitCodes.h:1357
void VisitStaticAssertDecl(StaticAssertDecl *D)
A PragmaDetectMismatchDecl record.
Definition: ASTBitCodes.h:1432
An UnresolvedUsingTypenameDecl record.
Definition: ASTBitCodes.h:1318
An identifier, stored as an IdentifierInfo*.
void setNothrow(bool Nothrow=true)
Definition: Decl.cpp:4253
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:566
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Definition: DeclFriend.h:54
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:807
void VisitNamedDecl(NamedDecl *ND)
Declaration of a redeclarable template.
Definition: DeclTemplate.h:736
An OMPCapturedExprDecl record.
Definition: ASTBitCodes.h:1426
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6307
A UsingShadowDecl record.
Definition: ASTBitCodes.h:1306
const unsigned int NUM_PREDEF_DECL_IDS
The number of declaration IDs that are predefined.
Definition: ASTBitCodes.h:1173
The "__interface" keyword.
Definition: Type.h:4693
Represents a variable template specialization, which refers to a variable template with a given set o...
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
A TemplateTemplateParmDecl record that stores an expanded template template parameter pack...
Definition: ASTBitCodes.h:1407
A namespace, stored as a NamespaceDecl*.
void VisitClassTemplateDecl(ClassTemplateDecl *D)
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
unsigned getODRHash() const
Definition: DeclCXX.cpp:412
void setSelfDecl(ImplicitParamDecl *SD)
Definition: DeclObjC.h:445
void VisitTypeAliasDecl(TypeAliasDecl *TD)
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:213
unsigned IsExplicitSpecified
Definition: Decl.h:1727
A TemplateTemplateParmDecl record.
Definition: ASTBitCodes.h:1384
ParmVarDecl - Represents a parameter to a function.
Definition: Decl.h:1514
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have...
Definition: Linkage.h:25
A ObjCInterfaceDecl record.
Definition: ASTBitCodes.h:1212
void setHasExternalVisibleStorage(bool ES=true)
State whether this DeclContext has external storage for declarations visible in this context...
Definition: DeclBase.h:1899
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
Definition: ASTReader.h:2377
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
RedeclarableResult VisitTagDecl(TagDecl *TD)
iterator begin(DeclarationName Name)
begin - Returns an iterator for decls with the name &#39;Name&#39;.
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1398
static void attachPreviousDeclImpl(ASTReader &Reader, Redeclarable< DeclT > *D, Decl *Previous, Decl *Canon)
Types, declared with &#39;struct foo&#39;, typedefs, etc.
Definition: DeclBase.h:130
A CXXConstructorDecl record for an inherited constructor.
Definition: ASTBitCodes.h:1339
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3482
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2371
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
Definition: Decl.h:291
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:87
ObjCProtocolDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C protocol.
Definition: DeclObjC.h:2269
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:3367
T * readDeclAs()
Reads a declaration from the given position in the record, advancing Idx.
Definition: ASTReader.h:2476
void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
void mergeRedeclarable(Redeclarable< T > *D, RedeclarableResult &Redecl, DeclID TemplatePatternID=0)
Attempts to merge the given declaration (D) with another declaration of the same entity.
static OMPThreadPrivateDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned N)
Definition: DeclOpenMP.cpp:41
void setManglingNumber(const NamedDecl *ND, unsigned Number)
void setCompleteDefinition(bool V)
Definition: Decl.h:3140
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2526
static IndirectFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4289
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:149
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition: Decl.h:567
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1178
bool CheckedICE
Whether we already checked whether this statement was an integral constant expression.
Definition: Decl.h:786
void VisitFriendTemplateDecl(FriendTemplateDecl *D)
void setLanguage(LanguageIDs L)
Set the language specified by this linkage specification.
Definition: DeclCXX.h:2792
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:34
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
Definition: Decl.h:2461
void setBlockMissingReturnType(bool val)
Definition: Decl.h:3822
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
void setLocStart(SourceLocation L)
Definition: Decl.h:488
static CXXRecordDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:156
void setVisibleDespiteOwningModule()
Set that this declaration is globally visible, even if it came from a module that is not visible...
Definition: DeclBase.h:772
RedeclarableResult VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D)
TODO: Unify with ClassTemplateSpecializationDecl version? May require unifying ClassTemplate(Partial)...
void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D)
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2046
Helper class that saves the current stream position and then restores it when destroyed.
Definition: ASTReader.h:2615
InheritedConstructor getInheritedConstructor() const
Get the constructor that this inheriting constructor is based on.
Definition: DeclCXX.h:2593
static NamespaceDecl * getNamespace(const NestedNameSpecifier *X)
void setOwningModuleID(unsigned ID)
Set the owning module ID.
Definition: DeclBase.h:627
void setStaticLocalNumber(const VarDecl *VD, unsigned Number)
void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD)
This declaration is definitely a definition.
Definition: Decl.h:1145
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Definition: DeclBase.h:1451
unsigned FromASTFile
Whether this declaration was loaded from an AST file.
Definition: DeclBase.h:322
void Profile(llvm::FoldingSetNodeID &ID)
Definition: DeclTemplate.h:590
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Definition: CharUnits.h:208
void setNumPositiveBits(unsigned Num)
Definition: Decl.h:3387
Represents an access specifier followed by colon &#39;:&#39;.
Definition: DeclCXX.h:131
void setReturnType(QualType T)
Definition: DeclObjC.h:362
Declaration of a function specialization at template class scope.
static StaticAssertDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2569
TypeSourceInfo * getTypeSourceInfo()
Reads a declarator info from the given record, advancing Idx.
Definition: ASTReader.h:2443
void VisitLabelDecl(LabelDecl *LD)
for(const auto &A :T->param_types())
static NamespaceDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2317
void setDeclImplementation(ImplementationControl ic)
Definition: DeclObjC.h:498
Describes a module or submodule.
Definition: Module.h:65
void setDefaultArgument(Expr *DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
A IndirectFieldDecl record.
Definition: ASTBitCodes.h:1399
size_t size() const
The length of this record.
Definition: ASTReader.h:2352
static OMPCapturedExprDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclOpenMP.cpp:98
iterator end()
end - Returns an iterator that has &#39;finished&#39;.
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Definition: DeclTemplate.h:507
Represents a C++ using-declaration.
Definition: DeclCXX.h:3275
Common * getCommonPtr() const
Definition: DeclTemplate.h:996
void setUsingLoc(SourceLocation L)
Set the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3311
void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static llvm::iterator_range< MergedRedeclIterator< DeclT > > merged_redecls(DeclT *D)
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:986
void setAccessControl(AccessControl ac)
Definition: DeclObjC.h:2001
TagKind getTagKind() const
Definition: Decl.h:3150
static void attachLatestDecl(Decl *D, Decl *latest)
< Capturing the *this object by copy
Definition: Lambda.h:37
RedeclarableResult VisitVarDeclImpl(VarDecl *D)
DeclLink RedeclLink
Points to the next redeclaration in the chain.
Definition: Redeclarable.h:190
An AccessSpecDecl record.
Definition: ASTBitCodes.h:1348
void setAtLoc(SourceLocation L)
Definition: DeclObjC.h:839
A convenient class for passing around template argument information.
Definition: TemplateBase.h:546
uint32_t Offset
Definition: CacheTokens.cpp:43
A ConstructorUsingShadowDecl record.
Definition: ASTBitCodes.h:1309
A UsingDirecitveDecl record.
Definition: ASTBitCodes.h:1312
void ReadFunctionDefinition(FunctionDecl *FD)
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
static UnresolvedUsingTypenameDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2551
void VisitCXXRecordDecl(CXXRecordDecl *D)
static ClassTemplateSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
void setSuperClass(ObjCInterfaceDecl *superCls)
Definition: DeclObjC.h:2712
A DecompositionDecl record.
Definition: ASTBitCodes.h:1257
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2754
void setHasObjectMember(bool val)
Definition: Decl.h:3556
void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D)
void VisitMSPropertyDecl(MSPropertyDecl *FD)
static ObjCCategoryImplDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2022
void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Definition: ASTReader.h:2268
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
Definition: Decl.h:3463
DeclID VisitTemplateDecl(TemplateDecl *D)
SourceRange readSourceRange()
Read a source range, advancing Idx.
Definition: ASTReader.h:2559
void setClassInterface(ObjCInterfaceDecl *D)
Definition: DeclObjC.h:2768
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:705
static FileScopeAsmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4393
void VisitCXXMethodDecl(CXXMethodDecl *D)
static TypeAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4363
A ClassTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1360
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Definition: DeclBase.h:820
void setNumNegativeBits(unsigned Num)
Definition: Decl.h:3404
static bool isSameEntity(NamedDecl *X, NamedDecl *Y)
Determine whether the two declarations refer to the same entity.
static FunctionTemplateSpecializationInfo * Create(ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template, TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs, const TemplateArgumentListInfo *TemplateArgsAsWritten, SourceLocation POI)
This represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:3860
Represents an ObjC class declaration.
Definition: DeclObjC.h:1191
Represents a linkage specification.
Definition: DeclCXX.h:2743
static ParmVarDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:2468
void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D)
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
bool isParameterPack() const
Whether this template template parameter is a template parameter pack.
A binding in a decomposition declaration.
Definition: DeclCXX.h:3718
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization, retrieves the member specialization information.
Definition: Decl.cpp:3207
void setInitVal(const llvm::APSInt &V)
Definition: Decl.h:2689
Ordinary names.
Definition: DeclBase.h:144
void setInitExpr(Expr *E)
Definition: Decl.h:2688
void setCachedLinkage(Linkage L) const
Definition: DeclBase.h:394
void setLocStart(SourceLocation L)
Definition: Decl.h:2782
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:865
void setGetterCXXConstructor(Expr *getterCXXConstructor)
Definition: DeclObjC.h:2872
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1521
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
Definition: Decl.h:1071
bool isExpandedParameterPack() const
Whether this parameter is a non-type template parameter pack that has a known list of different types...
void setInline(bool Inline)
Set whether this is an inline namespace declaration.
Definition: Decl.h:572
static CXXDeductionGuideDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:1624
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2778
llvm::FoldingSetVector< FunctionTemplateSpecializationInfo > Specializations
The function template specializations for this function template, including explicit specializations ...
Definition: DeclTemplate.h:967
void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType)
Change the result type of a function type once it is deduced.
void setVariadic(bool isVar)
Definition: DeclObjC.h:455
static TemplateTypeParmDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
typename Representation::iterator iterator
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Definition: Decl.h:2912
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3270
RedeclarableResult VisitRedeclarable(Redeclarable< T > *D)
void setHasDestructors(bool val)
Definition: DeclObjC.h:2679
void VisitObjCContainerDecl(ObjCContainerDecl *D)
static ObjCCompatibleAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:2176
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
CXXDestructorDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2660
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:681
A CXXDeductionGuideDecl record.
Definition: ASTBitCodes.h:1330
void VisitParmVarDecl(ParmVarDecl *PD)
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
void VisitLinkageSpecDecl(LinkageSpecDecl *D)
void setIvarRBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2716
A StaticAssertDecl record.
Definition: ASTBitCodes.h:1390
llvm::FoldingSetVector< ClassTemplatePartialSpecializationDecl > PartialSpecializations
The class template partial specializations for this class template.
A VarTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1369
void VisitUsingPackDecl(UsingPackDecl *D)
void VisitUsingShadowDecl(UsingShadowDecl *D)
void VisitVarTemplatePartialSpecializationDecl(VarTemplatePartialSpecializationDecl *D)
TODO: Unify with ClassTemplatePartialSpecializationDecl version? May require unifying ClassTemplate(P...
void setNextIvar(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1999
void setSynthesize(bool synth)
Definition: DeclObjC.h:2009
void VisitFriendDecl(FriendDecl *D)
An ObjCTypeParamDecl record.
Definition: ASTBitCodes.h:1423
void VisitDecl(Decl *D)
A record containing CXXBaseSpecifiers.
Definition: ASTBitCodes.h:1393
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
Definition: ASTReader.cpp:8962
void setType(QualType T, TypeSourceInfo *TSI)
Definition: DeclObjC.h:848
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Definition: DeclTemplate.h:432
bool isCanonicalDecl() const
Whether this particular Decl is a canonical one.
Definition: DeclBase.h:871
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:940
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3163
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Definition: Decl.h:3689
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Definition: Decl.h:628
Expr - This represents one expression.
Definition: Expr.h:106
A ObjCCategoryImplDecl record.
Definition: ASTBitCodes.h:1227
void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD)
void setBitWidth(Expr *Width)
setBitWidth - Set the bit-field width for this member.
Definition: Decl.h:2563
llvm::FoldingSetVector< VarTemplatePartialSpecializationDecl > PartialSpecializations
The variable template partial specializations for this variable template.
static LinkageSpecDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2261
A ObjCPropertyImplDecl record.
Definition: ASTBitCodes.h:1239
const FunctionProtoType * T
StateNode * Previous
Declaration of a template type parameter.
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:943
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2620
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void setInit(Expr *I)
Definition: Decl.cpp:2152
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:132
A CXXConstructorDecl record.
Definition: ASTBitCodes.h:1336
void VisitTypedefDecl(TypedefDecl *TD)
Module * getImportedOwningModule() const
Get the imported owning module, if this decl is from an imported (non-local) module.
Definition: DeclBase.h:721
void setContextParam(unsigned i, ImplicitParamDecl *P)
Definition: Decl.h:3929
void setAtEndRange(SourceRange atEnd)
Definition: DeclObjC.h:1141
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2804
static DeclLink PreviousDeclLink(decl_type *D)
Definition: Redeclarable.h:171
DeclContext * getDeclContext()
Definition: DeclBase.h:425
A record containing CXXCtorInitializers.
Definition: ASTBitCodes.h:1396
A VarTemplateDecl record.
Definition: ASTBitCodes.h:1366
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl *> typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1395
void setMemberSpecialization()
Note that this member template is a specialization.
Definition: DeclTemplate.h:874
Decl * readDecl()
Reads a declaration from the given position in a record in the given module, advancing Idx...
Definition: ASTReader.h:2466
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
Definition: DeclBase.h:1952
void setDefined(bool isDefined)
Definition: DeclObjC.h:463
bool isTemplateParameterPack() const
isTemplateParameter - Determines whether this declaration is a template parameter pack...
Definition: DeclBase.cpp:201
void setCompleteDefinitionRequired(bool V=true)
Definition: Decl.h:3142
RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D)
Information about a module that has been loaded by the ASTReader.
Definition: Module.h:100
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this...
A namespace alias, stored as a NamespaceAliasDecl*.
static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, Decl *Canon)
IdentifierInfo * getAsIdentifierInfo() const
getAsIdentifierInfo - Retrieve the IdentifierInfo * stored in this declaration name, or NULL if this declaration name isn&#39;t a simple identifier.
const uint64_t & back() const
The last element in this record.
Definition: ASTReader.h:2358
A CXXDestructorDecl record.
Definition: ASTBitCodes.h:1342
SmallVector< uint64_t, 1 > ObjCCategories
The Objective-C category lists for categories known to this module.
Definition: Module.h:424
unsigned IsCopyDeductionCandidate
[C++17] Only used by CXXDeductionGuideDecl.
Definition: Decl.h:1760
A NonTypeTemplateParmDecl record that stores an expanded non-type template parameter pack...
Definition: ASTBitCodes.h:1403
static NamespaceAliasDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2379
static CXXConstructorDecl * CreateDeserialized(ASTContext &C, unsigned ID, bool InheritsConstructor)
Definition: DeclCXX.cpp:2047
bool isFunctionOrMethod() const
Definition: DeclBase.h:1380
StorageClass
Storage classes.
Definition: Specifiers.h:203
static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody)
Determine whether the consumer will be interested in seeing this declaration (via HandleTopLevelDecl)...
PragmaMSCommentKind
Definition: PragmaKinds.h:15
This declaration has an owning module, and is visible when that module is imported.
A NamespaceAliasDecl record.
Definition: ASTBitCodes.h:1297
void setTypename(bool TN)
Sets whether the using declaration has &#39;typename&#39;.
Definition: DeclCXX.h:3333
Declaration of an alias template.
unsigned IsScopedUsingClassTag
IsScopedUsingClassTag - If this tag declaration is a scoped enum, then this is true if the scoped enu...
Definition: Decl.h:2980
void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy)
Definition: Decl.h:2857
unsigned getNumExpansionTemplateParameters() const
Retrieves the number of expansion template parameters in an expanded parameter pack.
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:1333
void setLocation(SourceLocation L)
Definition: DeclBase.h:417
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
An ImplicitParamDecl record.
Definition: ASTBitCodes.h:1251
void setIvarRBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2437
void VisitDecompositionDecl(DecompositionDecl *DD)
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1911
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2682
static UsingDirectiveDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2282
An EnumConstantDecl record.
Definition: ASTBitCodes.h:1203
static ObjCTypeParamDecl * CreateDeserialized(ASTContext &ctx, unsigned ID)
Definition: DeclObjC.cpp:1362
std::string readString()
Read a string, advancing Idx.
Definition: ASTReader.h:2579
void VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
An ImportDecl recording a module import.
Definition: ASTBitCodes.h:1414
A ObjCCategoryDecl record.
Definition: ASTBitCodes.h:1224
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:284
static ObjCMethodDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:784
static void AddLazySpecializations(T *D, SmallVectorImpl< serialization::DeclID > &IDs)
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
Definition: Redeclarable.h:220
void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
void VisitObjCProtocolDecl(ObjCProtocolDecl *D)
A ObjCCompatibleAliasDecl record.
Definition: ASTBitCodes.h:1233
bool hasAttrs() const
Definition: DeclBase.h:471
void VisitPragmaCommentDecl(PragmaCommentDecl *D)
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:3743
static TypeAliasTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty alias template node.
unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID)
Reads a record with id AbbrevID from Cursor, resetting the internal state.
void setIsVariadic(bool value)
Definition: Decl.h:3764
void addAttr(Attr *A)
Definition: DeclBase.h:484
static bool isSameQualifier(const NestedNameSpecifier *X, const NestedNameSpecifier *Y)
void VisitCXXConstructorDecl(CXXConstructorDecl *D)
static PragmaDetectMismatchDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NameValueSize)
Definition: Decl.cpp:4136
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
Definition: ASTBitCodes.h:172
Represents a C++ Modules TS module export declaration.
Definition: Decl.h:4030
QualifierInfo - A struct with extended info about a syntactic name qualifier, to be used for the case...
Definition: Decl.h:653
void setColonLoc(SourceLocation CLoc)
Sets the location of the colon.
Definition: DeclCXX.h:156
An UnresolvedUsingValueDecl record.
Definition: ASTBitCodes.h:1315
#define false
Definition: stdbool.h:33
The "struct" keyword.
Definition: Type.h:4690
void VisitDeclaratorDecl(DeclaratorDecl *DD)
static ObjCProtocolDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1831
static EnumConstantDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4263
Kind
static UsingShadowDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2404
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:208
void setIsConversionFromLambda(bool val)
Definition: Decl.h:3825
static void markIncompleteDeclChainImpl(Redeclarable< DeclT > *D)
static CXXDestructorDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2191
bool isParameterPack() const
Returns whether this is a parameter pack.
Encodes a location in the source.
static EmptyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4405
void setTopLevelDeclInObjCContainer(bool V=true)
Definition: DeclBase.h:590
static TemplateTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
void setModuleOwnershipKind(ModuleOwnershipKind MOK)
Set whether this declaration is hidden from name lookup.
Definition: DeclBase.h:783
This represents &#39;#pragma omp declare reduction ...&#39; directive.
Definition: DeclOpenMP.h:102
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1288
Pseudo declaration for capturing expressions.
Definition: DeclOpenMP.h:187
void setIvarLBraceLoc(SourceLocation Loc)
Definition: DeclObjC.h:2435
void setBraceRange(SourceRange R)
Definition: Decl.h:3067
void setAtStartLoc(SourceLocation Loc)
Definition: DeclObjC.h:1134
void VisitEmptyDecl(EmptyDecl *D)
void setAnonymousNamespace(NamespaceDecl *D)
Definition: Decl.h:593
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition: Module.h:268
void setFreeStanding(bool isFreeStanding=true)
Definition: Decl.h:3114
void setObjCDeclQualifier(ObjCDeclQualifier QV)
Definition: DeclObjC.h:302
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2938
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:365
static DecompositionDecl * CreateDeserialized(ASTContext &C, unsigned ID, unsigned NumBindings)
Definition: DeclCXX.cpp:2612
void setReferenced(bool R=true)
Definition: DeclBase.h:581
LabelDecl - Represents the declaration of a label.
Definition: Decl.h:460
void mergeTemplatePattern(RedeclarableTemplateDecl *D, RedeclarableTemplateDecl *Existing, DeclID DsID, bool IsKeyDecl)
Merge together the pattern declarations from two template declarations.
void setPropertyAttributesAsWritten(PropertyAttributeKind PRVal)
Definition: DeclObjC.h:873
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3494
void setPosition(unsigned P)
void VisitObjCImplDecl(ObjCImplDecl *D)
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1964
void setHasFlexibleArrayMember(bool V)
Definition: Decl.h:3536
EnumDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: Decl.h:3281
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void VisitBindingDecl(BindingDecl *BD)
A TemplateTypeParmDecl record.
Definition: ASTBitCodes.h:1378
void demoteThisDefinitionToDeclaration()
This is a definition which should be demoted to a declaration.
Definition: Decl.h:1292
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: Redeclarable.h:227
Data that is common to all of the declarations of a given function template.
Definition: DeclTemplate.h:964
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2299
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template...
void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name)
Definition: ASTReader.h:2493
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:89
void setDeclName(DeclarationName N)
Set the name of this declaration.
Definition: Decl.h:294
static MSPropertyDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2648
SourceLocation getLocation() const
Definition: ASTBitCodes.h:217
Common * getCommonPtr() const
static ConstructorUsingShadowDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2427
Describes the categories of an Objective-C class.
Definition: ASTBitCodes.h:1924
bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
Definition: ASTReader.cpp:7075
void init(NamedDecl *templatedDecl, TemplateParameterList *templateParams)
Initialize the underlying templated declaration and template parameters.
Definition: DeclTemplate.h:496
void setPointOfInstantiation(SourceLocation Loc)
void setTagKind(TagKind TK)
Definition: Decl.h:3154
unsigned getIdx() const
The current position in this record.
Definition: ASTReader.h:2349
CommonBase * Common
Pointer to the common data shared by all declarations of this template.
Definition: DeclTemplate.h:815
static FunctionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4219
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:746
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:2363
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:694
uint32_t TypeID
An ID number that refers to a type in an AST file.
Definition: ASTBitCodes.h:86
void setInitializer(Expr *E, InitKind IK)
Set initializer expression for the declare reduction construct.
Definition: DeclOpenMP.h:159
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:70
const unsigned int DECL_UPDATES
Record of updates for a declaration that was modified after being deserialized.
Definition: ASTBitCodes.h:1177
void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
void VisitRecordDecl(RecordDecl *RD)
static T assert_cast(T t)
"Cast" to type T, asserting if we don&#39;t have an implicit conversion.
serialization::SubmoduleID getGlobalSubmoduleID(unsigned LocalID)
Retrieve the global submodule ID its local ID number.
Definition: ASTReader.h:2372
static VarTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty variable template node.
A NamespaceDecl record.
Definition: ASTBitCodes.h:1294
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:3669
uint32_t BitOffset
Offset in the AST file.
Definition: ASTBitCodes.h:207
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:565
void VisitExportDecl(ExportDecl *D)
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:586
File is a PCH file treated as the actual main file.
Definition: Module.h:52
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1042
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:3526
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:3965
serialization::DeclID readDeclID()
Reads a declaration ID from the given position in this record.
Definition: ASTReader.h:2460
void VisitValueDecl(ValueDecl *VD)
A ObjCProtocolDecl record.
Definition: ASTBitCodes.h:1215
void setDeclaredWithTypename(bool withTypename)
Set whether this template type parameter was declared with the &#39;typename&#39; or &#39;class&#39; keyword...
bool hasPendingBody() const
Determine whether this declaration has a pending body.
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2384
void setSetterCXXAssignment(Expr *setterCXXAssignment)
Definition: DeclObjC.h:2880
void VisitEnumDecl(EnumDecl *ED)
static TypedefDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4351
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2796
void setPropertyDecl(ObjCPropertyDecl *Prop)
Definition: DeclObjC.h:2840
A CXXConversionDecl record.
Definition: ASTBitCodes.h:1345
TagTypeKind
The kind of a tag type.
Definition: Type.h:4688
ObjCTypeParamList * ReadObjCTypeParamList()
Dataflow Directional Tag Classes.
void VisitCXXConversionDecl(CXXConversionDecl *D)
void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT)
Definition: Decl.h:2930
void setBody(CompoundStmt *B)
Definition: Decl.h:3768
void setImplicitlyInline()
Flag that this function is implicitly inline.
Definition: Decl.h:2248
static CXXConversionDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:2223
llvm::BitstreamCursor DeclsCursor
DeclsCursor - This is a cursor to the start of the DECLS_BLOCK block.
Definition: Module.h:387
static ClassScopeFunctionSpecializationDecl * CreateDeserialized(ASTContext &Context, unsigned ID)
static bool isSameTemplateParameterList(const TemplateParameterList *X, const TemplateParameterList *Y)
Determine whether two template parameter lists are similar enough that they may be used in declaratio...
void setHasVolatileMember(bool val)
Definition: Decl.h:3559
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:926
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
static ClassTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty class template node.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
void VisitFunctionDecl(FunctionDecl *FD)
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:358
IndirectFieldDecl - An instance of this class is created to represent a field injected from an anonym...
Definition: Decl.h:2705
A ClassTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1363
void setUsingLoc(SourceLocation L)
Set the source location of the &#39;using&#39; keyword.
Definition: DeclCXX.h:3529
DeclCode
Record codes for each kind of declaration.
Definition: ASTBitCodes.h:1189
const Expr * getInit() const
Definition: Decl.h:1213
unsigned IsScoped
IsScoped - True if this tag declaration is a scoped enumeration.
Definition: Decl.h:2974
A decomposition declaration.
Definition: DeclCXX.h:3766
RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D)
void setIvarList(ObjCIvarDecl *ivar)
Definition: DeclObjC.h:1507
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:115
static VarTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3590
A ClassScopeFunctionSpecializationDecl record a class scope function specialization.
Definition: ASTBitCodes.h:1411
DeclarationName - The name of a declaration.
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:576
Kind getKind() const
Definition: DeclBase.h:419
void VisitObjCMethodDecl(ObjCMethodDecl *D)
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:3384
A LinkageSpecDecl record.
Definition: ASTBitCodes.h:1321
RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD)
static NonTypeTemplateParmDecl * CreateDeserialized(ASTContext &C, unsigned ID)
ParmVarDeclBitfields ParmVarDeclBits
Definition: Decl.h:966
static ObjCCategoryDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1977
void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
void VisitObjCImplementationDecl(ObjCImplementationDecl *D)
EnumDecl - Represents an enum.
Definition: Decl.h:3233
void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D)
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:143
static void forAllLaterRedecls(DeclT *D, Fn F)
void setExternLoc(SourceLocation L)
Definition: DeclCXX.h:2803
static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, Decl *ToD)
Inherit the default template argument from From to To.
Tags, declared with &#39;struct foo;&#39; and referenced with &#39;struct foo&#39;.
Definition: DeclBase.h:125
A type that was preceded by the &#39;template&#39; keyword, stored as a Type*.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1048
static FriendTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
static LabelDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4163
uint32_t DeclID
An ID number that refers to a declaration in an AST file.
Definition: ASTBitCodes.h:69
All of the names in this module are visible.
Definition: Module.h:264
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it&#39;s a function-local extern declaration...
Definition: DeclBase.h:1030
Capturing variable-length array type.
Definition: Lambda.h:39
A PragmaCommentDecl record.
Definition: ASTBitCodes.h:1429
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope...
static ObjCAtDefsFieldDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclObjC.cpp:1796
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2571
void VisitObjCPropertyDecl(ObjCPropertyDecl *D)
bool isIncompleteArrayType() const
Definition: Type.h:6001
Provides common interface for the Decls that cannot be redeclared, but can be merged if the same decl...
Definition: Redeclarable.h:317
static ExportDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4491
NonParmVarDeclBitfields NonParmVarDeclBits
Definition: Decl.h:967
void UpdateDecl(Decl *D, llvm::SmallVectorImpl< serialization::DeclID > &)
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
Definition: DeclTemplate.h:920
QualType getCanonicalTypeInternal() const
Definition: Type.h:2109
void setHasNonZeroConstructors(bool val)
Definition: DeclObjC.h:2674
static ClassTemplatePartialSpecializationDecl * CreateDeserialized(ASTContext &C, unsigned ID)
LanguageIDs
Represents the language in a linkage specification.
Definition: DeclCXX.h:2753
uint64_t getGlobalBitOffset(uint32_t LocalOffset)
Get the global offset corresponding to a local offset.
Definition: ASTReader.h:2400
static ImplicitParamDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:4199
static RecordDecl * CreateDeserialized(const ASTContext &C, unsigned ID)
Definition: Decl.cpp:3910
void setCombiner(Expr *E)
Set combiner expression for the declare reduction construct.
Definition: DeclOpenMP.h:150
static CXXMethodDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: DeclCXX.cpp:1709
RedeclarableTemplateDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this template.
Definition: DeclTemplate.h:844
static EnumDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Definition: Decl.cpp:3797
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1648
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2190
void VisitNamespaceDecl(NamespaceDecl *D)
static FunctionTemplateDecl * CreateDeserialized(ASTContext &C, unsigned ID)
Create an empty function template node.
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1934
void setCategoryListRaw(ObjCCategoryDecl *category)
Set the raw pointer to the start of the category/extension list.
Definition: DeclObjC.h:1816
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:934
The "class" keyword.
Definition: Type.h:4699
Capturing the *this object by reference.
Definition: Lambda.h:35
void VisitUsingDirectiveDecl(UsingDirectiveDecl *D)