-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clangd] "Assertion 'LocalDeclID < LocalNumDecls' failed." when using clangd with --experimental-modules-support
#130280
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
Comments
This is the assertion in question:
It isn't hit if I compile the project normally with clang/cmake. |
LocalDeclID < LocalNumDecls' failed." when using clangd with
--experimental-modules-support`--experimental-modules-support
@llvm/issue-subscribers-clangd Author: Jan Kokemüller (jiixyj)
I'm trying out the new experimental module support of clangd with a ~25 KLOC large code base. On some files (~5 out of ~170), clangd crashes with an assertion failure in `clang/lib/Serialization/ASTReader.cpp`: "Assertion `LocalDeclID < LocalNumDecls' failed." With assertions disabled there are instead "random" crashes in the parser (I guess because of UB?).
The git hash is ff993f9 . I haven't found a minimal, standalone reproducer yet, sadly. I have attached the output of Any ideas how to further debug this? I haven't found any pattern in the ~5 files that crash, although the crashes are reproducible. |
@llvm/issue-subscribers-clang-modules Author: Jan Kokemüller (jiixyj)
I'm trying out the new experimental module support of clangd with a ~25 KLOC large code base. On some files (~5 out of ~170), clangd crashes with an assertion failure in `clang/lib/Serialization/ASTReader.cpp`: "Assertion `LocalDeclID < LocalNumDecls' failed." With assertions disabled there are instead "random" crashes in the parser (I guess because of UB?).
The git hash is ff993f9 . I haven't found a minimal, standalone reproducer yet, sadly. I have attached the output of Any ideas how to further debug this? I haven't found any pattern in the ~5 files that crash, although the crashes are reproducible. |
Did you use the correct compilation databases? |
I think so. I've symlinked it into the main project folder, but it also crashes if I directly run clangd inside the build folder where the compilation database lives. I've had a quick look at the output of
When I delete the
Maybe those errors are to blame somehow?
|
Here is the compilation database in question, generated by CMake 3.30.1. |
I guess so. The assertion says, the loaded decls are more than what expected. And may be it is due to inconsistent setups. Did you use
I had no clue. Did you restart the clangd server after removing these .pcm in build dir? |
Oh, it looks like CMake generate the compilation database with different manner with previous version, which I tested with. Could you try again with removing all pattern like |
OK, I will try this!
Yes, to get those outputs I'm running clangd in
I'll try this as well. |
Just as another data point, those
|
The execution trace in gdb-log.txt make me believe that the crash itself is related to issue #132059 and should be fixed in trunk by #133462. Using a clangd build from the given git hash, I was able to make Crashnav@nixos:~/llvm-project/debug-env/test1$ ../../build-ff993f9/bin/clangd --compile-commands-dir=./ff993f9-build --check=main.cpp
I[15:35:14.316] clangd version 21.0.0git ([email protected]:llvm/llvm-project.git ff993f9a4c23cfaae54f2a2708bed23954b8d9c0)
I[15:35:14.316] Features: linux+debug
I[15:35:14.316] PID: 138061
I[15:35:14.316] Working directory: /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1
I[15:35:14.316] argv[0]: ../../build-ff993f9/bin/clangd
I[15:35:14.316] argv[1]: --compile-commands-dir=./ff993f9-build
I[15:35:14.316] argv[2]: --check=main.cpp
I[15:35:14.316] Entering check mode (no LSP server)
I[15:35:14.316] Testing on source file /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/main.cpp
I[15:35:14.316] Loading compilation database...
I[15:35:14.317] Loaded compilation database from /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/./ff993f9-build/compile_commands.json
I[15:35:14.318] Compile command from CDB is: [/home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/ff993f9-build] /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/build-ff993f9/bin/clang++ --driver-mode=g++ -std=gnu++23 -fmodule-file=A=CMakeFiles/main.dir/B.pcm -o CMakeFiles/main.dir/main.cpp.o -c -resource-dir=/home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/build-ff993f9/lib/clang/21 -- /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/main.cpp
I[15:35:14.319] Parsing command...
I[15:35:14.321] internal (cc1) args are: -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/ff993f9-build -fcoverage-compilation-dir=/home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/ff993f9-build -resource-dir /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/build-ff993f9/lib/clang/21 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/build-ff993f9/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=gnu++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=A=CMakeFiles/main.dir/B.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/main.cpp
I[15:35:14.322] Building preamble...
I[15:35:14.347] Built preamble of size 261968 for file /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/main.cpp version null in 0.02 seconds
I[15:35:14.347] Indexing headers...
I[15:35:14.349] Building AST...
clangd: /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Serialization/ASTReader.cpp:9581: serialization::SubmoduleID clang::ASTReader::getGlobalSubmoduleID(ModuleFile &, unsigned int) const: Assertion `I != M.SubmoduleRemap.end() && "Invalid index into submodule index remap"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.Stack dump:
0. Program arguments: ../../build-ff993f9/bin/clangd --compile-commands-dir=./ff993f9-build --check=main.cpp
1. /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/debug-env/test1/main.cpp:4:1: current parser token 'int'
#0 0x000055f1e1a2471d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:804:11
#1 0x000055f1e1a24bdb PrintStackTraceSignalHandler(void*) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:880:1
#2 0x000055f1e1a22d7f llvm::sys::RunSignalHandlers() /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/llvm/lib/Support/Signals.cpp:105:5
#3 0x000055f1e1a252b9 SignalHandler(int, siginfo_t*, void*) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:418:7
#4 0x00007f86ac59c250 (/lib/x86_64-linux-gnu/libc.so.6+0x45250)
#5 0x00007f86ac5faf1c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0xa3f1c)
#6 0x00007f86ac59c19e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4519e)
#7 0x00007f86ac57f902 abort (/lib/x86_64-linux-gnu/libc.so.6+0x28902)
#8 0x00007f86ac57f81e (/lib/x86_64-linux-gnu/libc.so.6+0x2881e)
#9 0x00007f86ac5927c7 (/lib/x86_64-linux-gnu/libc.so.6+0x3b7c7)
#10 0x000055f1e651b981 clang::ASTReader::getGlobalSubmoduleID(clang::serialization::ModuleFile&, unsigned int) const /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Serialization/ASTReader.cpp:9583:10
#11 0x000055f1e6531c29 clang::ASTReader::ReadAST(llvm::StringRef, clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, clang::serialization::ModuleFile**) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Serialization/ASTReader.cpp:4834:28
#12 0x000055f1e60aba14 clang::CompilerInstance::findOrCompileModuleAndReadAST(llvm::StringRef, clang::SourceLocation, clang::SourceLocation, bool) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1902:27
#13 0x000055f1e60ac960 clang::CompilerInstance::loadModule(clang::SourceLocation, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, clang::Module::NameVisibilityKind, bool) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:2054:31
#14 0x000055f1e335c660 clang::Sema::ActOnModuleImport(clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, llvm::ArrayRef<std::pair<clang::IdentifierInfo*, clang::SourceLocation>>, bool) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Sema/SemaModule.cpp:616:35
#15 0x000055f1e64ecec7 clang::Parser::ParseModuleImport(clang::SourceLocation, clang::Sema::ModuleImportState&) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Parse/Parser.cpp:2667:22
#16 0x000055f1e64eba6d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Parse/Parser.cpp:673:24
#17 0x000055f1e64eb7a0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Parse/Parser.cpp:608:8
#18 0x000055f1e63e16b9 clang::ParseAST(clang::Sema&, bool, bool) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Parse/ParseAST.cpp:170:15
#19 0x000055f1e617ab47 clang::ASTFrontendAction::ExecuteAction() /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1188:1
#20 0x000055f1e617a5a6 clang::FrontendAction::Execute() /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1076:7
#21 0x000055f1e40eaf97 clang::clangd::ParsedAST::build(llvm::StringRef, clang::clangd::ParseInputs const&, std::unique_ptr<clang::CompilerInvocation, std::default_delete<clang::CompilerInvocation>>, llvm::ArrayRef<clang::clangd::Diag>, std::shared_ptr<clang::clangd::PreambleData const>) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang-tools-extra/clangd/ParsedAST.cpp:713:19
#22 0x000055f1e3bd33a6 clang::clangd::(anonymous namespace)::Checker::buildAST() /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang-tools-extra/clangd/tool/Check.cpp:262:11
#23 0x000055f1e3bd249c clang::clangd::check(llvm::StringRef, clang::clangd::ThreadsafeFS const&, clang::clangd::ClangdLSPServer::Options const&) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang-tools-extra/clangd/tool/Check.cpp:522:7
#24 0x000055f1e3ba0704 clang::clangd::clangdMain(int, char**) /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang-tools-extra/clangd/tool/ClangdMain.cpp:1014:12
#25 0x000055f1e186cf92 main /home/nav/.distrobox/ubuntu-24-10-compiler-dev/llvm-project/clang-tools-extra/clangd/tool/ClangdToolMain.cpp:12:3
#26 0x00007f86ac5813b8 (/lib/x86_64-linux-gnu/libc.so.6+0x2a3b8)
#27 0x00007f86ac58147b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a47b)
#28 0x000055f1e15208e5 _start (../../build-ff993f9/bin/clangd+0x33d68e5)
Aborted (core dumped) Because exact location of the crash depends on the source file contents (context), I couldn’t reproduce the crash on the exactly same assert, but also from inside of
(For the second crash, I am clueless.) |
Thanks for looking into this. Do the crash still exist if the PCMs in the build directory are not used? We intended to ignore all PCMs built in build dir in clang-tools-extra/clangd/ModulesBuilder.cpp:155 : adjustHeaderSearchOptions |
I'm trying out the new experimental module support of clangd with a ~25 KLOC large code base. On some files (~5 out of ~170), clangd crashes with an assertion failure in
clang/lib/Serialization/ASTReader.cpp
: "Assertion `LocalDeclID < LocalNumDecls' failed." With assertions disabled there are instead "random" crashes in the parser (I guess because of UB?).The git hash is ff993f9 .
I haven't found a minimal, standalone reproducer yet, sadly. I have attached the output of
clangd --compile-commands-dir=. --experimental-modules-support --check=src/ldgr/core.cppm
and the backtrace in gdb.Any ideas how to further debug this? I haven't found any pattern in the ~5 files that crash, although the crashes are reproducible.
clangd-output.txt
gdb-log.txt
The text was updated successfully, but these errors were encountered: