From cdbf2c3796769961bd29f376314a7f050033988f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 20 Mar 2014 19:44:17 +0000 Subject: [PATCH] Rearrange serialization block order to put decl update emission into the same block as decl and type emission. This allows decl updates include statements and expressions. No functionality change (but the generated PCM files are incompatible with earlier versions of Clang). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204385 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Serialization/ASTBitCodes.h | 3 - include/clang/Serialization/ASTWriter.h | 2 +- lib/Serialization/ASTReader.cpp | 21 +++--- lib/Serialization/ASTWriter.cpp | 79 ++++++++++++----------- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index c24177913f..35765b67f0 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -213,9 +213,6 @@ namespace clang { /// types and decls used within the AST file. DECLTYPES_BLOCK_ID, - /// \brief The block containing DECL_UPDATES records. - DECL_UPDATES_BLOCK_ID, - /// \brief The block containing the detailed preprocessing record. PREPROCESSOR_DETAIL_BLOCK_ID, diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index c20477fc43..e22d0499ec 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -448,7 +448,7 @@ private: bool IsModule); void WriteAttributes(ArrayRef Attrs, RecordDataImpl &Record); void ResolveDeclUpdatesBlocks(); - void WriteDeclUpdatesBlocks(); + void WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord); void WriteDeclReplacementsBlock(); void WriteDeclContextVisibleUpdate(const DeclContext *DC); void WriteFPPragmaOptions(const FPOptions &Opts); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index a0ee3d37c5..f7a1921e51 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2352,14 +2352,7 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { return true; } break; - - case DECL_UPDATES_BLOCK_ID: - if (Stream.SkipBlock()) { - Error("malformed block record in AST file"); - return true; - } - break; - + case PREPROCESSOR_BLOCK_ID: F.MacroCursor = Stream; if (!PP.getExternalSource()) @@ -2707,9 +2700,9 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { // Initialize the remapping table. // Invalid stays invalid. - F.SLocRemap.insert(std::make_pair(0U, 0)); + F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); // This module. Base was 2 when being compiled. - F.SLocRemap.insert(std::make_pair(2U, + F.SLocRemap.insertOrReplace(std::make_pair(2U, static_cast(F.SLocEntryBaseOffset - 2))); TotalNumSLocEntries += F.LocalNumSLocEntries; @@ -2720,7 +2713,13 @@ bool ASTReader::ReadASTBlock(ModuleFile &F) { // Additional remapping information. const unsigned char *Data = (const unsigned char*)Blob.data(); const unsigned char *DataEnd = Data + Blob.size(); - + + // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. + if (F.SLocRemap.find(0) == F.SLocRemap.end()) { + F.SLocRemap.insert(std::make_pair(0U, 0)); + F.SLocRemap.insert(std::make_pair(2U, 1)); + } + // Continuous range maps we may be updating in our module. ContinuousRangeMap::Builder SLocRemap(F.SLocRemap); ContinuousRangeMap::Builder diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 3e0cb85e1d..2967fb3486 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -4104,9 +4104,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, } } - // Resolve any declaration pointers within the declaration updates block. - ResolveDeclUpdatesBlocks(); - // Form the record of special types. RecordData SpecialTypes; AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); @@ -4118,30 +4115,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); AddTypeRef(Context.getucontext_tType(), SpecialTypes); - // Keep writing types and declarations until all types and - // declarations have been written. - Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); - WriteDeclsBlockAbbrevs(); - for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), - E = DeclsToRewrite.end(); - I != E; ++I) - DeclTypesToEmit.push(const_cast(*I)); - while (!DeclTypesToEmit.empty()) { - DeclOrType DOT = DeclTypesToEmit.front(); - DeclTypesToEmit.pop(); - if (DOT.isType()) - WriteType(DOT.getType()); - else - WriteDecl(Context, DOT.getDecl()); - } - Stream.ExitBlock(); - - DoneWritingDeclsAndTypes = true; - - WriteFileDeclIDsMap(); - WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); - WriteComments(); - if (Chain) { // Write the mapping information describing our module dependencies and how // each of those modules were mapped into our own offset/ID space, so that @@ -4186,6 +4159,44 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, Buffer.data(), Buffer.size()); } + + // Resolve any declaration pointers within the declaration updates block. + // FIXME: Fold this into WriteDeclUpdatesBlocks. + ResolveDeclUpdatesBlocks(); + + RecordData DeclUpdatesOffsetsRecord; + + // Keep writing types and declarations until all types and + // declarations have been written. + Stream.EnterSubblock(DECLTYPES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); + WriteDeclsBlockAbbrevs(); + for (DeclsToRewriteTy::iterator I = DeclsToRewrite.begin(), + E = DeclsToRewrite.end(); + I != E; ++I) + DeclTypesToEmit.push(const_cast(*I)); + while (!DeclTypesToEmit.empty()) { + DeclOrType DOT = DeclTypesToEmit.front(); + DeclTypesToEmit.pop(); + if (DOT.isType()) + WriteType(DOT.getType()); + else + WriteDecl(Context, DOT.getDecl()); + } + WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); + Stream.ExitBlock(); + + if (!DeclUpdatesOffsetsRecord.empty()) + Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); + + DoneWritingDeclsAndTypes = true; + + // These things can only be done once we've written out decls and types. + WriteTypeDeclOffsets(); + WriteCXXBaseSpecifiersOffsets(); + WriteFileDeclIDsMap(); + WriteSourceManagerBlock(Context.getSourceManager(), PP, isysroot); + + WriteComments(); WritePreprocessor(PP, isModule); WriteHeaderSearch(PP.getHeaderSearchInfo(), isysroot); WriteSelectors(SemaRef); @@ -4193,12 +4204,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); WriteFPPragmaOptions(SemaRef.getFPOptions()); WriteOpenCLExtensions(SemaRef); - - WriteTypeDeclOffsets(); WritePragmaDiagnosticMappings(Context.getDiagnostics(), isModule); - WriteCXXBaseSpecifiersOffsets(); - // If we're emitting a module, write out the submodule information. if (WritingModule) WriteSubmodules(WritingModule); @@ -4290,7 +4297,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, } } - WriteDeclUpdatesBlocks(); WriteDeclReplacementsBlock(); WriteRedeclarations(); WriteMergedDecls(); @@ -4343,12 +4349,10 @@ void ASTWriter::ResolveDeclUpdatesBlocks() { } } -void ASTWriter::WriteDeclUpdatesBlocks() { +void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { if (DeclUpdates.empty()) return; - RecordData OffsetsRecord; - Stream.EnterSubblock(DECL_UPDATES_BLOCK_ID, NUM_ALLOWED_ABBREVS_SIZE); for (DeclUpdateMap::iterator I = DeclUpdates.begin(), E = DeclUpdates.end(); I != E; ++I) { const Decl *D = I->first; @@ -4360,11 +4364,12 @@ void ASTWriter::WriteDeclUpdatesBlocks() { uint64_t Offset = Stream.GetCurrentBitNo(); Stream.EmitRecord(DECL_UPDATES, URec); + // Flush any statements that were written as part of this update record. + FlushStmts(); + OffsetsRecord.push_back(GetDeclRef(D)); OffsetsRecord.push_back(Offset); } - Stream.ExitBlock(); - Stream.EmitRecord(DECL_UPDATE_OFFSETS, OffsetsRecord); } void ASTWriter::WriteDeclReplacementsBlock() { -- 2.40.0