From 049d2301fe9993aa9e71ee47f67bc9df2de2750e Mon Sep 17 00:00:00 2001 From: LemonJ <1632798336@qq.com> Date: Fri, 10 Jan 2025 22:17:40 +0800 Subject: [PATCH 1/2] add missing safety in intrinsics --- library/core/src/intrinsics/mod.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 7b31bbec7547c..a5d5a8937177a 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2014,6 +2014,10 @@ pub fn ptr_mask(_ptr: *const T, _mask: usize) -> *const T { /// The volatile parameter is set to `true`, so it will not be optimized out /// unless size is equal to zero. /// +/// # Safety +/// +/// The safety concerns are the same with [`copy_nonoverlapping`]. +/// /// This intrinsic does not have a stable counterpart. #[rustc_intrinsic] #[rustc_intrinsic_must_be_overridden] @@ -2042,6 +2046,16 @@ pub unsafe fn volatile_copy_memory(_dst: *mut T, _src: *const T, _count: usiz /// The volatile parameter is set to `true`, so it will not be optimized out /// unless size is equal to zero. /// +/// # Safety +/// +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * `_dst` must be [valid] for writes of `_count * size_of::()` bytes. +/// +/// * `_dst` must be properly aligned. +/// +/// Note that even if `T` has size `0`, the pointer must be properly aligned. +/// /// This intrinsic does not have a stable counterpart. #[rustc_intrinsic] #[rustc_intrinsic_must_be_overridden] @@ -3965,8 +3979,15 @@ pub const fn is_val_statically_known(_arg: T) -> bool { /// The stabilized form of this intrinsic is [`crate::mem::swap`]. /// /// # Safety +/// Behavior is undefined if any of the following conditions are violated: +/// +/// * Both `x` and `y` must be [valid] for both reads and writes. +/// +/// * Both `x` and `y` must be properly aligned. +/// +/// * The region of memory beginning at `x` must *not* overlap with the region of memory +/// beginning at `y`. /// -/// `x` and `y` are readable and writable as `T`, and non-overlapping. #[rustc_nounwind] #[inline] #[rustc_intrinsic] From fb435df33be1bc3a72d05929181d7e386e287100 Mon Sep 17 00:00:00 2001 From: LemonJ <1632798336@qq.com> Date: Sat, 11 Jan 2025 11:07:59 +0800 Subject: [PATCH 2/2] fix valid link --- library/core/src/intrinsics/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index a5d5a8937177a..bc621e8c1ea62 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -2056,6 +2056,8 @@ pub unsafe fn volatile_copy_memory(_dst: *mut T, _src: *const T, _count: usiz /// /// Note that even if `T` has size `0`, the pointer must be properly aligned. /// +/// [valid]: crate::ptr#safety +/// /// This intrinsic does not have a stable counterpart. #[rustc_intrinsic] #[rustc_intrinsic_must_be_overridden] @@ -3988,6 +3990,7 @@ pub const fn is_val_statically_known(_arg: T) -> bool { /// * The region of memory beginning at `x` must *not* overlap with the region of memory /// beginning at `y`. /// +/// [valid]: crate::ptr#safety #[rustc_nounwind] #[inline] #[rustc_intrinsic]