Fix miscompilation in transmute_unchecked
introduced by bug in LLVM
#25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently some casts from byte primitives to two element tuple lead to miscompilation on release builds on Rust
>=1.70.0
:castaway::cast!(123_u8, (u8, u8))
unexpectedly returnsOk(...)
that leads to UB.castaway::cast!(false, (bool, u16))
leads toSIGILL: illegal instruction
runtime error.Upstream issues:
std::ptr::read
is used to cast byte primitive to some tuples in unreachable code paths rust-lang/rust#127286I suggest considering adding a safe "workaround" to fix the issue in this crate without having to wait for the upstream fixes. This way we will have this fixed in older Rust versions as well.
This PR adds size eq
assert
totransmute_unchecked
. This workaround was found while preparing an MRE for an upstream issue.Checked locally with
cargo test --release
for Rust1.38
,1.68.0
,1.69.0
,1.70.0
,1.71.0
,1.72.0
,stable
,beta
,nightly
. Generated assembly for other tests cases for the release build seems the same (checks and casts are optimized away).Btw: it might also be a good idea to run tests in
--release
mode as well since the crate relies heavily on optimizing the casts to zero-cost.