llvm / llvm/llvm-project

[clangd] [modules] clangd uses stale PCM after prerequisite module construction fails

Open
#213,499 5 comments 0 reactions 0 assignees View on GitHub
clang:modules clangd
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When processing a consumer with `--experimental-modules-support`, clangd attempts to build its own PCM for each imported module.

If the module interface listed in the compilation database no longer exists, this step fails. However, clangd then continues processing the consumer using the existing PCM specified by the consumer’s original -fmodule-file argument.

This fallback is not reported to the user, even though the existing PCM may no longer represent the current project state.

1. Build a named module and consumer.
2. Delete the module interface, leaving the CDB and PCM unchanged.
3. Open the consumer in clangd.

Logs:
```
Scanning modules dependencies for M.cppm failed: no such file
Failed to build module M
```
However, it retains -fmodule-file=M=.../M.pcm, loads that PCM, and publishes no diagnostic.

Expected: Report the failed module construction and potentially stale PCM fallback.
Tested with clangd 22.1.8 and --experimental-modules-support.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with clangd using --experimental-modules-support: build a named module and consumer, delete the module interface while leaving the compilation database and PCM unchanged, then open the consumer. Trace the failed module construction and the existing -fmodule-file fallback. Done means clangd reports the failed construction and potentially stale PCM use to the user.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.