Skip to content

Commit 6a607fa

Browse files
committed
Follow up commit for the issue 39827
- updates documentation on volatile memory intrinsics, now the case of zero-sized types is mentioned explicitly. Volatile memory operations which doesn't affect memory at all are omitted in LLVM backend, e.g. if number of elements is zero or type used in generic specialisation is zero-sized, then LLVM intrinsic or related code is not generated. This was not explicitly documented before in Rust documentation and potentially could cause issues.
1 parent 0cd3587 commit 6a607fa

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/libcore/intrinsics.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,20 +1044,23 @@ extern "rust-intrinsic" {
10441044
/// a size of `count` * `size_of::<T>()` and an alignment of
10451045
/// `min_align_of::<T>()`
10461046
///
1047-
/// The volatile parameter is set to `true`, so it will not be optimized out.
1047+
/// The volatile parameter is set to `true`, so it will not be optimized out
1048+
/// unless size is equal to zero.
10481049
pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
10491050
count: usize);
10501051
/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
10511052
/// a size of `count` * `size_of::<T>()` and an alignment of
10521053
/// `min_align_of::<T>()`
10531054
///
1054-
/// The volatile parameter is set to `true`, so it will not be optimized out.
1055+
/// The volatile parameter is set to `true`, so it will not be optimized out
1056+
/// unless size is equal to zero..
10551057
pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
10561058
/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
10571059
/// size of `count` * `size_of::<T>()` and an alignment of
10581060
/// `min_align_of::<T>()`.
10591061
///
1060-
/// The volatile parameter is set to `true`, so it will not be optimized out.
1062+
/// The volatile parameter is set to `true`, so it will not be optimized out
1063+
/// unless size is equal to zero.
10611064
pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
10621065

10631066
/// Perform a volatile load from the `src` pointer.

src/libcore/ptr.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
384384
/// over time. That being said, the semantics will almost always end up pretty
385385
/// similar to [C11's definition of volatile][c11].
386386
///
387+
/// Compiler shouldn't change relative order or number of volatile memory
388+
/// operations, however this implies that memory operation actually takes place.
389+
/// If a zero-sized type is used in a specialisation of `read_volatile`, value
390+
/// is known at any time and can not be modified outside of program control.
391+
/// In this case such operation may be omitted by compiler backend.
392+
///
387393
/// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
388394
///
389395
/// # Safety
@@ -427,6 +433,12 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
427433
/// over time. That being said, the semantics will almost always end up pretty
428434
/// similar to [C11's definition of volatile][c11].
429435
///
436+
/// Compiler shouldn't change relative order or number of volatile memory
437+
/// operations, however this implies that memory operation actually takes place.
438+
/// If a zero-sized type is used in a specialisation of `write_volatile`, value
439+
/// is known at any time and can not be modified outside of program control.
440+
/// In this case such operation may be omitted by compiler backend.
441+
///
430442
/// [c11]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
431443
///
432444
/// # Safety

0 commit comments

Comments
 (0)