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

Refactor _Copy_memmove and _Copy_memmove_n #5046

Merged
merged 12 commits into from
Nov 8, 2024

Conversation

CaseyCarter
Copy link
Member

@CaseyCarter CaseyCarter commented Oct 27, 2024

  • BUG: _Copy_memmove_n adds a size_t directly to an iterator.
  • BUG: ranges::copy_n converts n to size_t without verifying it is non-negative.
  • There's a redundant recalculation of n in our existing implementation of _Copy_memmove_n which calls _Copy_memmove. Eliminate that redundancy by extracting the commonality into a new function _Copy_memmove_tail called by both _Copy_memmove and _Copy_memmove_n.
  • _Copy_n_unchecked4 should verify its precondition that n >= 0. Drive-by: We can unconditionally _STL_INTERNAL_STATIC_ASSERT(_Integer_like<_SizeTy>) since Unwrapping output iterators in range algorithms #5015 defined _Integer_like in pre-20 modes

@CaseyCarter CaseyCarter added the bug Something isn't working label Oct 27, 2024
@CaseyCarter CaseyCarter self-assigned this Oct 27, 2024
@CaseyCarter

This comment was marked as resolved.

@CaseyCarter CaseyCarter marked this pull request as ready for review October 27, 2024 18:00
@CaseyCarter CaseyCarter requested a review from a team as a code owner October 27, 2024 18:00
There's a redundant recalculation of `n` in our existing implementation of `_Copy_memmove_n` which calls `_Copy_memmove`. Eliminate that redundancy by extracting the commonality into a new function `_Copy_memmove_tail` called by both `_Copy_memmove` and `_Copy_memmove_n`. This also corrects an error in `_Copy_memmove_n` where it was adding a `size_t` directly to an iterator.
@CaseyCarter

This comment was marked as outdated.

…gative counts

* `ranges::copy_n` takes a difference argument that it was blindly converting to `size_t`

Drive-by: `_Copy_n_unchecked4` no longer needs to guard its `_STL_INTERNAL_STATIC_ASSERT(_Integer_like<_SizeTy>);` for `_HAS_CXX20` since microsoft#5015 defined `_Integer_like` in pre-20 modes.
@CaseyCarter

This comment was marked as outdated.

@CaseyCarter

This comment was marked as spam.

@CaseyCarter CaseyCarter reopened this Oct 27, 2024
@CaseyCarter

This comment was marked as outdated.

@CaseyCarter CaseyCarter removed their assignment Oct 28, 2024
@StephanTLavavej

This comment was marked as resolved.

@CaseyCarter

This comment was marked as resolved.

@CaseyCarter CaseyCarter removed their assignment Oct 30, 2024
stl/inc/xutility Outdated Show resolved Hide resolved
@CaseyCarter

This comment was marked as resolved.

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej self-assigned this Oct 30, 2024
stl/inc/xutility Outdated Show resolved Hide resolved
stl/inc/xutility Outdated Show resolved Hide resolved
stl/inc/xutility Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
tests/std/tests/GH_000431_copy_move_family/test.cpp Outdated Show resolved Hide resolved
@StephanTLavavej
Copy link
Member

Thanks! 😻 I pushed various nitpicks and a significant expansion of test coverage - please meow if you have any objections, I was a bit more daring than usual.

@StephanTLavavej StephanTLavavej removed their assignment Nov 2, 2024
@StephanTLavavej StephanTLavavej self-assigned this Nov 7, 2024
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 645cac9 into microsoft:main Nov 8, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

Thanks for memmoving these bugs out of our implementation! 🐞 🚚 😹

@CaseyCarter CaseyCarter deleted the copy_memmove branch November 8, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants