Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initially use [[msvc::no_unique_address]] for some C++23 components #4960

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Sep 17, 2024

Towards #1364.

Applied:

  • in_value_result
  • out_value_result
  • mdspan
  • join_with_view's sentinel
  • enumerate_view's iterator and sentinel
  • chunk_view's iterator
  • slide_view's sentinel
  • elements_of

Not yet applied due to DevCom-10588147 and possibly related issues.

  • views, as they have view_interface as their empty bases.
  • some iterators with empty bases due to conditionally existing iterator_category.
  • chunk_by_view's iterator, possibly because the non-potentially-overlapping member is listed first.

Not yet applied because it's unclear to me how to reuse padding bytes in tuple

  • zip-family

Not yet applied due to another unclear reasons

  • expected

Other changes:

  • remove /* [[no_unique_address]] */ for _Index_type of repeat_view's iterator because the _Index_type never has padding bytes
  • move the test coverage added in <mdspan>: More EBO #3847 to a separated test file
  • attempt to test NVCC for these changes failed and reverted.

- `in_value_result`
- `out_value_result`
- `mdspan`
- `join_with_view`'s sentinel
- `enumerate_view`'s iterator and sentinel
- `chunk_view`'s iterator
- `slide_view`'s sentinel
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner September 17, 2024 16:05
@frederick-vs-ja

This comment was marked as resolved.

@CaseyCarter CaseyCarter added performance Must go faster decision needed We need to choose something before working on this labels Sep 17, 2024
@CaseyCarter

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej removed the decision needed We need to choose something before working on this label Sep 18, 2024
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej self-assigned this Sep 19, 2024
@StephanTLavavej

This comment was marked as resolved.

@CaseyCarter

This comment was marked as resolved.

@frederick-vs-ja

This comment was marked as resolved.

@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej removed their assignment Oct 20, 2024
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej added the blocked Something is preventing work on this label Oct 21, 2024
@StephanTLavavej
Copy link
Member

This is blocked by DevCom-10754777 VSO-2266748 "Wrong code generation when initializing a variable of class type that contains multiple instances of the same empty class in its layout", fixed by MSVC-PR-583942 on 2024-10-10, shipping in 17.13p2.

Click to expand fully reduced repro:
C:\Temp>type meow.cpp
#include <cassert>

using Extents = signed char;

struct Holder {
    constexpr Holder(const Extents& e) : exts(e) {}
    [[msvc::no_unique_address]] Extents exts;
};

struct Empty {};

struct Mdspan {
    [[msvc::no_unique_address]] Holder holder;
    [[msvc::no_unique_address]] Empty acc{};
    [[msvc::no_unique_address]] int val{1729};
};

int main() {
    Extents extents{7};
    Mdspan md{extents};
    assert(md.holder.exts == extents);
}

17.12 Preview 3 x64:

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /d1reportSingleClassLayoutMdspan meow.cpp && meow
meow.cpp

class Mdspan    size(4):
        +---
 0      | Holder holder
 0      | Empty acc
 0      | val
        +---
Assertion failed: md.holder.exts == extents, file meow.cpp, line 21

Current prod/fe x64:

C:\Temp>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /d1reportSingleClassLayoutMdspan meow.cpp && meow
meow.cpp

class Mdspan    size(8):
        +---
 0      | Holder holder
 0      | Empty acc
        | <alignment member> (size=3)
 4      | val
        +---

C:\Temp>

We talked about this in Discord, and I now agree with @AlexGuteniev that all use of [[msvc::no_unique_address]] should be avoided until we have this fix - even though only mdspan is directly affected now, user usage could reveal other problems, and since it happens only at runtime in a catastrophic way, this isn't worth the risk when the compiler is known to be unreliable.

  • Merge with the VS 2022 17.13 Preview 2 toolset update.
  • Verify that llvm-project\libcxx\test\std\containers\views\mdspan\mdspan passes again.

@StephanTLavavej StephanTLavavej marked this pull request as draft October 26, 2024 14:56
@StephanTLavavej
Copy link
Member

Resolved a trivial merge conflict in <xmemory> with #4987. (Set to draft mode to avoid running the CI while this PR is blocked.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Something is preventing work on this performance Must go faster
Projects
Status: Blocked
Development

Successfully merging this pull request may close these issues.

3 participants