Skip to content

Commit a8f85da

Browse files
committed
Revert "[clang][AST] Support AST files larger than 512M"
Bitcode file alignment is only 32-bit so 64-bit offsets need special handling. /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28: runtime error: load of misaligned address 0x7fca2bcfe54c for type 'const uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment 0x7fca2bcfe54c: note: pointer points here 00 00 00 00 5a a6 01 00 00 00 00 00 19 a7 01 00 00 00 00 00 48 a7 01 00 00 00 00 00 7d a7 01 00 ^ #0 0x3be2fe4 in clang::ASTReader::TypeCursorForIndex(unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28 #1 0x3be30a0 in clang::ASTReader::readTypeRecord(unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6348:24 rust-lang#2 0x3bd3d4a in clang::ASTReader::GetType(unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6985:26 rust-lang#3 0x3c5d9ae in clang::ASTDeclReader::Visit(clang::Decl*) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:533:31 rust-lang#4 0x3c91cac in clang::ASTReader::ReadDeclRecord(unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:4045:10 rust-lang#5 0x3bd4fb1 in clang::ASTReader::GetDecl(unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:7352:5 rust-lang#6 0x3bce2f9 in clang::ASTReader::ReadASTBlock(clang::serialization::ModuleFile&, unsigned int) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:3625:22 rust-lang#7 0x3bd6d75 in clang::ASTReader::ReadAST(llvm::StringRef, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, llvm::SmallVectorImpl<clang::ASTReader::ImportedSubmodule>*) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:4230:32 rust-lang#8 0x3a6b415 in clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, llvm::StringRef, bool, bool, clang::Preprocessor&, clang::InMemoryModuleCache&, clang::ASTContext&, clang::PCHContainerReader const&, llvm::ArrayRef<std::shared_ptr<clang::ModuleFileExtension> >, llvm::ArrayRef<std::shared_ptr<clang::DependencyCollector> >, void*, bool, bool, bool) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:539:19 rust-lang#9 0x3a6b00e in clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, bool, bool, void*, bool) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:501:18 rust-lang#10 0x3abac80 in clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, clang::FrontendInputFile const&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/FrontendAction.cpp:865:12 rust-lang#11 0x3a6e61c in clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:972:13 rust-lang#12 0x3ba74bf in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:282:25 rust-lang#13 0xa3f753 in cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/cc1_main.cpp:240:15 rust-lang#14 0xa3a68a in ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:330:12 rust-lang#15 0xa37f31 in main /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:407:12 rust-lang#16 0x7fca2a7032e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) rust-lang#17 0xa21029 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/clang-11+0xa21029) This reverts commit 30d5946.
1 parent dfcc403 commit a8f85da

File tree

8 files changed

+40
-81
lines changed

8 files changed

+40
-81
lines changed

clang/include/clang/Serialization/ASTBitCodes.h

