diff options
| author | Ralf Jung <post@ralfj.de> | 2023-11-12 16:06:50 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-12-03 21:51:14 +0100 |
| commit | bebba4f6e05fae60ce8dcddc5eb6b4e7686bd995 (patch) | |
| tree | abfa4f9082f8369161b2cfa7a6dce5d8f32e4781 /library/core/src/slice | |
| parent | 7ceaf198684b7ca94986a436bf623e20ba62bd23 (diff) | |
| download | rust-bebba4f6e05fae60ce8dcddc5eb6b4e7686bd995.tar.gz rust-bebba4f6e05fae60ce8dcddc5eb6b4e7686bd995.zip | |
miri: support 'promising' alignment for symbolic alignment check
Diffstat (limited to 'library/core/src/slice')
| -rw-r--r-- | library/core/src/slice/mod.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index a7b36fe7d29..7d88f70efd1 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -3868,6 +3868,18 @@ impl<T> [T] { } else { let (left, rest) = self.split_at(offset); let (us_len, ts_len) = rest.align_to_offsets::<U>(); + // Inform Miri that we want to consider the "middle" pointer to be suitably aligned. + #[cfg(miri)] + { + extern "Rust" { + pub fn miri_promise_symbolic_alignment(ptr: *const (), align: usize); + } + + // SAFETY: this call is always safe. + unsafe { + miri_promise_symbolic_alignment(rest.as_ptr().cast(), mem::align_of::<U>()); + } + } // SAFETY: now `rest` is definitely aligned, so `from_raw_parts` below is okay, // since the caller guarantees that we can transmute `T` to `U` safely. unsafe { @@ -3938,6 +3950,21 @@ impl<T> [T] { let (us_len, ts_len) = rest.align_to_offsets::<U>(); let rest_len = rest.len(); let mut_ptr = rest.as_mut_ptr(); + // Inform Miri that we want to consider the "middle" pointer to be suitably aligned. + #[cfg(miri)] + { + extern "Rust" { + pub fn miri_promise_symbolic_alignment(ptr: *const (), align: usize); + } + + // SAFETY: this call is always safe. + unsafe { + miri_promise_symbolic_alignment( + mut_ptr.cast() as *const (), + mem::align_of::<U>(), + ); + } + } // We can't use `rest` again after this, that would invalidate its alias `mut_ptr`! // SAFETY: see comments for `align_to`. unsafe { |
