aarch64: fix UB in non-power-of-two reads and writes#2042
aarch64: fix UB in non-power-of-two reads and writes#2042sayantn merged 1 commit intorust-lang:mainfrom
Conversation
|
Did you check that this doesn't interfere with the LLVM optimization? |
| $crate::ptr::copy_nonoverlapping( | ||
| $ptr.cast::<$elem>(), | ||
| mem.as_mut_ptr().cast::<$elem>(), | ||
| $lanes * 3, | ||
| ); |
There was a problem hiding this comment.
copy_nonoverlapping requires aligned pointers, so shouldn't this use read_unaligned($ptr) before writing to mem?
Same with the store needing to use write_unaligned rather than copy_nonoverlapping because that would require dst to be aligned.
There was a problem hiding this comment.
As this is copying elementwise, it should be ok if the pointer is element-aligned. I am not too familiar with ARM load semantics, is the pointer at least guaranteed to be element-aligned (I guess that's the case just from the type). @folkertdev could you just confirm this please?
There was a problem hiding this comment.
The pointer should be aligned to the element type, that is assumed by the implementation. You can see that e.g. in the Operation section here:
https://developer.arm.com/architectures/instruction-sets/intrinsics/vld3q_f16
|
Looks right to me? https://godbolt.org/z/fcbEq19cv |
fixes #2036
I believe this fixes the issue. We should think about how to test that, but also the beta cutoff is soon and so we should try to sync this quickly.
cc @okaneco
r? sayantn