1 //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file implements the ASTReader::ReadDeclRecord method, which is the 11 // entrypoint for loading a decl. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "clang/Serialization/ASTReader.h" 16 #include "ASTCommon.h" 17 #include "ASTReaderInternals.h" 18 #include "clang/AST/ASTConsumer.h" 19 #include "clang/AST/ASTContext.h" 20 #include "clang/AST/DeclCXX.h" 21 #include "clang/AST/DeclGroup.h" 22 #include "clang/AST/DeclTemplate.h" 23 #include "clang/AST/DeclVisitor.h" 24 #include "clang/AST/Expr.h" 25 #include "clang/Sema/IdentifierResolver.h" 26 #include "clang/Sema/Sema.h" 27 #include "clang/Sema/SemaDiagnostic.h" 28 #include "llvm/Support/SaveAndRestore.h" 29 using namespace clang; 30 using namespace clang::serialization; 31 32 //===----------------------------------------------------------------------===// 33 // Declaration deserialization 34 //===----------------------------------------------------------------------===// 35 36 namespace clang { 37 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { 38 ASTReader &Reader; 39 ModuleFile &F; 40 const DeclID ThisDeclID; 41 const unsigned RawLocation; 42 typedef ASTReader::RecordData RecordData; 43 const RecordData &Record; 44 unsigned &Idx; 45 TypeID TypeIDForTypeDecl; 46 47 bool HasPendingBody; 48 49 uint64_t GetCurrentCursorOffset(); 50 51 SourceLocation ReadSourceLocation(const RecordData &R, unsigned &I) { 52 return Reader.ReadSourceLocation(F, R, I); 53 } 54 55 SourceRange ReadSourceRange(const RecordData &R, unsigned &I) { 56 return Reader.ReadSourceRange(F, R, I); 57 } 58 59 TypeSourceInfo *GetTypeSourceInfo(const RecordData &R, unsigned &I) { 60 return Reader.GetTypeSourceInfo(F, R, I); 61 } 62 63 serialization::DeclID ReadDeclID(const RecordData &R, unsigned &I) { 64 return Reader.ReadDeclID(F, R, I); 65 } 66 67 Decl *ReadDecl(const RecordData &R, unsigned &I) { 68 return Reader.ReadDecl(F, R, I); 69 } 70 71 template<typename T> 72 T *ReadDeclAs(const RecordData &R, unsigned &I) { 73 return Reader.ReadDeclAs<T>(F, R, I); 74 } 75 76 void ReadQualifierInfo(QualifierInfo &Info, 77 const RecordData &R, unsigned &I) { 78 Reader.ReadQualifierInfo(F, Info, R, I); 79 } 80 81 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name, 82 const RecordData &R, unsigned &I) { 83 Reader.ReadDeclarationNameLoc(F, DNLoc, Name, R, I); 84 } 85 86 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo, 87 const RecordData &R, unsigned &I) { 88 Reader.ReadDeclarationNameInfo(F, NameInfo, R, I); 89 } 90 91 serialization::SubmoduleID readSubmoduleID(const RecordData &R, 92 unsigned &I) { 93 if (I >= R.size()) 94 return 0; 95 96 return Reader.getGlobalSubmoduleID(F, R[I++]); 97 } 98 99 Module *readModule(const RecordData &R, unsigned &I) { 100 return Reader.getSubmodule(readSubmoduleID(R, I)); 101 } 102 103 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, 104 const RecordData &R, unsigned &I); 105 106 /// \brief RAII class used to capture the first ID within a redeclaration 107 /// chain and to introduce it into the list of pending redeclaration chains 108 /// on destruction. 109 /// 110 /// The caller can choose not to introduce this ID into the redeclaration 111 /// chain by calling \c suppress(). 112 class RedeclarableResult { 113 ASTReader &Reader; 114 GlobalDeclID FirstID; 115 mutable bool Owning; 116 Decl::Kind DeclKind; 117 118 void operator=(RedeclarableResult &) LLVM_DELETED_FUNCTION; 119 120 public: 121 RedeclarableResult(ASTReader &Reader, GlobalDeclID FirstID, 122 Decl::Kind DeclKind) 123 : Reader(Reader), FirstID(FirstID), Owning(true), DeclKind(DeclKind) { } 124 125 RedeclarableResult(const RedeclarableResult &Other) 126 : Reader(Other.Reader), FirstID(Other.FirstID), Owning(Other.Owning) , 127 DeclKind(Other.DeclKind) 128 { 129 Other.Owning = false; 130 } 131 132 ~RedeclarableResult() { 133 if (FirstID && Owning && isRedeclarableDeclKind(DeclKind) && 134 Reader.PendingDeclChainsKnown.insert(FirstID)) 135 Reader.PendingDeclChains.push_back(FirstID); 136 } 137 138 /// \brief Retrieve the first ID. 139 GlobalDeclID getFirstID() const { return FirstID; } 140 141 /// \brief Do not introduce this declaration ID into the set of pending 142 /// declaration chains. 143 void suppress() { 144 Owning = false; 145 } 146 }; 147 148 /// \brief Class used to capture the result of searching for an existing 149 /// declaration of a specific kind and name, along with the ability 150 /// to update the place where this result was found (the declaration 151 /// chain hanging off an identifier or the DeclContext we searched in) 152 /// if requested. 153 class FindExistingResult { 154 ASTReader &Reader; 155 NamedDecl *New; 156 NamedDecl *Existing; 157 mutable bool AddResult; 158 159 void operator=(FindExistingResult&) LLVM_DELETED_FUNCTION; 160 161 public: 162 FindExistingResult(ASTReader &Reader) 163 : Reader(Reader), New(0), Existing(0), AddResult(false) { } 164 165 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing) 166 : Reader(Reader), New(New), Existing(Existing), AddResult(true) { } 167 168 FindExistingResult(const FindExistingResult &Other) 169 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), 170 AddResult(Other.AddResult) 171 { 172 Other.AddResult = false; 173 } 174 175 ~FindExistingResult(); 176 177 /// \brief Suppress the addition of this result into the known set of 178 /// names. 179 void suppress() { AddResult = false; } 180 181 operator NamedDecl*() const { return Existing; } 182 183 template<typename T> 184 operator T*() const { return dyn_cast_or_null<T>(Existing); } 185 }; 186 187 FindExistingResult findExisting(NamedDecl *D); 188 189 public: 190 ASTDeclReader(ASTReader &Reader, ModuleFile &F, 191 DeclID thisDeclID, 192 unsigned RawLocation, 193 const RecordData &Record, unsigned &Idx) 194 : Reader(Reader), F(F), ThisDeclID(thisDeclID), 195 RawLocation(RawLocation), Record(Record), Idx(Idx), 196 TypeIDForTypeDecl(0), HasPendingBody(false) { } 197 198 static void attachPreviousDecl(Decl *D, Decl *previous); 199 static void attachLatestDecl(Decl *D, Decl *latest); 200 201 /// \brief Determine whether this declaration has a pending body. 202 bool hasPendingBody() const { return HasPendingBody; } 203 204 void Visit(Decl *D); 205 206 void UpdateDecl(Decl *D, ModuleFile &ModuleFile, 207 const RecordData &Record); 208 209 static void setNextObjCCategory(ObjCCategoryDecl *Cat, 210 ObjCCategoryDecl *Next) { 211 Cat->NextClassCategory = Next; 212 } 213 214 void VisitDecl(Decl *D); 215 void VisitTranslationUnitDecl(TranslationUnitDecl *TU); 216 void VisitNamedDecl(NamedDecl *ND); 217 void VisitLabelDecl(LabelDecl *LD); 218 void VisitNamespaceDecl(NamespaceDecl *D); 219 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); 220 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); 221 void VisitTypeDecl(TypeDecl *TD); 222 void VisitTypedefNameDecl(TypedefNameDecl *TD); 223 void VisitTypedefDecl(TypedefDecl *TD); 224 void VisitTypeAliasDecl(TypeAliasDecl *TD); 225 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); 226 RedeclarableResult VisitTagDecl(TagDecl *TD); 227 void VisitEnumDecl(EnumDecl *ED); 228 RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); 229 void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } 230 RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); 231 void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } 232 RedeclarableResult VisitClassTemplateSpecializationDeclImpl( 233 ClassTemplateSpecializationDecl *D); 234 void VisitClassTemplateSpecializationDecl( 235 ClassTemplateSpecializationDecl *D) { 236 VisitClassTemplateSpecializationDeclImpl(D); 237 } 238 void VisitClassTemplatePartialSpecializationDecl( 239 ClassTemplatePartialSpecializationDecl *D); 240 void VisitClassScopeFunctionSpecializationDecl( 241 ClassScopeFunctionSpecializationDecl *D); 242 RedeclarableResult 243 VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); 244 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { 245 VisitVarTemplateSpecializationDeclImpl(D); 246 } 247 void VisitVarTemplatePartialSpecializationDecl( 248 VarTemplatePartialSpecializationDecl *D); 249 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); 250 void VisitValueDecl(ValueDecl *VD); 251 void VisitEnumConstantDecl(EnumConstantDecl *ECD); 252 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); 253 void VisitDeclaratorDecl(DeclaratorDecl *DD); 254 void VisitFunctionDecl(FunctionDecl *FD); 255 void VisitCXXMethodDecl(CXXMethodDecl *D); 256 void VisitCXXConstructorDecl(CXXConstructorDecl *D); 257 void VisitCXXDestructorDecl(CXXDestructorDecl *D); 258 void VisitCXXConversionDecl(CXXConversionDecl *D); 259 void VisitFieldDecl(FieldDecl *FD); 260 void VisitMSPropertyDecl(MSPropertyDecl *FD); 261 void VisitIndirectFieldDecl(IndirectFieldDecl *FD); 262 RedeclarableResult VisitVarDeclImpl(VarDecl *D); 263 void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } 264 void VisitImplicitParamDecl(ImplicitParamDecl *PD); 265 void VisitParmVarDecl(ParmVarDecl *PD); 266 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); 267 void VisitTemplateDecl(TemplateDecl *D); 268 RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); 269 void VisitClassTemplateDecl(ClassTemplateDecl *D); 270 void VisitVarTemplateDecl(VarTemplateDecl *D); 271 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); 272 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); 273 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); 274 void VisitUsingDecl(UsingDecl *D); 275 void VisitUsingShadowDecl(UsingShadowDecl *D); 276 void VisitLinkageSpecDecl(LinkageSpecDecl *D); 277 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); 278 void VisitImportDecl(ImportDecl *D); 279 void VisitAccessSpecDecl(AccessSpecDecl *D); 280 void VisitFriendDecl(FriendDecl *D); 281 void VisitFriendTemplateDecl(FriendTemplateDecl *D); 282 void VisitStaticAssertDecl(StaticAssertDecl *D); 283 void VisitBlockDecl(BlockDecl *BD); 284 void VisitCapturedDecl(CapturedDecl *CD); 285 void VisitEmptyDecl(EmptyDecl *D); 286 287 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); 288 289 template<typename T> 290 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); 291 292 template<typename T> 293 void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl); 294 295 template<typename T> 296 void mergeRedeclarable(Redeclarable<T> *D, T *Existing, 297 RedeclarableResult &Redecl); 298 299 template<typename T> 300 void mergeMergeable(Mergeable<T> *D); 301 302 // FIXME: Reorder according to DeclNodes.td? 303 void VisitObjCMethodDecl(ObjCMethodDecl *D); 304 void VisitObjCContainerDecl(ObjCContainerDecl *D); 305 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); 306 void VisitObjCIvarDecl(ObjCIvarDecl *D); 307 void VisitObjCProtocolDecl(ObjCProtocolDecl *D); 308 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); 309 void VisitObjCCategoryDecl(ObjCCategoryDecl *D); 310 void VisitObjCImplDecl(ObjCImplDecl *D); 311 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); 312 void VisitObjCImplementationDecl(ObjCImplementationDecl *D); 313 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); 314 void VisitObjCPropertyDecl(ObjCPropertyDecl *D); 315 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); 316 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); 317 }; 318 } 319 320 uint64_t ASTDeclReader::GetCurrentCursorOffset() { 321 return F.DeclsCursor.GetCurrentBitNo() + F.GlobalBitOffset; 322 } 323 324 void ASTDeclReader::Visit(Decl *D) { 325 DeclVisitor<ASTDeclReader, void>::Visit(D); 326 327 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) { 328 if (DD->DeclInfo) { 329 DeclaratorDecl::ExtInfo *Info = 330 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>(); 331 Info->TInfo = 332 GetTypeSourceInfo(Record, Idx); 333 } 334 else { 335 DD->DeclInfo = GetTypeSourceInfo(Record, Idx); 336 } 337 } 338 339 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) { 340 // if we have a fully initialized TypeDecl, we can safely read its type now. 341 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull()); 342 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 343 // if we have a fully initialized TypeDecl, we can safely read its type now. 344 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull(); 345 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 346 // FunctionDecl's body was written last after all other Stmts/Exprs. 347 // We only read it if FD doesn't already have a body (e.g., from another 348 // module). 349 // FIXME: Also consider = default and = delete. 350 // FIXME: Can we diagnose ODR violations somehow? 351 if (Record[Idx++]) { 352 Reader.PendingBodies[FD] = GetCurrentCursorOffset(); 353 HasPendingBody = true; 354 } 355 } 356 } 357 358 void ASTDeclReader::VisitDecl(Decl *D) { 359 if (D->isTemplateParameter() || D->isTemplateParameterPack() || 360 isa<ParmVarDecl>(D)) { 361 // We don't want to deserialize the DeclContext of a template 362 // parameter or of a parameter of a function template immediately. These 363 // entities might be used in the formulation of its DeclContext (for 364 // example, a function parameter can be used in decltype() in trailing 365 // return type of the function). Use the translation unit DeclContext as a 366 // placeholder. 367 GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(Record, Idx); 368 GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(Record, Idx); 369 Reader.addPendingDeclContextInfo(D, 370 SemaDCIDForTemplateParmDecl, 371 LexicalDCIDForTemplateParmDecl); 372 D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); 373 } else { 374 DeclContext *SemaDC = ReadDeclAs<DeclContext>(Record, Idx); 375 DeclContext *LexicalDC = ReadDeclAs<DeclContext>(Record, Idx); 376 DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); 377 // Avoid calling setLexicalDeclContext() directly because it uses 378 // Decl::getASTContext() internally which is unsafe during derialization. 379 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, 380 Reader.getContext()); 381 } 382 D->setLocation(Reader.ReadSourceLocation(F, RawLocation)); 383 D->setInvalidDecl(Record[Idx++]); 384 if (Record[Idx++]) { // hasAttrs 385 AttrVec Attrs; 386 Reader.ReadAttributes(F, Attrs, Record, Idx); 387 // Avoid calling setAttrs() directly because it uses Decl::getASTContext() 388 // internally which is unsafe during derialization. 389 D->setAttrsImpl(Attrs, Reader.getContext()); 390 } 391 D->setImplicit(Record[Idx++]); 392 D->Used = Record[Idx++]; 393 D->setReferenced(Record[Idx++]); 394 D->setTopLevelDeclInObjCContainer(Record[Idx++]); 395 D->setAccess((AccessSpecifier)Record[Idx++]); 396 D->FromASTFile = true; 397 D->setModulePrivate(Record[Idx++]); 398 D->Hidden = D->isModulePrivate(); 399 400 // Determine whether this declaration is part of a (sub)module. If so, it 401 // may not yet be visible. 402 if (unsigned SubmoduleID = readSubmoduleID(Record, Idx)) { 403 // Store the owning submodule ID in the declaration. 404 D->setOwningModuleID(SubmoduleID); 405 406 // Module-private declarations are never visible, so there is no work to do. 407 if (!D->isModulePrivate()) { 408 if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { 409 if (Owner->NameVisibility != Module::AllVisible) { 410 // The owning module is not visible. Mark this declaration as hidden. 411 D->Hidden = true; 412 413 // Note that this declaration was hidden because its owning module is 414 // not yet visible. 415 Reader.HiddenNamesMap[Owner].HiddenDecls.push_back(D); 416 } 417 } 418 } 419 } 420 } 421 422 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { 423 llvm_unreachable("Translation units are not serialized"); 424 } 425 426 void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { 427 VisitDecl(ND); 428 ND->setDeclName(Reader.ReadDeclarationName(F, Record, Idx)); 429 } 430 431 void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { 432 VisitNamedDecl(TD); 433 TD->setLocStart(ReadSourceLocation(Record, Idx)); 434 // Delay type reading until after we have fully initialized the decl. 435 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]); 436 } 437 438 void ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { 439 RedeclarableResult Redecl = VisitRedeclarable(TD); 440 VisitTypeDecl(TD); 441 TypeSourceInfo *TInfo = GetTypeSourceInfo(Record, Idx); 442 if (Record[Idx++]) { // isModed 443 QualType modedT = Reader.readType(F, Record, Idx); 444 TD->setModedTypeSourceInfo(TInfo, modedT); 445 } else 446 TD->setTypeSourceInfo(TInfo); 447 mergeRedeclarable(TD, Redecl); 448 } 449 450 void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { 451 VisitTypedefNameDecl(TD); 452 } 453 454 void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { 455 VisitTypedefNameDecl(TD); 456 } 457 458 ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { 459 RedeclarableResult Redecl = VisitRedeclarable(TD); 460 VisitTypeDecl(TD); 461 462 TD->IdentifierNamespace = Record[Idx++]; 463 TD->setTagKind((TagDecl::TagKind)Record[Idx++]); 464 TD->setCompleteDefinition(Record[Idx++]); 465 TD->setEmbeddedInDeclarator(Record[Idx++]); 466 TD->setFreeStanding(Record[Idx++]); 467 TD->setCompleteDefinitionRequired(Record[Idx++]); 468 TD->setRBraceLoc(ReadSourceLocation(Record, Idx)); 469 470 if (Record[Idx++]) { // hasExtInfo 471 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo(); 472 ReadQualifierInfo(*Info, Record, Idx); 473 TD->NamedDeclOrQualifier = Info; 474 } else 475 TD->NamedDeclOrQualifier = ReadDeclAs<NamedDecl>(Record, Idx); 476 477 mergeRedeclarable(TD, Redecl); 478 return Redecl; 479 } 480 481 void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { 482 VisitTagDecl(ED); 483 if (TypeSourceInfo *TI = Reader.GetTypeSourceInfo(F, Record, Idx)) 484 ED->setIntegerTypeSourceInfo(TI); 485 else 486 ED->setIntegerType(Reader.readType(F, Record, Idx)); 487 ED->setPromotionType(Reader.readType(F, Record, Idx)); 488 ED->setNumPositiveBits(Record[Idx++]); 489 ED->setNumNegativeBits(Record[Idx++]); 490 ED->IsScoped = Record[Idx++]; 491 ED->IsScopedUsingClassTag = Record[Idx++]; 492 ED->IsFixed = Record[Idx++]; 493 494 // If this is a definition subject to the ODR, and we already have a 495 // definition, merge this one into it. 496 if (ED->IsCompleteDefinition && 497 Reader.getContext().getLangOpts().Modules && 498 Reader.getContext().getLangOpts().CPlusPlus) { 499 if (EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]) { 500 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); 501 ED->IsCompleteDefinition = false; 502 } else { 503 OldDef = ED; 504 } 505 } 506 507 if (EnumDecl *InstED = ReadDeclAs<EnumDecl>(Record, Idx)) { 508 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 509 SourceLocation POI = ReadSourceLocation(Record, Idx); 510 ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); 511 ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); 512 } 513 } 514 515 ASTDeclReader::RedeclarableResult 516 ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { 517 RedeclarableResult Redecl = VisitTagDecl(RD); 518 RD->setHasFlexibleArrayMember(Record[Idx++]); 519 RD->setAnonymousStructOrUnion(Record[Idx++]); 520 RD->setHasObjectMember(Record[Idx++]); 521 RD->setHasVolatileMember(Record[Idx++]); 522 return Redecl; 523 } 524 525 void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { 526 VisitNamedDecl(VD); 527 VD->setType(Reader.readType(F, Record, Idx)); 528 } 529 530 void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { 531 VisitValueDecl(ECD); 532 if (Record[Idx++]) 533 ECD->setInitExpr(Reader.ReadExpr(F)); 534 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx)); 535 mergeMergeable(ECD); 536 } 537 538 void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { 539 VisitValueDecl(DD); 540 DD->setInnerLocStart(ReadSourceLocation(Record, Idx)); 541 if (Record[Idx++]) { // hasExtInfo 542 DeclaratorDecl::ExtInfo *Info 543 = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); 544 ReadQualifierInfo(*Info, Record, Idx); 545 DD->DeclInfo = Info; 546 } 547 } 548 549 void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { 550 RedeclarableResult Redecl = VisitRedeclarable(FD); 551 VisitDeclaratorDecl(FD); 552 553 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName(), Record, Idx); 554 FD->IdentifierNamespace = Record[Idx++]; 555 556 // FunctionDecl's body is handled last at ASTDeclReader::Visit, 557 // after everything else is read. 558 559 FD->SClass = (StorageClass)Record[Idx++]; 560 FD->IsInline = Record[Idx++]; 561 FD->IsInlineSpecified = Record[Idx++]; 562 FD->IsVirtualAsWritten = Record[Idx++]; 563 FD->IsPure = Record[Idx++]; 564 FD->HasInheritedPrototype = Record[Idx++]; 565 FD->HasWrittenPrototype = Record[Idx++]; 566 FD->IsDeleted = Record[Idx++]; 567 FD->IsTrivial = Record[Idx++]; 568 FD->IsDefaulted = Record[Idx++]; 569 FD->IsExplicitlyDefaulted = Record[Idx++]; 570 FD->HasImplicitReturnZero = Record[Idx++]; 571 FD->IsConstexpr = Record[Idx++]; 572 FD->HasSkippedBody = Record[Idx++]; 573 FD->IsLateTemplateParsed = Record[Idx++]; 574 FD->setCachedLinkage(Linkage(Record[Idx++])); 575 FD->EndRangeLoc = ReadSourceLocation(Record, Idx); 576 577 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) { 578 case FunctionDecl::TK_NonTemplate: 579 mergeRedeclarable(FD, Redecl); 580 break; 581 case FunctionDecl::TK_FunctionTemplate: 582 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>(Record, 583 Idx)); 584 break; 585 case FunctionDecl::TK_MemberSpecialization: { 586 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>(Record, Idx); 587 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 588 SourceLocation POI = ReadSourceLocation(Record, Idx); 589 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); 590 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); 591 break; 592 } 593 case FunctionDecl::TK_FunctionTemplateSpecialization: { 594 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>(Record, 595 Idx); 596 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 597 598 // Template arguments. 599 SmallVector<TemplateArgument, 8> TemplArgs; 600 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 601 602 // Template args as written. 603 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; 604 SourceLocation LAngleLoc, RAngleLoc; 605 bool HasTemplateArgumentsAsWritten = Record[Idx++]; 606 if (HasTemplateArgumentsAsWritten) { 607 unsigned NumTemplateArgLocs = Record[Idx++]; 608 TemplArgLocs.reserve(NumTemplateArgLocs); 609 for (unsigned i=0; i != NumTemplateArgLocs; ++i) 610 TemplArgLocs.push_back( 611 Reader.ReadTemplateArgumentLoc(F, Record, Idx)); 612 613 LAngleLoc = ReadSourceLocation(Record, Idx); 614 RAngleLoc = ReadSourceLocation(Record, Idx); 615 } 616 617 SourceLocation POI = ReadSourceLocation(Record, Idx); 618 619 ASTContext &C = Reader.getContext(); 620 TemplateArgumentList *TemplArgList 621 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size()); 622 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); 623 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i) 624 TemplArgsInfo.addArgument(TemplArgLocs[i]); 625 FunctionTemplateSpecializationInfo *FTInfo 626 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, 627 TemplArgList, 628 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : 0, 629 POI); 630 FD->TemplateOrSpecialization = FTInfo; 631 632 if (FD->isCanonicalDecl()) { // if canonical add to template's set. 633 // The template that contains the specializations set. It's not safe to 634 // use getCanonicalDecl on Template since it may still be initializing. 635 FunctionTemplateDecl *CanonTemplate 636 = ReadDeclAs<FunctionTemplateDecl>(Record, Idx); 637 // Get the InsertPos by FindNodeOrInsertPos() instead of calling 638 // InsertNode(FTInfo) directly to avoid the getASTContext() call in 639 // FunctionTemplateSpecializationInfo's Profile(). 640 // We avoid getASTContext because a decl in the parent hierarchy may 641 // be initializing. 642 llvm::FoldingSetNodeID ID; 643 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(), 644 TemplArgs.size(), C); 645 void *InsertPos = 0; 646 FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); 647 CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); 648 if (InsertPos) 649 CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); 650 else { 651 assert(Reader.getContext().getLangOpts().Modules && 652 "already deserialized this template specialization"); 653 // FIXME: This specialization is a redeclaration of one from another 654 // module. Merge it. 655 } 656 } 657 break; 658 } 659 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { 660 // Templates. 661 UnresolvedSet<8> TemplDecls; 662 unsigned NumTemplates = Record[Idx++]; 663 while (NumTemplates--) 664 TemplDecls.addDecl(ReadDeclAs<NamedDecl>(Record, Idx)); 665 666 // Templates args. 667 TemplateArgumentListInfo TemplArgs; 668 unsigned NumArgs = Record[Idx++]; 669 while (NumArgs--) 670 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(F, Record, Idx)); 671 TemplArgs.setLAngleLoc(ReadSourceLocation(Record, Idx)); 672 TemplArgs.setRAngleLoc(ReadSourceLocation(Record, Idx)); 673 674 FD->setDependentTemplateSpecialization(Reader.getContext(), 675 TemplDecls, TemplArgs); 676 break; 677 } 678 } 679 680 // Read in the parameters. 681 unsigned NumParams = Record[Idx++]; 682 SmallVector<ParmVarDecl *, 16> Params; 683 Params.reserve(NumParams); 684 for (unsigned I = 0; I != NumParams; ++I) 685 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 686 FD->setParams(Reader.getContext(), Params); 687 } 688 689 void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { 690 VisitNamedDecl(MD); 691 if (Record[Idx++]) { 692 // Load the body on-demand. Most clients won't care, because method 693 // definitions rarely show up in headers. 694 Reader.PendingBodies[MD] = GetCurrentCursorOffset(); 695 HasPendingBody = true; 696 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx)); 697 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>(Record, Idx)); 698 } 699 MD->setInstanceMethod(Record[Idx++]); 700 MD->setVariadic(Record[Idx++]); 701 MD->setPropertyAccessor(Record[Idx++]); 702 MD->setDefined(Record[Idx++]); 703 MD->IsOverriding = Record[Idx++]; 704 MD->HasSkippedBody = Record[Idx++]; 705 706 MD->IsRedeclaration = Record[Idx++]; 707 MD->HasRedeclaration = Record[Idx++]; 708 if (MD->HasRedeclaration) 709 Reader.getContext().setObjCMethodRedeclaration(MD, 710 ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 711 712 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]); 713 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]); 714 MD->SetRelatedResultType(Record[Idx++]); 715 MD->setReturnType(Reader.readType(F, Record, Idx)); 716 MD->setReturnTypeSourceInfo(GetTypeSourceInfo(Record, Idx)); 717 MD->DeclEndLoc = ReadSourceLocation(Record, Idx); 718 unsigned NumParams = Record[Idx++]; 719 SmallVector<ParmVarDecl *, 16> Params; 720 Params.reserve(NumParams); 721 for (unsigned I = 0; I != NumParams; ++I) 722 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 723 724 MD->SelLocsKind = Record[Idx++]; 725 unsigned NumStoredSelLocs = Record[Idx++]; 726 SmallVector<SourceLocation, 16> SelLocs; 727 SelLocs.reserve(NumStoredSelLocs); 728 for (unsigned i = 0; i != NumStoredSelLocs; ++i) 729 SelLocs.push_back(ReadSourceLocation(Record, Idx)); 730 731 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); 732 } 733 734 void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { 735 VisitNamedDecl(CD); 736 CD->setAtStartLoc(ReadSourceLocation(Record, Idx)); 737 CD->setAtEndRange(ReadSourceRange(Record, Idx)); 738 } 739 740 void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { 741 RedeclarableResult Redecl = VisitRedeclarable(ID); 742 VisitObjCContainerDecl(ID); 743 TypeIDForTypeDecl = Reader.getGlobalTypeID(F, Record[Idx++]); 744 mergeRedeclarable(ID, Redecl); 745 746 if (Record[Idx++]) { 747 // Read the definition. 748 ID->allocateDefinitionData(); 749 750 // Set the definition data of the canonical declaration, so other 751 // redeclarations will see it. 752 ID->getCanonicalDecl()->Data = ID->Data; 753 754 ObjCInterfaceDecl::DefinitionData &Data = ID->data(); 755 756 // Read the superclass. 757 Data.SuperClass = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx); 758 Data.SuperClassLoc = ReadSourceLocation(Record, Idx); 759 760 Data.EndLoc = ReadSourceLocation(Record, Idx); 761 Data.HasDesignatedInitializers = Record[Idx++]; 762 763 // Read the directly referenced protocols and their SourceLocations. 764 unsigned NumProtocols = Record[Idx++]; 765 SmallVector<ObjCProtocolDecl *, 16> Protocols; 766 Protocols.reserve(NumProtocols); 767 for (unsigned I = 0; I != NumProtocols; ++I) 768 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 769 SmallVector<SourceLocation, 16> ProtoLocs; 770 ProtoLocs.reserve(NumProtocols); 771 for (unsigned I = 0; I != NumProtocols; ++I) 772 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 773 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(), 774 Reader.getContext()); 775 776 // Read the transitive closure of protocols referenced by this class. 777 NumProtocols = Record[Idx++]; 778 Protocols.clear(); 779 Protocols.reserve(NumProtocols); 780 for (unsigned I = 0; I != NumProtocols; ++I) 781 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 782 ID->data().AllReferencedProtocols.set(Protocols.data(), NumProtocols, 783 Reader.getContext()); 784 785 // We will rebuild this list lazily. 786 ID->setIvarList(0); 787 788 // Note that we have deserialized a definition. 789 Reader.PendingDefinitions.insert(ID); 790 791 // Note that we've loaded this Objective-C class. 792 Reader.ObjCClassesLoaded.push_back(ID); 793 } else { 794 ID->Data = ID->getCanonicalDecl()->Data; 795 } 796 } 797 798 void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { 799 VisitFieldDecl(IVD); 800 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]); 801 // This field will be built lazily. 802 IVD->setNextIvar(0); 803 bool synth = Record[Idx++]; 804 IVD->setSynthesize(synth); 805 } 806 807 void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { 808 RedeclarableResult Redecl = VisitRedeclarable(PD); 809 VisitObjCContainerDecl(PD); 810 mergeRedeclarable(PD, Redecl); 811 812 if (Record[Idx++]) { 813 // Read the definition. 814 PD->allocateDefinitionData(); 815 816 // Set the definition data of the canonical declaration, so other 817 // redeclarations will see it. 818 PD->getCanonicalDecl()->Data = PD->Data; 819 820 unsigned NumProtoRefs = Record[Idx++]; 821 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; 822 ProtoRefs.reserve(NumProtoRefs); 823 for (unsigned I = 0; I != NumProtoRefs; ++I) 824 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 825 SmallVector<SourceLocation, 16> ProtoLocs; 826 ProtoLocs.reserve(NumProtoRefs); 827 for (unsigned I = 0; I != NumProtoRefs; ++I) 828 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 829 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), 830 Reader.getContext()); 831 832 // Note that we have deserialized a definition. 833 Reader.PendingDefinitions.insert(PD); 834 } else { 835 PD->Data = PD->getCanonicalDecl()->Data; 836 } 837 } 838 839 void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { 840 VisitFieldDecl(FD); 841 } 842 843 void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { 844 VisitObjCContainerDecl(CD); 845 CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx)); 846 CD->setIvarLBraceLoc(ReadSourceLocation(Record, Idx)); 847 CD->setIvarRBraceLoc(ReadSourceLocation(Record, Idx)); 848 849 // Note that this category has been deserialized. We do this before 850 // deserializing the interface declaration, so that it will consider this 851 /// category. 852 Reader.CategoriesDeserialized.insert(CD); 853 854 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(Record, Idx); 855 unsigned NumProtoRefs = Record[Idx++]; 856 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; 857 ProtoRefs.reserve(NumProtoRefs); 858 for (unsigned I = 0; I != NumProtoRefs; ++I) 859 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>(Record, Idx)); 860 SmallVector<SourceLocation, 16> ProtoLocs; 861 ProtoLocs.reserve(NumProtoRefs); 862 for (unsigned I = 0; I != NumProtoRefs; ++I) 863 ProtoLocs.push_back(ReadSourceLocation(Record, Idx)); 864 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), 865 Reader.getContext()); 866 } 867 868 void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { 869 VisitNamedDecl(CAD); 870 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 871 } 872 873 void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { 874 VisitNamedDecl(D); 875 D->setAtLoc(ReadSourceLocation(Record, Idx)); 876 D->setLParenLoc(ReadSourceLocation(Record, Idx)); 877 D->setType(GetTypeSourceInfo(Record, Idx)); 878 // FIXME: stable encoding 879 D->setPropertyAttributes( 880 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); 881 D->setPropertyAttributesAsWritten( 882 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]); 883 // FIXME: stable encoding 884 D->setPropertyImplementation( 885 (ObjCPropertyDecl::PropertyControl)Record[Idx++]); 886 D->setGetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector()); 887 D->setSetterName(Reader.ReadDeclarationName(F,Record, Idx).getObjCSelector()); 888 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 889 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>(Record, Idx)); 890 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>(Record, Idx)); 891 } 892 893 void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { 894 VisitObjCContainerDecl(D); 895 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 896 } 897 898 void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { 899 VisitObjCImplDecl(D); 900 D->setIdentifier(Reader.GetIdentifierInfo(F, Record, Idx)); 901 D->CategoryNameLoc = ReadSourceLocation(Record, Idx); 902 } 903 904 void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { 905 VisitObjCImplDecl(D); 906 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx)); 907 D->SuperLoc = ReadSourceLocation(Record, Idx); 908 D->setIvarLBraceLoc(ReadSourceLocation(Record, Idx)); 909 D->setIvarRBraceLoc(ReadSourceLocation(Record, Idx)); 910 D->setHasNonZeroConstructors(Record[Idx++]); 911 D->setHasDestructors(Record[Idx++]); 912 std::tie(D->IvarInitializers, D->NumIvarInitializers) = 913 Reader.ReadCXXCtorInitializers(F, Record, Idx); 914 } 915 916 917 void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { 918 VisitDecl(D); 919 D->setAtLoc(ReadSourceLocation(Record, Idx)); 920 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>(Record, Idx)); 921 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(Record, Idx); 922 D->IvarLoc = ReadSourceLocation(Record, Idx); 923 D->setGetterCXXConstructor(Reader.ReadExpr(F)); 924 D->setSetterCXXAssignment(Reader.ReadExpr(F)); 925 } 926 927 void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { 928 VisitDeclaratorDecl(FD); 929 FD->Mutable = Record[Idx++]; 930 if (int BitWidthOrInitializer = Record[Idx++]) { 931 FD->InitializerOrBitWidth.setInt(BitWidthOrInitializer - 1); 932 FD->InitializerOrBitWidth.setPointer(Reader.ReadExpr(F)); 933 } 934 if (!FD->getDeclName()) { 935 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>(Record, Idx)) 936 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); 937 } 938 mergeMergeable(FD); 939 } 940 941 void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { 942 VisitDeclaratorDecl(PD); 943 PD->GetterId = Reader.GetIdentifierInfo(F, Record, Idx); 944 PD->SetterId = Reader.GetIdentifierInfo(F, Record, Idx); 945 } 946 947 void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { 948 VisitValueDecl(FD); 949 950 FD->ChainingSize = Record[Idx++]; 951 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); 952 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; 953 954 for (unsigned I = 0; I != FD->ChainingSize; ++I) 955 FD->Chaining[I] = ReadDeclAs<NamedDecl>(Record, Idx); 956 } 957 958 ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { 959 RedeclarableResult Redecl = VisitRedeclarable(VD); 960 VisitDeclaratorDecl(VD); 961 962 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++]; 963 VD->VarDeclBits.TSCSpec = Record[Idx++]; 964 VD->VarDeclBits.InitStyle = Record[Idx++]; 965 VD->VarDeclBits.ExceptionVar = Record[Idx++]; 966 VD->VarDeclBits.NRVOVariable = Record[Idx++]; 967 VD->VarDeclBits.CXXForRangeDecl = Record[Idx++]; 968 VD->VarDeclBits.ARCPseudoStrong = Record[Idx++]; 969 VD->VarDeclBits.IsConstexpr = Record[Idx++]; 970 VD->VarDeclBits.IsInitCapture = Record[Idx++]; 971 VD->VarDeclBits.PreviousDeclInSameBlockScope = Record[Idx++]; 972 Linkage VarLinkage = Linkage(Record[Idx++]); 973 VD->setCachedLinkage(VarLinkage); 974 975 // Reconstruct the one piece of the IdentifierNamespace that we need. 976 if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && 977 VD->getLexicalDeclContext()->isFunctionOrMethod()) 978 VD->setLocalExternDecl(); 979 980 // Only true variables (not parameters or implicit parameters) can be merged. 981 if (VD->getKind() != Decl::ParmVar && VD->getKind() != Decl::ImplicitParam) 982 mergeRedeclarable(VD, Redecl); 983 984 if (uint64_t Val = Record[Idx++]) { 985 VD->setInit(Reader.ReadExpr(F)); 986 if (Val > 1) { 987 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); 988 Eval->CheckedICE = true; 989 Eval->IsICE = Val == 3; 990 } 991 } 992 993 enum VarKind { 994 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization 995 }; 996 switch ((VarKind)Record[Idx++]) { 997 case VarNotTemplate: 998 break; 999 case VarTemplate: 1000 VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>(Record, Idx)); 1001 break; 1002 case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. 1003 VarDecl *Tmpl = ReadDeclAs<VarDecl>(Record, Idx); 1004 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 1005 SourceLocation POI = ReadSourceLocation(Record, Idx); 1006 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); 1007 break; 1008 } 1009 } 1010 1011 return Redecl; 1012 } 1013 1014 void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { 1015 VisitVarDecl(PD); 1016 } 1017 1018 void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { 1019 VisitVarDecl(PD); 1020 unsigned isObjCMethodParam = Record[Idx++]; 1021 unsigned scopeDepth = Record[Idx++]; 1022 unsigned scopeIndex = Record[Idx++]; 1023 unsigned declQualifier = Record[Idx++]; 1024 if (isObjCMethodParam) { 1025 assert(scopeDepth == 0); 1026 PD->setObjCMethodScopeInfo(scopeIndex); 1027 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; 1028 } else { 1029 PD->setScopeInfo(scopeDepth, scopeIndex); 1030 } 1031 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++]; 1032 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++]; 1033 if (Record[Idx++]) // hasUninstantiatedDefaultArg. 1034 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(F)); 1035 1036 // FIXME: If this is a redeclaration of a function from another module, handle 1037 // inheritance of default arguments. 1038 } 1039 1040 void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { 1041 VisitDecl(AD); 1042 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(F))); 1043 AD->setRParenLoc(ReadSourceLocation(Record, Idx)); 1044 } 1045 1046 void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { 1047 VisitDecl(BD); 1048 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(F))); 1049 BD->setSignatureAsWritten(GetTypeSourceInfo(Record, Idx)); 1050 unsigned NumParams = Record[Idx++]; 1051 SmallVector<ParmVarDecl *, 16> Params; 1052 Params.reserve(NumParams); 1053 for (unsigned I = 0; I != NumParams; ++I) 1054 Params.push_back(ReadDeclAs<ParmVarDecl>(Record, Idx)); 1055 BD->setParams(Params); 1056 1057 BD->setIsVariadic(Record[Idx++]); 1058 BD->setBlockMissingReturnType(Record[Idx++]); 1059 BD->setIsConversionFromLambda(Record[Idx++]); 1060 1061 bool capturesCXXThis = Record[Idx++]; 1062 unsigned numCaptures = Record[Idx++]; 1063 SmallVector<BlockDecl::Capture, 16> captures; 1064 captures.reserve(numCaptures); 1065 for (unsigned i = 0; i != numCaptures; ++i) { 1066 VarDecl *decl = ReadDeclAs<VarDecl>(Record, Idx); 1067 unsigned flags = Record[Idx++]; 1068 bool byRef = (flags & 1); 1069 bool nested = (flags & 2); 1070 Expr *copyExpr = ((flags & 4) ? Reader.ReadExpr(F) : 0); 1071 1072 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); 1073 } 1074 BD->setCaptures(Reader.getContext(), captures.begin(), 1075 captures.end(), capturesCXXThis); 1076 } 1077 1078 void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { 1079 VisitDecl(CD); 1080 // Body is set by VisitCapturedStmt. 1081 for (unsigned i = 0; i < CD->NumParams; ++i) 1082 CD->setParam(i, ReadDeclAs<ImplicitParamDecl>(Record, Idx)); 1083 } 1084 1085 void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { 1086 VisitDecl(D); 1087 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]); 1088 D->setExternLoc(ReadSourceLocation(Record, Idx)); 1089 D->setRBraceLoc(ReadSourceLocation(Record, Idx)); 1090 } 1091 1092 void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { 1093 VisitNamedDecl(D); 1094 D->setLocStart(ReadSourceLocation(Record, Idx)); 1095 } 1096 1097 1098 void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { 1099 RedeclarableResult Redecl = VisitRedeclarable(D); 1100 VisitNamedDecl(D); 1101 D->setInline(Record[Idx++]); 1102 D->LocStart = ReadSourceLocation(Record, Idx); 1103 D->RBraceLoc = ReadSourceLocation(Record, Idx); 1104 // FIXME: At the point of this call, D->getCanonicalDecl() returns 0. 1105 mergeRedeclarable(D, Redecl); 1106 1107 if (Redecl.getFirstID() == ThisDeclID) { 1108 // Each module has its own anonymous namespace, which is disjoint from 1109 // any other module's anonymous namespaces, so don't attach the anonymous 1110 // namespace at all. 1111 NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>(Record, Idx); 1112 if (F.Kind != MK_Module) 1113 D->setAnonymousNamespace(Anon); 1114 } else { 1115 // Link this namespace back to the first declaration, which has already 1116 // been deserialized. 1117 D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); 1118 } 1119 } 1120 1121 void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { 1122 VisitNamedDecl(D); 1123 D->NamespaceLoc = ReadSourceLocation(Record, Idx); 1124 D->IdentLoc = ReadSourceLocation(Record, Idx); 1125 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1126 D->Namespace = ReadDeclAs<NamedDecl>(Record, Idx); 1127 } 1128 1129 void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { 1130 VisitNamedDecl(D); 1131 D->setUsingLoc(ReadSourceLocation(Record, Idx)); 1132 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1133 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx); 1134 D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>(Record, Idx)); 1135 D->setTypename(Record[Idx++]); 1136 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>(Record, Idx)) 1137 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); 1138 } 1139 1140 void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { 1141 RedeclarableResult Redecl = VisitRedeclarable(D); 1142 VisitNamedDecl(D); 1143 D->setTargetDecl(ReadDeclAs<NamedDecl>(Record, Idx)); 1144 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(Record, Idx); 1145 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>(Record, Idx); 1146 if (Pattern) 1147 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); 1148 mergeRedeclarable(D, Redecl); 1149 } 1150 1151 void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { 1152 VisitNamedDecl(D); 1153 D->UsingLoc = ReadSourceLocation(Record, Idx); 1154 D->NamespaceLoc = ReadSourceLocation(Record, Idx); 1155 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1156 D->NominatedNamespace = ReadDeclAs<NamedDecl>(Record, Idx); 1157 D->CommonAncestor = ReadDeclAs<DeclContext>(Record, Idx); 1158 } 1159 1160 void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { 1161 VisitValueDecl(D); 1162 D->setUsingLoc(ReadSourceLocation(Record, Idx)); 1163 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1164 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record, Idx); 1165 } 1166 1167 void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( 1168 UnresolvedUsingTypenameDecl *D) { 1169 VisitTypeDecl(D); 1170 D->TypenameLocation = ReadSourceLocation(Record, Idx); 1171 D->QualifierLoc = Reader.ReadNestedNameSpecifierLoc(F, Record, Idx); 1172 } 1173 1174 void ASTDeclReader::ReadCXXDefinitionData( 1175 struct CXXRecordDecl::DefinitionData &Data, 1176 const RecordData &Record, unsigned &Idx) { 1177 // Note: the caller has deserialized the IsLambda bit already. 1178 Data.UserDeclaredConstructor = Record[Idx++]; 1179 Data.UserDeclaredSpecialMembers = Record[Idx++]; 1180 Data.Aggregate = Record[Idx++]; 1181 Data.PlainOldData = Record[Idx++]; 1182 Data.Empty = Record[Idx++]; 1183 Data.Polymorphic = Record[Idx++]; 1184 Data.Abstract = Record[Idx++]; 1185 Data.IsStandardLayout = Record[Idx++]; 1186 Data.HasNoNonEmptyBases = Record[Idx++]; 1187 Data.HasPrivateFields = Record[Idx++]; 1188 Data.HasProtectedFields = Record[Idx++]; 1189 Data.HasPublicFields = Record[Idx++]; 1190 Data.HasMutableFields = Record[Idx++]; 1191 Data.HasVariantMembers = Record[Idx++]; 1192 Data.HasOnlyCMembers = Record[Idx++]; 1193 Data.HasInClassInitializer = Record[Idx++]; 1194 Data.HasUninitializedReferenceMember = Record[Idx++]; 1195 Data.NeedOverloadResolutionForMoveConstructor = Record[Idx++]; 1196 Data.NeedOverloadResolutionForMoveAssignment = Record[Idx++]; 1197 Data.NeedOverloadResolutionForDestructor = Record[Idx++]; 1198 Data.DefaultedMoveConstructorIsDeleted = Record[Idx++]; 1199 Data.DefaultedMoveAssignmentIsDeleted = Record[Idx++]; 1200 Data.DefaultedDestructorIsDeleted = Record[Idx++]; 1201 Data.HasTrivialSpecialMembers = Record[Idx++]; 1202 Data.HasIrrelevantDestructor = Record[Idx++]; 1203 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++]; 1204 Data.DefaultedDefaultConstructorIsConstexpr = Record[Idx++]; 1205 Data.HasConstexprDefaultConstructor = Record[Idx++]; 1206 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++]; 1207 Data.ComputedVisibleConversions = Record[Idx++]; 1208 Data.UserProvidedDefaultConstructor = Record[Idx++]; 1209 Data.DeclaredSpecialMembers = Record[Idx++]; 1210 Data.ImplicitCopyConstructorHasConstParam = Record[Idx++]; 1211 Data.ImplicitCopyAssignmentHasConstParam = Record[Idx++]; 1212 Data.HasDeclaredCopyConstructorWithConstParam = Record[Idx++]; 1213 Data.HasDeclaredCopyAssignmentWithConstParam = Record[Idx++]; 1214 1215 Data.NumBases = Record[Idx++]; 1216 if (Data.NumBases) 1217 Data.Bases = Reader.readCXXBaseSpecifiers(F, Record, Idx); 1218 Data.NumVBases = Record[Idx++]; 1219 if (Data.NumVBases) 1220 Data.VBases = Reader.readCXXBaseSpecifiers(F, Record, Idx); 1221 1222 Reader.ReadUnresolvedSet(F, Data.Conversions, Record, Idx); 1223 Reader.ReadUnresolvedSet(F, Data.VisibleConversions, Record, Idx); 1224 assert(Data.Definition && "Data.Definition should be already set!"); 1225 Data.FirstFriend = ReadDeclID(Record, Idx); 1226 1227 if (Data.IsLambda) { 1228 typedef LambdaExpr::Capture Capture; 1229 CXXRecordDecl::LambdaDefinitionData &Lambda 1230 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); 1231 Lambda.Dependent = Record[Idx++]; 1232 Lambda.IsGenericLambda = Record[Idx++]; 1233 Lambda.CaptureDefault = Record[Idx++]; 1234 Lambda.NumCaptures = Record[Idx++]; 1235 Lambda.NumExplicitCaptures = Record[Idx++]; 1236 Lambda.ManglingNumber = Record[Idx++]; 1237 Lambda.ContextDecl = ReadDecl(Record, Idx); 1238 Lambda.Captures 1239 = (Capture*)Reader.Context.Allocate(sizeof(Capture)*Lambda.NumCaptures); 1240 Capture *ToCapture = Lambda.Captures; 1241 Lambda.MethodTyInfo = GetTypeSourceInfo(Record, Idx); 1242 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { 1243 SourceLocation Loc = ReadSourceLocation(Record, Idx); 1244 bool IsImplicit = Record[Idx++]; 1245 LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record[Idx++]); 1246 switch (Kind) { 1247 case LCK_This: 1248 *ToCapture++ = Capture(Loc, IsImplicit, Kind, 0, SourceLocation()); 1249 break; 1250 case LCK_ByCopy: 1251 case LCK_ByRef: 1252 VarDecl *Var = ReadDeclAs<VarDecl>(Record, Idx); 1253 SourceLocation EllipsisLoc = ReadSourceLocation(Record, Idx); 1254 *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); 1255 break; 1256 } 1257 } 1258 } 1259 } 1260 1261 ASTDeclReader::RedeclarableResult 1262 ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { 1263 RedeclarableResult Redecl = VisitRecordDeclImpl(D); 1264 1265 ASTContext &C = Reader.getContext(); 1266 bool WasDefinition = Record[Idx++]; 1267 if (WasDefinition) { 1268 // Determine whether this is a lambda closure type, so that we can 1269 // allocate the appropriate DefinitionData structure. 1270 bool IsLambda = Record[Idx++]; 1271 if (IsLambda) 1272 D->DefinitionData = new (C) CXXRecordDecl::LambdaDefinitionData(D, 0, 1273 false, 1274 false, LCD_None); 1275 else 1276 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D); 1277 1278 ReadCXXDefinitionData(*D->DefinitionData, Record, Idx); 1279 1280 // Propagate the DefinitionData pointer to the canonical declaration, so 1281 // that all other deserialized declarations will see it. 1282 CXXRecordDecl *Canon = D->getCanonicalDecl(); 1283 if (Canon == D) { 1284 // Nothing to do. 1285 } else if (!Canon->DefinitionData) { 1286 Canon->DefinitionData = D->DefinitionData; 1287 1288 // Note that we have deserialized a definition. Any declarations 1289 // deserialized before this one will be be given the DefinitionData 1290 // pointer at the end. 1291 Reader.PendingDefinitions.insert(D); 1292 } else { 1293 // We have already deserialized a definition of this record. This 1294 // definition is no longer really a definition. Note that the pre-existing 1295 // definition is the *real* definition. 1296 // FIXME: Check DefinitionData for consistency with prior definition. 1297 Reader.MergedDeclContexts.insert( 1298 std::make_pair(D, D->getCanonicalDecl()->DefinitionData->Definition)); 1299 D->IsCompleteDefinition = false; 1300 D->DefinitionData = D->getCanonicalDecl()->DefinitionData; 1301 } 1302 } else { 1303 // Propagate DefinitionData pointer from the canonical declaration. 1304 D->DefinitionData = D->getCanonicalDecl()->DefinitionData; 1305 } 1306 1307 enum CXXRecKind { 1308 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization 1309 }; 1310 switch ((CXXRecKind)Record[Idx++]) { 1311 case CXXRecNotTemplate: 1312 break; 1313 case CXXRecTemplate: 1314 D->TemplateOrInstantiation = ReadDeclAs<ClassTemplateDecl>(Record, Idx); 1315 break; 1316 case CXXRecMemberSpecialization: { 1317 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(Record, Idx); 1318 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++]; 1319 SourceLocation POI = ReadSourceLocation(Record, Idx); 1320 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); 1321 MSI->setPointOfInstantiation(POI); 1322 D->TemplateOrInstantiation = MSI; 1323 break; 1324 } 1325 } 1326 1327 // Lazily load the key function to avoid deserializing every method so we can 1328 // compute it. 1329 if (WasDefinition) { 1330 DeclID KeyFn = ReadDeclID(Record, Idx); 1331 if (KeyFn && D->IsCompleteDefinition) 1332 C.KeyFunctions[D] = KeyFn; 1333 } 1334 1335 return Redecl; 1336 } 1337 1338 void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { 1339 VisitFunctionDecl(D); 1340 unsigned NumOverridenMethods = Record[Idx++]; 1341 while (NumOverridenMethods--) { 1342 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, 1343 // MD may be initializing. 1344 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>(Record, Idx)) 1345 Reader.getContext().addOverriddenMethod(D, MD); 1346 } 1347 } 1348 1349 void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { 1350 VisitCXXMethodDecl(D); 1351 1352 if (auto *CD = ReadDeclAs<CXXConstructorDecl>(Record, Idx)) 1353 D->setInheritedConstructor(CD); 1354 D->IsExplicitSpecified = Record[Idx++]; 1355 std::tie(D->CtorInitializers, D->NumCtorInitializers) = 1356 Reader.ReadCXXCtorInitializers(F, Record, Idx); 1357 } 1358 1359 void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { 1360 VisitCXXMethodDecl(D); 1361 1362 D->OperatorDelete = ReadDeclAs<FunctionDecl>(Record, Idx); 1363 } 1364 1365 void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { 1366 VisitCXXMethodDecl(D); 1367 D->IsExplicitSpecified = Record[Idx++]; 1368 } 1369 1370 void ASTDeclReader::VisitImportDecl(ImportDecl *D) { 1371 VisitDecl(D); 1372 D->ImportedAndComplete.setPointer(readModule(Record, Idx)); 1373 D->ImportedAndComplete.setInt(Record[Idx++]); 1374 SourceLocation *StoredLocs = reinterpret_cast<SourceLocation *>(D + 1); 1375 for (unsigned I = 0, N = Record.back(); I != N; ++I) 1376 StoredLocs[I] = ReadSourceLocation(Record, Idx); 1377 ++Idx; // The number of stored source locations. 1378 } 1379 1380 void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { 1381 VisitDecl(D); 1382 D->setColonLoc(ReadSourceLocation(Record, Idx)); 1383 } 1384 1385 void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { 1386 VisitDecl(D); 1387 if (Record[Idx++]) // hasFriendDecl 1388 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx); 1389 else 1390 D->Friend = GetTypeSourceInfo(Record, Idx); 1391 for (unsigned i = 0; i != D->NumTPLists; ++i) 1392 D->getTPLists()[i] = Reader.ReadTemplateParameterList(F, Record, Idx); 1393 D->NextFriend = ReadDeclID(Record, Idx); 1394 D->UnsupportedFriend = (Record[Idx++] != 0); 1395 D->FriendLoc = ReadSourceLocation(Record, Idx); 1396 } 1397 1398 void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { 1399 VisitDecl(D); 1400 unsigned NumParams = Record[Idx++]; 1401 D->NumParams = NumParams; 1402 D->Params = new TemplateParameterList*[NumParams]; 1403 for (unsigned i = 0; i != NumParams; ++i) 1404 D->Params[i] = Reader.ReadTemplateParameterList(F, Record, Idx); 1405 if (Record[Idx++]) // HasFriendDecl 1406 D->Friend = ReadDeclAs<NamedDecl>(Record, Idx); 1407 else 1408 D->Friend = GetTypeSourceInfo(Record, Idx); 1409 D->FriendLoc = ReadSourceLocation(Record, Idx); 1410 } 1411 1412 void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { 1413 VisitNamedDecl(D); 1414 1415 NamedDecl *TemplatedDecl = ReadDeclAs<NamedDecl>(Record, Idx); 1416 TemplateParameterList* TemplateParams 1417 = Reader.ReadTemplateParameterList(F, Record, Idx); 1418 D->init(TemplatedDecl, TemplateParams); 1419 1420 // FIXME: If this is a redeclaration of a template from another module, handle 1421 // inheritance of default template arguments. 1422 } 1423 1424 ASTDeclReader::RedeclarableResult 1425 ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { 1426 RedeclarableResult Redecl = VisitRedeclarable(D); 1427 1428 // Make sure we've allocated the Common pointer first. We do this before 1429 // VisitTemplateDecl so that getCommonPtr() can be used during initialization. 1430 RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); 1431 if (!CanonD->Common) { 1432 CanonD->Common = CanonD->newCommon(Reader.getContext()); 1433 Reader.PendingDefinitions.insert(CanonD); 1434 } 1435 D->Common = CanonD->Common; 1436 1437 // If this is the first declaration of the template, fill in the information 1438 // for the 'common' pointer. 1439 if (ThisDeclID == Redecl.getFirstID()) { 1440 if (RedeclarableTemplateDecl *RTD 1441 = ReadDeclAs<RedeclarableTemplateDecl>(Record, Idx)) { 1442 assert(RTD->getKind() == D->getKind() && 1443 "InstantiatedFromMemberTemplate kind mismatch"); 1444 D->setInstantiatedFromMemberTemplate(RTD); 1445 if (Record[Idx++]) 1446 D->setMemberSpecialization(); 1447 } 1448 } 1449 1450 VisitTemplateDecl(D); 1451 D->IdentifierNamespace = Record[Idx++]; 1452 1453 mergeRedeclarable(D, Redecl); 1454 1455 // If we merged the template with a prior declaration chain, merge the common 1456 // pointer. 1457 // FIXME: Actually merge here, don't just overwrite. 1458 D->Common = D->getCanonicalDecl()->Common; 1459 1460 return Redecl; 1461 } 1462 1463 void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { 1464 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); 1465 1466 if (ThisDeclID == Redecl.getFirstID()) { 1467 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of 1468 // the specializations. 1469 SmallVector<serialization::DeclID, 2> SpecIDs; 1470 SpecIDs.push_back(0); 1471 1472 // Specializations. 1473 unsigned Size = Record[Idx++]; 1474 SpecIDs[0] += Size; 1475 for (unsigned I = 0; I != Size; ++I) 1476 SpecIDs.push_back(ReadDeclID(Record, Idx)); 1477 1478 // Partial specializations. 1479 Size = Record[Idx++]; 1480 SpecIDs[0] += Size; 1481 for (unsigned I = 0; I != Size; ++I) 1482 SpecIDs.push_back(ReadDeclID(Record, Idx)); 1483 1484 ClassTemplateDecl::Common *CommonPtr = D->getCommonPtr(); 1485 if (SpecIDs[0]) { 1486 typedef serialization::DeclID DeclID; 1487 1488 // FIXME: Append specializations! 1489 CommonPtr->LazySpecializations 1490 = new (Reader.getContext()) DeclID [SpecIDs.size()]; 1491 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(), 1492 SpecIDs.size() * sizeof(DeclID)); 1493 } 1494 1495 CommonPtr->InjectedClassNameType = Reader.readType(F, Record, Idx); 1496 } 1497 } 1498 1499 /// TODO: Unify with ClassTemplateDecl version? 1500 /// May require unifying ClassTemplateDecl and 1501 /// VarTemplateDecl beyond TemplateDecl... 1502 void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { 1503 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); 1504 1505 if (ThisDeclID == Redecl.getFirstID()) { 1506 // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of 1507 // the specializations. 1508 SmallVector<serialization::DeclID, 2> SpecIDs; 1509 SpecIDs.push_back(0); 1510 1511 // Specializations. 1512 unsigned Size = Record[Idx++]; 1513 SpecIDs[0] += Size; 1514 for (unsigned I = 0; I != Size; ++I) 1515 SpecIDs.push_back(ReadDeclID(Record, Idx)); 1516 1517 // Partial specializations. 1518 Size = Record[Idx++]; 1519 SpecIDs[0] += Size; 1520 for (unsigned I = 0; I != Size; ++I) 1521 SpecIDs.push_back(ReadDeclID(Record, Idx)); 1522 1523 VarTemplateDecl::Common *CommonPtr = D->getCommonPtr(); 1524 if (SpecIDs[0]) { 1525 typedef serialization::DeclID DeclID; 1526 1527 // FIXME: Append specializations! 1528 CommonPtr->LazySpecializations = 1529 new (Reader.getContext()) DeclID[SpecIDs.size()]; 1530 memcpy(CommonPtr->LazySpecializations, SpecIDs.data(), 1531 SpecIDs.size() * sizeof(DeclID)); 1532 } 1533 } 1534 } 1535 1536 ASTDeclReader::RedeclarableResult 1537 ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( 1538 ClassTemplateSpecializationDecl *D) { 1539 RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); 1540 1541 ASTContext &C = Reader.getContext(); 1542 if (Decl *InstD = ReadDecl(Record, Idx)) { 1543 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { 1544 D->SpecializedTemplate = CTD; 1545 } else { 1546 SmallVector<TemplateArgument, 8> TemplArgs; 1547 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 1548 TemplateArgumentList *ArgList 1549 = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), 1550 TemplArgs.size()); 1551 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS 1552 = new (C) ClassTemplateSpecializationDecl:: 1553 SpecializedPartialSpecialization(); 1554 PS->PartialSpecialization 1555 = cast<ClassTemplatePartialSpecializationDecl>(InstD); 1556 PS->TemplateArgs = ArgList; 1557 D->SpecializedTemplate = PS; 1558 } 1559 } 1560 1561 SmallVector<TemplateArgument, 8> TemplArgs; 1562 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 1563 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs.data(), 1564 TemplArgs.size()); 1565 D->PointOfInstantiation = ReadSourceLocation(Record, Idx); 1566 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++]; 1567 1568 bool writtenAsCanonicalDecl = Record[Idx++]; 1569 if (writtenAsCanonicalDecl) { 1570 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>(Record,Idx); 1571 if (D->isCanonicalDecl()) { // It's kept in the folding set. 1572 // Set this as, or find, the canonical declaration for this specialization 1573 ClassTemplateSpecializationDecl *CanonSpec; 1574 if (ClassTemplatePartialSpecializationDecl *Partial = 1575 dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { 1576 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations 1577 .GetOrInsertNode(Partial); 1578 } else { 1579 CanonSpec = 1580 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); 1581 } 1582 // If there was already a canonical specialization, merge into it. 1583 if (CanonSpec != D) { 1584 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); 1585 1586 // This declaration might be a definition. Merge with any existing 1587 // definition. 1588 if (D->DefinitionData) { 1589 if (!CanonSpec->DefinitionData) { 1590 CanonSpec->DefinitionData = D->DefinitionData; 1591 } else { 1592 // FIXME: Check DefinitionData for consistency with prior definition 1593 Reader.PendingDefinitions.erase(D); 1594 Reader.MergedDeclContexts.insert( 1595 std::make_pair(D, CanonSpec->DefinitionData->Definition)); 1596 D->IsCompleteDefinition = false; 1597 D->DefinitionData = CanonSpec->DefinitionData; 1598 } 1599 } 1600 } 1601 } 1602 } 1603 1604 // Explicit info. 1605 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) { 1606 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo 1607 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; 1608 ExplicitInfo->TypeAsWritten = TyInfo; 1609 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx); 1610 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx); 1611 D->ExplicitInfo = ExplicitInfo; 1612 } 1613 1614 return Redecl; 1615 } 1616 1617 void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( 1618 ClassTemplatePartialSpecializationDecl *D) { 1619 RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); 1620 1621 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx); 1622 D->ArgsAsWritten = Reader.ReadASTTemplateArgumentListInfo(F, Record, Idx); 1623 1624 // These are read/set from/to the first declaration. 1625 if (ThisDeclID == Redecl.getFirstID()) { 1626 D->InstantiatedFromMember.setPointer( 1627 ReadDeclAs<ClassTemplatePartialSpecializationDecl>(Record, Idx)); 1628 D->InstantiatedFromMember.setInt(Record[Idx++]); 1629 } 1630 } 1631 1632 void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( 1633 ClassScopeFunctionSpecializationDecl *D) { 1634 VisitDecl(D); 1635 D->Specialization = ReadDeclAs<CXXMethodDecl>(Record, Idx); 1636 } 1637 1638 void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 1639 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); 1640 1641 if (ThisDeclID == Redecl.getFirstID()) { 1642 // This FunctionTemplateDecl owns a CommonPtr; read it. 1643 1644 // Read the function specialization declaration IDs. The specializations 1645 // themselves will be loaded if they're needed. 1646 if (unsigned NumSpecs = Record[Idx++]) { 1647 // FIXME: Append specializations! 1648 FunctionTemplateDecl::Common *CommonPtr = D->getCommonPtr(); 1649 CommonPtr->LazySpecializations = new (Reader.getContext()) 1650 serialization::DeclID[NumSpecs + 1]; 1651 CommonPtr->LazySpecializations[0] = NumSpecs; 1652 for (unsigned I = 0; I != NumSpecs; ++I) 1653 CommonPtr->LazySpecializations[I + 1] = ReadDeclID(Record, Idx); 1654 } 1655 } 1656 } 1657 1658 /// TODO: Unify with ClassTemplateSpecializationDecl version? 1659 /// May require unifying ClassTemplate(Partial)SpecializationDecl and 1660 /// VarTemplate(Partial)SpecializationDecl with a new data 1661 /// structure Template(Partial)SpecializationDecl, and 1662 /// using Template(Partial)SpecializationDecl as input type. 1663 ASTDeclReader::RedeclarableResult 1664 ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( 1665 VarTemplateSpecializationDecl *D) { 1666 RedeclarableResult Redecl = VisitVarDeclImpl(D); 1667 1668 ASTContext &C = Reader.getContext(); 1669 if (Decl *InstD = ReadDecl(Record, Idx)) { 1670 if (VarTemplateDecl *VTD = dyn_cast<VarTemplateDecl>(InstD)) { 1671 D->SpecializedTemplate = VTD; 1672 } else { 1673 SmallVector<TemplateArgument, 8> TemplArgs; 1674 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 1675 TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( 1676 C, TemplArgs.data(), TemplArgs.size()); 1677 VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS = 1678 new (C) 1679 VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); 1680 PS->PartialSpecialization = 1681 cast<VarTemplatePartialSpecializationDecl>(InstD); 1682 PS->TemplateArgs = ArgList; 1683 D->SpecializedTemplate = PS; 1684 } 1685 } 1686 1687 // Explicit info. 1688 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo(Record, Idx)) { 1689 VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo = 1690 new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; 1691 ExplicitInfo->TypeAsWritten = TyInfo; 1692 ExplicitInfo->ExternLoc = ReadSourceLocation(Record, Idx); 1693 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(Record, Idx); 1694 D->ExplicitInfo = ExplicitInfo; 1695 } 1696 1697 SmallVector<TemplateArgument, 8> TemplArgs; 1698 Reader.ReadTemplateArgumentList(TemplArgs, F, Record, Idx); 1699 D->TemplateArgs = 1700 TemplateArgumentList::CreateCopy(C, TemplArgs.data(), TemplArgs.size()); 1701 D->PointOfInstantiation = ReadSourceLocation(Record, Idx); 1702 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++]; 1703 1704 bool writtenAsCanonicalDecl = Record[Idx++]; 1705 if (writtenAsCanonicalDecl) { 1706 VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>(Record, Idx); 1707 if (D->isCanonicalDecl()) { // It's kept in the folding set. 1708 if (VarTemplatePartialSpecializationDecl *Partial = 1709 dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { 1710 CanonPattern->getCommonPtr()->PartialSpecializations 1711 .GetOrInsertNode(Partial); 1712 } else { 1713 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); 1714 } 1715 } 1716 } 1717 1718 return Redecl; 1719 } 1720 1721 /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? 1722 /// May require unifying ClassTemplate(Partial)SpecializationDecl and 1723 /// VarTemplate(Partial)SpecializationDecl with a new data 1724 /// structure Template(Partial)SpecializationDecl, and 1725 /// using Template(Partial)SpecializationDecl as input type. 1726 void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( 1727 VarTemplatePartialSpecializationDecl *D) { 1728 RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); 1729 1730 D->TemplateParams = Reader.ReadTemplateParameterList(F, Record, Idx); 1731 D->ArgsAsWritten = Reader.ReadASTTemplateArgumentListInfo(F, Record, Idx); 1732 1733 // These are read/set from/to the first declaration. 1734 if (ThisDeclID == Redecl.getFirstID()) { 1735 D->InstantiatedFromMember.setPointer( 1736 ReadDeclAs<VarTemplatePartialSpecializationDecl>(Record, Idx)); 1737 D->InstantiatedFromMember.setInt(Record[Idx++]); 1738 } 1739 } 1740 1741 void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { 1742 VisitTypeDecl(D); 1743 1744 D->setDeclaredWithTypename(Record[Idx++]); 1745 1746 bool Inherited = Record[Idx++]; 1747 TypeSourceInfo *DefArg = GetTypeSourceInfo(Record, Idx); 1748 D->setDefaultArgument(DefArg, Inherited); 1749 } 1750 1751 void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { 1752 VisitDeclaratorDecl(D); 1753 // TemplateParmPosition. 1754 D->setDepth(Record[Idx++]); 1755 D->setPosition(Record[Idx++]); 1756 if (D->isExpandedParameterPack()) { 1757 void **Data = reinterpret_cast<void **>(D + 1); 1758 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { 1759 Data[2*I] = Reader.readType(F, Record, Idx).getAsOpaquePtr(); 1760 Data[2*I + 1] = GetTypeSourceInfo(Record, Idx); 1761 } 1762 } else { 1763 // Rest of NonTypeTemplateParmDecl. 1764 D->ParameterPack = Record[Idx++]; 1765 if (Record[Idx++]) { 1766 Expr *DefArg = Reader.ReadExpr(F); 1767 bool Inherited = Record[Idx++]; 1768 D->setDefaultArgument(DefArg, Inherited); 1769 } 1770 } 1771 } 1772 1773 void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { 1774 VisitTemplateDecl(D); 1775 // TemplateParmPosition. 1776 D->setDepth(Record[Idx++]); 1777 D->setPosition(Record[Idx++]); 1778 if (D->isExpandedParameterPack()) { 1779 void **Data = reinterpret_cast<void **>(D + 1); 1780 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); 1781 I != N; ++I) 1782 Data[I] = Reader.ReadTemplateParameterList(F, Record, Idx); 1783 } else { 1784 // Rest of TemplateTemplateParmDecl. 1785 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(F, Record, Idx); 1786 bool IsInherited = Record[Idx++]; 1787 D->setDefaultArgument(Arg, IsInherited); 1788 D->ParameterPack = Record[Idx++]; 1789 } 1790 } 1791 1792 void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { 1793 VisitRedeclarableTemplateDecl(D); 1794 } 1795 1796 void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { 1797 VisitDecl(D); 1798 D->AssertExprAndFailed.setPointer(Reader.ReadExpr(F)); 1799 D->AssertExprAndFailed.setInt(Record[Idx++]); 1800 D->Message = cast<StringLiteral>(Reader.ReadExpr(F)); 1801 D->RParenLoc = ReadSourceLocation(Record, Idx); 1802 } 1803 1804 void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { 1805 VisitDecl(D); 1806 } 1807 1808 std::pair<uint64_t, uint64_t> 1809 ASTDeclReader::VisitDeclContext(DeclContext *DC) { 1810 uint64_t LexicalOffset = Record[Idx++]; 1811 uint64_t VisibleOffset = Record[Idx++]; 1812 return std::make_pair(LexicalOffset, VisibleOffset); 1813 } 1814 1815 template <typename T> 1816 ASTDeclReader::RedeclarableResult 1817 ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { 1818 DeclID FirstDeclID = ReadDeclID(Record, Idx); 1819 1820 // 0 indicates that this declaration was the only declaration of its entity, 1821 // and is used for space optimization. 1822 if (FirstDeclID == 0) 1823 FirstDeclID = ThisDeclID; 1824 1825 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); 1826 if (FirstDecl != D) { 1827 // We delay loading of the redeclaration chain to avoid deeply nested calls. 1828 // We temporarily set the first (canonical) declaration as the previous one 1829 // which is the one that matters and mark the real previous DeclID to be 1830 // loaded & attached later on. 1831 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); 1832 } 1833 1834 // Note that this declaration has been deserialized. 1835 Reader.RedeclsDeserialized.insert(static_cast<T *>(D)); 1836 1837 // The result structure takes care to note that we need to load the 1838 // other declaration chains for this ID. 1839 return RedeclarableResult(Reader, FirstDeclID, 1840 static_cast<T *>(D)->getKind()); 1841 } 1842 1843 /// \brief Attempts to merge the given declaration (D) with another declaration 1844 /// of the same entity. 1845 template<typename T> 1846 void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *D, 1847 RedeclarableResult &Redecl) { 1848 // If modules are not available, there is no reason to perform this merge. 1849 if (!Reader.getContext().getLangOpts().Modules) 1850 return; 1851 1852 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) 1853 if (T *Existing = ExistingRes) 1854 mergeRedeclarable(D, Existing, Redecl); 1855 } 1856 1857 /// \brief Attempts to merge the given declaration (D) with another declaration 1858 /// of the same entity. 1859 template<typename T> 1860 void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *D, T *Existing, 1861 RedeclarableResult &Redecl) { 1862 T *ExistingCanon = Existing->getCanonicalDecl(); 1863 T *DCanon = static_cast<T*>(D)->getCanonicalDecl(); 1864 if (ExistingCanon != DCanon) { 1865 // Have our redeclaration link point back at the canonical declaration 1866 // of the existing declaration, so that this declaration has the 1867 // appropriate canonical declaration. 1868 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); 1869 1870 // When we merge a namespace, update its pointer to the first namespace. 1871 if (NamespaceDecl *Namespace 1872 = dyn_cast<NamespaceDecl>(static_cast<T*>(D))) { 1873 Namespace->AnonOrFirstNamespaceAndInline.setPointer( 1874 static_cast<NamespaceDecl *>(static_cast<void*>(ExistingCanon))); 1875 } 1876 1877 // Don't introduce DCanon into the set of pending declaration chains. 1878 Redecl.suppress(); 1879 1880 // Introduce ExistingCanon into the set of pending declaration chains, 1881 // if in fact it came from a module file. 1882 if (ExistingCanon->isFromASTFile()) { 1883 GlobalDeclID ExistingCanonID = ExistingCanon->getGlobalID(); 1884 assert(ExistingCanonID && "Unrecorded canonical declaration ID?"); 1885 if (Reader.PendingDeclChainsKnown.insert(ExistingCanonID)) 1886 Reader.PendingDeclChains.push_back(ExistingCanonID); 1887 } 1888 1889 // If this declaration was the canonical declaration, make a note of 1890 // that. We accept the linear algorithm here because the number of 1891 // unique canonical declarations of an entity should always be tiny. 1892 if (DCanon == static_cast<T*>(D)) { 1893 SmallVectorImpl<DeclID> &Merged = Reader.MergedDecls[ExistingCanon]; 1894 if (std::find(Merged.begin(), Merged.end(), Redecl.getFirstID()) 1895 == Merged.end()) 1896 Merged.push_back(Redecl.getFirstID()); 1897 1898 // If ExistingCanon did not come from a module file, introduce the 1899 // first declaration that *does* come from a module file to the 1900 // set of pending declaration chains, so that we merge this 1901 // declaration. 1902 if (!ExistingCanon->isFromASTFile() && 1903 Reader.PendingDeclChainsKnown.insert(Redecl.getFirstID())) 1904 Reader.PendingDeclChains.push_back(Merged[0]); 1905 } 1906 } 1907 } 1908 1909 /// \brief Attempts to merge the given declaration (D) with another declaration 1910 /// of the same entity, for the case where the entity is not actually 1911 /// redeclarable. This happens, for instance, when merging the fields of 1912 /// identical class definitions from two different modules. 1913 template<typename T> 1914 void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { 1915 // If modules are not available, there is no reason to perform this merge. 1916 if (!Reader.getContext().getLangOpts().Modules) 1917 return; 1918 1919 // ODR-based merging is only performed in C++. In C, identically-named things 1920 // in different translation units are not redeclarations (but may still have 1921 // compatible types). 1922 if (!Reader.getContext().getLangOpts().CPlusPlus) 1923 return; 1924 1925 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) 1926 if (T *Existing = ExistingRes) 1927 Reader.Context.setPrimaryMergedDecl(static_cast<T*>(D), 1928 Existing->getCanonicalDecl()); 1929 } 1930 1931 void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { 1932 VisitDecl(D); 1933 unsigned NumVars = D->varlist_size(); 1934 SmallVector<Expr *, 16> Vars; 1935 Vars.reserve(NumVars); 1936 for (unsigned i = 0; i != NumVars; ++i) { 1937 Vars.push_back(Reader.ReadExpr(F)); 1938 } 1939 D->setVars(Vars); 1940 } 1941 1942 //===----------------------------------------------------------------------===// 1943 // Attribute Reading 1944 //===----------------------------------------------------------------------===// 1945 1946 /// \brief Reads attributes from the current stream position. 1947 void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs, 1948 const RecordData &Record, unsigned &Idx) { 1949 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) { 1950 Attr *New = 0; 1951 attr::Kind Kind = (attr::Kind)Record[Idx++]; 1952 SourceRange Range = ReadSourceRange(F, Record, Idx); 1953 1954 #include "clang/Serialization/AttrPCHRead.inc" 1955 1956 assert(New && "Unable to decode attribute?"); 1957 Attrs.push_back(New); 1958 } 1959 } 1960 1961 //===----------------------------------------------------------------------===// 1962 // ASTReader Implementation 1963 //===----------------------------------------------------------------------===// 1964 1965 /// \brief Note that we have loaded the declaration with the given 1966 /// Index. 1967 /// 1968 /// This routine notes that this declaration has already been loaded, 1969 /// so that future GetDecl calls will return this declaration rather 1970 /// than trying to load a new declaration. 1971 inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { 1972 assert(!DeclsLoaded[Index] && "Decl loaded twice?"); 1973 DeclsLoaded[Index] = D; 1974 } 1975 1976 1977 /// \brief Determine whether the consumer will be interested in seeing 1978 /// this declaration (via HandleTopLevelDecl). 1979 /// 1980 /// This routine should return true for anything that might affect 1981 /// code generation, e.g., inline function definitions, Objective-C 1982 /// declarations with metadata, etc. 1983 static bool isConsumerInterestedIn(Decl *D, bool HasBody) { 1984 // An ObjCMethodDecl is never considered as "interesting" because its 1985 // implementation container always is. 1986 1987 if (isa<FileScopeAsmDecl>(D) || 1988 isa<ObjCProtocolDecl>(D) || 1989 isa<ObjCImplDecl>(D) || 1990 isa<ImportDecl>(D)) 1991 return true; 1992 if (VarDecl *Var = dyn_cast<VarDecl>(D)) 1993 return Var->isFileVarDecl() && 1994 Var->isThisDeclarationADefinition() == VarDecl::Definition; 1995 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) 1996 return Func->doesThisDeclarationHaveABody() || HasBody; 1997 1998 return false; 1999 } 2000 2001 /// \brief Get the correct cursor and offset for loading a declaration. 2002 ASTReader::RecordLocation 2003 ASTReader::DeclCursorForID(DeclID ID, unsigned &RawLocation) { 2004 // See if there's an override. 2005 DeclReplacementMap::iterator It = ReplacedDecls.find(ID); 2006 if (It != ReplacedDecls.end()) { 2007 RawLocation = It->second.RawLoc; 2008 return RecordLocation(It->second.Mod, It->second.Offset); 2009 } 2010 2011 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); 2012 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); 2013 ModuleFile *M = I->second; 2014 const DeclOffset & 2015 DOffs = M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; 2016 RawLocation = DOffs.Loc; 2017 return RecordLocation(M, DOffs.BitOffset); 2018 } 2019 2020 ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { 2021 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I 2022 = GlobalBitOffsetsMap.find(GlobalOffset); 2023 2024 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); 2025 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); 2026 } 2027 2028 uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { 2029 return LocalOffset + M.GlobalBitOffset; 2030 } 2031 2032 static bool isSameTemplateParameterList(const TemplateParameterList *X, 2033 const TemplateParameterList *Y); 2034 2035 /// \brief Determine whether two template parameters are similar enough 2036 /// that they may be used in declarations of the same template. 2037 static bool isSameTemplateParameter(const NamedDecl *X, 2038 const NamedDecl *Y) { 2039 if (X->getKind() != Y->getKind()) 2040 return false; 2041 2042 if (const TemplateTypeParmDecl *TX = dyn_cast<TemplateTypeParmDecl>(X)) { 2043 const TemplateTypeParmDecl *TY = cast<TemplateTypeParmDecl>(Y); 2044 return TX->isParameterPack() == TY->isParameterPack(); 2045 } 2046 2047 if (const NonTypeTemplateParmDecl *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { 2048 const NonTypeTemplateParmDecl *TY = cast<NonTypeTemplateParmDecl>(Y); 2049 return TX->isParameterPack() == TY->isParameterPack() && 2050 TX->getASTContext().hasSameType(TX->getType(), TY->getType()); 2051 } 2052 2053 const TemplateTemplateParmDecl *TX = cast<TemplateTemplateParmDecl>(X); 2054 const TemplateTemplateParmDecl *TY = cast<TemplateTemplateParmDecl>(Y); 2055 return TX->isParameterPack() == TY->isParameterPack() && 2056 isSameTemplateParameterList(TX->getTemplateParameters(), 2057 TY->getTemplateParameters()); 2058 } 2059 2060 /// \brief Determine whether two template parameter lists are similar enough 2061 /// that they may be used in declarations of the same template. 2062 static bool isSameTemplateParameterList(const TemplateParameterList *X, 2063 const TemplateParameterList *Y) { 2064 if (X->size() != Y->size()) 2065 return false; 2066 2067 for (unsigned I = 0, N = X->size(); I != N; ++I) 2068 if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) 2069 return false; 2070 2071 return true; 2072 } 2073 2074 /// \brief Determine whether the two declarations refer to the same entity. 2075 static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { 2076 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); 2077 2078 if (X == Y) 2079 return true; 2080 2081 // Must be in the same context. 2082 if (!X->getDeclContext()->getRedeclContext()->Equals( 2083 Y->getDeclContext()->getRedeclContext())) 2084 return false; 2085 2086 // Two typedefs refer to the same entity if they have the same underlying 2087 // type. 2088 if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X)) 2089 if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y)) 2090 return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), 2091 TypedefY->getUnderlyingType()); 2092 2093 // Must have the same kind. 2094 if (X->getKind() != Y->getKind()) 2095 return false; 2096 2097 // Objective-C classes and protocols with the same name always match. 2098 if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) 2099 return true; 2100 2101 if (isa<ClassTemplateSpecializationDecl>(X)) { 2102 // No need to handle these here: we merge them when adding them to the 2103 // template. 2104 return false; 2105 } 2106 2107 // Compatible tags match. 2108 if (TagDecl *TagX = dyn_cast<TagDecl>(X)) { 2109 TagDecl *TagY = cast<TagDecl>(Y); 2110 return (TagX->getTagKind() == TagY->getTagKind()) || 2111 ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || 2112 TagX->getTagKind() == TTK_Interface) && 2113 (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || 2114 TagY->getTagKind() == TTK_Interface)); 2115 } 2116 2117 // Functions with the same type and linkage match. 2118 // FIXME: This needs to cope with function template specializations, 2119 // merging of prototyped/non-prototyped functions, etc. 2120 if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) { 2121 FunctionDecl *FuncY = cast<FunctionDecl>(Y); 2122 return (FuncX->getLinkageInternal() == FuncY->getLinkageInternal()) && 2123 FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType()); 2124 } 2125 2126 // Variables with the same type and linkage match. 2127 if (VarDecl *VarX = dyn_cast<VarDecl>(X)) { 2128 VarDecl *VarY = cast<VarDecl>(Y); 2129 return (VarX->getLinkageInternal() == VarY->getLinkageInternal()) && 2130 VarX->getASTContext().hasSameType(VarX->getType(), VarY->getType()); 2131 } 2132 2133 // Namespaces with the same name and inlinedness match. 2134 if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) { 2135 NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y); 2136 return NamespaceX->isInline() == NamespaceY->isInline(); 2137 } 2138 2139 // Identical template names and kinds match if their template parameter lists 2140 // and patterns match. 2141 if (TemplateDecl *TemplateX = dyn_cast<TemplateDecl>(X)) { 2142 TemplateDecl *TemplateY = cast<TemplateDecl>(Y); 2143 return isSameEntity(TemplateX->getTemplatedDecl(), 2144 TemplateY->getTemplatedDecl()) && 2145 isSameTemplateParameterList(TemplateX->getTemplateParameters(), 2146 TemplateY->getTemplateParameters()); 2147 } 2148 2149 // Fields with the same name and the same type match. 2150 if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) { 2151 FieldDecl *FDY = cast<FieldDecl>(Y); 2152 // FIXME: Diagnose if the types don't match. More generally, diagnose if we 2153 // get a declaration in a class definition that isn't in the canonical class 2154 // definition. 2155 // FIXME: Also check the bitwidth is odr-equivalent, if any. 2156 return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); 2157 } 2158 2159 // Enumerators with the same name match. 2160 if (isa<EnumConstantDecl>(X)) 2161 // FIXME: Also check the value is odr-equivalent. 2162 return true; 2163 2164 // Using shadow declarations with the same target match. 2165 if (UsingShadowDecl *USX = dyn_cast<UsingShadowDecl>(X)) { 2166 UsingShadowDecl *USY = cast<UsingShadowDecl>(Y); 2167 return USX->getTargetDecl() == USY->getTargetDecl(); 2168 } 2169 2170 // FIXME: Many other cases to implement. 2171 return false; 2172 } 2173 2174 /// Find the context in which we should search for previous declarations when 2175 /// looking for declarations to merge. 2176 static DeclContext *getPrimaryContextForMerging(DeclContext *DC) { 2177 if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC)) 2178 return ND->getOriginalNamespace(); 2179 2180 if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) 2181 return RD->getDefinition(); 2182 2183 if (EnumDecl *ED = dyn_cast<EnumDecl>(DC)) 2184 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() : 0; 2185 2186 return 0; 2187 } 2188 2189 ASTDeclReader::FindExistingResult::~FindExistingResult() { 2190 if (!AddResult || Existing) 2191 return; 2192 2193 DeclContext *DC = New->getDeclContext()->getRedeclContext(); 2194 if (DC->isTranslationUnit() && Reader.SemaObj) { 2195 Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, New->getDeclName()); 2196 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(DC)) { 2197 // Add the declaration to its redeclaration context so later merging 2198 // lookups will find it. 2199 MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); 2200 } 2201 } 2202 2203 ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { 2204 DeclarationName Name = D->getDeclName(); 2205 if (!Name) { 2206 // Don't bother trying to find unnamed declarations. 2207 FindExistingResult Result(Reader, D, /*Existing=*/0); 2208 Result.suppress(); 2209 return Result; 2210 } 2211 2212 // FIXME: Bail out for non-canonical declarations. We will have performed any 2213 // necessary merging already. 2214 2215 DeclContext *DC = D->getDeclContext()->getRedeclContext(); 2216 if (DC->isTranslationUnit() && Reader.SemaObj) { 2217 IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver; 2218 2219 // Temporarily consider the identifier to be up-to-date. We don't want to 2220 // cause additional lookups here. 2221 class UpToDateIdentifierRAII { 2222 IdentifierInfo *II; 2223 bool WasOutToDate; 2224 2225 public: 2226 explicit UpToDateIdentifierRAII(IdentifierInfo *II) 2227 : II(II), WasOutToDate(false) 2228 { 2229 if (II) { 2230 WasOutToDate = II->isOutOfDate(); 2231 if (WasOutToDate) 2232 II->setOutOfDate(false); 2233 } 2234 } 2235 2236 ~UpToDateIdentifierRAII() { 2237 if (WasOutToDate) 2238 II->setOutOfDate(true); 2239 } 2240 } UpToDate(Name.getAsIdentifierInfo()); 2241 2242 for (IdentifierResolver::iterator I = IdResolver.begin(Name), 2243 IEnd = IdResolver.end(); 2244 I != IEnd; ++I) { 2245 if (isSameEntity(*I, D)) 2246 return FindExistingResult(Reader, D, *I); 2247 } 2248 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(DC)) { 2249 DeclContext::lookup_result R = MergeDC->noload_lookup(Name); 2250 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { 2251 if (isSameEntity(*I, D)) 2252 return FindExistingResult(Reader, D, *I); 2253 } 2254 } else { 2255 // Not in a mergeable context. 2256 return FindExistingResult(Reader); 2257 } 2258 2259 // If this declaration is from a merged context, make a note that we need to 2260 // check that the canonical definition of that context contains the decl. 2261 if (Reader.MergedDeclContexts.count(D->getLexicalDeclContext())) 2262 Reader.PendingOdrMergeChecks.push_back(D); 2263 2264 return FindExistingResult(Reader, D, /*Existing=*/0); 2265 } 2266 2267 void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { 2268 assert(D && previous); 2269 if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 2270 TD->RedeclLink.setNext(cast<TagDecl>(previous)); 2271 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 2272 FD->RedeclLink.setNext(cast<FunctionDecl>(previous)); 2273 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { 2274 VD->RedeclLink.setNext(cast<VarDecl>(previous)); 2275 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) { 2276 TD->RedeclLink.setNext(cast<TypedefNameDecl>(previous)); 2277 } else if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D)) { 2278 USD->RedeclLink.setNext(cast<UsingShadowDecl>(previous)); 2279 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 2280 ID->RedeclLink.setNext(cast<ObjCInterfaceDecl>(previous)); 2281 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { 2282 PD->RedeclLink.setNext(cast<ObjCProtocolDecl>(previous)); 2283 } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) { 2284 ND->RedeclLink.setNext(cast<NamespaceDecl>(previous)); 2285 } else { 2286 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); 2287 TD->RedeclLink.setNext(cast<RedeclarableTemplateDecl>(previous)); 2288 } 2289 2290 // If the declaration was visible in one module, a redeclaration of it in 2291 // another module remains visible even if it wouldn't be visible by itself. 2292 // 2293 // FIXME: In this case, the declaration should only be visible if a module 2294 // that makes it visible has been imported. 2295 D->IdentifierNamespace |= 2296 previous->IdentifierNamespace & 2297 (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); 2298 } 2299 2300 void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { 2301 assert(D && Latest); 2302 if (TagDecl *TD = dyn_cast<TagDecl>(D)) { 2303 TD->RedeclLink 2304 = Redeclarable<TagDecl>::LatestDeclLink(cast<TagDecl>(Latest)); 2305 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { 2306 FD->RedeclLink 2307 = Redeclarable<FunctionDecl>::LatestDeclLink(cast<FunctionDecl>(Latest)); 2308 } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) { 2309 VD->RedeclLink 2310 = Redeclarable<VarDecl>::LatestDeclLink(cast<VarDecl>(Latest)); 2311 } else if (TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) { 2312 TD->RedeclLink 2313 = Redeclarable<TypedefNameDecl>::LatestDeclLink( 2314 cast<TypedefNameDecl>(Latest)); 2315 } else if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D)) { 2316 USD->RedeclLink 2317 = Redeclarable<UsingShadowDecl>::LatestDeclLink( 2318 cast<UsingShadowDecl>(Latest)); 2319 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) { 2320 ID->RedeclLink 2321 = Redeclarable<ObjCInterfaceDecl>::LatestDeclLink( 2322 cast<ObjCInterfaceDecl>(Latest)); 2323 } else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) { 2324 PD->RedeclLink 2325 = Redeclarable<ObjCProtocolDecl>::LatestDeclLink( 2326 cast<ObjCProtocolDecl>(Latest)); 2327 } else if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(D)) { 2328 ND->RedeclLink 2329 = Redeclarable<NamespaceDecl>::LatestDeclLink( 2330 cast<NamespaceDecl>(Latest)); 2331 } else { 2332 RedeclarableTemplateDecl *TD = cast<RedeclarableTemplateDecl>(D); 2333 TD->RedeclLink 2334 = Redeclarable<RedeclarableTemplateDecl>::LatestDeclLink( 2335 cast<RedeclarableTemplateDecl>(Latest)); 2336 } 2337 } 2338 2339 ASTReader::MergedDeclsMap::iterator 2340 ASTReader::combineStoredMergedDecls(Decl *Canon, GlobalDeclID CanonID) { 2341 // If we don't have any stored merged declarations, just look in the 2342 // merged declarations set. 2343 StoredMergedDeclsMap::iterator StoredPos = StoredMergedDecls.find(CanonID); 2344 if (StoredPos == StoredMergedDecls.end()) 2345 return MergedDecls.find(Canon); 2346 2347 // Append the stored merged declarations to the merged declarations set. 2348 MergedDeclsMap::iterator Pos = MergedDecls.find(Canon); 2349 if (Pos == MergedDecls.end()) 2350 Pos = MergedDecls.insert(std::make_pair(Canon, 2351 SmallVector<DeclID, 2>())).first; 2352 Pos->second.append(StoredPos->second.begin(), StoredPos->second.end()); 2353 StoredMergedDecls.erase(StoredPos); 2354 2355 // Sort and uniquify the set of merged declarations. 2356 llvm::array_pod_sort(Pos->second.begin(), Pos->second.end()); 2357 Pos->second.erase(std::unique(Pos->second.begin(), Pos->second.end()), 2358 Pos->second.end()); 2359 return Pos; 2360 } 2361 2362 /// \brief Read the declaration at the given offset from the AST file. 2363 Decl *ASTReader::ReadDeclRecord(DeclID ID) { 2364 unsigned Index = ID - NUM_PREDEF_DECL_IDS; 2365 unsigned RawLocation = 0; 2366 RecordLocation Loc = DeclCursorForID(ID, RawLocation); 2367 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; 2368 // Keep track of where we are in the stream, then jump back there 2369 // after reading this declaration. 2370 SavedStreamPosition SavedPosition(DeclsCursor); 2371 2372 ReadingKindTracker ReadingKind(Read_Decl, *this); 2373 2374 // Note that we are loading a declaration record. 2375 Deserializing ADecl(this); 2376 2377 DeclsCursor.JumpToBit(Loc.Offset); 2378 RecordData Record; 2379 unsigned Code = DeclsCursor.ReadCode(); 2380 unsigned Idx = 0; 2381 ASTDeclReader Reader(*this, *Loc.F, ID, RawLocation, Record,Idx); 2382 2383 Decl *D = 0; 2384 switch ((DeclCode)DeclsCursor.readRecord(Code, Record)) { 2385 case DECL_CONTEXT_LEXICAL: 2386 case DECL_CONTEXT_VISIBLE: 2387 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); 2388 case DECL_TYPEDEF: 2389 D = TypedefDecl::CreateDeserialized(Context, ID); 2390 break; 2391 case DECL_TYPEALIAS: 2392 D = TypeAliasDecl::CreateDeserialized(Context, ID); 2393 break; 2394 case DECL_ENUM: 2395 D = EnumDecl::CreateDeserialized(Context, ID); 2396 break; 2397 case DECL_RECORD: 2398 D = RecordDecl::CreateDeserialized(Context, ID); 2399 break; 2400 case DECL_ENUM_CONSTANT: 2401 D = EnumConstantDecl::CreateDeserialized(Context, ID); 2402 break; 2403 case DECL_FUNCTION: 2404 D = FunctionDecl::CreateDeserialized(Context, ID); 2405 break; 2406 case DECL_LINKAGE_SPEC: 2407 D = LinkageSpecDecl::CreateDeserialized(Context, ID); 2408 break; 2409 case DECL_LABEL: 2410 D = LabelDecl::CreateDeserialized(Context, ID); 2411 break; 2412 case DECL_NAMESPACE: 2413 D = NamespaceDecl::CreateDeserialized(Context, ID); 2414 break; 2415 case DECL_NAMESPACE_ALIAS: 2416 D = NamespaceAliasDecl::CreateDeserialized(Context, ID); 2417 break; 2418 case DECL_USING: 2419 D = UsingDecl::CreateDeserialized(Context, ID); 2420 break; 2421 case DECL_USING_SHADOW: 2422 D = UsingShadowDecl::CreateDeserialized(Context, ID); 2423 break; 2424 case DECL_USING_DIRECTIVE: 2425 D = UsingDirectiveDecl::CreateDeserialized(Context, ID); 2426 break; 2427 case DECL_UNRESOLVED_USING_VALUE: 2428 D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); 2429 break; 2430 case DECL_UNRESOLVED_USING_TYPENAME: 2431 D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); 2432 break; 2433 case DECL_CXX_RECORD: 2434 D = CXXRecordDecl::CreateDeserialized(Context, ID); 2435 break; 2436 case DECL_CXX_METHOD: 2437 D = CXXMethodDecl::CreateDeserialized(Context, ID); 2438 break; 2439 case DECL_CXX_CONSTRUCTOR: 2440 D = CXXConstructorDecl::CreateDeserialized(Context, ID); 2441 break; 2442 case DECL_CXX_DESTRUCTOR: 2443 D = CXXDestructorDecl::CreateDeserialized(Context, ID); 2444 break; 2445 case DECL_CXX_CONVERSION: 2446 D = CXXConversionDecl::CreateDeserialized(Context, ID); 2447 break; 2448 case DECL_ACCESS_SPEC: 2449 D = AccessSpecDecl::CreateDeserialized(Context, ID); 2450 break; 2451 case DECL_FRIEND: 2452 D = FriendDecl::CreateDeserialized(Context, ID, Record[Idx++]); 2453 break; 2454 case DECL_FRIEND_TEMPLATE: 2455 D = FriendTemplateDecl::CreateDeserialized(Context, ID); 2456 break; 2457 case DECL_CLASS_TEMPLATE: 2458 D = ClassTemplateDecl::CreateDeserialized(Context, ID); 2459 break; 2460 case DECL_CLASS_TEMPLATE_SPECIALIZATION: 2461 D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); 2462 break; 2463 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: 2464 D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); 2465 break; 2466 case DECL_VAR_TEMPLATE: 2467 D = VarTemplateDecl::CreateDeserialized(Context, ID); 2468 break; 2469 case DECL_VAR_TEMPLATE_SPECIALIZATION: 2470 D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); 2471 break; 2472 case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: 2473 D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); 2474 break; 2475 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: 2476 D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); 2477 break; 2478 case DECL_FUNCTION_TEMPLATE: 2479 D = FunctionTemplateDecl::CreateDeserialized(Context, ID); 2480 break; 2481 case DECL_TEMPLATE_TYPE_PARM: 2482 D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); 2483 break; 2484 case DECL_NON_TYPE_TEMPLATE_PARM: 2485 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); 2486 break; 2487 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: 2488 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, Record[Idx++]); 2489 break; 2490 case DECL_TEMPLATE_TEMPLATE_PARM: 2491 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); 2492 break; 2493 case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: 2494 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, 2495 Record[Idx++]); 2496 break; 2497 case DECL_TYPE_ALIAS_TEMPLATE: 2498 D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); 2499 break; 2500 case DECL_STATIC_ASSERT: 2501 D = StaticAssertDecl::CreateDeserialized(Context, ID); 2502 break; 2503 case DECL_OBJC_METHOD: 2504 D = ObjCMethodDecl::CreateDeserialized(Context, ID); 2505 break; 2506 case DECL_OBJC_INTERFACE: 2507 D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); 2508 break; 2509 case DECL_OBJC_IVAR: 2510 D = ObjCIvarDecl::CreateDeserialized(Context, ID); 2511 break; 2512 case DECL_OBJC_PROTOCOL: 2513 D = ObjCProtocolDecl::CreateDeserialized(Context, ID); 2514 break; 2515 case DECL_OBJC_AT_DEFS_FIELD: 2516 D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); 2517 break; 2518 case DECL_OBJC_CATEGORY: 2519 D = ObjCCategoryDecl::CreateDeserialized(Context, ID); 2520 break; 2521 case DECL_OBJC_CATEGORY_IMPL: 2522 D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); 2523 break; 2524 case DECL_OBJC_IMPLEMENTATION: 2525 D = ObjCImplementationDecl::CreateDeserialized(Context, ID); 2526 break; 2527 case DECL_OBJC_COMPATIBLE_ALIAS: 2528 D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); 2529 break; 2530 case DECL_OBJC_PROPERTY: 2531 D = ObjCPropertyDecl::CreateDeserialized(Context, ID); 2532 break; 2533 case DECL_OBJC_PROPERTY_IMPL: 2534 D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); 2535 break; 2536 case DECL_FIELD: 2537 D = FieldDecl::CreateDeserialized(Context, ID); 2538 break; 2539 case DECL_INDIRECTFIELD: 2540 D = IndirectFieldDecl::CreateDeserialized(Context, ID); 2541 break; 2542 case DECL_VAR: 2543 D = VarDecl::CreateDeserialized(Context, ID); 2544 break; 2545 case DECL_IMPLICIT_PARAM: 2546 D = ImplicitParamDecl::CreateDeserialized(Context, ID); 2547 break; 2548 case DECL_PARM_VAR: 2549 D = ParmVarDecl::CreateDeserialized(Context, ID); 2550 break; 2551 case DECL_FILE_SCOPE_ASM: 2552 D = FileScopeAsmDecl::CreateDeserialized(Context, ID); 2553 break; 2554 case DECL_BLOCK: 2555 D = BlockDecl::CreateDeserialized(Context, ID); 2556 break; 2557 case DECL_MS_PROPERTY: 2558 D = MSPropertyDecl::CreateDeserialized(Context, ID); 2559 break; 2560 case DECL_CAPTURED: 2561 D = CapturedDecl::CreateDeserialized(Context, ID, Record[Idx++]); 2562 break; 2563 case DECL_CXX_BASE_SPECIFIERS: 2564 Error("attempt to read a C++ base-specifier record as a declaration"); 2565 return 0; 2566 case DECL_IMPORT: 2567 // Note: last entry of the ImportDecl record is the number of stored source 2568 // locations. 2569 D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); 2570 break; 2571 case DECL_OMP_THREADPRIVATE: 2572 D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record[Idx++]); 2573 break; 2574 case DECL_EMPTY: 2575 D = EmptyDecl::CreateDeserialized(Context, ID); 2576 break; 2577 } 2578 2579 assert(D && "Unknown declaration reading AST file"); 2580 LoadedDecl(Index, D); 2581 // Set the DeclContext before doing any deserialization, to make sure internal 2582 // calls to Decl::getASTContext() by Decl's methods will find the 2583 // TranslationUnitDecl without crashing. 2584 D->setDeclContext(Context.getTranslationUnitDecl()); 2585 Reader.Visit(D); 2586 2587 // If this declaration is also a declaration context, get the 2588 // offsets for its tables of lexical and visible declarations. 2589 if (DeclContext *DC = dyn_cast<DeclContext>(D)) { 2590 // FIXME: This should really be 2591 // DeclContext *LookupDC = DC->getPrimaryContext(); 2592 // but that can walk the redeclaration chain, which might not work yet. 2593 DeclContext *LookupDC = DC; 2594 if (isa<NamespaceDecl>(DC)) 2595 LookupDC = DC->getPrimaryContext(); 2596 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); 2597 if (Offsets.first || Offsets.second) { 2598 if (Offsets.first != 0) 2599 DC->setHasExternalLexicalStorage(true); 2600 if (Offsets.second != 0) 2601 LookupDC->setHasExternalVisibleStorage(true); 2602 if (ReadDeclContextStorage(*Loc.F, DeclsCursor, Offsets, 2603 Loc.F->DeclContextInfos[DC])) 2604 return 0; 2605 } 2606 2607 // Now add the pending visible updates for this decl context, if it has any. 2608 DeclContextVisibleUpdatesPending::iterator I = 2609 PendingVisibleUpdates.find(ID); 2610 if (I != PendingVisibleUpdates.end()) { 2611 // There are updates. This means the context has external visible 2612 // storage, even if the original stored version didn't. 2613 LookupDC->setHasExternalVisibleStorage(true); 2614 for (const auto &Update : I->second) { 2615 DeclContextInfo &Info = Update.second->DeclContextInfos[DC]; 2616 delete Info.NameLookupTableData; 2617 Info.NameLookupTableData = Update.first; 2618 } 2619 PendingVisibleUpdates.erase(I); 2620 } 2621 } 2622 assert(Idx == Record.size()); 2623 2624 // Load any relevant update records. 2625 loadDeclUpdateRecords(ID, D); 2626 2627 // Load the categories after recursive loading is finished. 2628 if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D)) 2629 if (Class->isThisDeclarationADefinition()) 2630 loadObjCCategories(ID, Class); 2631 2632 // If we have deserialized a declaration that has a definition the 2633 // AST consumer might need to know about, queue it. 2634 // We don't pass it to the consumer immediately because we may be in recursive 2635 // loading, and some declarations may still be initializing. 2636 if (isConsumerInterestedIn(D, Reader.hasPendingBody())) 2637 InterestingDecls.push_back(D); 2638 2639 return D; 2640 } 2641 2642 void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) { 2643 // The declaration may have been modified by files later in the chain. 2644 // If this is the case, read the record containing the updates from each file 2645 // and pass it to ASTDeclReader to make the modifications. 2646 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); 2647 if (UpdI != DeclUpdateOffsets.end()) { 2648 FileOffsetsTy &UpdateOffsets = UpdI->second; 2649 bool WasInteresting = isConsumerInterestedIn(D, false); 2650 for (FileOffsetsTy::iterator 2651 I = UpdateOffsets.begin(), E = UpdateOffsets.end(); I != E; ++I) { 2652 ModuleFile *F = I->first; 2653 uint64_t Offset = I->second; 2654 llvm::BitstreamCursor &Cursor = F->DeclsCursor; 2655 SavedStreamPosition SavedPosition(Cursor); 2656 Cursor.JumpToBit(Offset); 2657 RecordData Record; 2658 unsigned Code = Cursor.ReadCode(); 2659 unsigned RecCode = Cursor.readRecord(Code, Record); 2660 (void)RecCode; 2661 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!"); 2662 2663 unsigned Idx = 0; 2664 ASTDeclReader Reader(*this, *F, ID, 0, Record, Idx); 2665 Reader.UpdateDecl(D, *F, Record); 2666 2667 // We might have made this declaration interesting. If so, remember that 2668 // we need to hand it off to the consumer. 2669 if (!WasInteresting && 2670 isConsumerInterestedIn(D, Reader.hasPendingBody())) { 2671 InterestingDecls.push_back(D); 2672 WasInteresting = true; 2673 } 2674 } 2675 } 2676 } 2677 2678 namespace { 2679 /// \brief Module visitor class that finds all of the redeclarations of a 2680 /// 2681 class RedeclChainVisitor { 2682 ASTReader &Reader; 2683 SmallVectorImpl<DeclID> &SearchDecls; 2684 llvm::SmallPtrSet<Decl *, 16> &Deserialized; 2685 GlobalDeclID CanonID; 2686 SmallVector<Decl *, 4> Chain; 2687 2688 public: 2689 RedeclChainVisitor(ASTReader &Reader, SmallVectorImpl<DeclID> &SearchDecls, 2690 llvm::SmallPtrSet<Decl *, 16> &Deserialized, 2691 GlobalDeclID CanonID) 2692 : Reader(Reader), SearchDecls(SearchDecls), Deserialized(Deserialized), 2693 CanonID(CanonID) { 2694 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I) 2695 addToChain(Reader.GetDecl(SearchDecls[I])); 2696 } 2697 2698 static bool visit(ModuleFile &M, bool Preorder, void *UserData) { 2699 if (Preorder) 2700 return false; 2701 2702 return static_cast<RedeclChainVisitor *>(UserData)->visit(M); 2703 } 2704 2705 void addToChain(Decl *D) { 2706 if (!D) 2707 return; 2708 2709 if (Deserialized.erase(D)) 2710 Chain.push_back(D); 2711 } 2712 2713 void searchForID(ModuleFile &M, GlobalDeclID GlobalID) { 2714 // Map global ID of the first declaration down to the local ID 2715 // used in this module file. 2716 DeclID ID = Reader.mapGlobalIDToModuleFileGlobalID(M, GlobalID); 2717 if (!ID) 2718 return; 2719 2720 // Perform a binary search to find the local redeclarations for this 2721 // declaration (if any). 2722 const LocalRedeclarationsInfo Compare = { ID, 0 }; 2723 const LocalRedeclarationsInfo *Result 2724 = std::lower_bound(M.RedeclarationsMap, 2725 M.RedeclarationsMap + M.LocalNumRedeclarationsInMap, 2726 Compare); 2727 if (Result == M.RedeclarationsMap + M.LocalNumRedeclarationsInMap || 2728 Result->FirstID != ID) { 2729 // If we have a previously-canonical singleton declaration that was 2730 // merged into another redeclaration chain, create a trivial chain 2731 // for this single declaration so that it will get wired into the 2732 // complete redeclaration chain. 2733 if (GlobalID != CanonID && 2734 GlobalID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && 2735 GlobalID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls) { 2736 addToChain(Reader.GetDecl(GlobalID)); 2737 } 2738 2739 return; 2740 } 2741 2742 // Dig out all of the redeclarations. 2743 unsigned Offset = Result->Offset; 2744 unsigned N = M.RedeclarationChains[Offset]; 2745 M.RedeclarationChains[Offset++] = 0; // Don't try to deserialize again 2746 for (unsigned I = 0; I != N; ++I) 2747 addToChain(Reader.GetLocalDecl(M, M.RedeclarationChains[Offset++])); 2748 } 2749 2750 bool visit(ModuleFile &M) { 2751 // Visit each of the declarations. 2752 for (unsigned I = 0, N = SearchDecls.size(); I != N; ++I) 2753 searchForID(M, SearchDecls[I]); 2754 return false; 2755 } 2756 2757 ArrayRef<Decl *> getChain() const { 2758 return Chain; 2759 } 2760 }; 2761 } 2762 2763 void ASTReader::loadPendingDeclChain(serialization::GlobalDeclID ID) { 2764 Decl *D = GetDecl(ID); 2765 Decl *CanonDecl = D->getCanonicalDecl(); 2766 2767 // Determine the set of declaration IDs we'll be searching for. 2768 SmallVector<DeclID, 1> SearchDecls; 2769 GlobalDeclID CanonID = 0; 2770 if (D == CanonDecl) { 2771 SearchDecls.push_back(ID); // Always first. 2772 CanonID = ID; 2773 } 2774 MergedDeclsMap::iterator MergedPos = combineStoredMergedDecls(CanonDecl, ID); 2775 if (MergedPos != MergedDecls.end()) 2776 SearchDecls.append(MergedPos->second.begin(), MergedPos->second.end()); 2777 2778 // Build up the list of redeclarations. 2779 RedeclChainVisitor Visitor(*this, SearchDecls, RedeclsDeserialized, CanonID); 2780 ModuleMgr.visitDepthFirst(&RedeclChainVisitor::visit, &Visitor); 2781 2782 // Retrieve the chains. 2783 ArrayRef<Decl *> Chain = Visitor.getChain(); 2784 if (Chain.empty()) 2785 return; 2786 2787 // Hook up the chains. 2788 Decl *MostRecent = CanonDecl->getMostRecentDecl(); 2789 for (unsigned I = 0, N = Chain.size(); I != N; ++I) { 2790 if (Chain[I] == CanonDecl) 2791 continue; 2792 2793 ASTDeclReader::attachPreviousDecl(Chain[I], MostRecent); 2794 MostRecent = Chain[I]; 2795 } 2796 2797 ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); 2798 } 2799 2800 namespace { 2801 /// \brief Given an ObjC interface, goes through the modules and links to the 2802 /// interface all the categories for it. 2803 class ObjCCategoriesVisitor { 2804 ASTReader &Reader; 2805 serialization::GlobalDeclID InterfaceID; 2806 ObjCInterfaceDecl *Interface; 2807 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> &Deserialized; 2808 unsigned PreviousGeneration; 2809 ObjCCategoryDecl *Tail; 2810 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; 2811 2812 void add(ObjCCategoryDecl *Cat) { 2813 // Only process each category once. 2814 if (!Deserialized.erase(Cat)) 2815 return; 2816 2817 // Check for duplicate categories. 2818 if (Cat->getDeclName()) { 2819 ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; 2820 if (Existing && 2821 Reader.getOwningModuleFile(Existing) 2822 != Reader.getOwningModuleFile(Cat)) { 2823 // FIXME: We should not warn for duplicates in diamond: 2824 // 2825 // MT // 2826 // / \ // 2827 // ML MR // 2828 // \ / // 2829 // MB // 2830 // 2831 // If there are duplicates in ML/MR, there will be warning when 2832 // creating MB *and* when importing MB. We should not warn when 2833 // importing. 2834 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) 2835 << Interface->getDeclName() << Cat->getDeclName(); 2836 Reader.Diag(Existing->getLocation(), diag::note_previous_definition); 2837 } else if (!Existing) { 2838 // Record this category. 2839 Existing = Cat; 2840 } 2841 } 2842 2843 // Add this category to the end of the chain. 2844 if (Tail) 2845 ASTDeclReader::setNextObjCCategory(Tail, Cat); 2846 else 2847 Interface->setCategoryListRaw(Cat); 2848 Tail = Cat; 2849 } 2850 2851 public: 2852 ObjCCategoriesVisitor(ASTReader &Reader, 2853 serialization::GlobalDeclID InterfaceID, 2854 ObjCInterfaceDecl *Interface, 2855 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> &Deserialized, 2856 unsigned PreviousGeneration) 2857 : Reader(Reader), InterfaceID(InterfaceID), Interface(Interface), 2858 Deserialized(Deserialized), PreviousGeneration(PreviousGeneration), 2859 Tail(0) 2860 { 2861 // Populate the name -> category map with the set of known categories. 2862 for (auto *Cat : Interface->known_categories()) { 2863 if (Cat->getDeclName()) 2864 NameCategoryMap[Cat->getDeclName()] = Cat; 2865 2866 // Keep track of the tail of the category list. 2867 Tail = Cat; 2868 } 2869 } 2870 2871 static bool visit(ModuleFile &M, void *UserData) { 2872 return static_cast<ObjCCategoriesVisitor *>(UserData)->visit(M); 2873 } 2874 2875 bool visit(ModuleFile &M) { 2876 // If we've loaded all of the category information we care about from 2877 // this module file, we're done. 2878 if (M.Generation <= PreviousGeneration) 2879 return true; 2880 2881 // Map global ID of the definition down to the local ID used in this 2882 // module file. If there is no such mapping, we'll find nothing here 2883 // (or in any module it imports). 2884 DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); 2885 if (!LocalID) 2886 return true; 2887 2888 // Perform a binary search to find the local redeclarations for this 2889 // declaration (if any). 2890 const ObjCCategoriesInfo Compare = { LocalID, 0 }; 2891 const ObjCCategoriesInfo *Result 2892 = std::lower_bound(M.ObjCCategoriesMap, 2893 M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, 2894 Compare); 2895 if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || 2896 Result->DefinitionID != LocalID) { 2897 // We didn't find anything. If the class definition is in this module 2898 // file, then the module files it depends on cannot have any categories, 2899 // so suppress further lookup. 2900 return Reader.isDeclIDFromModule(InterfaceID, M); 2901 } 2902 2903 // We found something. Dig out all of the categories. 2904 unsigned Offset = Result->Offset; 2905 unsigned N = M.ObjCCategories[Offset]; 2906 M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again 2907 for (unsigned I = 0; I != N; ++I) 2908 add(cast_or_null<ObjCCategoryDecl>( 2909 Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); 2910 return true; 2911 } 2912 }; 2913 } 2914 2915 void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, 2916 ObjCInterfaceDecl *D, 2917 unsigned PreviousGeneration) { 2918 ObjCCategoriesVisitor Visitor(*this, ID, D, CategoriesDeserialized, 2919 PreviousGeneration); 2920 ModuleMgr.visit(ObjCCategoriesVisitor::visit, &Visitor); 2921 } 2922 2923 void ASTDeclReader::UpdateDecl(Decl *D, ModuleFile &ModuleFile, 2924 const RecordData &Record) { 2925 unsigned Idx = 0; 2926 while (Idx < Record.size()) { 2927 switch ((DeclUpdateKind)Record[Idx++]) { 2928 case UPD_CXX_ADDED_IMPLICIT_MEMBER: 2929 cast<CXXRecordDecl>(D)->addedMember(Reader.ReadDecl(ModuleFile, Record, Idx)); 2930 break; 2931 2932 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: 2933 // It will be added to the template's specializations set when loaded. 2934 (void)Reader.ReadDecl(ModuleFile, Record, Idx); 2935 break; 2936 2937 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { 2938 NamespaceDecl *Anon 2939 = Reader.ReadDeclAs<NamespaceDecl>(ModuleFile, Record, Idx); 2940 2941 // Each module has its own anonymous namespace, which is disjoint from 2942 // any other module's anonymous namespaces, so don't attach the anonymous 2943 // namespace at all. 2944 if (ModuleFile.Kind != MK_Module) { 2945 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D)) 2946 TU->setAnonymousNamespace(Anon); 2947 else 2948 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); 2949 } 2950 break; 2951 } 2952 2953 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER: 2954 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation( 2955 Reader.ReadSourceLocation(ModuleFile, Record, Idx)); 2956 break; 2957 2958 case UPD_CXX_INSTANTIATED_FUNCTION_DEFINITION: { 2959 FunctionDecl *FD = cast<FunctionDecl>(D); 2960 if (Reader.PendingBodies[FD]) 2961 // FIXME: Maybe check for ODR violations. 2962 break; 2963 2964 if (Record[Idx++]) 2965 FD->setImplicitlyInline(); 2966 FD->setInnerLocStart(Reader.ReadSourceLocation(ModuleFile, Record, Idx)); 2967 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) 2968 std::tie(CD->CtorInitializers, CD->NumCtorInitializers) = 2969 Reader.ReadCXXCtorInitializers(ModuleFile, Record, Idx); 2970 // Store the offset of the body so we can lazily load it later. 2971 Reader.PendingBodies[FD] = GetCurrentCursorOffset(); 2972 HasPendingBody = true; 2973 assert(Idx == Record.size() && "lazy body must be last"); 2974 break; 2975 } 2976 2977 case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { 2978 auto *FD = cast<FunctionDecl>(D); 2979 auto *FPT = FD->getType()->castAs<FunctionProtoType>(); 2980 auto EPI = FPT->getExtProtoInfo(); 2981 SmallVector<QualType, 8> ExceptionStorage; 2982 Reader.readExceptionSpec(ModuleFile, ExceptionStorage, EPI, Record, Idx); 2983 FD->setType(Reader.Context.getFunctionType(FPT->getReturnType(), 2984 FPT->getParamTypes(), EPI)); 2985 break; 2986 } 2987 2988 case UPD_CXX_DEDUCED_RETURN_TYPE: { 2989 FunctionDecl *FD = cast<FunctionDecl>(D); 2990 Reader.Context.adjustDeducedFunctionResultType( 2991 FD, Reader.readType(ModuleFile, Record, Idx)); 2992 break; 2993 } 2994 2995 case UPD_DECL_MARKED_USED: { 2996 // FIXME: This doesn't send the right notifications if there are 2997 // ASTMutationListeners other than an ASTWriter. 2998 D->Used = true; 2999 break; 3000 } 3001 3002 case UPD_MANGLING_NUMBER: 3003 Reader.Context.setManglingNumber(cast<NamedDecl>(D), Record[Idx++]); 3004 break; 3005 3006 case UPD_STATIC_LOCAL_NUMBER: 3007 Reader.Context.setStaticLocalNumber(cast<VarDecl>(D), Record[Idx++]); 3008 break; 3009 } 3010 } 3011 } 3012