Skip to content

MSVC: disable [[msvc::no_unique_address]] due to incorrect codegen - #2383

Open
KassaSana wants to merge 1 commit into
NVIDIA:mainfrom
KassaSana:msvc-disable-no-unique-address
Open

KassaSana wants to merge 1 commit into
NVIDIA:mainfrom
KassaSana:msvc-disable-no-unique-address

Conversation

@KassaSana

@KassaSana KassaSana commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #2099.

MSVC still miscompiles [[msvc::no_unique_address]]. With cl 19.50 (the toolset in the 14.50 Windows CI job), the code from the issue writes past the end of a stack temporary while constructing the let_value sender at __let.hpp:519. Under /fsanitize=address that's a stack-buffer-overflow. Without ASan the program runs, but the lambda's captures come back corrupted. The C4789 in the issue is the compiler warning about the same write, which -sdl turns into an error.

turned the attribute off for MSVC once before for incorrect codegen (4ccd753). It came back for _MSC_VER >= 1943, which covers both MSVC versions in CI. This diff turns it off for all MSVC versions again. clang-cl is unchanged.

It also adds a regression test to test_let_value.cpp that checks the captured values after sync_wait, so it fails with or without ASan. And it removes the MSVC-only expectation in the fork_join test. As #2302 (comment) found, that move was missing only because of this attribute. With it off, MSVC does the move like the other compilers.

Tested with MSVC 19.50 and the flags from test-windows.ps1 (/fsanitize=address /EHsc). The new test fails on main in Debug and Release. With this change, all 1106 tests pass in both.

The cost is that types with empty no_unique_address members get bigger on MSVC, same as after the 2023 change.

ASan output on main
ERROR: AddressSanitizer: stack-buffer-overflow ...
WRITE of size 8 at ... thread T0
    #0 in __let::__let_t<let_value_t>::operator()<just_t::__sender<unsigned __int64>, ...> __let.hpp:519

Current MSVC (reproduced with cl 19.50) still miscompiles
[[msvc::no_unique_address]]: constructing a let_value sender whose
function captures a value alongside a nested sender writes past the end
of a stack temporary (ASan stack-buffer-overflow, C4789 under /sdl) and
corrupts the captured values. Disable the attribute for all MSVC
versions instead of only for _MSC_VER < 1943.

Add a regression test for the let_value case, and drop the MSVC-only
expectation in the fork_join test: the missing move it worked around
came from the same miscompile, and MSVC now matches other compilers.

Fixes NVIDIA#2099
Copilot AI balanced review requested due to automatic review settings October 29, 2026 04:06
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MSVC: error C4789: in function 'main' buffer '' of size 12 bytes will be overrun; 8 bytes will be written starting at offset 11

2 participants