Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang 17 compilation failure: New required parameter for PrecompiledPreamble #938

Open
swan-amazon opened this issue May 10, 2023 · 1 comment

Comments

@swan-amazon
Copy link

When compiling with clang version 17.0.0 a build failure is encountered. The build failure error message is below. You can see that it's complaining about the function signature of buildPreamble function.

Recently (2023-Mar-07), a new parameter was added to this function.

StoragePath The path to a directory, in which to create a temporary file to store PCH in. If empty, the default system temporary directory is used. This parameter is ignored if StoreInMemory is true.

To address the issue, the StoragePath parameter can be set to StringRef() which is an empty string ref.

Build Failure

% cmake --build Release
[  2%] Building CXX object CMakeFiles/ccls.dir/src/sema_manager.cc.o
/home/jameswan/.local/share/ccls/src/sema_manager.cc: In function 'void ccls::{anonymous}::buildPreamble(ccls::Session&, clang::CompilerInvo
cation&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, const ccls::SemaManager::PreambleTask&, std::unique_ptr<ccls::PreambleStatCache>)'
:
/home/jameswan/.local/share/ccls/src/sema_manager.cc:407:64: error: no matching function for call to 'clang::PrecompiledPreamble::Build(clan
g::CompilerInvocation&, std::unique_ptr<llvm::MemoryBuffer>::pointer, clang::PreambleBounds&, clang::DiagnosticsEngine&, llvm::IntrusiveRefC
ntPtr<llvm::vfs::FileSystem>&, std::shared_ptr<clang::PCHContainerOperations>&, bool, ccls::{anonymous}::CclsPreambleCallbacks&)'
           ci, buf.get(), bounds, *de, fs, session.pch, true, pc)) {
                                                                ^
In file included from /home/jameswan/.local/include/clang/Frontend/ASTUnit.h:30:0,
                 from /home/jameswan/.local/include/clang/Frontend/FrontendAction.h:23,
                 from /home/jameswan/.local/include/clang/Frontend/FrontendActions.h:12,
                 from /home/jameswan/.local/share/ccls/src/sema_manager.hh:13,
                 from /home/jameswan/.local/share/ccls/src/sema_manager.cc:4:
/home/jameswan/.local/include/clang/Frontend/PrecompiledPreamble.h:85:3: note: candidate: static llvm::ErrorOr<clang::PrecompiledPreamble> c
lang::PrecompiledPreamble::Build(const clang::CompilerInvocation&, const llvm::MemoryBuffer*, clang::PreambleBounds, clang::DiagnosticsEngin
e&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::shared_ptr<clang::PCHContainerOperations>, bool, llvm::StringRef, clang::PreambleC
allbacks&)
   Build(const CompilerInvocation &Invocation,
   ^~~~~
/home/jameswan/.local/include/clang/Frontend/PrecompiledPreamble.h:85:3: note:   candidate expects 9 arguments, 8 provided
gmake[2]: *** [CMakeFiles/ccls.dir/src/sema_manager.cc.o] Error 1
gmake[1]: *** [CMakeFiles/ccls.dir/all] Error 2
gmake: *** [all] Error 2

Version Information (after patch and build)

ccls version 0.20220729-4-g8bc39595
clang version 17.0.0 (https://github.com/llvm/llvm-project.git f031fc35716cd48c7b1eb32604dbba45d99c5fef)

Local Fix

I was able to resolve the issue by modifying the src/sema_manager.cc file to set the new parameter to a permissive value.

I'm not sure that this is a good change to make. It should then make the code incompatible with older versions of clang.

dev-dsk-jameswan-2c-c560a4da % cat 0001-Clang-17-compilation-failure-New-required-parameter-.patch
From ddafb26724c90d59afcb13453ca6aa1c1fd83a7d Mon Sep 17 00:00:00 2001
From: James Swan <122404367+swan-amazon@users.noreply.github.com>
Date: Wed, 10 May 2023 18:52:55 +0000
Subject: [PATCH] Clang 17 compilation failure: New required parameter for
 PrecompiledPreamble

When compiling with [clang version 17.0.0](https://github.com/llvm/llvm-project/commit/f031fc35716cd48c7b1eb32604dbba45d99c5fef)
a build failure is encountered.

Recently (2023-Mar-07), a new parameter [was added to this function](https://github.com/llvm/llvm-project/blame/dda2a5d4570e1cccc30f078844e8e9b39b1b4d7a/clang/include/clang/Frontend/PrecompiledPreamble.h#L78).

> StoragePath The path to a directory, in which to create a temporary
file to store PCH in. If empty, the default system temporary directory
is used. This parameter is ignored if StoreInMemory is true.

To address the issue, the `StoragePath` parameter can be set to
`StringRef()` which is an [empty string ref](https://llvm.org/doxygen/classllvm_1_1StringRef.html#a95fff1cbaf3b1b5b51870a60df57a6e8).
---
 src/sema_manager.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sema_manager.cc b/src/sema_manager.cc
index 14f303b5..af8a98fc 100644
--- a/src/sema_manager.cc
+++ b/src/sema_manager.cc
@@ -404,7 +404,7 @@ void buildPreamble(Session &session, CompilerInvocation &ci,

   CclsPreambleCallbacks pc;
   if (auto newPreamble = PrecompiledPreamble::Build(
-          ci, buf.get(), bounds, *de, fs, session.pch, true, pc)) {
+          ci, buf.get(), bounds, *de, fs, session.pch, true, StringRef(), pc)) {
     assert(!ci.getPreprocessorOpts().RetainRemappedFileBuffers);
     if (oldP) {
       auto &old_includes = oldP->includes;
--
2.39.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant