| Issue |
203799
|
| Summary |
[clangd] Segfault when module imported through a header
|
| Labels |
|
| Assignees |
|
| Reporter |
itzexpoexpo
|
I'm encountering a crash on Windows when running `clangd` on a source file that imports a named module through a header:
```
I[00:02:32.967] clangd version 23.0.0git (https://github.com/llvm/llvm-project.git 71f69c19ae1a2887cb642695e574eab9e23708cf)
I[00:02:32.968] Features: windows
I[00:02:32.969] PID: 22120
I[00:02:32.969] Working directory: G:\Work\clangd-crash-repro
I[00:02:32.969] argv[0]: G:\Work\contributor\llvm-clangd-crash\build\bin\clangd.exe
I[00:02:32.969] argv[1]: --experimental-modules-support
I[00:02:32.969] argv[2]: --compile-commands-dir=build
I[00:02:32.969] argv[3]: --check=src/main.cpp
I[00:02:32.972] Entering check mode (no LSP server)
I[00:02:32.972] Testing on source file G:\Work\clangd-crash-repro\src\main.cpp
I[00:02:32.973] Loading compilation database...
I[00:02:32.974] Loaded compilation database from G:\Work\clangd-crash-repro\build\compile_commands.json
I[00:02:32.975] Compile command from CDB is: [G:/Work/clangd-crash-repro/build] "G:\\Work\\contributor\\llvm-clangd-crash\\build\\bin\\clang++.exe" --driver-mode=g++ -O0 -std=gnu++20 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -fmodule-file=mymodule=CMakeFiles/mymodule.dir/mymodule.pcm -o "CMakeFiles\\testbin.dir\\src\\main.cpp.obj" -c "-resource-dir=G:\\Work\\contributor\\llvm-clangd-crash\\build\\lib\\clang\\23" -- "G:\\Work\\clangd-crash-repro\\src\\main.cpp"
I[00:02:32.975] Parsing command...
I[00:02:32.978] internal (cc1) args are: -cc1 -triple x86_64-pc-windows-msvc19.44.35228 -O0 -fsyntax-only -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -gno-column-info -gcodeview -debug-info-kind=constructor -fdebug-compilation-dir=G:/Work/clangd-crash-repro/build -fcoverage-compilation-dir=G:/Work/clangd-crash-repro/build -resource-dir "G:\\Work\\contributor\\llvm-clangd-crash\\build\\lib\\clang\\23" -D _DEBUG -D _DLL -D _MT -internal-isystem "G:\\Work\\contributor\\llvm-clangd-crash\\build\\lib\\clang\\23\\include" -internal-isystem "G:\\Apps\\VisualStudio\\VC\\Tools\\MSVC\\14.44.35207\\include" -internal-isystem "G:\\Apps\\VisualStudio\\VC\\Tools\\MSVC\\14.44.35207\\atlmfc\\include" -internal-isystem "G:\\Windows Kits\\10\\Include\\10.0.26100.0\\ucrt" -internal-isystem "G:\\Windows Kits\\10\\Include\\10.0.26100.0\\shared" -internal-isystem "G:\\Windows Kits\\10\\Include\\10.0.26100.0\\um" -internal-isystem "G:\\Windows Kits\\10\\Include\\10.0.26100.0\\winrt" -internal-isystem "G:\\Windows Kits\\10\\Include\\10.0.26100.0\\cppwinrt" -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fmessage-length=146 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fwrapv -fms-compatibility-version=19.44.35228 -fno-implicit-modules -fmodule-file=mymodule=CMakeFiles/mymodule.dir/mymodule.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -no-round-trip-args --dependent-lib=msvcrtd -gcodeview -faddrsig -x c++ "G:\\Work\\clangd-crash-repro\\src\\main.cpp"
I[00:02:32.978] Building preamble...
I[00:02:32.986] Built preamble of size 274376 for file G:\Work\clangd-crash-repro\src\main.cpp version null in 0.01 seconds
I[00:02:33.007] Running GC pass for clangd built module files under G:\Work\clangd-crash-repro\build\.cache\clangd\modules with age threshold 259200 seconds (adjust with --modules-builder-versioned-gc-threshold-seconds)
I[00:02:33.008] Done running GC pass for clangd built module files under G:\Work\clangd-crash-repro\build\.cache\clangd\modules
I[00:02:33.012] Reusing persistent module mymodule from G:\Work\clangd-crash-repro\build\.cache\clangd\modules\mymodule.ixx-BBC01294A4E5679A\0552EB11F77B3EF7\mymodule.pcm
I[00:02:33.013] Built prerequisite modules for file G:\Work\clangd-crash-repro\src\main.cpp in 0.03 seconds
I[00:02:33.013] Indexing headers...
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: G:\\Work\\contributor\\llvm-clangd-crash\\build\\bin\\clangd.exe --experimental-modules-support --compile-commands-dir=build --check=src/main.cpp
Exception Code: 0xC0000005
#0 0x00007ff63d3b47cc clang::ASTReader::getGlobalDeclID G:\Work\contributor\llvm-clangd-crash\clang\lib\Serialization\ASTReader.cpp:8405:0
#1 0x00007ff63d3b47cc clang::ASTReader::GetLocalDecl G:\Work\contributor\llvm-clangd-crash\clang\include\clang\Serialization\ASTReader.h:2135:0
#2 0x00007ff63d3b47cc clang::ASTReader::FindExternalLexicalDecls::<lambda_0>::operator() G:\Work\contributor\llvm-clangd-crash\clang\lib\Serialization\ASTReader.cpp:8802:0
#3 0x00007ff63d3b469b std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<std::pair<clang::serialization::ModuleFile *,llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned long long,1,1,1> > > > > >::operator++ G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\vector:82:0
#4 0x00007ff63d3b469b std::_Vector_iterator<std::_Vector_val<std::_Simple_types<std::pair<clang::serialization::ModuleFile *,llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<unsigned long long,1,1,1> > > > > >::operator++ G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\vector:287:0
#5 0x00007ff63d3b469b clang::ASTReader::FindExternalLexicalDecls(class clang::DeclContext const *, class llvm::function_ref<(enum clang::Decl::Kind)>, class llvm::SmallVectorImpl<class clang::Decl *> &) G:\Work\contributor\llvm-clangd-crash\clang\lib\Serialization\ASTReader.cpp:8811:0
#6 0x00007ff63b95fef4 llvm::SmallVectorBase<unsigned int>::empty G:\Work\contributor\llvm-clangd-crash\llvm\include\llvm\ADT\SmallVector.h:86:0
#7 0x00007ff63b95fef4 clang::DeclContext::LoadLexicalDeclsFromExternalStorage(void) const G:\Work\contributor\llvm-clangd-crash\clang\lib\AST\DeclBase.cpp:1625:0
#8 0x00007ff63b96066a clang::DeclContext::decls_begin(void) const G:\Work\contributor\llvm-clangd-crash\clang\lib\AST\DeclBase.cpp:1680:0
#9 0x00007ff63d2cf643 llvm::iterator_range<clang::DeclContext::decl_iterator>::iterator_range G:\Work\contributor\llvm-clangd-crash\llvm\include\llvm\ADT\iterator_range.h:55:0
#10 0x00007ff63d2cf643 clang::DeclContext::decls G:\Work\contributor\llvm-clangd-crash\clang\include\clang\AST\DeclBase.h:2386:0
#11 0x00007ff63d2cf643 clang::clangd::indexHeaderSymbols(class llvm::StringRef, class clang::ASTContext &, class clang::Preprocessor &, class clang::include_cleaner::PragmaIncludes const &, enum clang::clangd::SymbolOrigin) G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\index\FileIndex.cpp:235:0
#12 0x00007ff63d2d38d3 std::tuple<std::optional<clang::clangd::SymbolSlab> &,const std::_Ignore &,std::optional<clang::clangd::RelationSlab> &>::operator= G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\tuple:614:0
#13 0x00007ff63d2d38d3 clang::clangd::FileIndex::updatePreamble(class llvm::StringRef, class llvm::StringRef, class clang::ASTContext &, class clang::Preprocessor &, class clang::include_cleaner::PragmaIncludes const &) G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\index\FileIndex.cpp:466:0
#14 0x00007ff63c38be20 clang::clangd::`anonymous namespace'::Checker::buildAST::<lambda_1>::operator() G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\tool\Check.cpp:257:0
#15 0x00007ff63c38be20 std::invoke G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\type_traits:1680:0
#16 0x00007ff63c38be20 std::_Func_impl_no_alloc<`lambda at G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\tool\Check.cpp:250:9',void,clang::clangd::CapturedASTCtx,std::shared_ptr<const clang::include_cleaner::PragmaIncludes> >::_Do_call G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\functional:880:0
#17 0x00007ff63c4416a8 std::_Func_class<void,clang::clangd::CapturedASTCtx,std::shared_ptr<const clang::include_cleaner::PragmaIncludes> >::operator() G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\functional:927:0
#18 0x00007ff63c4416a8 clang::clangd::buildPreamble(class llvm::StringRef, class clang::CompilerInvocation, struct clang::clangd::ParseInputs const &, bool, class std::function<(struct clang::clangd::CapturedASTCtx, class std::shared_ptr<class clang::include_cleaner::PragmaIncludes const>)>, struct clang::clangd::PreambleBuildStats *) G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\Preamble.cpp:707:0
#19 0x00007ff63c387db1 std::_Ptr_base<const clang::clangd::PreambleData>::_Move_construct_from G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\memory:1327:0
#20 0x00007ff63c387db1 std::shared_ptr<const clang::clangd::PreambleData>::shared_ptr G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\memory:1645:0
#21 0x00007ff63c387db1 std::shared_ptr<const clang::clangd::PreambleData>::operator= G:\Apps\VisualStudio\VC\Tools\MSVC\14.44.35207\include\memory:1705:0
#22 0x00007ff63c387db1 clang::clangd::`anonymous namespace'::Checker::buildAST G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\tool\Check.cpp:248:0
#23 0x00007ff63c387db1 clang::clangd::check(class llvm::StringRef, class clang::clangd::ThreadsafeFS const &, struct clang::clangd::ClangdLSPServer::Options const &) G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\tool\Check.cpp:524:0
#24 0x00007ff63bbe4410 clang::clangd::clangdMain(int, char **const) G:\Work\contributor\llvm-clangd-crash\clang-tools-extra\clangd\tool\ClangdMain.cpp:1038:0
#25 0x00007ff63eeffac4 invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#26 0x00007ff63eeffac4 __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#27 0x00007ffd0d4ce957 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e957)
#28 0x00007ffd0f5a7c1c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x87c1c)
```
### Steps to reproduce
1. Create a static library target with a single implementation file containing `export module X;`
2. Create a header containing `import X;` (important, directly using `import` in the source file does not cause a crash)
3. Create an executable target linking against the static library - single source file including the header
4. Run CMake configure to get `compile_commands.json`
5. Run `clangd` on the source file of the executable target with `--experimental-modules-support`
I've also made a repository at https://github.com/itzexpoexpo/clangd-crash-repro.git that has the exact CMake setup I've used to reproduce this.
### Notes
Happens at least since 22.1.0, also tested 21.1.8 which doesn't crash on these specific steps, but still crashes on my actual codebase in a very similar fashion, unsure if relevant.
I've already seen issues with similar stack traces (failing somewhere in `clang::ASTReader::FindExternalLexicalDecls`) being reported (#189450 and #2647), however `--skip-preamble-build` did not fix this for me, and this seems to be about import declarations in headers.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs