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

Crash of clangd during indexation #1614

Open
albkharisov opened this issue Apr 30, 2023 · 2 comments
Open

Crash of clangd during indexation #1614

albkharisov opened this issue Apr 30, 2023 · 2 comments

Comments

@albkharisov
Copy link

albkharisov commented Apr 30, 2023

clangd crashes after indexing some files.
I have a VScode with clangd plugin and clangd 16.
VScode uses a docker container plugin, build (compiler: g++ is used, gnu++14) is done inside container.
compile_commands.json is provided (it's seen in logs clangd accepts it).
What's important: when remove all other files and leave one which caused an error - nothing is produced on a disk (no *.idx files), and no error occurs. When I run clangd manually with --check - still no crush.
Running with option (--clang-tidy=0) gives no result - the crash remains.

Sorry, but I can't provide the code. It's under NDA.

Logs are attached (but truncated, because it often sends a file inside a json).
crash_report.log

Backtrace:

 #0 0x00000000005398bb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:567:13
 #1 0x00000000005378bc llvm::sys::RunSignalHandlers() /__w/clangd/clangd/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x0000000000539f66 SignalHandler(int) /__w/clangd/clangd/llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1
 #3 0x00007f4c09862420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00000000014f1f1a getName /__w/clangd/clangd/llvm-project/clang/include/clang/Basic/SourceManager.h:349:38
 #5 0x00000000014f1f1a clang::clangd::isSpelledInSource(clang::SourceLocation, clang::SourceManager const&) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/SourceCode.cpp:234:70
 #6 0x00000000012f95e3 clang::clangd::nameLocation(clang::Decl const&, clang::SourceManager const&) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/AST.cpp:177:7
 #7 0x0000000001666b22 isPrivateProtoDecl /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/SymbolCollector.cpp:56:8
 #8 0x0000000001666b22 clang::clangd::SymbolCollector::shouldCollectSymbol(clang::NamedDecl const&, clang::ASTContext const&, clang::clangd::SymbolCollector::Options const&, bool) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/SymbolCollector.cpp:490:7
 #9 0x00000000016671c7 clang::clangd::SymbolCollector::handleDeclOccurrence(clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::SourceLocation, clang::index::IndexDataConsumer::ASTNodeInfo) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/SymbolCollector.cpp:580:7
#10 0x0000000001cccf01 clang::index::IndexingContext::handleDeclOccurrence(clang::Decl const*, clang::SourceLocation, bool, clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>, clang::Expr const*, clang::Decl const*, clang::DeclContext const*) /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexingContext.cpp:450:23
#11 0x0000000001ccc320 clang::index::IndexingContext::handleDecl(clang::Decl const*, unsigned int, llvm::ArrayRef<clang::index::SymbolRelation>) /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexingContext.cpp:55:3
#12 0x0000000001cd8dcc VisitNamespaceDecl /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexDecl.cpp:593:5
#13 0x0000000001cd8dcc clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::IndexingDeclVisitor, bool>::Visit(clang::Decl const*) /__w/clangd/clangd/clangd_16.0.2/tools/clang/include/clang/AST/DeclNodes.inc:143:1
#14 0x0000000001cd8b49 clang::index::IndexingContext::indexDecl(clang::Decl const*) /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexDecl.cpp:783:7
#15 0x0000000001cda10f clang::index::IndexingContext::indexTopLevelDecl(clang::Decl const*) /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexDecl.cpp:809:10
#16 0x0000000001ccb4bc clang::index::indexTopLevelDecls(clang::ASTContext&, clang::Preprocessor&, llvm::ArrayRef<clang::Decl const*>, clang::index::IndexDataConsumer&, clang::index::IndexingOptions) /__w/clangd/clangd/llvm-project/clang/lib/Index/IndexingAction.cpp:285:22
#17 0x000000000163c3f9 ~_Function_base /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/std_function.h:275:11
#18 0x000000000163c3f9 ~IndexingOptions /__w/clangd/clangd/llvm-project/clang/include/clang/Index/IndexingOptions.h:20:8
#19 0x000000000163c3f9 clang::clangd::(anonymous namespace)::indexSymbols(clang::ASTContext&, clang::Preprocessor&, llvm::ArrayRef<clang::Decl*>, clang::clangd::MainFileMacros const*, clang::clangd::CanonicalIncludes const&, bool, llvm::StringRef, bool) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/FileIndex.cpp:82:3
#20 0x0000000001640f96 indexMainDecls /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/FileIndex.cpp:223:10
#21 0x0000000001640f96 clang::clangd::FileIndex::updateMain(llvm::StringRef, clang::clangd::ParsedAST&) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/index/FileIndex.cpp:469:19
#22 0x0000000001381db7 size /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_vector.h:671:66
#23 0x0000000001381db7 vector /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/stl_vector.h:327:19
#24 0x0000000001381db7 clang::clangd::(anonymous namespace)::UpdateIndexCallbacks::onMainAST(llvm::StringRef, clang::clangd::ParsedAST&, llvm::function_ref<void (llvm::function_ref<void ()>)>) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/ClangdServer.cpp:111:37
#25 0x0000000001511176 generateDiagnostics /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1228:15
#26 0x0000000001511176 clang::clangd::(anonymous namespace)::ASTWorker::updatePreamble(std::unique_ptr<clang::CompilerInvocation, std::default_delete<clang::CompilerInvocation> >, clang::clangd::ParseInputs, std::shared_ptr<clang::clangd::PreambleData const>, std::vector<clang::clangd::Diag, std::allocator<clang::clangd::Diag> >, clang::clangd::WantDiagnostics)::$_2::operator()() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1124:5
#27 0x000000000150bf53 operator() /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#28 0x000000000150bf53 clang::clangd::(anonymous namespace)::ASTWorker::runTask(llvm::StringRef, llvm::function_ref<void ()>) /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1304:3
#29 0x000000000150a9c0 run /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:1438:5
#30 0x000000000150a9c0 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/TUScheduler.cpp:820:42
#31 0x000000000150a9c0 void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::(anonymous namespace)::ASTWorker::create(llvm::StringRef, clang::clangd::GlobalCompilationDatabase const&, clang::clangd::TUScheduler::ASTCache&, clang::clangd::TUScheduler::HeaderIncluderCache&, clang::clangd::AsyncTaskRunner*, clang::clangd::Semaphore&, clang::clangd::TUScheduler::Options const&, clang::clangd::ParsingCallbacks&)::$_7>(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:221:12
#32 0x00000000016b11c1 PointerIntPair /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:49:12
#33 0x00000000016b11c1 UniqueFunctionBase /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:339:3
#34 0x00000000016b11c1 unique_function /__w/clangd/clangd/llvm-project/llvm/include/llvm/ADT/FunctionExtras.h:368:3
#35 0x00000000016b11c1 operator() /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:103:14
#36 0x00000000016b11c1 operator()<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15) &> /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:43:11
#37 0x00000000016b11c1 __invoke_impl<void, (lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42:9), (lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15) &> /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/invoke.h:60:14
#38 0x00000000016b11c1 __invoke<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42:9), (lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15) &> /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/bits/invoke.h:95:14
#39 0x00000000016b11c1 __apply_impl<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42:9), std::tuple<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15)> &, 0> /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/tuple:1662:14
#40 0x00000000016b11c1 apply<(lambda at /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:42:9), std::tuple<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15)> &> /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/tuple:1671:14
#41 0x00000000016b11c1 GenericThreadProxy<std::tuple<(lambda at /__w/clangd/clangd/llvm-project/clang-tools-extra/clangd/support/Threading.cpp:98:15)> > /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:41:5
#42 0x00000000016b11c1 void* llvm::thread::ThreadProxy<std::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1> >(void*) /__w/clangd/clangd/llvm-project/llvm/include/llvm/Support/thread.h:55:5
#43 0x00007f4c09856609 start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8609)
#44 0x00007f4c0961c133 clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f133)

System information

Output of clangd --version:
clangd version 16.0.2 (https://github.com/llvm/llvm-project 18ddebe1a1a9bde349441631365f0472e9693520)
Features: linux+grpc
Platform: x86_64-unknown-linux-gnu
First tried on 15.0.6 and 15.0.7 - crash remains in all versions.

Editor/LSP plugin:
VSCode + plugin clangd

Operating system:
Ubuntu 22.04

@HighCommander4
Copy link

If you can get your hands on a version of clangd with assertions enabled, it might be interesting to see if this assertion is firing before the crash.

Regardless, it may be challenging to track this down without a reproducer. If you can try reducing your file to a minimal reproducer that no longer contains proprietary code, that would be helpful.

@HighCommander4
Copy link

This looks like it's probably the same crash that was reported in llvm/llvm-project#76667, and should therefore be fixed by the hardening being pursued in that issue.

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

2 participants