Skip to content

Commit

Permalink
[compiler] Include file offset when loading builtins PCH
Browse files Browse the repository at this point in the history
Commit d4a912153488 changed how the offsets into AST bitstream
files are handled. This patch changes our loading of the builtins
PCH to include the new `InputFilesOffsetBase` field.

As this only affects LLVM tip/18, it is locked behind a preprocessor
macro.
  • Loading branch information
RossBrunton committed Nov 21, 2023
1 parent db2f73e commit 6b87c3c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modules/compiler/source/base/source/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ static bool loadKernelAPIHeader(clang::CompilerInstance &compiler,
// stored inside the PCH file.
llvm::BitstreamCursor &Cursor = moduleFile->InputFilesCursor;
clang::SavedStreamPosition SavedPosition(Cursor);
if (Cursor.JumpToBit(moduleFile->InputFileOffsets[0])) {
uint64_t Base = 0;
#if LLVM_VERSION_GREATER_EQUAL(18, 0)
// LLVM 18 introduces a new offset that should be included
Base = moduleFile->InputFilesOffsetBase;
#endif
if (Cursor.JumpToBit(Base + moduleFile->InputFileOffsets[0])) {
return false;
}

Expand All @@ -250,7 +255,7 @@ static bool loadKernelAPIHeader(clang::CompilerInstance &compiler,
// warning. However, this assert is guaranteed to be correct due to the
// above `Cursor.JumpToBit` call, and provides enough information for
// clang-tidy to understand that the undefined shift is impossible.
assert((Cursor.GetCurrentBitNo() == moduleFile->InputFileOffsets[0]) &&
assert((Cursor.GetCurrentBitNo() == Base + moduleFile->InputFileOffsets[0]) &&
"Clang bitstream reader is in invalid state.");
clang::ASTReader::RecordData Record;
llvm::StringRef Filename;
Expand Down

0 comments on commit 6b87c3c

Please sign in to comment.