@@ -1893,6 +1893,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
1893
1893
// Write out the source location entry table. We skip the first
1894
1894
// entry, which is always the same dummy entry.
1895
1895
std::vector<uint32_t> SLocEntryOffsets;
1896
+ uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo();
1896
1897
RecordData PreloadSLocs;
1897
1898
SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
1898
1899
for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
@@ -1903,7 +1904,9 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
1903
1904
assert(&SourceMgr.getSLocEntry(FID) == SLoc);
1904
1905
1905
1906
// 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);
1907
1910
1908
1911
// Figure out which record code to use.
1909
1912
unsigned Code;
@@ -2011,12 +2014,14 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
2011
2014
Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
2012
2015
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
2013
2016
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
2017
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
2014
2018
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
2015
2019
unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2016
2020
{
2017
2021
RecordData::value_type Record[] = {
2018
2022
SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
2019
- SourceMgr.getNextLocalOffset() - 1 /* skip dummy */};
2023
+ SourceMgr.getNextLocalOffset() - 1 /* skip dummy */,
2024
+ SLocEntryOffsetsBase};
2020
2025
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
2021
2026
bytes(SLocEntryOffsets));
2022
2027
}
@@ -2093,9 +2098,11 @@ static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
2093
2098
/// Writes the block containing the serialized form of the
2094
2099
/// preprocessor.
2095
2100
void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2101
+ uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
2102
+
2096
2103
PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
2097
2104
if (PPRec)
2098
- WritePreprocessorDetail(*PPRec);
2105
+ WritePreprocessorDetail(*PPRec, MacroOffsetsBase );
2099
2106
2100
2107
RecordData Record;
2101
2108
RecordData ModuleMacroRecord;
@@ -2156,7 +2163,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2156
2163
// identifier they belong to.
2157
2164
for (const IdentifierInfo *Name : MacroIdentifiers) {
2158
2165
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");
2160
2168
2161
2169
// Emit the macro directives in reverse source order.
2162
2170
for (; MD; MD = MD->getPrevious()) {
@@ -2229,14 +2237,12 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2229
2237
2230
2238
// Record the local offset of this macro.
2231
2239
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);
2237
2242
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;
2240
2246
2241
2247
AddIdentifierRef(Name, Record);
2242
2248
AddSourceLocation(MI->getDefinitionLoc(), Record);
@@ -2287,17 +2293,20 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2287
2293
Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET));
2288
2294
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros
2289
2295
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
2296
+ Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
2290
2297
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2291
2298
2292
2299
unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
2293
2300
{
2294
2301
RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(),
2295
- FirstMacroID - NUM_PREDEF_MACRO_IDS};
2302
+ FirstMacroID - NUM_PREDEF_MACRO_IDS,
2303
+ MacroOffsetsBase};
2296
2304
Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
2297
2305
}
2298
2306
}
2299
2307
2300
- void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
2308
+ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
2309
+ uint64_t MacroOffsetsBase) {
2301
2310
if (PPRec.local_begin() == PPRec.local_end())
2302
2311
return;
2303
2312
@@ -2334,8 +2343,10 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
2334
2343
(void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
2335
2344
Record.clear();
2336
2345
2346
+ uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2347
+ assert((Offset >> 32) == 0 && "Preprocessed entity offset too large");
2337
2348
PreprocessedEntityOffsets.push_back(
2338
- PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo() ));
2349
+ PPEntityOffset((*E)->getSourceRange(), Offset ));
2339
2350
2340
2351
if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
2341
2352
// Record this macro definition's ID.
@@ -5144,7 +5155,7 @@ MacroID ASTWriter::getMacroID(MacroInfo *MI) {
5144
5155
return MacroIDs[MI];
5145
5156
}
5146
5157
5147
- uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) {
5158
+ uint32_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) {
5148
5159
return IdentMacroDirectivesOffsetMap.lookup(Name);
5149
5160
}
5150
5161
0 commit comments