Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Issue 97: aligned allocation under the MSVC STL, and a workaround the maintained engine no longer needs

Status: implemented in server 0.24.1 / VS Code 0.24.1 · supplements the workaround register (#24 UP-05,
`WA-CLANGD-005`) · evidence: the report (mcppls 0.23.0, clangd `23.1.0-mcppls.12`, Windows 11, MSVC 14.52,
Slint 1.19 through `mcpplibs.mwrap.slint`), the clang 23.1.0 sources, the mcppls-clangd patch series, and a
platform-neutral reproduction on the bundled engine (§2). **Server only: no engine change, no change to Slint or
slint-m.**

## 1. What is wrong

`WA-CLANGD-005` gives every unit of an MSVC STL context `-fno-aligned-allocation`. It was added for
llvm-project#218152 (mcpp-community/mcpp#640): clang 23.1.0 declares an implicit `std::align_val_t` when aligned
allocation is on, does not merge it with the one MSVC's `vcruntime_new.h` exports from the `std` module's purview,
and every lookup of `align_val_t` in `std.ixx` is ambiguous.

The flag removes clang's implicit declaration, and with it the predefined `__cpp_aligned_new`
(`InitPreprocessor.cpp`: the macro is defined only when `AlignedAllocation` is on). `vcruntime_new.h` declares
`std::align_val_t` and the aligned `operator new`/`delete` only `#ifdef __cpp_aligned_new`. A header that uses them
unconditionally -- standard C++17, as Slint 1.19's `slint/private/vtable.h` does -- then fails in clangd only:
"no type named 'align_val_t' in namespace 'std'", and every module that includes it "did not compile". The build
(mcpp's clang 23.1.3) passes no such flag and compiles it.

Two facts make the flag unnecessary for the engine mcppls bundles:

- **The maintained engine carries the fix.** mcppls-clangd's `patches/0001-UP-05-backport-std-predefined-decl-merge.patch`
is llvm-project#219151 (commit `52774473867e`, released in 23.1.1), with its test `clang/test/Modules/pr218152.cppm`,
in every release since v0.0.2. `23.1.0-mcppls.<n>` has never had the defect.
- **The register does not know it.** `WA-CLANGD-005` is retired by `fixedIn = "23.1.1"`, a comparison of LLVM base
versions. `23.1.0-mcppls.12` does not parse as a release of the line (`0-mcppls` is no number), so `needs()` answers
"needed", and the flag has been passed for a defect the engine does not have.

So the fault is mcppls's, and so is the fix: retiring the workaround for the maintained engine is a root fix for it,
not a further compensation. Neither the engine nor Slint is at fault: Slint's code is conforming, and the engine
compiles it once mcppls stops turning aligned allocation off.

## 2. Evidence

On the bundled engine (`clangd --check`, the 0.24.0 payload, Linux host), a fake `std` module shaped like `std.ixx`
(headers in the purview, declarations exported inside `extern "C++"`, guarded `#ifdef __cpp_aligned_new` as
`vcruntime_new.h` guards them) and an importer that uses `std::align_val_t` the way Slint's `vtable.h` does:

| Engine arguments | Result |
|---|---|
| none (aligned allocation on) | 0 errors |
| `-fno-aligned-allocation` (0.24.0, `WA-CLANGD-005`) | `no type named 'align_val_t' in namespace 'std'` -- the report's error |
| `-fno-aligned-allocation -D__cpp_aligned_new=201606L` | 0 errors |

The upstream minimal reproducer of #218152 gives no diagnostic on the bundled engine with aligned allocation on, for
an x86_64-linux and an x86_64-pc-windows-msvc target: the backport is in effect.

Not run locally: the real MSVC STL (no MSVC on the machine). That is what the Windows conformance fixtures
`mcpp-msvc` and `cmake-msvc-std` (`import std` with the MSVC STL, built by clangd) and the new fixture of §4 prove
in CI.

## 3. Changes

**R1 -- the maintained engine retires `WA-CLANGD-005`.** The register gets `fixedInMaintained`: the maintained
engine (`<line>.<z>-mcppls.<n>`, mcppls-clangd) carries the fix in every release. `needs()` answers "not needed" for
such a version. Nothing else of the register changes; a workaround without the field is decided as before.

Not by an engine feature (`engine.json`'s `features`, the way `WA-CLANGD-001` is retired): the engine declares no
feature for the backport, and declaring one is an engine change this fix does not need. A later engine release may
add one; the register then names it in `fixed_by_verified_features` and the version rule can go.

**R2 -- where the workaround still applies, it keeps the standard library's declarations.** A clangd of the line
without the backport (an upstream 23.1.0 the person names with `mcppls.clangd`) still needs aligned allocation
off. With it the server now also defines `__cpp_aligned_new=201606L`: clang declares no implicit `std::align_val_t`
(that needs `AlignedAllocation`, `SemaExprCXX.cpp`), so nothing is ambiguous, and `vcruntime_new.h` declares its own.
The macro is a standard library macro for `std_unit_arguments`, so `std` and its importers agree. Not added when the
build itself turns aligned new off (`/Zc:alignedNew-`, `-fno-aligned-allocation`): that is the project's choice, and
its headers are compiled without the declarations in the build too.

What R2 costs: a new-expression of an over-aligned type does not call the aligned allocation function in clangd's
reading. clangd generates no code; the warning clang may give for it was already there under `WA-CLANGD-005`.

**R3 -- words.** CHANGELOG (`server 0.24.1`, `vscode 0.24.1`), the troubleshooting entry for "no type named
'align_val_t'", the register entry, #24's UP-05 comment, and an answer on #97.

Upgrade cost of R1: the commands of MSVC STL units lose `-fno-aligned-allocation`, so the first session after the
upgrade builds `std` and the modules once more ("command" rebuild reason).

## 4. Tests

- `tests/unit/test_workarounds.cpp`: `WA-CLANGD-005` is needed for `23.1.0`, not for `23.1.0-mcppls.12`, not for
`23.1.1`; the traits of `23.1.0-mcppls.12` have `msvcStlNeedsNoAlignedAllocation` off.
- `tests/unit/test_normalize.cpp`: an MSVC STL unit under the workaround has `-fno-aligned-allocation` and
`-D__cpp_aligned_new=201606L`, and `std`'s entry keeps the macro; without the workaround, neither; with
`/Zc:alignedNew-` in the build, the flag and no macro.
- Conformance, `win32-x64`: `mcpp-msvc-aligned-new`, an mcpp project on the MSVC STL whose module includes a header
that uses `std::align_val_t` and `::operator new(size, std::align_val_t)` unconditionally, as Slint 1.19 does, and
imports `std`: no diagnostics, and the engine command has no `-fno-aligned-allocation`. The existing `mcpp-msvc`
and `cmake-msvc-std` keep proving that `std` builds without the flag.

## 5. Release

Server 0.24.1 and VS Code 0.24.1 (`version --bump server`, `--bump vscode`), released as `vscode-v0.24.1`: a
plugin's patch carries the newest server patch of its series (docs/92-release.md "Versions"), so the VSIX carries
server 0.24.1. CLion and Zed get the server patch with their next patch.

## 6. Carried with it

The same change carries S1 0.4.0 (formerly PR #98, one CI run for both): `origin` on a `source` entry of
`ide.generated` (S1-7.2-14, a producer rule; mcpp-community/mcpp#1004, #1006). Its consumer rule is split in two:
S1-7.2-15 (the authored file as the unit's source for navigation and diagnostics) is pending, G3 of the issue 95
design; S1-7.2-16 (an `origin` is no second provider) is what issue 95's G1 already does, with a stated origin now
tested.

24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ Versions are three-part semantic versions, `X.Y.Z`: `X.Y` is the series of the s
patch is `## [<component> X.Y.Z]` (`server`, `vscode`, `clion`, `zed`, `claude-code`).


## [vscode 0.24.1] — 2026-11-23

### Fixed

- Carries server 0.24.1: no false "no type named 'align_val_t' in namespace 'std'" with the MSVC STL (#97).

## [server 0.24.1] — 2026-11-23

### Fixed

- **"no type named 'align_val_t' in namespace 'std'", and modules that "did not compile", in projects on the MSVC
STL whose headers use aligned allocation** ([#97](https://github.com/Sunrisepeak/mcpp-language-server/issues/97)).
Slint 1.19 is one: its `vtable.h` calls `::operator new(size, std::align_val_t)` as C++17 allows, and the project
builds. mcppls gave every MSVC STL unit `-fno-aligned-allocation` (`WA-CLANGD-005`), a workaround for a clang 23.1.0
defect that made `align_val_t` ambiguous in the MSVC STL's `std` module (llvm-project#218152). The flag also takes
`__cpp_aligned_new` away, and `vcruntime_new.h` then declares no `std::align_val_t` and no aligned
`operator new`/`delete`. The bundled engine has carried the upstream fix of that defect (llvm-project#219151, in
clang 23.1.1) in every release; the workaround was kept only because it was retired by the LLVM base version, which
the maintained engine (`23.1.0-mcppls.<n>`) does not change. It is retired for the maintained engine now, and MSVC
STL units keep aligned allocation, as the build does. With a clangd of the line that lacks the fix (an upstream
23.1.0 named with `mcppls.clangd`), the workaround stays and also defines `__cpp_aligned_new`, so the standard
library still declares what such headers use. The first session after the upgrade builds `std` and the modules of
an MSVC STL project once more, since their commands change.

## [0.24.0] — 2026-11-22

### Fixed
Expand Down
6 changes: 6 additions & 0 deletions docs/50-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ a file nothing generates from: a stale copy, or a source no `sources` pattern co
clangd or kept it busy is not formatted until it is given back, and nothing is formatted while clangd is starting
or restarting.

**"no type named 'align_val_t' in namespace 'std'" with the MSVC STL (0.24.0 and earlier), the project builds.**
A header that uses aligned allocation as C++17 allows (Slint 1.19's `vtable.h`) failed in the editor only: mcppls gave
MSVC STL units `-fno-aligned-allocation` (`WA-CLANGD-005`), which hides `std::align_val_t` in `vcruntime_new.h`. From
server 0.24.1 the bundled engine is read with aligned allocation on, as the build is (#97). On 0.24.0,
`"mcppls.disableWorkaround": ["WA-CLANGD-005"]` does the same: the bundled engine has the fix the workaround was for.

**"clangd crashed while building NormalJsonTranslator.Core.cpp".** clangd names the file it crashed
on (its crash context), and that file is set aside: answered by mcppls's own engine while clangd is
restarted without it. A clangd that ends without saying anything -- the bundled clangd traps where a
Expand Down
9 changes: 9 additions & 0 deletions docs/specs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 2026-11-23 — S1 0.4.0: a generated unit names the file it copies

S1 §7.2: a `source` entry of `ide.generated` may carry `origin`, the absolute path of the authored file the generated
unit is a transformed copy of, one of its generator's `inputs`, as the step that writes the unit states it; a producer
does not infer it from `inputs` (S1-7.2-14). A consumer treats that file as the unit's source for navigation and
diagnostics, and not as a second provider of the unit's module (S1-7.2-15). mcpp writes it from the build rule's
`mcpp::action::origin` (mcpp-community/mcpp#1004). Additive: a MINOR version of the profile; a consumer of 0.3.0 reads
a 0.4.0 document as before.

## 2026-11-22 — S3: a shadowed source, and a file not formatted

Two notice codes are named (mcpp-language-server#95). `shadowed-source`: an open file that is not compiled as it is,
Expand Down
2 changes: 1 addition & 1 deletion docs/specs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This directory holds the normative specifications that let C++ named modules be

| Spec | Title | Version | Status | Schema |
|---|---|---|---|---|
| [S1](s1-build-database.md) | C++ Build Database: IDE Profile | profile-version 0.3.0 | Draft | [s1-build-database.schema.json](schema/s1-build-database.schema.json) |
| [S1](s1-build-database.md) | C++ Build Database: IDE Profile | profile-version 0.4.0 | Draft | [s1-build-database.schema.json](schema/s1-build-database.schema.json) |
| [S2](s2-discovery.md) | Build Database Discovery Protocol | 0.3.0 | Draft | [s2-discovery.schema.json](schema/s2-discovery.schema.json) |
| [S3](s3-lsp-extensions.md) | Language Server Protocol Extensions for C++ Modules | protocol version 1 | Draft | TypeScript interfaces in the text; [target selection field](schema/s3-target-selection.schema.json) |
| [S4](s4-semantic-kit.md) | Semantic Kit | kit-version 1 | Draft | [s4-kit.schema.json](schema/s4-kit.schema.json) |
Expand Down
5 changes: 4 additions & 1 deletion docs/specs/s1-build-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| | |
|---|---|
| Specification | S1 |
| Profile version | 0.3.0 |
| Profile version | 0.4.0 |
| Status | Draft |
| Schema | [`schema/s1-build-database.schema.json`](schema/s1-build-database.schema.json) |
| Examples | [`examples/s1-level3-gcc.json`](examples/s1-level3-gcc.json), [`examples/s1-level2-clang-two-sets.json`](examples/s1-level2-clang-two-sets.json) |
Expand Down Expand Up @@ -179,6 +179,7 @@ A build can generate files that the units of a set compile or include: sources a
| `path` | string | MUST | Absolute path of the file or directory in the configuration this document describes, as the units' `arguments` name it. <a id="S1-7.2-1"></a><sup>S1-7.2-1</sup> |
| `build-path` | string | SHOULD | Absolute path at which the build of the same configuration writes it. It differs from `path` when the producer plans in a directory of its own, and equals `path` otherwise. It is stated whether or not the file exists. <a id="S1-7.2-2"></a><sup>S1-7.2-2</sup> |
| `kind` | enum | MUST | `source` (a unit of the set is compiled from it), `header` (units of the set include it) or `directory` (an include directory whose contents are generated). <a id="S1-7.2-3"></a><sup>S1-7.2-3</sup> |
| `origin` | string | MAY | For `source` only: the absolute path of the authored file the generated unit is a transformed copy of (the file a person edits to change the unit), one of the generator's `inputs`, as the step that writes the unit states it. A producer **MUST NOT** infer it from `inputs`. <a id="S1-7.2-14"></a><sup>S1-7.2-14</sup> (0.4.0) |
| `generator` | object | conditional MUST | REQUIRED for `source` and `header`, absent for `directory`. It has `id` (string, MUST), the producer's name for the step that writes the file; `inputs` (string[], SHOULD), the absolute paths of the files the step reads; `arguments` (string[], SHOULD), the step's command, program first; and `work-directory` (string, MAY). <a id="S1-7.2-4"></a><a id="S1-7.2-5"></a><a id="S1-7.2-6"></a><a id="S1-7.2-7"></a><a id="S1-7.2-8"></a><sup>S1-7.2-4, S1-7.2-5, S1-7.2-6, S1-7.2-7, S1-7.2-8</sup> |

A producer **SHOULD** list every generated file that a unit's `arguments` name, and every generated file in an include directory that the `arguments` name, whenever it knows the step that writes the file. <a id="S1-7.2-9"></a><sup>S1-7.2-9</sup> A translation unit whose `source` is the `path` of a `source` entry is a generated unit: before a build its source may be absent or empty.
Expand All @@ -188,6 +189,8 @@ A consumer:
- **MUST NOT** report a unit's reference to a generated file that does not exist as an error in that unit's source, and **SHOULD** tell the user that the file is generated, by which step, and that a build writes it; <a id="S1-7.2-10"></a><a id="S1-7.2-11"></a><sup>S1-7.2-10, S1-7.2-11</sup>
- **MAY** read the file at `build-path` when it exists, read-only (section 14), and **MUST** then treat it as possibly stale relative to the step's inputs; <a id="S1-7.2-12"></a><sup>S1-7.2-12</sup>
- **MUST NOT** run a step's `arguments` unless the user has allowed it for the workspace (section 14). <a id="S1-7.2-13"></a><sup>S1-7.2-13</sup>
- **SHOULD**, for a `source` entry with `origin`, treat the authored file as the source of the generated unit for navigation and diagnostics; <a id="S1-7.2-15"></a><sup>S1-7.2-15</sup> (0.4.0)
- **MUST NOT** treat a `source` entry's `origin` as a second provider of the module the generated unit provides. <a id="S1-7.2-16"></a><sup>S1-7.2-16</sup> (0.4.0)

Rationale: a producer that does not build (for example mcpp's `emit build-database`, which writes nothing into the project and runs no build step) plans in a directory of its own, so a generated header named by the units' `-I` arguments is absent there. Without this object a consumer reports a missing header in every source that includes it and loses the semantics of that source. The object states which files are generated and where the build writes them; running the generators remains a decision of the consumer and its user.

Expand Down
3 changes: 3 additions & 0 deletions docs/specs/schema/s1-build-database.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@
"directory"
]
},
"origin": {
"$ref": "#/$defs/nonEmptyString"
},
"generator": {
"type": "object",
"required": [
Expand Down
2 changes: 2 additions & 0 deletions docs/zh-CN/50-troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ mcppls report --bundle problem.zip --root path/to/project # 可加 --hide-proj

**clangd 反复重启。** 看 `engines[].restarts`、`engines[].details.restartBudget` 和 `events` 日志。每种原因各有十分钟三次的重启额度:引擎数据库变化(`plan`)、恢复停止应答或空转的 clangd(`recovery`)、clangd 退出(`crash`)。用完之后,同类的下一次重启依次等待一、二、四、八分钟——是退避而不是拒绝,所以卡住的 clangd 总能恢复——状态会说明(`engine-restart-capped`)并提供 **Restart clangd** 按钮(其他编辑器用 `workspace/executeCommand` `mcppls.restartEngine`),它立即重启且从不计入额度。切换工具链、profile 或 context 也从不计入,模块编译不过从来不是重启的理由。引擎数据库的每次变化都会记入日志并写明改了什么(`engine database changed: … compiled otherwise (main.cpp: argument 3: -O0 -> -O2)`),重启密集时能直接看到原因。

**MSVC STL 下报 "no type named 'align_val_t' in namespace 'std'"(0.24.0 及更早),而项目能构建。** 按 C++17 使用对齐分配的头文件(例如 Slint 1.19 的 `vtable.h`)只在编辑器里报错:mcppls 给 MSVC STL 的单元加了 `-fno-aligned-allocation`(`WA-CLANGD-005`),它让 `vcruntime_new.h` 不再声明 `std::align_val_t`。从 server 0.24.1 起,bundled 引擎按构建本身的方式开启对齐分配(#97)。在 0.24.0 上,`"mcppls.disableWorkaround": ["WA-CLANGD-005"]` 效果相同:bundled 引擎已经带有这个 workaround 所针对缺陷的修复。

**文件里加入或删掉 `import std` 时 clangd 就重启(0.23.0 及更早)。** 标准库的单元按项目里某一个单元(代表单元)的参数构建。0.24.0 之前,代表单元是第一个导入 `std` 且不是模块接口的单元,而且编辑缓冲区里的导入也算:在 `build.mcpp` 和 `main.cpp` 都导入 `std` 的包里,输入或删掉这个导入会让 `std` 在两者之间来回切换,`std` 的命令随之改变,所有模块重新准备(#95)。现在先按集合选——target 的集合优先于构建程序的集合,构建描述里有单元导入 `std` 的集合优先于没有的——再取该集合里第一个不是接口的单元,不看它导入什么;编辑缓冲区不会再让它移动。计划里记着它(报告中的 `plan.stdFollows`),移动时日志会写明:`engine database changed: … ; std follows src/main.cpp now (was build.mcpp)`。升级后的第一次会话里,部分项目会因为代表单元换了一个而重新构建一次 `std`。

**"app.cppm is not compiled as it is: the build generates src_app.cppm from it"。** 构建规则(例如 HuxerUI 的 `hcg`)把你编辑的文件转换成构建实际编译的单元,构建数据库只描述那份副本(`[build] sources = []`)。你打开的文件声明了副本提供的模块;它是一个*被遮蔽的源文件*,不是第二个提供者:状态保持 `ready`(0.23.0 报 `ambiguous-module` 并 `degraded`),文件上有一条信息级诊断,状态里有 `shadowed-source` 提示,mcppls 自己的引擎回答它,**Format Document** 能格式化它——clangd 以旁边的一个临时名字(`app.mcppls-format.cppm`,从不写到磁盘)格式化它的文本,所以它上方的 `.clang-format` 照样生效。clangd 的悬停、诊断和跳转针对的是生成的单元;原文件上的这些是后续步骤(mcpp-community/mcpp#1004)。"… is not part of the build: no build target compiles it" 是同一种情况,只是没有任何东西从这个文件生成:一份过期的副本,或者没有被任何 `sources` 模式覆盖的源文件。
Expand Down
Loading
Loading