Fix tests crashing with miri due to misalignment. #14
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, three tests are failing with the latest nightly version of miri:
test_eq
,test_ne
,test_ord
.Example output:
This happens because of these lines:
Since a
[u8; N]
array is unaligned, its stack addr isn't necessarily aligned to 8 (asu64
requires). I'm not sure where the exact semantics are documented, but I think miri randomized the layout of data to catch these types of errors? Not sure, but it seems that the tests are passing when run not under miri "by accident", i.e. they rely on the fact that the memory happens to be aligned correctly.My fix simply stores
u64
s on the stack, instead of[u8; 8]
s, and usesAsBytes::as_bytes()
to use them as a buffer for the creation of theLayoutVerified
s. Since the stack memory is now guaranteed to be properly aligned, this seems to appease miri.