-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add and modify safety descriptions in some of intrinsics APIs #135334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2014,6 +2014,10 @@ pub fn ptr_mask<T>(_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,18 @@ pub unsafe fn volatile_copy_memory<T>(_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::<T>()` bytes. | ||
/// | ||
/// * `_dst` must be properly aligned. | ||
/// | ||
/// Note that even if `T` has size `0`, the pointer must be properly aligned. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just point at Except of course they aren't really -- these are volatile operations which can be used in ways that would be invalid for |
||
/// | ||
/// [valid]: crate::ptr#safety | ||
/// | ||
/// This intrinsic does not have a stable counterpart. | ||
#[rustc_intrinsic] | ||
#[rustc_intrinsic_must_be_overridden] | ||
|
@@ -3965,8 +3981,16 @@ pub const fn is_val_statically_known<T: Copy>(_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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incomplete. The operation is typed, so the pointers must point to data that is valid at the given type. |
||
/// | ||
/// `x` and `y` are readable and writable as `T`, and non-overlapping. | ||
/// * 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`. | ||
/// | ||
/// [valid]: crate::ptr#safety | ||
#[rustc_nounwind] | ||
#[inline] | ||
#[rustc_intrinsic] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be much more important do clarify here is whether both the read and the write are volatile, or only one of them. Also, "the volatile parameter is set to
true
" makes no sense, that's talking about a parameter inside the codegen backend that shouldn't show up in such docs. Same forllvm.memset.p0i8
; maybe it's useful to mention it but the first summary should not refer to LLVM-specific concepts.