Skip to content

Commit 49eb67c

Browse files
committed
Reland "[clang][modules] Use relative offsets for input files"
This reverts commit 870f158, effectively relanding commit b9d78bd.
1 parent 2b5ff47 commit 49eb67c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

clang/include/clang/Serialization/ModuleFile.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ class ModuleFile {
253253
/// The cursor to the start of the input-files block.
254254
llvm::BitstreamCursor InputFilesCursor;
255255

256-
/// Offsets for all of the input file entries in the AST file.
256+
/// Absolute offset of the start of the input-files block.
257+
uint64_t InputFilesOffsetBase = 0;
258+
259+
/// Relative offsets for all of the input file entries in the AST file.
257260
const llvm::support::unaligned_uint64_t *InputFileOffsets = nullptr;
258261

259262
/// The input files that have been loaded from this AST file.

clang/lib/Serialization/ASTReader.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,8 @@ InputFileInfo ASTReader::getInputFileInfo(ModuleFile &F, unsigned ID) {
22782278
// Go find this input file.
22792279
BitstreamCursor &Cursor = F.InputFilesCursor;
22802280
SavedStreamPosition SavedPosition(Cursor);
2281-
if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) {
2281+
if (llvm::Error Err = Cursor.JumpToBit(F.InputFilesOffsetBase +
2282+
F.InputFileOffsets[ID - 1])) {
22822283
// FIXME this drops errors on the floor.
22832284
consumeError(std::move(Err));
22842285
}
@@ -2362,7 +2363,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
23622363
// Go find this input file.
23632364
BitstreamCursor &Cursor = F.InputFilesCursor;
23642365
SavedStreamPosition SavedPosition(Cursor);
2365-
if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) {
2366+
if (llvm::Error Err = Cursor.JumpToBit(F.InputFilesOffsetBase +
2367+
F.InputFileOffsets[ID - 1])) {
23662368
// FIXME this drops errors on the floor.
23672369
consumeError(std::move(Err));
23682370
}
@@ -2732,6 +2734,7 @@ ASTReader::ReadControlBlock(ModuleFile &F,
27322734
Error("malformed block record in AST file");
27332735
return Failure;
27342736
}
2737+
F.InputFilesOffsetBase = F.InputFilesCursor.GetCurrentBitNo();
27352738
continue;
27362739

27372740
case OPTIONS_BLOCK_ID:
@@ -5287,6 +5290,7 @@ bool ASTReader::readASTFileControlBlock(
52875290
bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation();
52885291
bool NeedsImports = Listener.needsImportVisitation();
52895292
BitstreamCursor InputFilesCursor;
5293+
uint64_t InputFilesOffsetBase = 0;
52905294

52915295
RecordData Record;
52925296
std::string ModuleDir;
@@ -5322,6 +5326,7 @@ bool ASTReader::readASTFileControlBlock(
53225326
if (NeedsInputFiles &&
53235327
ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))
53245328
return true;
5329+
InputFilesOffsetBase = InputFilesCursor.GetCurrentBitNo();
53255330
break;
53265331

53275332
default:
@@ -5394,7 +5399,8 @@ bool ASTReader::readASTFileControlBlock(
53945399

53955400
BitstreamCursor &Cursor = InputFilesCursor;
53965401
SavedStreamPosition SavedPosition(Cursor);
5397-
if (llvm::Error Err = Cursor.JumpToBit(InputFileOffs[I])) {
5402+
if (llvm::Error Err =
5403+
Cursor.JumpToBit(InputFilesOffsetBase + InputFileOffs[I])) {
53985404
// FIXME this drops errors on the floor.
53995405
consumeError(std::move(Err));
54005406
}

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,8 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
16001600
IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
16011601
unsigned IFHAbbrevCode = Stream.EmitAbbrev(std::move(IFHAbbrev));
16021602

1603+
uint64_t InputFilesOffsetBase = Stream.GetCurrentBitNo();
1604+
16031605
// Get all ContentCache objects for files.
16041606
std::vector<InputFileEntry> UserFiles;
16051607
std::vector<InputFileEntry> SystemFiles;
@@ -1663,7 +1665,7 @@ void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
16631665
continue; // already recorded this file.
16641666

16651667
// Record this entry's offset.
1666-
InputFileOffsets.push_back(Stream.GetCurrentBitNo());
1668+
InputFileOffsets.push_back(Stream.GetCurrentBitNo() - InputFilesOffsetBase);
16671669

16681670
InputFileID = InputFileOffsets.size();
16691671

0 commit comments

Comments
 (0)