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