-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
This intrinsic takes a raw pointer and an alignment and checks whether the pointer is aligned wrt the given alignment. Implementations like miri can use this to always return false, if the requested alignment is bigger than the alignment given at creation of the allocation that the pointer points into.
In the future platforms which don't require alignment can return true unconditionally, which will probably allow more optimizations to trigger on those platforms.
The signature of the intrinsic can either be fn<T>(* const T, usize)
or just fn<T>(* const T)
where the latter obtains the alignment to be checked from the pointee type.
Most platforms should simply generate (ptr as usize) & ((1 << (align - 1) - 1) == 0
An example of such a check in the stdlib is
Line 1433 in f09576c
let align = (ptr as usize + index) & (usize_bytes - 1); |
Does a change like this require an rfc?