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