-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
std::ptr::swap_nonoverlapping is not always untyped #134713
Copy link
Copy link
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Code
I tried this code:
godbolt link
I expected to see this happen: The two
assert_eq!s should succeed;b1andb2should be completely swapped, sincestd::ptr::swap_nonoverlapping::<T>claims to swap bytes, notTs.Instead, this happened: They are not entirely swapped.
swap_nonoverlappingappears to be doing a typed swap atFoo, skipping/zeroing/not-correctly-swapping the 7 padding bytes at the end ofFoo.I think this only happens with types where
size_of::<T>() > size_of::<usize>()from looking at the implementation, but I'm not sure.In debug mode:
Rust 1.61-1.70 appear to consistently give
[3000, 160].Rust 1.71-nightly appear to consistently give
[3000, 1952].4000 is
0x0fa0160 is
0x00a01952 is
0x07a02000 is
0x07d0so it looks like Rust 1.61-1.70 are zeroing the padding bytes, and Rust 1.71-nightly are ignoring them.
Version it worked on
It most recently worked on: Rust 1.60
Version with regression
rustc --version --verbose:@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged