diff --git a/src/doc/book b/src/doc/book index db919bc6bb907..9cffbeabec3bc 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit db919bc6bb9071566e9c4f05053672133eaac33e +Subproject commit 9cffbeabec3bcec42d09432bfe7705125c848889 diff --git a/src/doc/edition-guide b/src/doc/edition-guide index c413d42a207bd..aa0022c875907 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit c413d42a207bd082f801ec0137c31b71e4bfed4c +Subproject commit aa0022c875907886cae8f3ef8e9ebf6e2a5e728d diff --git a/src/doc/embedded-book b/src/doc/embedded-book index de3d55f521e65..9e656ead82bfe 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit de3d55f521e657863df45260ebbca1b10527f662 +Subproject commit 9e656ead82bfe869493dec82653a52e27fa6a05c diff --git a/src/doc/nomicon b/src/doc/nomicon index fb29b147be4d9..f1ff93b668444 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit fb29b147be4d9a1f8e24aba753a7e1de537abf61 +Subproject commit f1ff93b66844493a7b03101c7df66ac958c62418 diff --git a/src/doc/reference b/src/doc/reference index 2a2de9ce09597..41493ffce5d0e 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 2a2de9ce095979978ad7b582daecf94e4070b916 +Subproject commit 41493ffce5d0e17d54eaf5ec9a995054e2b9aece diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 1ff0f8e018838..2ce92beabb912 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 1ff0f8e018838a710ebc0cc1a7bf74ebe73ad9f1 +Subproject commit 2ce92beabb912d417a7314d6da83ac9b50dc2afb diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 99e1b1d53656b..344c4e437ba4c 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 99e1b1d53656be08654df399fc200584aebb50e4 +Subproject commit 344c4e437ba4cfa5c14db643ec4d6b68dcd164c5 diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 782a7ba455984..bd7570d0f68f4 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -41,6 +41,8 @@ since = "1.18.0")] pub use crate::ptr::drop_in_place; +use crate::mem; + extern "rust-intrinsic" { // N.B., these intrinsics take raw pointers because they mutate aliased // memory, which is not valid for either `&` or `&mut`. @@ -1323,6 +1325,26 @@ mod real_intrinsics { } } +/// Checks whether `ptr` is properly aligned with respect to +/// `align_of::()`. +pub(crate) fn is_aligned_and_not_null(ptr: *const T) -> bool { + return !ptr.is_null() && ptr as usize % mem::align_of::() == 0; +} + +/// Checks whether the regions of memory starting at `src` and `dst` of size +/// `count * size_of::()` overlap. +fn overlaps(src: *const T, dst: *const T, count: usize) -> bool { + let src_usize = src as usize; + let dst_usize = dst as usize; + let size = mem::size_of::().checked_mul(count).unwrap(); + let diff = if src_usize > dst_usize { + src_usize - dst_usize + } else { + dst_usize - src_usize + }; + size > diff +} + /// Copies `count * size_of::()` bytes from `src` to `dst`. The source /// and destination must *not* overlap. /// @@ -1409,6 +1431,9 @@ mod real_intrinsics { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { + debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer"); + debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer"); + debug_assert!(!overlaps(src, dst, count), "attempt to copy to overlapping memory"); real_intrinsics::copy_nonoverlapping(src, dst, count); } @@ -1466,6 +1491,8 @@ pub unsafe fn copy_nonoverlapping(src: *const T, dst: *mut T, count: usize) { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub unsafe fn copy(src: *const T, dst: *mut T, count: usize) { + debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer"); + debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer"); real_intrinsics::copy(src, dst, count) } @@ -1544,5 +1571,6 @@ pub unsafe fn copy(src: *const T, dst: *mut T, count: usize) { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub unsafe fn write_bytes(dst: *mut T, val: u8, count: usize) { + debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer"); real_intrinsics::write_bytes(dst, val, count) } diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 8731f48675356..593ca4d8160b6 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -26,6 +26,7 @@ use crate::cmp::Ordering::{self, Less, Equal, Greater}; use crate::cmp; use crate::fmt; use crate::intrinsics::assume; +use crate::intrinsics::is_aligned_and_not_null; use crate::isize; use crate::iter::*; use crate::ops::{FnMut, Try, self}; @@ -5084,7 +5085,7 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] { - debug_assert!(data as usize % mem::align_of::() == 0, "attempt to create unaligned slice"); + debug_assert!(is_aligned_and_not_null(data), "attempt to create unaligned or null slice"); debug_assert!(mem::size_of::().saturating_mul(len) <= isize::MAX as usize, "attempt to create slice covering half the address space"); Repr { raw: FatPtr { data, len } }.rust @@ -5105,7 +5106,7 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] { - debug_assert!(data as usize % mem::align_of::() == 0, "attempt to create unaligned slice"); + debug_assert!(is_aligned_and_not_null(data), "attempt to create unaligned or null slice"); debug_assert!(mem::size_of::().saturating_mul(len) <= isize::MAX as usize, "attempt to create slice covering half the address space"); Repr { raw: FatPtr { data, len } }.rust_mut diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index f88923fc9f1c5..01fe1afd51e2c 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1706,7 +1706,9 @@ extern "C" { pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>); pub fn LLVMRustDestroyArchive(AR: &'static mut Archive); - pub fn LLVMRustGetSectionName(SI: &SectionIterator<'_>, data: &mut *const c_char) -> size_t; + #[allow(improper_ctypes)] + pub fn LLVMRustGetSectionName(SI: &SectionIterator<'_>, + data: &mut Option>) -> size_t; #[allow(improper_ctypes)] pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString); diff --git a/src/librustc_codegen_llvm/metadata.rs b/src/librustc_codegen_llvm/metadata.rs index 7cf497cb5d036..9bddd29d2e88f 100644 --- a/src/librustc_codegen_llvm/metadata.rs +++ b/src/librustc_codegen_llvm/metadata.rs @@ -8,7 +8,6 @@ use rustc_data_structures::owning_ref::OwningRef; use rustc_codegen_ssa::METADATA_FILENAME; use std::path::Path; -use std::ptr; use std::slice; use rustc_fs_util::path_to_c_string; @@ -67,10 +66,14 @@ fn search_meta_section<'a>(of: &'a ObjectFile, unsafe { let si = mk_section_iter(of.llof); while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False { - let mut name_buf = ptr::null(); + let mut name_buf = None; let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf); - let name = slice::from_raw_parts(name_buf as *const u8, name_len as usize).to_vec(); - let name = String::from_utf8(name).unwrap(); + let name = name_buf.map_or( + "".to_string(), + |buf| String::from_utf8( + slice::from_raw_parts(buf.as_ptr() as *const u8, + name_len as usize) + .to_vec()).unwrap()); debug!("get_metadata_section: name {}", name); if read_metadata_section_name(target) == name { let cbuf = llvm::LLVMGetSectionContents(si.llsi); diff --git a/src/llvm-project b/src/llvm-project index 84abffda0e03b..4fc9fb8245abe 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 84abffda0e03b03c62bdfc3cfeda1c2cf1f88c85 +Subproject commit 4fc9fb8245abe24680192535870c4522644a4212 diff --git a/src/stdsimd b/src/stdsimd index 4bf456c35e85f..359845eb7cae8 160000 --- a/src/stdsimd +++ b/src/stdsimd @@ -1 +1 @@ -Subproject commit 4bf456c35e85fcca5cf95008401af8ab25abf850 +Subproject commit 359845eb7cae85799dc2ec81f2fb05da0aa6276d diff --git a/src/tools/cargo b/src/tools/cargo index 6be12653dcefb..0e35bd8af0ec7 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 6be12653dcefb46ee7b605f063ee75b5e6cba513 +Subproject commit 0e35bd8af0ec72d3225c4819b330b94628f0e9d0 diff --git a/src/tools/clippy b/src/tools/clippy index 8c0e038f6f25e..016d92d6ed5ae 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit 8c0e038f6f25e0d8db8e24bcd37b4b11ca9665c6 +Subproject commit 016d92d6ed5ae8a3785b65aa300768abbc26f818 diff --git a/src/tools/miri b/src/tools/miri index 7d7cf4d42e414..72b4ee0381dec 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 7d7cf4d42e41437f5a5b04a6b8dd567f330ae6ee +Subproject commit 72b4ee0381decf609204e5548c1f5e79bdfb18b7 diff --git a/src/tools/rls b/src/tools/rls index 20e32686df573..6840dd69af3ad 160000 --- a/src/tools/rls +++ b/src/tools/rls @@ -1 +1 @@ -Subproject commit 20e32686df573fc44ac1052bf3e6982b0da27cfc +Subproject commit 6840dd69af3ada1f8a432075f1f0be679ea8a468 diff --git a/src/tools/rustfmt b/src/tools/rustfmt index b860feaffccb8..d6829d62dca64 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit b860feaffccb81199c045e9b1511c2e25825dc0c +Subproject commit d6829d62dca64dfe7ceaa96d1a9c1cd36428221d