[clang] [clang-tools-extra] [clangd] Handle C++20 annot_module_name token and don't discard successfully built modules when on fail (PR #187858)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 19:51:35 PDT 2026
ChuanqiXu9 wrote:
interesting, it seems like either you or me made some basic problems, I still can't reproduce the crash in trunk again. Here is my steps:
```
$bin/clangd --version
clangd version 23.0.0git (git at github.com:llvm/llvm-project.git 9085f74018a4f465afa84815d64af850f09b733f)
Features: linux
Platform: x86_64-unknown-linux-gnu
[chuanqi.xcq at i32g15300.sqa.eu95 /home/chuanqi.xcq/llvm-project-for-work/build]
$bin/llvm-lit ../clang-tools-extra/clangd/test/non-exist.test -v
-- Testing: 1 tests, 1 workers --
PASS: Clangd :: non-exist.test (1 of 1)
Testing Time: 0.12s
Total Discovered Tests: 1
Passed: 1 (100.00%)
[chuanqi.xcq at i32g15300.sqa.eu95 /home/chuanqi.xcq/llvm-project-for-work/build]
$cat ../clang-tools-extra/clangd/test/non-exist.test
#
## reproduce a crash in module processing - seems having a non-existent module imported
## as the last statement in a file causes clangd to crash
## modified from modules.test
#
# Windows have different escaping modes.
# FIXME: We should add one for windows.
# UNSUPPORTED: system-windows
#
# RUN: rm -fr %t
# RUN: mkdir -p %t
# RUN: split-file %s %t
#
# RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp
# RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json
# RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc
#
# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc
#--- A.cppm
module;
export module A;
#--- Use.cpp
module;
export module Use;
import A;
import NonExistent;
#--- compile_commands.json.tmpl
[
{
"directory": "DIR",
"command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o DIR/Use.cpp -fmodule-file=A=DIR/A.pcm",
"file": "DIR/Use.cpp",
"output": "DIR/main.cpp.o"
},
{
"directory": "DIR",
"command": "CLANG_CC -fprebuilt-module-path=DIR --std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm",
"file": "DIR/A.cppm",
"output": "DIR/A.pcm"
}
]
#--- definition.jsonrpc.tmpl
{
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"processId": 123,
"rootPath": "clangd",
"capabilities": {
"textDocument": {
"completion": {
"completionItem": {
"snippetSupport": true
}
}
}
},
"trace": "off"
}
}
---
{
"jsonrpc": "2.0",
"method": "textDocument/didOpen",
"params": {
"textDocument": {
"uri": "file://DIR/Use.cpp",
"languageId": "cpp",
"version": 1,
"text": "module;\nexport module Use;\nimport A;\nimport NonExistent;\n"
}
}
}
---
{"jsonrpc":"2.0","id":2,"method":"shutdown"}
---
{"jsonrpc":"2.0","method":"exit"}
```
https://github.com/llvm/llvm-project/pull/187858
More information about the cfe-commits
mailing list