[clangd] Fails to analyze `.cppm` module interface files in MSVC environment
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
In an MSVC environment, clangd fails to analyze C++ module interface files when the file extension is `.cppm` instead of `.ixx`.
Environment:
* OS: Windows 11
* clangd: version 22.1.8
* Compiler: MSVC 14.50 (with Visual Studio 2026)
* IDE: VS Code, with official [vscode-clangd](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd) extention
It appears that `/interface` and `/TP` compilation flags (documented [here](https://learn.microsoft.com/en-us/cpp/build/reference/interface)) are not passed to `cl.exe` when building AST. These flags are required for module interface files whose extension is not `.ixx` when using MSVC.
I explicitly specified both `/interface` and `/TP` in my `CMakeLists.txt`, and both flags are present in `compile_commands.json`.
`compile_commands.json`:
```json
[
{
"directory": "C:/Users/xxx/my_project/build",
"command": "\"C:\\Program Files\\Microsoft Visual Studio\\18\\Community\\VC\\Tools\\MSVC\\14.51.36231\\bin\\Hostx64\\x64\\cl.exe\" /nologo /TP -D_MBCS /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od -std:c++latest -MDd -RTC1 -Zi /interface /TP @CMakeFiles\\my_math.dir\\lib.cppm.obj.modmap /FoCMakeFiles\\my_math.dir\\lib.cppm.obj /FdCMakeFiles\\my_math.dir\\my_math.pdb /FS -c C:\\Users\\xxx\\my_project\\lib.cppm",
"file": "C:/Users/xxx/my_project/lib.cppm",
"output": "C:/Users/xxx/my_project/build/CMakeFiles/my_math.dir/lib.cppm.obj"
}
]
```
Below is a clangd LSP log. Notice that the `/interface` and `/TP` flags are missing, while an unexpected `-interface` flag is present.
```text
I[16:08:25.962] ASTWorker building file c:\Users\xxx\my_project\lib.cppm version 143 with command
[C:/Users/xxx/my_project/build]
"C:\\Program Files\\Microsoft Visual Studio\\18\\Community\\VC\\Tools\\MSVC\\14.51.36231\\bin\\Hostx64\\x64\\cl.exe" --driver-mode=cl /nologo -D_MBCS /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od -MDd -RTC1 -Zi -interface -ifcOutput "/FdCMakeFiles\\my_math.dir\\my_math.pdb" /FS -c
"-resource-dir=C:\\Program Files\\LLVM\\lib\\clang\\22" -- "c:\\Users\\xxx\\my_project\\lib.cppm"
```
I have attached a minimal reproduction code: [reproduction.zip](https://github.com/user-attachments/files/30820585/reproduction.zip)
Contributor guide
Research direction
Start by unpacking reproduction.zip and comparing its compile_commands.json with the clangd ASTWorker command in the attached LSP log. Trace how the /interface and /TP options from the MSVC command are translated before building the AST for lib.cppm. Done means clangd analyzes the .cppm module interface successfully with the required flags preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp, vscode
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100