@@ -1893,6 +1893,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
18931893 // Write out the source location entry table. We skip the first
18941894 // entry, which is always the same dummy entry.
18951895 std::vector<uint32_t > SLocEntryOffsets;
1896+ uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo ();
18961897 RecordData PreloadSLocs;
18971898 SLocEntryOffsets.reserve (SourceMgr.local_sloc_entry_size () - 1 );
18981899 for (unsigned I = 1 , N = SourceMgr.local_sloc_entry_size ();
@@ -1903,7 +1904,9 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
19031904 assert (&SourceMgr.getSLocEntry (FID) == SLoc);
19041905
19051906 // Record the offset of this source-location entry.
1906- SLocEntryOffsets.push_back (Stream.GetCurrentBitNo ());
1907+ uint64_t Offset = Stream.GetCurrentBitNo () - SLocEntryOffsetsBase;
1908+ assert ((Offset >> 32 ) == 0 && " SLocEntry offset too large" );
1909+ SLocEntryOffsets.push_back (Offset);
19071910
19081911 // Figure out which record code to use.
19091912 unsigned Code;
@@ -2011,12 +2014,14 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
20112014 Abbrev->Add (BitCodeAbbrevOp (SOURCE_LOCATION_OFFSETS));
20122015 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 16 )); // # of slocs
20132016 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 16 )); // total size
2017+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 32 )); // base offset
20142018 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob)); // offsets
20152019 unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
20162020 {
20172021 RecordData::value_type Record[] = {
20182022 SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size (),
2019- SourceMgr.getNextLocalOffset () - 1 /* skip dummy */ };
2023+ SourceMgr.getNextLocalOffset () - 1 /* skip dummy */ ,
2024+ SLocEntryOffsetsBase};
20202025 Stream.EmitRecordWithBlob (SLocOffsetsAbbrev, Record,
20212026 bytes (SLocEntryOffsets));
20222027 }
@@ -2093,9 +2098,11 @@ static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
20932098// / Writes the block containing the serialized form of the
20942099// / preprocessor.
20952100void ASTWriter::WritePreprocessor (const Preprocessor &PP, bool IsModule) {
2101+ uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo ();
2102+
20962103 PreprocessingRecord *PPRec = PP.getPreprocessingRecord ();
20972104 if (PPRec)
2098- WritePreprocessorDetail (*PPRec);
2105+ WritePreprocessorDetail (*PPRec, MacroOffsetsBase );
20992106
21002107 RecordData Record;
21012108 RecordData ModuleMacroRecord;
@@ -2156,7 +2163,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
21562163 // identifier they belong to.
21572164 for (const IdentifierInfo *Name : MacroIdentifiers) {
21582165 MacroDirective *MD = PP.getLocalMacroDirectiveHistory (Name);
2159- auto StartOffset = Stream.GetCurrentBitNo ();
2166+ uint64_t StartOffset = Stream.GetCurrentBitNo () - MacroOffsetsBase;
2167+ assert ((StartOffset >> 32 ) == 0 && " Macro identifiers offset too large" );
21602168
21612169 // Emit the macro directives in reverse source order.
21622170 for (; MD; MD = MD->getPrevious ()) {
@@ -2229,14 +2237,12 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
22292237
22302238 // Record the local offset of this macro.
22312239 unsigned Index = ID - FirstMacroID;
2232- if (Index == MacroOffsets.size ())
2233- MacroOffsets.push_back (Stream.GetCurrentBitNo ());
2234- else {
2235- if (Index > MacroOffsets.size ())
2236- MacroOffsets.resize (Index + 1 );
2240+ if (Index >= MacroOffsets.size ())
2241+ MacroOffsets.resize (Index + 1 );
22372242
2238- MacroOffsets[Index] = Stream.GetCurrentBitNo ();
2239- }
2243+ uint64_t Offset = Stream.GetCurrentBitNo () - MacroOffsetsBase;
2244+ assert ((Offset >> 32 ) == 0 && " Macro offset too large" );
2245+ MacroOffsets[Index] = Offset;
22402246
22412247 AddIdentifierRef (Name, Record);
22422248 AddSourceLocation (MI->getDefinitionLoc (), Record);
@@ -2287,17 +2293,20 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
22872293 Abbrev->Add (BitCodeAbbrevOp (MACRO_OFFSET));
22882294 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Fixed, 32 )); // # of macros
22892295 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Fixed, 32 )); // first ID
2296+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::VBR, 32 )); // base offset
22902297 Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob));
22912298
22922299 unsigned MacroOffsetAbbrev = Stream.EmitAbbrev (std::move (Abbrev));
22932300 {
22942301 RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size (),
2295- FirstMacroID - NUM_PREDEF_MACRO_IDS};
2302+ FirstMacroID - NUM_PREDEF_MACRO_IDS,
2303+ MacroOffsetsBase};
22962304 Stream.EmitRecordWithBlob (MacroOffsetAbbrev, Record, bytes (MacroOffsets));
22972305 }
22982306}
22992307
2300- void ASTWriter::WritePreprocessorDetail (PreprocessingRecord &PPRec) {
2308+ void ASTWriter::WritePreprocessorDetail (PreprocessingRecord &PPRec,
2309+ uint64_t MacroOffsetsBase) {
23012310 if (PPRec.local_begin () == PPRec.local_end ())
23022311 return ;
23032312
@@ -2334,8 +2343,10 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
23342343 (void )++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
23352344 Record.clear ();
23362345
2346+ uint64_t Offset = Stream.GetCurrentBitNo () - MacroOffsetsBase;
2347+ assert ((Offset >> 32 ) == 0 && " Preprocessed entity offset too large" );
23372348 PreprocessedEntityOffsets.push_back (
2338- PPEntityOffset ((*E)->getSourceRange (), Stream. GetCurrentBitNo () ));
2349+ PPEntityOffset ((*E)->getSourceRange (), Offset ));
23392350
23402351 if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
23412352 // Record this macro definition's ID.
@@ -5144,7 +5155,7 @@ MacroID ASTWriter::getMacroID(MacroInfo *MI) {
51445155 return MacroIDs[MI];
51455156}
51465157
5147- uint64_t ASTWriter::getMacroDirectivesOffset (const IdentifierInfo *Name) {
5158+ uint32_t ASTWriter::getMacroDirectivesOffset (const IdentifierInfo *Name) {
51485159 return IdentMacroDirectivesOffsetMap.lookup (Name);
51495160}
51505161
0 commit comments