Skip to content

Commit

Permalink
Merge pull request #222 from RossBrunton/bitcode_read
Browse files Browse the repository at this point in the history
[compiler] Include file offset when loading builtins PCH
  • Loading branch information
RossBrunton authored Nov 21, 2023
2 parents 7ce82c7 + 6b87c3c commit 7a69ab0
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 7a69ab0

Please sign in to comment.