MaskRay / ccls

C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting
Apache License 2.0
3.72k stars 254 forks source link

ccls crashes when `getHeaderSearchOpts().ModuleFormat` is obj (e.g. `-gmodules`) #926

Closed lanza closed 1 year ago

lanza commented 1 year ago

I didn't look too much into it, I just ended up disabling the module build. But I had:

set(LLVM_ENABLE_MODULES ON CACHE BOOL "")

ccls was crashing here: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Frontend/CompilerInstance.h#L549

getHeaderSearchOpts().ModuleFormat; was obj.

lanza commented 1 year ago

clang seems to register the obj reader and writer during cc1_main for some reason.

https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/cc1_main.cpp#L193

The default ctor for the PCH just registers the RawPCHContainer{Writer,Reader}:

https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/PCHContainerOperations.cpp#L66

which is whats used in ccls:

https://github.com/MaskRay/ccls/blob/6dc564f2a8608fff778a7d7e8ed0d5acd8d61e6b/src/indexer.cc#L1286 https://github.com/MaskRay/ccls/blob/6dc564f2a8608fff778a7d7e8ed0d5acd8d61e6b/src/sema_manager.cc#L724

MaskRay commented 1 year ago

Do you have the full cmake command line including -DLLVM_ENABLE_MODULES=on when configuring llvm-project? I think in the ccls build, the value of LLVM_ENABLE_MODULES should match llvm-project's.

lanza commented 1 year ago

Do you have the full cmake command line including -DLLVM_ENABLE_MODULES=on when configuring llvm-project? I think in the ccls build, the value of LLVM_ENABLE_MODULES should match llvm-project's.

Sorry I'm not talking of the build of ccls itself, I'm using ccls as my LSP while editing clang.

I reduced it to a minimal repro:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(test CXX)
set(CMAKE_CXX_FLAGS -gmodules)
add_executable(main main.cpp)

main.cpp:

int main() {}
MaskRay commented 1 year ago

Thanks for the report. Fixed by 8bc3959537adae26b470c8223845555ea26693cc

Similar to libclang https://github.com/llvm/llvm-project/commit/a3e2ff19e59c587ea14611eb64400c6d0ecabcee