From 9c1755c55509f38c256b7f0191b01d674b7cb619 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 18 Jun 2024 11:28:03 +0800 Subject: [PATCH] Draft --- .../include/clang/Serialization/ASTBitCodes.h | 3 + clang/include/clang/Serialization/ASTReader.h | 10 +- .../clang/Serialization/ASTRecordReader.h | 15 ++ .../clang/Serialization/ASTRecordWriter.h | 28 +++ clang/lib/Serialization/ASTReader.cpp | 159 ++++++++-------- clang/lib/Serialization/ASTReaderDecl.cpp | 29 +-- clang/lib/Serialization/ASTReaderStmt.cpp | 5 +- clang/lib/Serialization/ASTWriter.cpp | 29 ++- clang/lib/Serialization/ASTWriterDecl.cpp | 169 ++++++++++++------ clang/utils/TableGen/ClangAttrEmitter.cpp | 4 +- 10 files changed, 280 insertions(+), 171 deletions(-) diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index a4728b1c06b3fe..d1f8545052fe88 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -261,6 +261,9 @@ using unaligned_decl_id_t = serialization::DeclID, llvm::endianness::native, llvm::support::unaligned>; +/// The number of slots needed to record a DeclID in bitstreams. +const unsigned int DeclIDRefSize = 2; + /// The number of predefined preprocessed entity IDs. const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1; diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 08f302c01f5387..c6c4a82bcddeca 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -599,7 +599,7 @@ class ASTReader /// An array of lexical contents of a declaration context, as a sequence of /// Decl::Kind, DeclID pairs. - using LexicalContents = ArrayRef; + using LexicalContents = ArrayRef; /// Map from a DeclContext to its lexical contents. llvm::DenseMap> @@ -960,7 +960,7 @@ class ASTReader SmallVector DelayedDeleteExprs; // A list of late parsed template function data with their module files. - SmallVector>, 4> + SmallVector, 4> LateParsedTemplates; /// The IDs of all decls to be checked for deferred diags. @@ -1955,12 +1955,12 @@ class ASTReader /// given module. /// /// \returns The declaration ID read from the record, adjusted to a global ID. - GlobalDeclID ReadDeclID(ModuleFile &F, const RecordData &Record, + GlobalDeclID ReadDeclID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx); /// Reads a declaration from the given position in a record in the /// given module. - Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) { + Decl *ReadDecl(ModuleFile &F, const RecordDataImpl &R, unsigned &I) { return GetDecl(ReadDeclID(F, R, I)); } @@ -1970,7 +1970,7 @@ class ASTReader /// \returns The declaration read from this location, casted to the given /// result type. template - T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) { + T *ReadDeclAs(ModuleFile &F, const RecordDataImpl &R, unsigned &I) { return cast_or_null(GetDecl(ReadDeclID(F, R, I))); } diff --git a/clang/include/clang/Serialization/ASTRecordReader.h b/clang/include/clang/Serialization/ASTRecordReader.h index d00fb182f05f4e..6a5d11f84cea7d 100644 --- a/clang/include/clang/Serialization/ASTRecordReader.h +++ b/clang/include/clang/Serialization/ASTRecordReader.h @@ -187,12 +187,27 @@ class ASTRecordReader /// Reads a declaration from the given position in a record in the /// given module, advancing Idx. Decl *readDecl() { +#ifndef NDEBUG + unsigned OldIdx = Idx; + Decl *D = Reader->ReadDecl(*F, Record, Idx); + assert(Idx - OldIdx == serialization::DeclIDRefSize); + return D; +#endif return Reader->ReadDecl(*F, Record, Idx); } Decl *readDeclRef() { return readDecl(); } + template + void readDeclArray(Func &&ConsumeFunc) { + unsigned LengthOfArray = readInt(); + unsigned End = Idx + LengthOfArray; + + while (Idx < End) + ConsumeFunc(readDeclAs()); + } + /// Reads a declaration from the given position in the record, /// advancing Idx. /// diff --git a/clang/include/clang/Serialization/ASTRecordWriter.h b/clang/include/clang/Serialization/ASTRecordWriter.h index 0c8ac75fc40f40..2e8c93c37a21a1 100644 --- a/clang/include/clang/Serialization/ASTRecordWriter.h +++ b/clang/include/clang/Serialization/ASTRecordWriter.h @@ -234,12 +234,40 @@ class ASTRecordWriter /// Emit a reference to a declaration. void AddDeclRef(const Decl *D) { +#ifndef NDEBUG + unsigned OldSize = size(); + Writer->AddDeclRef(D, *Record); + assert(size() - OldSize == serialization::DeclIDRefSize); + return; +#endif return Writer->AddDeclRef(D, *Record); } void writeDeclRef(const Decl *D) { AddDeclRef(D); } + void writeNullDeclRef() { +#ifndef NDEBUG + unsigned OldSize = size(); +#endif + + push_back(0); + push_back(0); + +#ifndef NDEBUG + assert(size() - OldSize == serialization::DeclIDRefSize); +#endif + } + + template + void writeDeclArray(ArrayRef Array) { + unsigned ElementNum = Array.size(); + push_back(ElementNum * serialization::DeclIDRefSize); + + for (DeclKind *D : Array) + AddDeclRef(D); + } + /// Emit a declaration name. void AddDeclarationName(DeclarationName Name) { writeDeclarationName(Name); diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index a2c322087fd1ed..22d3bae087392f 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1266,8 +1266,8 @@ bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, if (!Lex.first) { Lex = std::make_pair( &M, llvm::ArrayRef( - reinterpret_cast(Blob.data()), - Blob.size() / sizeof(DeclID))); + reinterpret_cast(Blob.data()), + Blob.size() / sizeof(uint32_t))); } DC->setHasExternalLexicalStorage(true); return false; @@ -3388,8 +3388,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, case TU_UPDATE_LEXICAL: { DeclContext *TU = ContextObj->getTranslationUnitDecl(); LexicalContents Contents( - reinterpret_cast(Blob.data()), - static_cast(Blob.size() / sizeof(DeclID))); + reinterpret_cast(Blob.data()), + static_cast(Blob.size() / sizeof(uint32_t))); TULexicalDecls.push_back(std::make_pair(&F, Contents)); TU->setHasExternalLexicalStorage(true); break; @@ -3457,9 +3457,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, case EAGERLY_DESERIALIZED_DECLS: // FIXME: Skip reading this record if our ASTConsumer doesn't care // about "interesting" decls (for instance, if we're building a module). - for (unsigned I = 0, N = Record.size(); I != N; ++I) - EagerlyDeserializedDecls.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + EagerlyDeserializedDecls.push_back(ReadDeclID(F, Record, I)); break; case MODULAR_CODEGEN_DECLS: @@ -3467,9 +3466,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, // them (ie: if we're not codegenerating this module). if (F.Kind == MK_MainFile || getContext().getLangOpts().BuildingPCHWithObjectFile) - for (unsigned I = 0, N = Record.size(); I != N; ++I) - EagerlyDeserializedDecls.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + EagerlyDeserializedDecls.push_back(ReadDeclID(F, Record, I)); break; case SPECIAL_TYPES: @@ -3500,15 +3498,13 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, break; case UNUSED_FILESCOPED_DECLS: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - UnusedFileScopedDecls.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + UnusedFileScopedDecls.push_back(ReadDeclID(F, Record, I)); break; case DELEGATING_CTORS: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - DelegatingCtorDecls.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + DelegatingCtorDecls.push_back(ReadDeclID(F, Record, I)); break; case WEAK_UNDECLARED_IDENTIFIERS: @@ -3674,48 +3670,47 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, break; case EXT_VECTOR_DECLS: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - ExtVectorDecls.push_back(getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + ExtVectorDecls.push_back(ReadDeclID(F, Record, I)); break; case VTABLE_USES: - if (Record.size() % 3 != 0) - return llvm::createStringError(std::errc::illegal_byte_sequence, - "Invalid VTABLE_USES record"); - // Later tables overwrite earlier ones. // FIXME: Modules will have some trouble with this. This is clearly not // the right way to do this. VTableUses.clear(); for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { + if (Idx > N) + return llvm::createStringError(std::errc::illegal_byte_sequence, + "Invalid VTABLE_USES record"); + VTableUses.push_back( - {getGlobalDeclID(F, LocalDeclID(Record[Idx++])), + {ReadDeclID(F, Record, Idx), ReadSourceLocation(F, Record, Idx).getRawEncoding(), (bool)Record[Idx++]}); } break; case PENDING_IMPLICIT_INSTANTIATIONS: - - if (Record.size() % 2 != 0) - return llvm::createStringError( + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + if (I > N) + return llvm::createStringError( std::errc::illegal_byte_sequence, "Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); - for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { PendingInstantiations.push_back( - {getGlobalDeclID(F, LocalDeclID(Record[I++])), + {ReadDeclID(F, Record, I), ReadSourceLocation(F, Record, I).getRawEncoding()}); } break; case SEMA_DECL_REFS: - if (Record.size() != 3) + if (Record.size() != 3 * serialization::DeclIDRefSize) return llvm::createStringError(std::errc::illegal_byte_sequence, "Invalid SEMA_DECL_REFS block"); - for (unsigned I = 0, N = Record.size(); I != N; ++I) - SemaDeclRefs.push_back(getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + SemaDeclRefs.push_back(ReadDeclID(F, Record, I)); break; case PPD_ENTITIES_OFFSETS: { @@ -3769,13 +3764,14 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, } case DECL_UPDATE_OFFSETS: - if (Record.size() % 2 != 0) - return llvm::createStringError( + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + if (I > N) + return llvm::createStringError( std::errc::illegal_byte_sequence, "invalid DECL_UPDATE_OFFSETS block in AST file"); - for (unsigned I = 0, N = Record.size(); I != N; I += 2) { - GlobalDeclID ID = getGlobalDeclID(F, LocalDeclID(Record[I])); - DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); + + GlobalDeclID ID = ReadDeclID(F, Record, I); + DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I++])); // If we've already loaded the decl, perform the updates when we finish // loading this block. @@ -3786,18 +3782,22 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, break; case DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD: { - if (Record.size() % 3 != 0) - return llvm::createStringError( + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + if (I > N) + return llvm::createStringError( std::errc::illegal_byte_sequence, "invalid DELAYED_NAMESPACE_LEXICAL_VISIBLE_RECORD block in AST " "file"); - for (unsigned I = 0, N = Record.size(); I != N; I += 3) { - GlobalDeclID ID = getGlobalDeclID(F, LocalDeclID(Record[I])); + + GlobalDeclID ID = ReadDeclID(F, Record, I); uint64_t BaseOffset = F.DeclsBlockStartOffset; assert(BaseOffset && "Invalid DeclsBlockStartOffset for module file!"); - uint64_t LexicalOffset = Record[I + 1] ? BaseOffset + Record[I + 1] : 0; - uint64_t VisibleOffset = Record[I + 2] ? BaseOffset + Record[I + 2] : 0; + + uint64_t LocalLexicalOffset = Record[I++]; + uint64_t LexicalOffset = LocalLexicalOffset ? BaseOffset + LocalLexicalOffset : 0; + uint64_t LocalVisibleOffset = Record[I++]; + uint64_t VisibleOffset = LocalVisibleOffset ? BaseOffset + LocalVisibleOffset : 0; DelayedNamespaceOffsetMap[ID] = {LexicalOffset, VisibleOffset}; @@ -3826,9 +3826,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, // Later tables overwrite earlier ones. // FIXME: Modules will have trouble with this. CUDASpecialDeclRefs.clear(); - for (unsigned I = 0, N = Record.size(); I != N; ++I) - CUDASpecialDeclRefs.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + CUDASpecialDeclRefs.push_back(ReadDeclID(F, Record, I)); break; case HEADER_SEARCH_TABLE: @@ -3868,31 +3867,30 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, break; case TENTATIVE_DEFINITIONS: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - TentativeDefinitions.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + TentativeDefinitions.push_back(ReadDeclID(F, Record, I)); break; case KNOWN_NAMESPACES: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - KnownNamespaces.push_back(getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + KnownNamespaces.push_back(ReadDeclID(F, Record, I)); break; case UNDEFINED_BUT_USED: - if (Record.size() % 2 != 0) - return llvm::createStringError(std::errc::illegal_byte_sequence, - "invalid undefined-but-used record"); for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + if (I > N) + return llvm::createStringError(std::errc::illegal_byte_sequence, + "invalid undefined-but-used record"); + UndefinedButUsed.push_back( - {getGlobalDeclID(F, LocalDeclID(Record[I++])), + {ReadDeclID(F, Record, I), ReadSourceLocation(F, Record, I).getRawEncoding()}); } break; case DELETE_EXPRS_TO_ANALYZE: - for (unsigned I = 0, N = Record.size(); I != N;) { - DelayedDeleteExprs.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I++])).get()); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { + DelayedDeleteExprs.push_back(ReadDeclID(F, Record, I).get()); const uint64_t Count = Record[I++]; DelayedDeleteExprs.push_back(Count); for (uint64_t C = 0; C < Count; ++C) { @@ -3906,8 +3904,9 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, case VTABLES_TO_EMIT: if (F.Kind == MK_MainFile || getContext().getLangOpts().BuildingPCHWithObjectFile) - for (unsigned I = 0, N = Record.size(); I != N;) - VTablesToEmit.push_back(getGlobalDeclID(F, LocalDeclID(Record[I++]))); + for (unsigned I = 0, N = Record.size(); I != N; /*in loop*/) + VTablesToEmit.push_back(ReadDeclID(F, Record, I)); + break; case IMPORTED_MODULES: @@ -3982,9 +3981,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, break; case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - UnusedLocalTypedefNameCandidates.push_back( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + UnusedLocalTypedefNameCandidates.push_back(ReadDeclID(F, Record, I)); break; case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: @@ -4039,9 +4037,8 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F, } case DECLS_TO_CHECK_FOR_DEFERRED_DIAGS: - for (unsigned I = 0, N = Record.size(); I != N; ++I) - DeclsToCheckForDeferredDiags.insert( - getGlobalDeclID(F, LocalDeclID(Record[I]))); + for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) + DeclsToCheckForDeferredDiags.insert(ReadDeclID(F, Record, I)); break; } } @@ -5997,8 +5994,8 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F, if (!ContextObj) break; SmallVector Inits; - for (auto &ID : Record) - Inits.push_back(getGlobalDeclID(F, LocalDeclID(ID))); + for (unsigned I = 0; I < Record.size(); /* in loop */) + Inits.push_back(ReadDeclID(F, Record, I)); ContextObj->addLazyModuleInitializers(CurrentModule, Inits); break; } @@ -7845,14 +7842,16 @@ LocalDeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, return LocalDeclID(ID, OrignalModuleFileIndex); } -GlobalDeclID ASTReader::ReadDeclID(ModuleFile &F, const RecordData &Record, +GlobalDeclID ASTReader::ReadDeclID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx) { if (Idx >= Record.size()) { Error("Corrupted AST file"); return GlobalDeclID(0); } - return getGlobalDeclID(F, LocalDeclID(Record[Idx++])); + uint32_t ModuleFileIndex = Record[Idx++]; + uint32_t LocalDeclIndex = Record[Idx++]; + return getGlobalDeclID(F, LocalDeclID(LocalDeclIndex, ModuleFileIndex)); } /// Resolve the offset of a statement into a statement. @@ -7882,24 +7881,24 @@ void ASTReader::FindExternalLexicalDecls( bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { - assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); - for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { + assert(LexicalDecls.size() % 3 == 0 && "incorrect number of entries"); + for (int I = 0, N = LexicalDecls.size(); I != N; I += 3) { auto K = (Decl::Kind)+LexicalDecls[I]; if (!IsKindWeWant(K)) continue; - auto ID = (DeclID) + LexicalDecls[I + 1]; + LocalDeclID ID = LocalDeclID(LexicalDecls[I + 2], LexicalDecls[I + 1]); // Don't add predefined declarations to the lexical context more // than once. - if (ID < NUM_PREDEF_DECL_IDS) { - if (PredefsVisited[ID]) + if (ID.get() < NUM_PREDEF_DECL_IDS) { + if (PredefsVisited[ID.get()]) continue; - PredefsVisited[ID] = true; + PredefsVisited[ID.get()] = true; } - if (Decl *D = GetLocalDecl(*M, LocalDeclID(ID))) { + if (Decl *D = GetLocalDecl(*M, ID)) { assert(D->getKind() == K && "wrong kind for lexical decl"); if (!DC->isDeclInLexicalTraversal(D)) Decls.push_back(D); @@ -8801,14 +8800,14 @@ void ASTReader::ReadLateParsedTemplates( &LPTMap) { for (auto &LPT : LateParsedTemplates) { ModuleFile *FMod = LPT.first; - RecordDataImpl &LateParsed = LPT.second; + const RecordData &LateParsed = LPT.second; for (unsigned Idx = 0, N = LateParsed.size(); Idx < N; /* In loop */) { - FunctionDecl *FD = cast( - GetLocalDecl(*FMod, LocalDeclID(LateParsed[Idx++]))); + FunctionDecl *FD = ReadDeclAs(*FMod, LateParsed, Idx); auto LT = std::make_unique(); - LT->D = GetLocalDecl(*FMod, LocalDeclID(LateParsed[Idx++])); + LT->D = ReadDecl(*FMod, LateParsed, Idx); + LT->FPO = FPOptions::getFromOpaqueInt(LateParsed[Idx++]); ModuleFile *F = getOwningModuleFile(LT->D); diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index eb0c8c6c099b16..44506f18c791ae 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1020,9 +1020,9 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { // Templates. UnresolvedSet<8> Candidates; - unsigned NumCandidates = Record.readInt(); - while (NumCandidates--) - Candidates.addDecl(readDeclAs()); + Record.readDeclArray([&Candidates](NamedDecl *ND) { + Candidates.addDecl(ND); + }); // Templates args. TemplateArgumentListInfo TemplArgsWritten; @@ -1152,11 +1152,10 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { FD->setIsPureVirtual(Pure); // Read in the parameters. - unsigned NumParams = Record.readInt(); SmallVector Params; - Params.reserve(NumParams); - for (unsigned I = 0; I != NumParams; ++I) - Params.push_back(readDeclAs()); + Record.readDeclArray([&Params](ParmVarDecl *ParmD) { + Params.push_back(ParmD); + }); FD->setParams(Reader.getContext(), Params); } @@ -2309,7 +2308,7 @@ void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { } else { // We don't care about which declarations this used to override; we get // the relevant information from the canonical declaration. - Record.skipInts(NumOverridenMethods); + Record.skipInts(NumOverridenMethods * serialization::DeclIDRefSize); } } @@ -3140,8 +3139,8 @@ class AttrReader { OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); } - template T *GetLocalDeclAs(LocalDeclID LocalID) { - return Reader.GetLocalDeclAs(LocalID); + template T *readDeclAs() { + return Reader.readDeclAs(); } }; } @@ -4356,8 +4355,10 @@ void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { // FIXME: We have several different dispatches on decl kind here; maybe // we should instead generate one loop per kind and dispatch up-front? Decl *MostRecent = FirstLocal; - for (unsigned I = 0, N = Record.size(); I != N; ++I) { - auto *D = GetLocalDecl(*M, LocalDeclID(Record[N - I - 1])); + for (unsigned I = 0, N = Record.size(); I != N; I += serialization::DeclIDRefSize) { + unsigned ModuleFileIndex = Record[N - I - 2]; + unsigned LocalDeclIndex = Record[N - I - 1]; + auto *D = GetLocalDecl(*M, LocalDeclID(LocalDeclIndex, ModuleFileIndex)); ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); MostRecent = D; } @@ -4466,8 +4467,8 @@ namespace { unsigned N = M.ObjCCategories[Offset]; M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again for (unsigned I = 0; I != N; ++I) - add(cast_or_null( - Reader.GetLocalDecl(M, LocalDeclID(M.ObjCCategories[Offset++])))); + add(Reader.ReadDeclAs(M, M.ObjCCategories, Offset)); + return true; } }; diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 67ef170251914e..72029d51eefe08 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -351,12 +351,13 @@ void ASTStmtReader::VisitDeclStmt(DeclStmt *S) { S->setStartLoc(readSourceLocation()); S->setEndLoc(readSourceLocation()); - if (Record.size() - Record.getIdx() == 1) { + unsigned NumDecls = (Record.size() - Record.getIdx()) / serialization::DeclIDRefSize; + if (NumDecls == 1) { // Single declaration S->setDeclGroup(DeclGroupRef(readDecl())); } else { SmallVector Decls; - int N = Record.size() - Record.getIdx(); + int N = NumDecls; Decls.reserve(N); for (int I = 0; I < N; ++I) Decls.push_back(readDecl()); diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 713091e070805d..7075346e221a54 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -3320,7 +3320,7 @@ uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, return 0; uint64_t Offset = Stream.GetCurrentBitNo(); - SmallVector KindDeclPairs; + SmallVector KindDeclPairs; for (const auto *D : DC->decls()) { if (DoneWritingDeclsAndTypes && !wasDeclEmitted(D)) continue; @@ -3335,7 +3335,9 @@ uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, continue; KindDeclPairs.push_back(D->getKind()); - KindDeclPairs.push_back(GetDeclRef(D).get()); + LocalDeclID ID = GetDeclRef(D); + KindDeclPairs.push_back(ID.getModuleFileIndex()); + KindDeclPairs.push_back(ID.getLocalDeclIndex()); } ++NumLexicalDeclContexts; @@ -4443,8 +4445,10 @@ void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { DC = cast(Chain->getKeyDeclaration(cast(DC))); // Write the lookup table + LocalDeclID ID = getDeclID(cast(DC)); RecordData::value_type Record[] = {UPDATE_VISIBLE, - getDeclID(cast(DC)).get()}; + ID.getModuleFileIndex(), + ID.getLocalDeclIndex()}; Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); } @@ -5227,9 +5231,10 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) { RecordData SemaDeclRefs; if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { auto AddEmittedDeclRefOrZero = [this, &SemaDeclRefs](Decl *D) { - if (!D || !wasDeclEmitted(D)) + if (!D || !wasDeclEmitted(D)) { SemaDeclRefs.push_back(0); - else + SemaDeclRefs.push_back(0); + } else AddDeclRef(D, SemaDeclRefs); }; @@ -5647,7 +5652,7 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) { const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); // Create a lexical update block containing all of the declarations in the // translation unit that do not come from other AST files. - SmallVector NewGlobalKindDeclPairs; + SmallVector NewGlobalKindDeclPairs; for (const auto *D : TU->noload_decls()) { if (D->isFromASTFile()) continue; @@ -5657,7 +5662,9 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) { continue; NewGlobalKindDeclPairs.push_back(D->getKind()); - NewGlobalKindDeclPairs.push_back(GetDeclRef(D).get()); + LocalDeclID ID = GetDeclRef(D); + NewGlobalKindDeclPairs.push_back(ID.getModuleFileIndex()); + NewGlobalKindDeclPairs.push_back(ID.getLocalDeclIndex()); } auto Abv = std::make_shared(); @@ -5672,6 +5679,7 @@ void ASTWriter::WriteDeclAndTypes(ASTContext &Context) { Abv = std::make_shared(); Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); + Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); @@ -6159,11 +6167,14 @@ void ASTWriter::AddEmittedDeclRef(const Decl *D, RecordDataImpl &Record) { if (!wasDeclEmitted(D)) return; - Record.push_back(GetDeclRef(D).get()); + AddDeclRef(D, Record); } void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { - Record.push_back(GetDeclRef(D).get()); + LocalDeclID ID = GetDeclRef(D); + + Record.push_back(ID.getModuleFileIndex()); + Record.push_back(ID.getLocalDeclIndex()); } LocalDeclID ASTWriter::GetDeclRef(const Decl *D) { diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 49b2f9bc1e6cff..c0318532f12b39 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -243,12 +243,14 @@ namespace clang { assert(D->isCanonicalDecl() && "non-canonical decl in set"); AddFirstDeclFromEachModule(D, /*IncludeLocal*/true); } - Record.append( - DeclIDIterator(LazySpecializations.begin()), - DeclIDIterator(LazySpecializations.end())); + + for (GlobalDeclID LazyID : LazySpecializations) { + Record.push_back(LazyID.getModuleFileIndex()); + Record.push_back(LazyID.getLocalDeclIndex()); + } // Update the size entry we added earlier. - Record[I] = Record.size() - I - 1; + Record[I] = (Record.size() - I - 1) / serialization::DeclIDRefSize; } /// Ensure that this template specialization is associated with the specified @@ -695,9 +697,7 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { DFTSInfo = D->getDependentSpecializationInfo(); // Candidates. - Record.push_back(DFTSInfo->getCandidates().size()); - for (FunctionTemplateDecl *FTD : DFTSInfo->getCandidates()) - Record.AddDeclRef(FTD); + Record.writeDeclArray(DFTSInfo->getCandidates()); // Templates args. Record.push_back(DFTSInfo->TemplateArgumentsAsWritten != nullptr); @@ -769,9 +769,7 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { } } - Record.push_back(D->param_size()); - for (auto *P : D->parameters()) - Record.AddDeclRef(P); + Record.writeDeclArray(D->parameters()); Code = serialization::DECL_FUNCTION; } @@ -1527,7 +1525,7 @@ void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { Record.AddDeclRef(Context); Record.push_back(D->getLambdaIndexInContext()); } else { - Record.push_back(0); + Record.writeNullDeclRef(); } } else { Record.push_back(CXXRecNotTemplate); @@ -1567,7 +1565,7 @@ void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { !D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() && D->getDeclName().getNameKind() == DeclarationName::Identifier && !shouldSkipCheckingODR(D) && !D->hasExtInfo() && - !D->isExplicitlyDefaulted()) { + !D->isExplicitlyDefaulted() && !D->size_overridden_methods()) { if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate || D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate || D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization || @@ -2060,7 +2058,7 @@ void ASTDeclWriter::VisitRedeclarable(Redeclarable *D) { if (Writer.Chain) AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false); // This is the number of imported first declarations + 1. - Record[I] = Record.size() - I; + Record[I] = ((Record.size() - I - 1) / serialization::DeclIDRefSize) + 1; // Collect the set of local redeclarations of this declaration, from // newest to oldest. @@ -2091,8 +2089,8 @@ void ASTDeclWriter::VisitRedeclarable(Redeclarable *D) { (void)Writer.GetDeclRef(D->getPreviousDecl()); (void)Writer.GetDeclRef(MostRecent); } else { - // We use the sentinel value 0 to indicate an only declaration. - Record.push_back(0); + // Use the null decl to indicate an only declaration. + Record.writeNullDeclRef(); } } @@ -2168,37 +2166,54 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) { auto Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(Code)); - // RedeclarableDecl - Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl + // CanonicalDecl of RedeclarableDecl + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); + // Kind Abv->Add(BitCodeAbbrevOp(Kind)); if constexpr (Kind == FunctionDecl::TK_NonTemplate) { } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) { // DescribedFunctionTemplate Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) { // Instantiated From Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) { - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom + // InstantiatedFrom + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // TemplateSpecializationKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, - 3)); // TemplateSpecializationKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location + 3)); + // Specialized Location + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplateSpecialization) { - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template + // Template + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // TemplateSpecializationKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, - 3)); // TemplateSpecializationKind - Abv->Add(BitCodeAbbrevOp(1)); // Template Argument Size - Abv->Add(BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind - Abv->Add( - BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted - Abv->Add(BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation + 3)); + // Template Argument Size + Abv->Add(BitCodeAbbrevOp(1)); + // Template Argument Kind + Abv->Add(BitCodeAbbrevOp(TemplateArgument::Type)); + // Template Argument Type + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // Is Defaulted + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); + // TemplateArgumentsAsWritten + Abv->Add(BitCodeAbbrevOp(0)); + // SourceLocation + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(0)); - Abv->Add( - BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template + // Canonical Decl of template + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); } else if constexpr (Kind == FunctionDecl:: TK_DependentFunctionTemplateSpecialization) { // Candidates of specialization @@ -2217,7 +2232,9 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) { // HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, // isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind @@ -2251,6 +2268,7 @@ getFunctionDeclAbbrev(serialization::DeclCode Code) { // // Add an AbbrevOp for 'size then elements' and use it here. Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + // NumOverriddenMethods Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); return Abv; } @@ -2278,7 +2296,9 @@ void ASTWriter::WriteDeclAbbrevs() { // isImplicit, HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, // isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2307,7 +2327,9 @@ void ASTWriter::WriteDeclAbbrevs() { // isInvalidDecl, HasAttrs, isImplicit, isUsed, // isReferenced, TopLevelDeclInObjCContainer, // AccessSpecifier, ModuleOwnershipKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2333,8 +2355,9 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_ENUM Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No Redeclarable + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // Packed DeclBits: ModuleOwnershipKind, @@ -2344,7 +2367,9 @@ void ASTWriter::WriteDeclAbbrevs() { // isImplicit, HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, // isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2368,7 +2393,9 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum + // InstantiatedMembEnum + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DC Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset @@ -2377,8 +2404,9 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_RECORD Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No redeclaration + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // Packed DeclBits: ModuleOwnershipKind, @@ -2388,7 +2416,9 @@ void ASTWriter::WriteDeclAbbrevs() { // isImplicit, HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, // isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2428,8 +2458,9 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_PARM_VAR Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No redeclaration + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed, @@ -2437,7 +2468,9 @@ void ASTWriter::WriteDeclAbbrevs() { // HasStandaloneLexicalDC, HasAttrs, isImplicit, // TopLevelDeclInObjCContainer, // isInvalidDecl, - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2470,8 +2503,9 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_TYPEDEF Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No redeclaration + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // Packed DeclBits: ModuleOwnershipKind, @@ -2479,7 +2513,9 @@ void ASTWriter::WriteDeclAbbrevs() { // higher bits should be 0: isImplicit, // HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2496,15 +2532,18 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_VAR Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No redeclaration + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 12)); // Packed DeclBits: HasStandaloneLexicalDC, // isInvalidDecl, HasAttrs, isImplicit, isUsed, // isReferenced, TopLevelDeclInObjCContainer, // AccessSpecifier, ModuleOwnershipKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2558,7 +2597,9 @@ void ASTWriter::WriteDeclAbbrevs() { // higher bits should be 0: isImplicit, // HasStandaloneLexicalDC, HasAttrs, // TopLevelDeclInObjCContainer, isInvalidDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier @@ -2576,26 +2617,34 @@ void ASTWriter::WriteDeclAbbrevs() { // Abbreviation for DECL_USING_SHADOW Abv = std::make_shared(); Abv->Add(BitCodeAbbrevOp(serialization::DECL_USING_SHADOW)); - // Redeclarable - Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration + // No redeclaration + Abv->Add(BitCodeAbbrevOp(0)); + Abv->Add(BitCodeAbbrevOp(0)); // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 12)); // Packed DeclBits: HasStandaloneLexicalDC, // isInvalidDecl, HasAttrs, isImplicit, isUsed, // isReferenced, TopLevelDeclInObjCContainer, // AccessSpecifier, ModuleOwnershipKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext + // DeclContext + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID // NamedDecl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name Abv->Add(BitCodeAbbrevOp(0)); // UsingShadowDecl - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl + // TargetDecl + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, - 6)); // InstantiatedFromUsingShadowDecl + // UsingOrNextShadow + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // InstantiatedFromUsingShadowDecl + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); DeclUsingShadowAbbrev = Stream.EmitAbbrev(std::move(Abv)); // Abbreviation for EXPR_DECL_REF @@ -2611,7 +2660,9 @@ void ASTWriter::WriteDeclAbbrevs() { // IsImmediateEscalating, NonOdrUseReason. // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0. Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef + // DeclRef + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv)); diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp index ca7630adfbb7b5..660d7b57d8e0b7 100644 --- a/clang/utils/TableGen/ClangAttrEmitter.cpp +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp @@ -105,9 +105,9 @@ GetFlattenedSpellings(const Record &Attr) { static std::string ReadPCHRecord(StringRef type) { return StringSwitch(type) - .EndsWith("Decl *", "Record.GetLocalDeclAs<" + + .EndsWith("Decl *", "Record.readDeclAs<" + std::string(type.data(), 0, type.size() - 1) + - ">(LocalDeclID(Record.readInt()))") + ">()") .Case("TypeSourceInfo *", "Record.readTypeSourceInfo()") .Case("Expr *", "Record.readExpr()") .Case("IdentifierInfo *", "Record.readIdentifier()")