From 26a8efe5e31477d249fb28d2c0ebcdfac59d7583 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Mon, 23 Nov 2026 04:07:05 +0900 Subject: [PATCH 1/3] server 0.24.1, vscode 0.24.1: the maintained engine keeps aligned allocation under the MSVC STL, so std::align_val_t is declared (#97) A header that uses aligned allocation as C++17 allows (Slint 1.19's vtable.h) failed in the editor only, with "no type named 'align_val_t' in namespace 'std'", and every module including it "did not compile". WA-CLANGD-005 gave every MSVC STL unit -fno-aligned-allocation for llvm-project#218152 (align_val_t ambiguous in the MSVC STL's std module in clang 23.1.0). The flag also removes __cpp_aligned_new, and vcruntime_new.h then declares neither std::align_val_t nor the aligned operator new/delete. The maintained engine has carried the upstream fix (llvm-project#219151, patch 0001-UP-05) in every release, but the workaround was retired by the LLVM base version, which 23.1.0-mcppls. keeps. The register now marks it fixed in the maintained engine (fixedInMaintained), so MSVC STL units keep aligned allocation, as the build does. Where it still applies (an upstream 23.1.0 clangd), the workaround also defines __cpp_aligned_new=201606L, kept for std too, so the library declares what such headers use. Design: .agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md --- ...issue-97-msvc-aligned-allocation-design.md | 98 +++++++++++++++++++ CHANGELOG.md | 24 +++++ docs/50-troubleshooting.md | 6 ++ docs/zh-CN/50-troubleshooting.md | 2 + editors/vscode/package.json | 2 +- mcpp.toml | 2 +- modules/base/src/version.cppm | 2 +- src/engine/clangd/workarounds.cpp | 14 ++- src/engine/clangd/workarounds.cppm | 3 + src/normalize/gnu.cpp | 5 + src/normalize/plan.cpp | 5 +- .../fixtures/mcpp-msvc-aligned-new/mcpp.toml | 8 ++ .../mcpp-msvc-aligned-new/scenario.json | 12 +++ .../mcpp-msvc-aligned-new/src/main.cpp | 10 ++ .../mcpp-msvc-aligned-new/src/shapes.cppm | 14 +++ .../fixtures/mcpp-msvc-aligned-new/src/vt.h | 15 +++ tests/cts/mcpp.cpp | 1 + tests/unit/test_normalize.cpp | 7 ++ tests/unit/test_workarounds.cpp | 7 ++ 19 files changed, 230 insertions(+), 7 deletions(-) create mode 100644 .agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md create mode 100644 tests/cts/fixtures/mcpp-msvc-aligned-new/mcpp.toml create mode 100644 tests/cts/fixtures/mcpp-msvc-aligned-new/scenario.json create mode 100644 tests/cts/fixtures/mcpp-msvc-aligned-new/src/main.cpp create mode 100644 tests/cts/fixtures/mcpp-msvc-aligned-new/src/shapes.cppm create mode 100644 tests/cts/fixtures/mcpp-msvc-aligned-new/src/vt.h diff --git a/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md b/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md new file mode 100644 index 00000000..56c4defc --- /dev/null +++ b/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md @@ -0,0 +1,98 @@ +# 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.` 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 (`.-mcppls.`, 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. diff --git a/CHANGELOG.md b/CHANGELOG.md index c01af3ab..188e6362 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,30 @@ Versions are three-part semantic versions, `X.Y.Z`: `X.Y` is the series of the s patch is `## [ 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.`) 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 diff --git a/docs/50-troubleshooting.md b/docs/50-troubleshooting.md index 2d73bc05..11a8ced9 100644 --- a/docs/50-troubleshooting.md +++ b/docs/50-troubleshooting.md @@ -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 diff --git a/docs/zh-CN/50-troubleshooting.md b/docs/zh-CN/50-troubleshooting.md index a76653be..1172618b 100644 --- a/docs/zh-CN/50-troubleshooting.md +++ b/docs/zh-CN/50-troubleshooting.md @@ -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` 模式覆盖的源文件。 diff --git a/editors/vscode/package.json b/editors/vscode/package.json index 65ae7e16..9aa09a26 100644 --- a/editors/vscode/package.json +++ b/editors/vscode/package.json @@ -2,7 +2,7 @@ "name": "mcpp-language-server", "displayName": "%displayName%", "description": "%description%", - "version": "0.24.0", + "version": "0.24.1", "publisher": "sunrisepeak", "license": "Apache-2.0", "icon": "icon.png", diff --git a/mcpp.toml b/mcpp.toml index e17a992f..169ca903 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -64,7 +64,7 @@ mcpplibs.mtest = "0.6.3" [package] name = "mcpp-language-server" -version = "0.24.0" +version = "0.24.1" description = "Compiler-agnostic C++ modules language server" license = "Apache-2.0" authors = ["Sunrisepeak"] diff --git a/modules/base/src/version.cppm b/modules/base/src/version.cppm index 0bb175a9..bedcd386 100644 --- a/modules/base/src/version.cppm +++ b/modules/base/src/version.cppm @@ -9,7 +9,7 @@ export namespace mcppls::base { // checked against mcpp.toml (the one source) by `mcppls-devtools version --check`, not kept in step by // hand. Three constants that lived here and nothing read were removed rather than left to drift: // the S1 profile version is spec::PROFILE_VERSION, the kit manifest version is spec::KIT_VERSION. -inline constexpr std::string_view VERSION { "0.24.0" }; +inline constexpr std::string_view VERSION { "0.24.1" }; // The clangd the payload ships (mcppls-clangd). Checked against packaging/payload.lock.json by the same command. inline constexpr std::string_view CLANGD_VERSION { "23.1.0-mcppls.12" }; // Maintained-engine identity stays intact in logs and caches. Its LLVM base diff --git a/src/engine/clangd/workarounds.cpp b/src/engine/clangd/workarounds.cpp index 1deb96ff..aa1a14d4 100644 --- a/src/engine/clangd/workarounds.cpp +++ b/src/engine/clangd/workarounds.cpp @@ -56,10 +56,12 @@ constexpr std::array REGISTRY { { .id = MSVC_STL_ALIGNED_ALLOCATION, .title = "clangd rejects the MSVC STL's aligned allocation; units using the MSVC STL turn it off", .fixedIn = "23.1.1", - .upstream = "llvm-project#218152, fixed in 23.1.1", - .evidence = ".agents/docs/design.md §7; conformance fixtures cmake-msvc-std, mcpp-msvc", + // mcppls-clangd patch 0001-UP-05 is the fix (llvm-project#219151), in every engine release since v0.0.2. + .fixedInMaintained = true, + .upstream = "llvm-project#218152, fixed in 23.1.1 (#219151); backported in mcppls-clangd", + .evidence = ".agents/docs/design.md §7; .agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md; conformance fixtures cmake-msvc-std, mcpp-msvc, mcpp-msvc-aligned-new", .added = "0.0.1", - .removeWhen = "the bundled clangd is 23.1.1 or later", + .removeWhen = "no supported clangd is upstream 23.1.0: the maintained engine never needs it (issue #97)", .canary = "", .premise = "the unit is compiled against the MSVC STL", }, @@ -231,7 +233,13 @@ const Workaround* find_workaround(std::string_view id) { return found == REGISTRY.end() ? nullptr : &*found; } +bool maintained_engine(std::string_view version) { + const std::size_t fork { version.find("-mcppls.") }; + return fork != std::string_view::npos && in_known_line(version.substr(0, fork)) && parse_version(version.substr(0, fork)).has_value(); +} + bool needs(const Workaround& workaround, std::string_view version) { + if (workaround.fixedInMaintained && maintained_engine(version)) return false; if (!in_known_line(version)) return true; if (workaround.fixedIn.empty()) return true; const auto have { parse_version(version) }; diff --git a/src/engine/clangd/workarounds.cppm b/src/engine/clangd/workarounds.cppm index 45a6ba18..b021d802 100644 --- a/src/engine/clangd/workarounds.cppm +++ b/src/engine/clangd/workarounds.cppm @@ -18,6 +18,9 @@ struct Workaround { std::string_view id; // WA-CLANGD-: grep-able, in logs and the report std::string_view title; // what it works around, in one line std::string_view fixedIn; // the first release of KNOWN_LINE that no longer needs it; empty: none yet + // The maintained engine (mcppls-clangd, `.-mcppls.`) carries the fix in every release, backported ahead + // of the line's own: it never needs the workaround, whatever its LLVM base (issue #97). + bool fixedInMaintained { false }; std::string_view upstream; // the upstream issue or fix, or "unfiled" std::string_view evidence; // where it was found and measured std::string_view added; // the mcppls version that added it diff --git a/src/normalize/gnu.cpp b/src/normalize/gnu.cpp index f825c56a..499fff7b 100644 --- a/src/normalize/gnu.cpp +++ b/src/normalize/gnu.cpp @@ -121,6 +121,11 @@ std::vector windows_msvc_arguments(const toolchain::ToolchainFacts& } if (noAlignedAllocation && facts.toolchain.stdlib && facts.toolchain.stdlib->name == "msvc-stl" && !has("-fno-aligned-allocation") && !has("-faligned-allocation")) { out.emplace_back("-fno-aligned-allocation"); + // Issue #97: with aligned allocation off clang declares no implicit std::align_val_t (the ambiguity of + // WA-CLANGD-005) and no __cpp_aligned_new either, and the MSVC STL's vcruntime_new.h then leaves out its own + // std::align_val_t and the aligned operator new/delete, which conforming code (Slint 1.19's vtable.h) uses. The + // macro keeps the library's declarations. Not when the build itself turns aligned new off (has() above). + out.emplace_back("-D__cpp_aligned_new=201606L"); } return out; } diff --git a/src/normalize/plan.cpp b/src/normalize/plan.cpp index e80cf255..8b7f31c3 100644 --- a/src/normalize/plan.cpp +++ b/src/normalize/plan.cpp @@ -285,7 +285,10 @@ bool standard_library_macro(std::string_view name) { name = name.substr(0, name.find('=')); // Explicit names: a prefix such as _GLIBCXX_ or _LIBCPP_ would also match those libraries' own header // guards (_GLIBCXX_RANGES, _LIBCPP_RANGES), which is exactly what must not reach std. - static constexpr std::array NAMES { + static constexpr std::array NAMES { + // The compiler's own (issue #97): defined for the MSVC STL beside WA-CLANGD-005, so that std declares what its + // importers' headers use. + "__cpp_aligned_new", // MSVC STL and the MSVC runtime "_ITERATOR_DEBUG_LEVEL", "_CONTAINER_DEBUG_LEVEL", "_DEBUG", "_DLL", "_MT", "_MSVC_STL_HARDENING", "_MSVC_STL_DESTRUCTOR_TOMBSTONES", "_STL_CALL_ABORT_INSTEAD_OF_INVALID_PARAMETER", diff --git a/tests/cts/fixtures/mcpp-msvc-aligned-new/mcpp.toml b/tests/cts/fixtures/mcpp-msvc-aligned-new/mcpp.toml new file mode 100644 index 00000000..fda90b75 --- /dev/null +++ b/tests/cts/fixtures/mcpp-msvc-aligned-new/mcpp.toml @@ -0,0 +1,8 @@ +[package] +name = "app" +version = "0.1.0" +description = "Conformance fixture: mcpp-msvc-aligned-new (issue #97)" +license = "Apache-2.0" + +[toolchain] +default = "llvm@23.1.3" diff --git a/tests/cts/fixtures/mcpp-msvc-aligned-new/scenario.json b/tests/cts/fixtures/mcpp-msvc-aligned-new/scenario.json new file mode 100644 index 00000000..8ca49371 --- /dev/null +++ b/tests/cts/fixtures/mcpp-msvc-aligned-new/scenario.json @@ -0,0 +1,12 @@ +{ + "name": "mcpp-msvc-aligned-new", + "description": "Issue #97: a header that uses std::align_val_t and the aligned operator new/delete unconditionally, as Slint 1.19's vtable.h does, included by a module unit and by main.cpp, both importing std, built with llvm@23.1.3 against the MSVC STL. mcppls 0.24.0 gave every unit -fno-aligned-allocation (WA-CLANGD-005), which hides vcruntime_new.h's declarations: \"no type named 'align_val_t' in namespace 'std'\" and the module did not compile. The maintained engine carries the fix of the defect the workaround was for, so no unit gets the flag, std builds, and neither file has a diagnostic.", + "checks": [ + { "id": "S1", "kind": "status", "source": "mcpp", "state": "ready" }, + { "id": "C1-the-module-unit-compiles", "kind": "diagnostics-empty", "file": "src/shapes.cppm" }, + { "id": "C2-main-compiles", "kind": "diagnostics-empty", "file": "src/main.cpp" }, + { "id": "E1-no-aligned-allocation-switch", "kind": "engine-command", "file": "src/main.cpp", "absent": ["-fno-aligned-allocation"], "timeout": 30 }, + { "id": "D1-the-module-resolves", "kind": "definition", "file": "src/main.cpp", "at": [6, 32], "expect": "src/shapes.cppm" }, + { "id": "W1", "kind": "workspace-unchanged" } + ] +} diff --git a/tests/cts/fixtures/mcpp-msvc-aligned-new/src/main.cpp b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/main.cpp new file mode 100644 index 00000000..cef2f189 --- /dev/null +++ b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/main.cpp @@ -0,0 +1,10 @@ +#include "vt.h" +import std; +import app.shapes; + +int main() { + int* value = vt::make(); + std::println("{} {}", app::describe(), *value); + vt::destroy(value); + return 0; +} diff --git a/tests/cts/fixtures/mcpp-msvc-aligned-new/src/shapes.cppm b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/shapes.cppm new file mode 100644 index 00000000..d4d7b1d5 --- /dev/null +++ b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/shapes.cppm @@ -0,0 +1,14 @@ +module; +#include "vt.h" +export module app.shapes; +import std; + +export namespace app { +struct alignas(32) Shape { int sides { 3 }; }; +std::string describe() { + Shape* shape = vt::make(); + std::string text { std::format("{} sides", shape->sides) }; + vt::destroy(shape); + return text; +} +} // namespace app diff --git a/tests/cts/fixtures/mcpp-msvc-aligned-new/src/vt.h b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/vt.h new file mode 100644 index 00000000..45df8a36 --- /dev/null +++ b/tests/cts/fixtures/mcpp-msvc-aligned-new/src/vt.h @@ -0,0 +1,15 @@ +// The shape of Slint 1.19's slint/private/vtable.h (issue #97): aligned allocation used unconditionally, as C++17 allows. +#pragma once +#include +#include + +namespace vt { +template T* make() { + void* memory = ::operator new(sizeof(T), static_cast(alignof(T))); + return ::new (memory) T {}; +} +template void destroy(T* object) { + object->~T(); + ::operator delete(static_cast(object), sizeof(T), static_cast(alignof(T))); +} +} // namespace vt diff --git a/tests/cts/mcpp.cpp b/tests/cts/mcpp.cpp index c151c20d..6384b17f 100644 --- a/tests/cts/mcpp.cpp +++ b/tests/cts/mcpp.cpp @@ -41,6 +41,7 @@ Fixture mcpp_llvm{"mcpp-llvm", on{"linux-x64", "darwin-arm64"}}; Fixture mcpp_llvm_linked{"mcpp-llvm@linked", on{"linux-x64"}}; Fixture mcpp_llvm_msvc{"mcpp-llvm-msvc", on{"win32-x64"}}; Fixture mcpp_msvc{"mcpp-msvc", on{"win32-x64"}}; +Fixture mcpp_msvc_aligned_new{"mcpp-msvc-aligned-new", on{"win32-x64"}}; Fixture mcpp_partition_definition{"mcpp-partition-definition", on{"linux-x64", "darwin-arm64", "win32-x64"}}; Fixture mcpp_polling_watch_inputs_polling{"mcpp-polling-watch-inputs@polling", on{"linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"}}; Fixture mcpp_producer_file_identity{"mcpp-producer-file-identity", on{"linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"}}; diff --git a/tests/unit/test_normalize.cpp b/tests/unit/test_normalize.cpp index 1a6e6ffe..4ac51a98 100644 --- a/tests/unit/test_normalize.cpp +++ b/tests/unit/test_normalize.cpp @@ -196,7 +196,12 @@ UTest normalize_tests{"normalize", [] { expect(contains(out, "-Xmicrosoft-visualc-tools-root") && contains(out, "C:/VS/VC/Tools/MSVC/14.44.35207")); expect(contains(out, "-Xmicrosoft-windows-sdk-root") && contains(out, "-Xmicrosoft-windows-sdk-version") && contains(out, "10.0.26100.0")); expect(contains(out, "-fno-aligned-allocation")); + // Issue #97: beside it, the macro that keeps vcruntime_new.h's std::align_val_t and aligned operator new. + expect(contains(out, "-D__cpp_aligned_new=201606L")); expect(out.size() >= 2 && out[out.size() - 2] == "-x" && out.back() == "c++-module"); + // Without the workaround (the maintained engine), neither. + const auto plain = n::translate_msvc(n::MsvcInput { arguments, "C:/p/src/greet.ixx", "C:/p/build", &facts, true, false }); + expect(!contains(plain, "-fno-aligned-allocation") && !contains_prefix(plain, "-D__cpp_aligned_new")) << std::format("{}", plain); }; "P7: an mcpp cl.exe command"_test = [] { @@ -221,6 +226,7 @@ UTest normalize_tests{"normalize", [] { expect(contains(out, "-Wno-unused") && contains(out, "-mavx2") && contains(out, "-fms-runtime-lib=static")); expect(!contains_prefix(out, "-fmodule-output") && !contains_prefix(out, "-fmodule-file")); expect(std::ranges::count(out, std::string { "-fno-aligned-allocation" }) == 1); + expect(!contains_prefix(out, "-D__cpp_aligned_new")) << "the build turned aligned new off itself (/Zc:alignedNew-)"; expect(contains(out, "-fms-compatibility-version=19.44")); }; @@ -1084,6 +1090,7 @@ UTest normalize_tests{"normalize", [] { if (entry.file.ends_with("std.ixx")) { ++stdEntries; expect(contains(entry.arguments, "-Wno-include-angled-in-module-purview") && contains(entry.arguments, "-fno-aligned-allocation")); + expect(contains(entry.arguments, "-D__cpp_aligned_new=201606L")) << "std keeps what its importers are read with (issue #97)"; expect(!contains(entry.arguments, "-interface")); expect(entry.arguments[entry.arguments.size() - 3] == "-x" && entry.arguments[entry.arguments.size() - 2] == "c++-module"); } diff --git a/tests/unit/test_workarounds.cpp b/tests/unit/test_workarounds.cpp index 89edb4a3..1847a749 100644 --- a/tests/unit/test_workarounds.cpp +++ b/tests/unit/test_workarounds.cpp @@ -39,6 +39,12 @@ UTest workarounds_tests{"workarounds", [] { expect(cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "22.1.8")) << "another line gets every workaround"; expect(cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "23.10.0")) << "23.10 is not the 23.1 line"; expect(cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "")) << "an unknown version gets every workaround"; + // Issue #97: the maintained engine carries the fix (mcppls-clangd patch 0001-UP-05) whatever its LLVM base. + expect(!cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "23.1.0-mcppls.12")); + expect(!cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "23.1.0-mcppls.1")); + expect(cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "23.10.0-mcppls.1")) << "only the line's own maintained builds"; + expect(cld::needs(cld::MSVC_STL_ALIGNED_ALLOCATION, "x-mcppls.1")); + expect(cld::needs(cld::TRAILING_DOT_MODULE_NAME, "23.1.0-mcppls.12")) << "a workaround without the mark is decided as before"; for (const auto version : { "23.1.0", "23.1.2", "22.1.8", "24.0.0" }) expect(cld::needs(cld::TRAILING_DOT_MODULE_NAME, version)) << version; expect(!cld::needs("WA-CLANGD-999", "23.1.0")); const auto active = cld::active_workarounds("23.1.1"); @@ -54,6 +60,7 @@ UTest workarounds_tests{"workarounds", [] { expect(!cld::traits_for_version("23.1.0-mcppls.8").tested) << "another maintained build is not"; expect(pinned.needsModulePreparation && pinned.needsModuleHints && pinned.msvcStlNeedsNoAlignedAllocation); expect(!cld::traits_for_version("23.1.1").msvcStlNeedsNoAlignedAllocation); + expect(!bundled.msvcStlNeedsNoAlignedAllocation) << "issue #97: the bundled engine has the fix, the MSVC STL keeps aligned new"; expect(cld::traits_for_version("23.1.1").hangsOnTrailingDotModuleName); }; From 05b46b4f0188e682affd71839a6072a8c3066a0d Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Mon, 23 Nov 2026 03:40:19 +0900 Subject: [PATCH 2/3] S1 0.4.0: a generated unit names the authored file it copies (ide.generated[].origin) --- docs/specs/CHANGELOG.md | 9 +++++++++ docs/specs/README.md | 2 +- docs/specs/s1-build-database.md | 4 +++- docs/specs/schema/s1-build-database.schema.json | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/specs/CHANGELOG.md b/docs/specs/CHANGELOG.md index 4aa7279f..f78502e5 100644 --- a/docs/specs/CHANGELOG.md +++ b/docs/specs/CHANGELOG.md @@ -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, diff --git a/docs/specs/README.md b/docs/specs/README.md index 8c909ddf..59a7cf5b 100644 --- a/docs/specs/README.md +++ b/docs/specs/README.md @@ -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) | diff --git a/docs/specs/s1-build-database.md b/docs/specs/s1-build-database.md index 740e2407..ba97bfb9 100644 --- a/docs/specs/s1-build-database.md +++ b/docs/specs/s1-build-database.md @@ -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) | @@ -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. S1-7.2-1 | | `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. S1-7.2-2 | | `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). S1-7.2-3 | +| `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`. S1-7.2-14 (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). S1-7.2-4, S1-7.2-5, S1-7.2-6, S1-7.2-7, S1-7.2-8 | 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. S1-7.2-9 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. @@ -188,6 +189,7 @@ 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; S1-7.2-10, S1-7.2-11 - **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; S1-7.2-12 - **MUST NOT** run a step's `arguments` unless the user has allowed it for the workspace (section 14). S1-7.2-13 +- **SHOULD**, for a `source` entry with `origin`, treat the authored file as the source of the generated unit for navigation and diagnostics, and **MUST NOT** treat it as a second provider of the module the unit provides. S1-7.2-15 (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. diff --git a/docs/specs/schema/s1-build-database.schema.json b/docs/specs/schema/s1-build-database.schema.json index f4696165..0666e95e 100644 --- a/docs/specs/schema/s1-build-database.schema.json +++ b/docs/specs/schema/s1-build-database.schema.json @@ -257,6 +257,9 @@ "directory" ] }, + "origin": { + "$ref": "#/$defs/nonEmptyString" + }, "generator": { "type": "object", "required": [ From 013ebd56f0299ae4da32b01c414b50612951393e Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Mon, 23 Nov 2026 04:43:21 +0900 Subject: [PATCH 3/3] spec(s1): an origin is no second provider (S1-7.2-16) apart from using it for navigation (S1-7.2-15, pending), each rule with its evidence S1 0.4.0 put two requirements under one identifier and gave its new rules no evidence, so validate.py failed. S1-7.2-14 is a producer rule (mcpp#1006); S1-7.2-15 waits for issue 95's G3; S1-7.2-16 is issue 95's G1, now tested with a stated origin. --- ...23-issue-97-msvc-aligned-allocation-design.md | 9 +++++++++ docs/specs/s1-build-database.md | 3 ++- tests/cts/traceability.json | 16 +++++++++++++++- tests/unit/test_normalize.cpp | 11 +++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md b/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md index 56c4defc..f1fafc88 100644 --- a/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md +++ b/.agents/docs/2026-11-23-issue-97-msvc-aligned-allocation-design.md @@ -96,3 +96,12 @@ upgrade builds `std` and the modules once more ("command" rebuild reason). 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. + diff --git a/docs/specs/s1-build-database.md b/docs/specs/s1-build-database.md index ba97bfb9..45aca797 100644 --- a/docs/specs/s1-build-database.md +++ b/docs/specs/s1-build-database.md @@ -189,7 +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; S1-7.2-10, S1-7.2-11 - **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; S1-7.2-12 - **MUST NOT** run a step's `arguments` unless the user has allowed it for the workspace (section 14). S1-7.2-13 -- **SHOULD**, for a `source` entry with `origin`, treat the authored file as the source of the generated unit for navigation and diagnostics, and **MUST NOT** treat it as a second provider of the module the unit provides. S1-7.2-15 (0.4.0) +- **SHOULD**, for a `source` entry with `origin`, treat the authored file as the source of the generated unit for navigation and diagnostics; S1-7.2-15 (0.4.0) +- **MUST NOT** treat a `source` entry's `origin` as a second provider of the module the generated unit provides. S1-7.2-16 (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. diff --git a/tests/cts/traceability.json b/tests/cts/traceability.json index c65e4fd0..f092439f 100644 --- a/tests/cts/traceability.json +++ b/tests/cts/traceability.json @@ -4,7 +4,8 @@ "S1-7.2-10": "the server reads `generated` only to tell a shadowed source (#95), not yet for the files a build has not written", "S1-7.2-11": "the server reads `generated` only to tell a shadowed source (#95), not yet for the files a build has not written", "S1-7.2-12": "the server reads `generated` only to tell a shadowed source (#95), not yet for the files a build has not written", - "S1-7.2-13": "the server reads `generated` only to tell a shadowed source (#95), not yet for the files a build has not written" + "S1-7.2-13": "the server reads `generated` only to tell a shadowed source (#95), not yet for the files a build has not written", + "S1-7.2-15": "mcppls answers the authored file with its own engine; clangd's results for the generated unit are not mapped to it yet (design 2026-11-22 issue 95, G3)" }, "S1-3-1": [ { @@ -2752,5 +2753,18 @@ "script": "src/engine/clangd.cpp", "contains": "\"payload-corrupt\", \"the extension's payload is corrupt or was modified; reinstall the extension\"" } + ], + "S1-7.2-14": [ + { + "manual": "A producer rule. mcpp-community/mcpp writes the field from a build rule's declaration (mcpp-community/mcpp#1006); this repository contains no producer that could be tested." + } + ], + "S1-7.2-16": [ + { + "test": "tests/unit/test_normalize.cpp: std's representative is chosen by set, then by unit, and an edit buffer does not move it (issue 95)" + }, + { + "check": "shadowed-source/P1-a-shadowed-source-generated-from" + } ] } diff --git a/tests/unit/test_normalize.cpp b/tests/unit/test_normalize.cpp index 4ac51a98..3331e6ca 100644 --- a/tests/unit/test_normalize.cpp +++ b/tests/unit/test_normalize.cpp @@ -1578,6 +1578,17 @@ UTest normalize_tests{"normalize", [] { expect(plan.stubModules.empty()) << std::format("{}", plan.stubModules); } + // A stated origin (S1 0.4.0, S1-7.2-16) names the file without asking the step's inputs: still no second provider. + { + s::Database database { database_with({ "app" }) }; + database.sets.back().generated.front().inputs = { "/p/src/app.cppm", "/p/templates/base.cppm" }; // two: no inference + database.sets.back().generated.front().origin = "/p/src/app.cppm"; + const auto plan = plan_of(database, {}, { "/p/src/app.cppm" }); + expect(std::ranges::none_of(plan.issues, [](const n::PlanIssue& issue) { return issue.code == "ambiguous-module"; })); + expect(fatal(plan.shadowedSources.size() == 1u)); + expect(plan.shadowedSources.front().kind == "generated-from" && plan.shadowedSources.front().stated); + } + // ... and without ide.generated, a file outside the build. { s::Database database { database_with({ "app" }) };