+6-21
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace serialization {
4141
/// Version 4 of AST files also requires that the version control branch and
4242
/// revision match exactly, since there is no backward compatibility of
4343
/// AST files at this time.
44-
const unsigned VERSION_MAJOR = 10;
44+
const unsigned VERSION_MAJOR = 9;
4545

4646
/// AST file minor version number supported by this version of
4747
/// Clang.
@@ -181,7 +181,7 @@ namespace serialization {
181181
/// Raw source location of end of range.
182182
unsigned End;
183183

184-
/// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
184+
/// Offset in the AST file.
185185
uint32_t BitOffset;
186186

187187
PPEntityOffset(SourceRange R, uint32_t BitOffset)
@@ -221,18 +221,12 @@ namespace serialization {
221221
/// Raw source location.
222222
unsigned Loc = 0;
223223

224-
/// Offset in the AST file. Split 64-bit integer into low/high parts
225-
/// to keep structure alignment 32-bit and don't have padding gap.
226-
/// This structure is serialized "as is" to the AST file and undefined
227-
/// value in the padding affects AST hash.
228-
uint32_t BitOffsetLow = 0;
229-
uint32_t BitOffsetHigh = 0;
224+
/// Offset in the AST file.
225+
uint32_t BitOffset = 0;
230226

231227
DeclOffset() = default;
232-
DeclOffset(SourceLocation Loc, uint64_t BitOffset) {
233-
setLocation(Loc);
234-
setBitOffset(BitOffset);
235-
}
228+
DeclOffset(SourceLocation Loc, uint32_t BitOffset)
229+
: Loc(Loc.getRawEncoding()), BitOffset(BitOffset) {}
236230

237231
void setLocation(SourceLocation L) {
238232
Loc = L.getRawEncoding();
@@ -241,15 +235,6 @@ namespace serialization {
241235
SourceLocation getLocation() const {
242236
return SourceLocation::getFromRawEncoding(Loc);
243237
}
244-
245-
void setBitOffset(uint64_t Offset) {
246-
BitOffsetLow = Offset;
247-
BitOffsetHigh = Offset >> 32;
248-
}
249-
250-
uint64_t getBitOffset() const {
251-
return BitOffsetLow | (uint64_t(BitOffsetHigh) << 32);
252-
}
253238
};
254239

255240
/// The number of predefined preprocessed entity IDs.

clang/include/clang/Serialization/ASTReader.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,9 @@ class ASTReader
723723

724724
struct PendingMacroInfo {
725725
ModuleFile *M;
726-
/// Offset relative to ModuleFile::MacroOffsetsBase.
727-
uint32_t MacroDirectivesOffset;
726+
uint64_t MacroDirectivesOffset;
728727

729-
PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset)
728+
PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
730729
: M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
731730
};
732731

@@ -2206,7 +2205,7 @@ class ASTReader
22062205
/// \param MacroDirectivesOffset Offset of the serialized macro directive
22072206
/// history.
22082207
void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2209-
uint32_t MacroDirectivesOffset);
2208+
uint64_t MacroDirectivesOffset);
22102209

22112210
/// Read the set of macros defined by this external macro source.
22122211
void ReadDefinedMacros() override;

clang/include/clang/Serialization/ASTWriter.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class ASTWriter : public ASTDeserializationListener,
243243

244244
/// Offset of each type in the bitstream, indexed by
245245
/// the type's ID.
246-
std::vector<uint64_t> TypeOffsets;
246+
std::vector<uint32_t> TypeOffsets;
247247

248248
/// The first ID number we can use for our own identifiers.
249249
serialization::IdentID FirstIdentID = serialization::NUM_PREDEF_IDENT_IDS;
@@ -277,8 +277,7 @@ class ASTWriter : public ASTDeserializationListener,
277277
/// The macro infos to emit.
278278
std::vector<MacroInfoToEmitData> MacroInfosToEmit;
279279

280-
llvm::DenseMap<const IdentifierInfo *, uint32_t>
281-
IdentMacroDirectivesOffsetMap;
280+
llvm::DenseMap<const IdentifierInfo *, uint64_t> IdentMacroDirectivesOffsetMap;
282281

283282
/// @name FlushStmt Caches
284283
/// @{
@@ -465,8 +464,7 @@ class ASTWriter : public ASTDeserializationListener,
465464
const Preprocessor &PP);
466465
void WritePreprocessor(const Preprocessor &PP, bool IsModule);
467466
void WriteHeaderSearch(const HeaderSearch &HS);
468-
void WritePreprocessorDetail(PreprocessingRecord &PPRec,
469-
uint64_t MacroOffsetsBase);
467+
void WritePreprocessorDetail(PreprocessingRecord &PPRec);
470468
void WriteSubmodules(Module *WritingModule);
471469

472470
void WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag,
@@ -590,7 +588,7 @@ class ASTWriter : public ASTDeserializationListener,
590588
/// Determine the ID of an already-emitted macro.
591589
serialization::MacroID getMacroID(MacroInfo *MI);
592590

