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