Issue 242422
Summary [clangd][modules] crash on module file
Labels new issue
Assignees
Reporter AverageBeerEnjoyer
    Hi, i found clangd crash on this example.

``` c++
// test.cppm

export module test;
import std;

export struct foo {
    constexpr foo(std::string_view sv) {}
 constexpr foo(int) {}
};

export int i = 1;
export constexpr std::string_view some_sv = "qwe";

export constexpr foo bar(some_sv); // crash
// export constexpr foo bar(i); // ok
// export constexpr foo bar(1); // ok
// export constexpr foo bar("qwe"); // ok
// export constexpr foo bar{some_sv}; // ok

```

This code compiles successfully using gcc 16.
```
g++ -fmodules -c test.cppm -std=c++23 --compile-std-module
```
clangd command

```
 ~/dev/llvm-project/build/bin/clangd --experimental-modules-support --check=test.cppm --recovery-ast --debug-modules-builder --log=verbose
```
output
```
The flag `-recovery-ast` is obsolete and ignored.
I[21:11:12.528] clangd version 24.0.0git (https://github.com/llvm/llvm-project.git 1e6edf70344960c48a7330261357683d494e61c2)
I[21:11:12.528] Features: linux+debug
I[21:11:12.528] PID: 356482
I[21:11:12.528] Working directory: /home/andrew/dev/clanggd-test
I[21:11:12.528] argv[0]: /home/andrew/dev/llvm-project/build/bin/clangd
I[21:11:12.528] argv[1]: --experimental-modules-support
I[21:11:12.528] argv[2]: --check=test.cppm
I[21:11:12.528] argv[3]: --recovery-ast
I[21:11:12.528] argv[4]: --debug-modules-builder
I[21:11:12.528] argv[5]: --log=verbose
V[21:11:12.528] User config file is /home/andrew/.config/clangd/config.yaml
I[21:11:12.529] Entering check mode (no LSP server)
I[21:11:12.529] Testing on source file /home/andrew/dev/clanggd-test/test.cppm
I[21:11:12.529] Loading config file at /home/andrew/.config/clangd/config.yaml
V[21:11:12.529] config note at /home/andrew/.config/clangd/config.yaml:1:0: Parsing config fragment
V[21:11:12.529] config note at /home/andrew/.config/clangd/config.yaml:1:0: Parsed 1 fragments from file
V[21:11:12.529] Config fragment: compiling /home/andrew/.config/clangd/config.yaml:1 -> 0x0000561CD3EA99D0 (trusted=true)
V[21:11:12.538] Config fragment: compiling <unknown>:0 -> 0x0000561CD3EA88D0 (trusted=false)
I[21:11:12.538] Loading compilation database...
I[21:11:12.538] Failed to find compilation database for /home/andrew/dev/clanggd-test/test.cppm
I[21:11:12.539] Generic fallback command is: [/home/andrew/dev/clanggd-test] /usr/bin/clang -std=c++26 -resource-dir=/home/andrew/dev/llvm-project/build/lib/clang/24 -- /home/andrew/dev/clanggd-test/test.cppm
I[21:11:12.539] Parsing command...
I[21:11:12.542] internal (cc1) args are: -cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -disable-free -clear-ast-before-backend -main-file-name test.cppm -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/andrew/dev/clanggd-test -fcoverage-compilation-dir=/home/andrew/dev/clanggd-test -resource-dir /home/andrew/dev/llvm-project/build/lib/clang/24 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../include/c++/16/x86_64-pc-linux-gnu -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /home/andrew/dev/llvm-project/build/lib/clang/24/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/16/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++26 -fdeprecated-macro -ferror-limit 19 -fmessage-length=173 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fmodules-reduced-bmi -fmodule-output=/home/andrew/dev/clanggd-test/test.pcm -fcxx-exceptions -fexceptions -no-round-trip-args -faddrsig -fdwarf2-cfi-asm -x c++ /home/andrew/dev/clanggd-test/test.cppm
I[21:11:12.542] Building preamble...
I[21:11:12.561] Built preamble of size 255864 for file /home/andrew/dev/clanggd-test/test.cppm version null in 0.02 seconds
I[21:11:12.561] Failed to get compilation Database for /home/andrew/dev/clanggd-test/test.cppm
E[21:11:12.561] Failed to get Project Modules information for /home/andrew/dev/clanggd-test/test.cppm
I[21:11:12.561] Built prerequisite modules for file /home/andrew/dev/clanggd-test/test.cppm in 0.00 seconds
I[21:11:12.561] Indexing headers...
V[21:11:12.562] indexed preamble AST for /home/andrew/dev/clanggd-test/test.cppm version null:
 symbol slab: 0 symbols, 112 bytes
  ref slab: 0 symbols, 0 refs, 120 bytes
 relations slab: 0 relations, 24 bytes
I[21:11:12.562] Building AST...
clangd: /home/andrew/dev/llvm-project/clang/include/clang/AST/TypeBase.h:954: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
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: /home/andrew/dev/llvm-project/build/bin/clangd --experimental-modules-support --check=test.cppm --recovery-ast --debug-modules-builder --log=verbose
1.      <eof> parser at end of file
 #0 0x0000561c9414fa8e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/andrew/dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:931:22
 #1 0x0000561c9414ff01 PrintStackTraceSignalHandler(void*) /home/andrew/dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:1013:1
 #2 0x0000561c9414ce94 llvm::sys::RunSignalHandlers() /home/andrew/dev/llvm-project/llvm/lib/Support/Signals.cpp:108:20
 #3 0x0000561c9414f1f5 SignalHandler(int, siginfo_t*, void*) /home/andrew/dev/llvm-project/llvm/lib/Support/Unix/Signals.inc:474:14
 #4 0x00007f7f4f044e70 (/usr/lib/libc.so.6+0x44e70)
 #5 0x00007f7f4f0aeb8b pthread_kill (/usr/lib/libc.so.6+0xaeb8b)
 #6 0x00007f7f4f044d48 raise (/usr/lib/libc.so.6+0x44d48)
 #7 0x00007f7f4f0257c1 abort (/usr/lib/libc.so.6+0x257c1)
 #8 0x00007f7f4f026a5d (/usr/lib/libc.so.6+0x26a5d)
 #9 0x00007f7f4f03b254 __assert_fail (/usr/lib/libc.so.6+0x3b254)
#10 0x0000561c93da3bba clang::QualType::getCommonPtr() const /home/andrew/dev/llvm-project/clang/include/clang/AST/TypeBase.h:955:73
#11 0x0000561c93da59d2 clang::QualType::getTypePtr() const /home/andrew/dev/llvm-project/clang/include/clang/AST/TypeBase.h:8670:26
#12 0x0000561c93da3d66 clang::QualType::operator->() const /home/andrew/dev/llvm-project/clang/include/clang/AST/TypeBase.h:999:3
#13 0x0000561c953a255c (anonymous namespace)::ExposureChecker::isTULocal(clang::QualType) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1158:24
#14 0x0000561c953a2acd (anonymous namespace)::ExposureChecker::isTULocal(clang::Expr const*) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1261:3
#15 0x0000561c953a3221 (anonymous namespace)::ExposureChecker::checkExposure(clang::VarDecl const*, bool) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1395:25
#16 0x0000561c953a2dac (anonymous namespace)::ExposureChecker::checkExposure(clang::NamedDecl const*, bool) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1335:34
#17 0x0000561c953a3ef4 (anonymous namespace)::ExposureChecker::checkExposureInContext(clang::DeclContext const*) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1553:20
#18 0x0000561c953a3de9 (anonymous namespace)::ExposureChecker::checkExposureInContext(clang::DeclContext const*) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1529:7
#19 0x0000561c953a41a8 clang::Sema::checkExposure(clang::TranslationUnitDecl const*) /home/andrew/dev/llvm-project/clang/lib/Sema/SemaModule.cpp:1573:41
#20 0x0000561c95967677 clang::Sema::ActOnEndOfTranslationUnit() /home/andrew/dev/llvm-project/clang/lib/Sema/Sema.cpp:1751:1
#21 0x0000561c9963978b clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/andrew/dev/llvm-project/clang/lib/Parse/Parser.cpp:706:12
#22 0x0000561c996255cd clang::ParseAST(clang::Sema&, bool, bool) /home/andrew/dev/llvm-project/clang/lib/Parse/ParseAST.cpp:165:37
#23 0x0000561c992929f9 clang::ASTFrontendAction::ExecuteAction() /home/andrew/dev/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1497:11
#24 0x0000561c99292269 clang::FrontendAction::Execute() /home/andrew/dev/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1381:38
#25 0x0000561c96b9185c 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/andrew/dev/llvm-project/clang-tools-extra/clangd/ParsedAST.cpp:496:42
#26 0x0000561c96552485 clang::clangd::(anonymous namespace)::Checker::buildAST() /home/andrew/dev/llvm-project/clang-tools-extra/clangd/tool/Check.cpp:267:27
#27 0x0000561c965547f2 clang::clangd::check(llvm::StringRef, clang::clangd::ThreadsafeFS const&, clang::clangd::ClangdLSPServer::Options&&) /home/andrew/dev/llvm-project/clang-tools-extra/clangd/tool/Check.cpp:542:7
#28 0x0000561c96520602 clang::clangd::clangdMain(int, char**) /home/andrew/dev/llvm-project/clang-tools-extra/clangd/tool/ClangdMain.cpp:1061:16
#29 0x0000561c93d17a39 main /home/andrew/dev/llvm-project/clang-tools-extra/clangd/tool/ClangdToolMain.cpp:12:46
#30 0x00007f7f4f027d0e (/usr/lib/libc.so.6+0x27d0e)
#31 0x00007f7f4f027e4b __libc_start_main (/usr/lib/libc.so.6+0x27e4b)
#32 0x0000561c93d17945 _start (/home/andrew/dev/llvm-project/build/bin/clangd+0xb5d945)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to