From 6b87c3cf5ddda18d0b16770c4f6f24ab34025af6 Mon Sep 17 00:00:00 2001 From: Ross Brunton Date: Mon, 20 Nov 2023 17:46:24 +0000 Subject: [PATCH] [compiler] Include file offset when loading builtins PCH 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. --- modules/compiler/source/base/source/module.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/compiler/source/base/source/module.cpp b/modules/compiler/source/base/source/module.cpp index 55df8f63a..e7d9c8efb 100644 --- a/modules/compiler/source/base/source/module.cpp +++ b/modules/compiler/source/base/source/module.cpp @@ -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; } @@ -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;