about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/lib.rs
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-07-05 16:04:31 +0530
committerGitHub <noreply@github.com>2022-07-05 16:04:31 +0530
commit8fa1ed8f123f2714a7796c03d7d634b046bdaed2 (patch)
tree9db087f1dc800fec89ad0fa1482fb3e5e94475e1 /compiler/rustc_codegen_llvm/src/lib.rs
parent4045ce641a9eede71cc12031a2cd71692b273890 (diff)
parentcb7cd97641b7a2d1646520b7bf785934f9c6aaeb (diff)
downloadrust-8fa1ed8f123f2714a7796c03d7d634b046bdaed2.tar.gz
rust-8fa1ed8f123f2714a7796c03d7d634b046bdaed2.zip
Rollup merge of #97712 - RalfJung:untyped, r=scottmcm
ptr::copy and ptr::swap are doing untyped copies

The consensus in https://github.com/rust-lang/rust/issues/63159 seemed to be that these operations should be "untyped", i.e., they should treat the data as raw bytes, should work when these bytes violate the validity invariant of `T`, and should exactly preserve the initialization state of the bytes that are being copied. This is already somewhat implied by the description of "copying/swapping size*N bytes" (rather than "N instances of `T`").

The implementations mostly already work that way (well, for LLVM's intrinsics the documentation is not precise enough to say what exactly happens to poison, but if this ever gets clarified to something that would *not* perfectly preserve poison, then I strongly assume there will be some way to make a copy that *does* perfectly preserve poison). However, I had to adjust `swap_nonoverlapping`; after ``@scottmcm's`` [recent changes](https://github.com/rust-lang/rust/pull/94212), that one (sometimes) made a typed copy. (Note that `mem::swap`, which works on mutable references, is unchanged. It is documented as "swapping the values at two mutable locations", which to me strongly indicates that it is indeed typed. It is also safe and can rely on `&mut T` pointing to a valid `T` as part of its safety invariant.)

On top of adding a test (that will be run by Miri), this PR then also adjusts the documentation to indeed stably promise the untyped semantics. I assume this means the PR has to go through t-libs (and maybe t-lang?) FCP.

Fixes https://github.com/rust-lang/rust/issues/63159
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/lib.rs')
0 files changed, 0 insertions, 0 deletions