593-
uint32_t getMacroDirectivesOffset(const IdentifierInfo *Name);
591+
uint64_t getMacroDirectivesOffset(const IdentifierInfo *Name);
594592

595593
/// Emit a reference to a type.
596594
void AddTypeRef(QualType T, RecordDataImpl &Record);

clang/include/clang/Serialization/ModuleFile.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ class ModuleFile {
251251
/// The base offset in the source manager's view of this module.
252252
unsigned SLocEntryBaseOffset = 0;
253253

254-
/// Base file offset for the offsets in SLocEntryOffsets. Real file offset
255-
/// for the entry is SLocEntryOffsetsBase + SLocEntryOffsets[i].
256-
uint64_t SLocEntryOffsetsBase = 0;
257-
258254
/// Offsets for all of the source location entries in the
259255
/// AST file.
260256
const uint32_t *SLocEntryOffsets = nullptr;
@@ -306,10 +302,6 @@ class ModuleFile {
306302
/// The number of macros in this AST file.
307303
unsigned LocalNumMacros = 0;
308304

309-
/// Base file offset for the offsets in MacroOffsets. Real file offset for
310-
/// the entry is MacroOffsetsBase + MacroOffsets[i].
311-
uint64_t MacroOffsetsBase = 0;
312-
313305
/// Offsets of macros in the preprocessor block.
314306
///
315307
/// This array is indexed by the macro ID (-1), and provides
@@ -458,7 +450,7 @@ class ModuleFile {
458450

459451
/// Offset of each type within the bitstream, indexed by the
460452
/// type ID, or the representation of a Type*.
461-
const uint64_t *TypeOffsets = nullptr;
453+
const uint32_t *TypeOffsets = nullptr;
462454

463455
/// Base type ID for types local to this module as represented in
464456
/// the global type ID space.

clang/lib/Serialization/ASTReader.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,6 @@ bool ASTReader::ReadSLocEntry(int ID) {
14701470

14711471
ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second;
14721472
if (llvm::Error Err = F->SLocEntryCursor.JumpToBit(
1473-
F->SLocEntryOffsetsBase +
14741473
F->SLocEntryOffsets[ID - F->SLocEntryBaseID])) {
14751474
Error(std::move(Err));
14761475
return true;
@@ -1933,8 +1932,9 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
19331932
return HFI;
19341933
}
19351934

1936-
void ASTReader::addPendingMacro(IdentifierInfo *II, ModuleFile *M,
1937-
uint32_t MacroDirectivesOffset) {
1935+
void ASTReader::addPendingMacro(IdentifierInfo *II,
1936+
ModuleFile *M,
1937+
uint64_t MacroDirectivesOffset) {
19381938
assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard");
19391939
PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset));
19401940
}
@@ -2099,8 +2099,7 @@ void ASTReader::resolvePendingMacro(IdentifierInfo *II,
20992099

21002100
BitstreamCursor &Cursor = M.MacroCursor;
21012101
SavedStreamPosition SavedPosition(Cursor);
2102-
if (llvm::Error Err =
2103-
Cursor.JumpToBit(M.MacroOffsetsBase + PMInfo.MacroDirectivesOffset)) {
2102+
if (llvm::Error Err = Cursor.JumpToBit(PMInfo.MacroDirectivesOffset)) {
21042103
Error(std::move(Err));
21052104
return;
21062105
}
@@ -3099,7 +3098,7 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
30993098
Error("duplicate TYPE_OFFSET record in AST file");
31003099
return Failure;
31013100
}
3102-
F.TypeOffsets = reinterpret_cast<const uint64_t *>(Blob.data());
3101+
F.TypeOffsets = (const uint32_t *)Blob.data();
31033102
F.LocalNumTypes = Record[0];
31043103
unsigned LocalBaseTypeIndex = Record[1];
31053104
F.BaseTypeIndex = getTotalNumTypes();
@@ -3377,7 +3376,6 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
33773376
F.SLocEntryOffsets = (const uint32_t *)Blob.data();
33783377
F.LocalNumSLocEntries = Record[0];
33793378
unsigned SLocSpaceSize = Record[1];
3380-
F.SLocEntryOffsetsBase = Record[2];
33813379
std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) =
33823380
SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries,
33833381
SLocSpaceSize);
@@ -3696,7 +3694,6 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
36963694
F.MacroOffsets = (const uint32_t *)Blob.data();
36973695
F.LocalNumMacros = Record[0];
36983696
unsigned LocalBaseMacroID = Record[1];
3699-
F.MacroOffsetsBase = Record[2];
37003697
F.BaseMacroID = getTotalNumMacros();
37013698

37023699
if (F.LocalNumMacros > 0) {
@@ -5910,8 +5907,8 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
59105907
}
59115908

59125909
SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor);
5913-
if (llvm::Error Err = M.PreprocessorDetailCursor.JumpToBit(
5914-
M.MacroOffsetsBase + PPOffs.BitOffset)) {
5910+
if (llvm::Error Err =
5911+
M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset)) {
59155912
Error(std::move(Err));
59165913
return nullptr;
59175914
}
@@ -8430,8 +8427,7 @@ MacroInfo *ASTReader::getMacro(MacroID ID) {
84308427
assert(I != GlobalMacroMap.end() && "Corrupted global macro map");
84318428
ModuleFile *M = I->second;
84328429
unsigned Index = ID - M->BaseMacroID;
8433-
MacrosLoaded[ID] =
8434-
ReadMacroRecord(*M, M->MacroOffsetsBase + M->MacroOffsets[Index]);
8430+
MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]);
84358431

84368432
if (DeserializationListener)
84378433
DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS,

clang/lib/Serialization/ASTReaderDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2870,7 +2870,7 @@ ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
28702870
const DeclOffset &DOffs =
28712871
M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
28722872
Loc = TranslateSourceLocation(*M, DOffs.getLocation());
2873-
return RecordLocation(M, DOffs.getBitOffset());
2873+
return RecordLocation(M, DOffs.BitOffset);
28742874
}
28752875

28762876
ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {

clang/lib/Serialization/ASTWriter.cpp

+15-26
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,6 @@ 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();
18971896
RecordData PreloadSLocs;
18981897
SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1);
18991898
for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size();
@@ -1904,9 +1903,7 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
19041903
assert(&SourceMgr.getSLocEntry(FID) == SLoc);
19051904

19061905
// Record the offset of this source-location entry.
1907-
uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase;
1908-
assert((Offset >> 32) == 0 && "SLocEntry offset too large");
1909-
SLocEntryOffsets.push_back(Offset);
1906+
SLocEntryOffsets.push_back(Stream.GetCurrentBitNo());
19101907

19111908
// Figure out which record code to use.
19121909
unsigned Code;
@@ -2014,14 +2011,12 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
20142011
Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS));
20152012
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs
20162013
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size
2017-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
20182014
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets
20192015
unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
20202016
{
20212017
RecordData::value_type Record[] = {
20222018
SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(),
2023-
SourceMgr.getNextLocalOffset() - 1 /* skip dummy */,
2024-
SLocEntryOffsetsBase};
2019+
SourceMgr.getNextLocalOffset() - 1 /* skip dummy */};
20252020
Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record,
20262021
bytes(SLocEntryOffsets));
20272022
}
@@ -2098,11 +2093,9 @@ static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule,
20982093
/// Writes the block containing the serialized form of the
20992094
/// preprocessor.
21002095
void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
2101-
uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo();
2102-
21032096
PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
21042097
if (PPRec)
2105-
WritePreprocessorDetail(*PPRec, MacroOffsetsBase);
2098+
WritePreprocessorDetail(*PPRec);
21062099

21072100
RecordData Record;
21082101
RecordData ModuleMacroRecord;
@@ -2163,8 +2156,7 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
21632156
// identifier they belong to.
21642157
for (const IdentifierInfo *Name : MacroIdentifiers) {
21652158
MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name);
2166-
uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2167-
assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large");
2159+
auto StartOffset = Stream.GetCurrentBitNo();
21682160

21692161
// Emit the macro directives in reverse source order.
21702162
for (; MD; MD = MD->getPrevious()) {
@@ -2237,12 +2229,14 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
22372229

22382230
// Record the local offset of this macro.
22392231
unsigned Index = ID - FirstMacroID;
2240-
if (Index >= MacroOffsets.size())
2241-
MacroOffsets.resize(Index + 1);
2232+
if (Index == MacroOffsets.size())
2233+
MacroOffsets.push_back(Stream.GetCurrentBitNo());
2234+
else {
2235+
if (Index > MacroOffsets.size())
2236+
MacroOffsets.resize(Index + 1);
22422237

2243-
uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2244-
assert((Offset >> 32) == 0 && "Macro offset too large");
2245-
MacroOffsets[Index] = Offset;
2238+
MacroOffsets[Index] = Stream.GetCurrentBitNo();
2239+
}
22462240

22472241
AddIdentifierRef(Name, Record);
22482242
AddSourceLocation(MI->getDefinitionLoc(), Record);
@@ -2293,20 +2287,17 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
22932287
Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET));
22942288
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros
22952289
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID
2296-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset
22972290
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
22982291

22992292
unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
23002293
{
23012294
RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(),
2302-
FirstMacroID - NUM_PREDEF_MACRO_IDS,
2303-
MacroOffsetsBase};
2295+
FirstMacroID - NUM_PREDEF_MACRO_IDS};
23042296
Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets));
23052297
}
23062298
}
23072299

2308-
void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
2309-
uint64_t MacroOffsetsBase) {
2300+
void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec) {
23102301
if (PPRec.local_begin() == PPRec.local_end())
23112302
return;
23122303

@@ -2343,10 +2334,8 @@ void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec,
23432334
(void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) {
23442335
Record.clear();
23452336

2346-
uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase;
2347-
assert((Offset >> 32) == 0 && "Preprocessed entity offset too large");
23482337
PreprocessedEntityOffsets.push_back(
2349-
PPEntityOffset((*E)->getSourceRange(), Offset));
2338+
PPEntityOffset((*E)->getSourceRange(), Stream.GetCurrentBitNo()));
23502339

23512340
if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) {
23522341
// Record this macro definition's ID.
@@ -5155,7 +5144,7 @@ MacroID ASTWriter::getMacroID(MacroInfo *MI) {
51555144
return MacroIDs[MI];
51565145
}
51575146

5158-
uint32_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) {
5147+
uint64_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) {
51595148
return IdentMacroDirectivesOffsetMap.lookup(Name);
51605149
}
51615150

clang/lib/Serialization/ASTWriterDecl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2434,12 +2434,12 @@ void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
24342434
SourceLocation Loc = D->getLocation();
24352435
unsigned Index = ID - FirstDeclID;
24362436
if (DeclOffsets.size() == Index)
2437-
DeclOffsets.emplace_back(Loc, Offset);
2437+
DeclOffsets.push_back(DeclOffset(Loc, Offset));
24382438
else if (DeclOffsets.size() < Index) {
24392439
// FIXME: Can/should this happen?
24402440
DeclOffsets.resize(Index+1);
24412441
DeclOffsets[Index].setLocation(Loc);
2442-
DeclOffsets[Index].setBitOffset(Offset);
2442+
DeclOffsets[Index].BitOffset = Offset;
24432443
} else {
24442444
llvm_unreachable("declarations should be emitted in ID order");
24452445
}

0 commit comments

Comments
 (0)