From d1052349affb49f87d6684f4b7781dbcba8db5a2 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Fri, 3 Feb 2023 16:50:49 -0700 Subject: [PATCH 1/7] reword descriptions of the deprecated int modules --- library/core/src/num/shells/i128.rs | 4 +--- library/core/src/num/shells/i16.rs | 4 +--- library/core/src/num/shells/i32.rs | 4 +--- library/core/src/num/shells/i64.rs | 4 +--- library/core/src/num/shells/i8.rs | 4 +--- library/core/src/num/shells/isize.rs | 4 +--- library/core/src/num/shells/u128.rs | 4 +--- library/core/src/num/shells/u16.rs | 4 +--- library/core/src/num/shells/u32.rs | 4 +--- library/core/src/num/shells/u64.rs | 4 +--- library/core/src/num/shells/u8.rs | 4 +--- library/core/src/num/shells/usize.rs | 4 +--- 12 files changed, 12 insertions(+), 36 deletions(-) diff --git a/library/core/src/num/shells/i128.rs b/library/core/src/num/shells/i128.rs index 7b048dc5206bc..b3b3d3b4875ab 100644 --- a/library/core/src/num/shells/i128.rs +++ b/library/core/src/num/shells/i128.rs @@ -1,6 +1,4 @@ -//! Constants for the 128-bit signed integer type. -//! -//! *[See also the `i128` primitive type][i128].* +//! Redundant constants module for the [`i128` primitive type][i128]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/i16.rs b/library/core/src/num/shells/i16.rs index 5c5812d5c5ecd..70a452e193983 100644 --- a/library/core/src/num/shells/i16.rs +++ b/library/core/src/num/shells/i16.rs @@ -1,6 +1,4 @@ -//! Constants for the 16-bit signed integer type. -//! -//! *[See also the `i16` primitive type][i16].* +//! Redundant constants module for the [`i16` primitive type][i16]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/i32.rs b/library/core/src/num/shells/i32.rs index b283ac64415f6..c30849e2591c3 100644 --- a/library/core/src/num/shells/i32.rs +++ b/library/core/src/num/shells/i32.rs @@ -1,6 +1,4 @@ -//! Constants for the 32-bit signed integer type. -//! -//! *[See also the `i32` primitive type][i32].* +//! Redundant constants module for the [`i32` primitive type][i32]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/i64.rs b/library/core/src/num/shells/i64.rs index a416fa7e9361d..77d95d712506b 100644 --- a/library/core/src/num/shells/i64.rs +++ b/library/core/src/num/shells/i64.rs @@ -1,6 +1,4 @@ -//! Constants for the 64-bit signed integer type. -//! -//! *[See also the `i64` primitive type][i64].* +//! Redundant constants module for the [`i64` primitive type][i64]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/i8.rs b/library/core/src/num/shells/i8.rs index 02465013a4a77..516ba8cdef3bf 100644 --- a/library/core/src/num/shells/i8.rs +++ b/library/core/src/num/shells/i8.rs @@ -1,6 +1,4 @@ -//! Constants for the 8-bit signed integer type. -//! -//! *[See also the `i8` primitive type][i8].* +//! Redundant constants module for the [`i8` primitive type][i8]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/isize.rs b/library/core/src/num/shells/isize.rs index 1579fbab6d47f..828f7345bafbe 100644 --- a/library/core/src/num/shells/isize.rs +++ b/library/core/src/num/shells/isize.rs @@ -1,6 +1,4 @@ -//! Constants for the pointer-sized signed integer type. -//! -//! *[See also the `isize` primitive type][isize].* +//! Redundant constants module for the [`isize` primitive type][isize]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/u128.rs b/library/core/src/num/shells/u128.rs index fe08cee586c3d..b1e30e3843525 100644 --- a/library/core/src/num/shells/u128.rs +++ b/library/core/src/num/shells/u128.rs @@ -1,6 +1,4 @@ -//! Constants for the 128-bit unsigned integer type. -//! -//! *[See also the `u128` primitive type][u128].* +//! Redundant constants module for the [`u128` primitive type][u128]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/u16.rs b/library/core/src/num/shells/u16.rs index 36f8c6978789d..b203806f46005 100644 --- a/library/core/src/num/shells/u16.rs +++ b/library/core/src/num/shells/u16.rs @@ -1,6 +1,4 @@ -//! Constants for the 16-bit unsigned integer type. -//! -//! *[See also the `u16` primitive type][u16].* +//! Redundant constants module for the [`i16` primitive type][i16]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/u32.rs b/library/core/src/num/shells/u32.rs index 1c369097dcdb0..4c84274e752ec 100644 --- a/library/core/src/num/shells/u32.rs +++ b/library/core/src/num/shells/u32.rs @@ -1,6 +1,4 @@ -//! Constants for the 32-bit unsigned integer type. -//! -//! *[See also the `u32` primitive type][u32].* +//! Redundant constants module for the [`u32` primitive type][u32]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/u64.rs b/library/core/src/num/shells/u64.rs index e8b691d155572..47a95c6820f2f 100644 --- a/library/core/src/num/shells/u64.rs +++ b/library/core/src/num/shells/u64.rs @@ -1,6 +1,4 @@ -//! Constants for the 64-bit unsigned integer type. -//! -//! *[See also the `u64` primitive type][u64].* +//! Redundant constants module for the [`u64` primitive type][u64]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/u8.rs b/library/core/src/num/shells/u8.rs index 817c6a18aaaa3..360baef722869 100644 --- a/library/core/src/num/shells/u8.rs +++ b/library/core/src/num/shells/u8.rs @@ -1,6 +1,4 @@ -//! Constants for the 8-bit unsigned integer type. -//! -//! *[See also the `u8` primitive type][u8].* +//! Redundant constants module for the [`u8` primitive type][u8]. //! //! New code should use the associated constants directly on the primitive type. diff --git a/library/core/src/num/shells/usize.rs b/library/core/src/num/shells/usize.rs index 3e1bec5ec4815..44c24dfc2cf58 100644 --- a/library/core/src/num/shells/usize.rs +++ b/library/core/src/num/shells/usize.rs @@ -1,6 +1,4 @@ -//! Constants for the pointer-sized unsigned integer type. -//! -//! *[See also the `usize` primitive type][usize].* +//! Redundant constants module for the [`usize` primitive type][usize]. //! //! New code should use the associated constants directly on the primitive type. From 404e9c5e3ad75057b6bbb3bcd44fe60480e50294 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 10 Feb 2023 12:50:17 -0800 Subject: [PATCH 2/7] Have a function for the `log(0)` panic, rather than copy-pasting the string constant --- library/core/src/num/int_log10.rs | 8 ++++++++ library/core/src/num/int_macros.rs | 21 +++++++++++++++------ library/core/src/num/uint_macros.rs | 21 +++++++++++++++------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/library/core/src/num/int_log10.rs b/library/core/src/num/int_log10.rs index 80472528f6c3a..0ce31b40a3845 100644 --- a/library/core/src/num/int_log10.rs +++ b/library/core/src/num/int_log10.rs @@ -138,3 +138,11 @@ pub const fn i64(val: i64) -> u32 { pub const fn i128(val: i128) -> u32 { u128(val as u128) } + +/// Instantiate this panic logic once, rather than for all the ilog methods +/// on every single primitive type. +#[cold] +#[track_caller] +pub const fn panic_for_nonpositive_argument() -> ! { + panic!("argument of integer logarithm must be positive") +} diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index b59f28193e2bd..479f8ffb78d01 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -2331,14 +2331,17 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog(self, base: Self) -> u32 { assert!(base >= 2, "base of integer logarithm must be at least 2"); - self.checked_ilog(base).expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog(base) { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the base 2 logarithm of the number, rounded down. @@ -2354,13 +2357,16 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog2(self) -> u32 { - self.checked_ilog2().expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog2() { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the base 10 logarithm of the number, rounded down. @@ -2376,13 +2382,16 @@ macro_rules! int_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog10(self) -> u32 { - self.checked_ilog10().expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog10() { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the logarithm of the number with respect to an arbitrary base, diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 1c97c46862833..411ea68674db3 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -705,14 +705,17 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog(self, base: Self) -> u32 { assert!(base >= 2, "base of integer logarithm must be at least 2"); - self.checked_ilog(base).expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog(base) { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the base 2 logarithm of the number, rounded down. @@ -728,13 +731,16 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog2(self) -> u32 { - self.checked_ilog2().expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog2() { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the base 10 logarithm of the number, rounded down. @@ -750,13 +756,16 @@ macro_rules! uint_impl { /// ``` #[stable(feature = "int_log", since = "1.67.0")] #[rustc_const_stable(feature = "int_log", since = "1.67.0")] - #[rustc_allow_const_fn_unstable(const_option)] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] #[track_caller] pub const fn ilog10(self) -> u32 { - self.checked_ilog10().expect("argument of integer logarithm must be positive") + if let Some(log) = self.checked_ilog10() { + log + } else { + int_log10::panic_for_nonpositive_argument() + } } /// Returns the logarithm of the number with respect to an arbitrary base, From cbd1b81bd2a308b0f8a1734daf3eb30b56c7537c Mon Sep 17 00:00:00 2001 From: kadmin Date: Sat, 11 Feb 2023 03:04:36 +0000 Subject: [PATCH 3/7] Add array::map benchmarks --- library/core/benches/array.rs | 19 +++++++++++++++++++ library/core/benches/lib.rs | 1 + 2 files changed, 20 insertions(+) create mode 100644 library/core/benches/array.rs diff --git a/library/core/benches/array.rs b/library/core/benches/array.rs new file mode 100644 index 0000000000000..845c60762949b --- /dev/null +++ b/library/core/benches/array.rs @@ -0,0 +1,19 @@ +use test::black_box; +use test::Bencher; + +macro_rules! map_array { + ($func_name:ident, $start_item: expr, $map_item: expr, $arr_size: expr) => { + #[bench] + fn $func_name(b: &mut Bencher) { + let arr = [$start_item; $arr_size]; + b.iter(|| black_box(arr).map(|_| black_box($map_item))); + } + }; +} + +map_array!(map_8byte_8byte_8, 0u64, 1u64, 800); +map_array!(map_8byte_8byte_64, 0u64, 1u64, 6400); +map_array!(map_8byte_8byte_256, 0u64, 1u64, 25600); + +map_array!(map_8byte_256byte_256, 0u64, [0u64; 4], 25600); +map_array!(map_256byte_8byte_256, [0u64; 4], 0u64, 25600); diff --git a/library/core/benches/lib.rs b/library/core/benches/lib.rs index f1244d93285e3..e4100120d8252 100644 --- a/library/core/benches/lib.rs +++ b/library/core/benches/lib.rs @@ -9,6 +9,7 @@ extern crate test; mod any; +mod array; mod ascii; mod char; mod fmt; From 79d2430e9961c9b38aa8366f028fbcbcf98e74a5 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 12 Feb 2023 10:37:25 -0800 Subject: [PATCH 4/7] Add a doc note about why `Chain` is not `ExactSizeIterator` --- library/core/src/iter/traits/exact_size.rs | 10 ++++++++++ library/core/src/iter/traits/marker.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/library/core/src/iter/traits/exact_size.rs b/library/core/src/iter/traits/exact_size.rs index 1757e37ec0e2f..908830d8a9514 100644 --- a/library/core/src/iter/traits/exact_size.rs +++ b/library/core/src/iter/traits/exact_size.rs @@ -21,6 +21,16 @@ /// /// [`len`]: ExactSizeIterator::len /// +/// # When *shouldn't* an adapter be `ExactSizeIterator`? +/// +/// If an adapter makes an iterator *longer*, then it's usually incorrect for +/// that adapter to implement `ExactSizeIterator`. The inner exact-sized +/// iterator might already be `usize::MAX`-long, and thus the length of the +/// longer adapted iterator would no longer be exactly representable in `usize`. +/// +/// This is why [`Chain`](crate::iter::Chain) isn't `ExactSizeIterator`, +/// even when `A` and `B` are both `ExactSizeIterator`. +/// /// # Examples /// /// Basic usage: diff --git a/library/core/src/iter/traits/marker.rs b/library/core/src/iter/traits/marker.rs index da753745740d7..af02848233d99 100644 --- a/library/core/src/iter/traits/marker.rs +++ b/library/core/src/iter/traits/marker.rs @@ -31,6 +31,17 @@ impl FusedIterator for &mut I {} /// The iterator must produce exactly the number of elements it reported /// or diverge before reaching the end. /// +/// # When *shouldn't* an adapter be `TrustedLen`? +/// +/// If an adapter makes an iterator *shorter* by a given amount, then it's +/// usually incorrect for that adapter to implement `TrustedLen`. The inner +/// iterator might return more than `usize::MAX` items, but there's no way to +/// know what `k` elements less than that will be, since the `size_hint` from +/// the inner iterator has already saturated and lost that information. +/// +/// This is why [`Skip`](crate::iter::Skip) isn't `TrustedLen`, even when +/// `I` implements `TrustedLen`. +/// /// # Safety /// /// This trait must only be implemented when the contract is upheld. Consumers From 5fe104666825c53552cfec88a9da81a1ccb44d4b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 12 Feb 2023 22:02:39 +0100 Subject: [PATCH 5/7] Update browser-ui-test version to 0.14.3 --- .../docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version index c39e9c5fbc9d6..94ec240129270 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version +++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version @@ -1 +1 @@ -0.14.1 \ No newline at end of file +0.14.3 \ No newline at end of file From 913a566c22c78d630a74a1c43c8a40d20f0e58a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 12 Feb 2023 23:37:58 +0100 Subject: [PATCH 6/7] Hermit: Remove floor symbol This symbol should be provided by Hermit. --- library/std/src/sys/hermit/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/library/std/src/sys/hermit/mod.rs b/library/std/src/sys/hermit/mod.rs index 6811fadb0188c..20fd3dd8f090d 100644 --- a/library/std/src/sys/hermit/mod.rs +++ b/library/std/src/sys/hermit/mod.rs @@ -72,11 +72,6 @@ pub fn unsupported_err() -> crate::io::Error { ) } -#[no_mangle] -pub extern "C" fn floor(x: f64) -> f64 { - unsafe { intrinsics::floorf64(x) } -} - pub fn abort_internal() -> ! { unsafe { abi::abort(); From 9c4696b940e2926ddc71dc138a2d57af10f02c94 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sun, 12 Feb 2023 14:37:09 -0500 Subject: [PATCH 7/7] Fix unintentional UB in SIMD tests --- tests/ui/simd/intrinsic/generic-cast-pass.rs | 146 +++++------------- .../ui/simd/intrinsic/generic-gather-pass.rs | 24 +-- tests/ui/simd/issue-89193.rs | 11 +- 3 files changed, 60 insertions(+), 121 deletions(-) diff --git a/tests/ui/simd/intrinsic/generic-cast-pass.rs b/tests/ui/simd/intrinsic/generic-cast-pass.rs index 15f232e2c0f70..89436c83e25ea 100644 --- a/tests/ui/simd/intrinsic/generic-cast-pass.rs +++ b/tests/ui/simd/intrinsic/generic-cast-pass.rs @@ -1,121 +1,59 @@ // run-pass -#![allow(unused_must_use)] // ignore-emscripten FIXME(#45351) hits an LLVM assert -#![feature(repr_simd, platform_intrinsics, concat_idents, test)] -#![allow(non_camel_case_types)] - -extern crate test; - -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct i32x4(i32, i32, i32, i32); -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct i8x4(i8, i8, i8, i8); - -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct u32x4(u32, u32, u32, u32); -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct u8x4(u8, u8, u8, u8); - -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct f32x4(f32, f32, f32, f32); - -#[repr(simd)] -#[derive(PartialEq, Debug)] -struct f64x4(f64, f64, f64, f64); - +#![feature(repr_simd, platform_intrinsics)] extern "platform-intrinsic" { fn simd_cast(x: T) -> U; } -const A: i32 = -1234567; -const B: i32 = 12345678; -const C: i32 = -123456789; -const D: i32 = 1234567890; +use std::cmp::{max, min}; -trait Foo { - fn is_float() -> bool { false } - fn in_range(x: i32) -> bool; -} -impl Foo for i32 { - fn in_range(_: i32) -> bool { true } -} -impl Foo for i8 { - fn in_range(x: i32) -> bool { -128 <= x && x < 128 } -} -impl Foo for u32 { - fn in_range(x: i32) -> bool { 0 <= x } -} -impl Foo for u8 { - fn in_range(x: i32) -> bool { 0 <= x && x < 128 } -} -impl Foo for f32 { - fn is_float() -> bool { true } - fn in_range(_: i32) -> bool { true } -} -impl Foo for f64 { - fn is_float() -> bool { true } - fn in_range(_: i32) -> bool { true } -} +#[derive(Copy, Clone)] +#[repr(simd)] +struct V([T; 2]); fn main() { - macro_rules! test { - ($from: ident, $to: ident) => {{ - // force the casts to actually happen, or else LLVM/rustc - // may fold them and get slightly different results. - let (a, b, c, d) = test::black_box((A as $from, B as $from, C as $from, D as $from)); - // the SIMD vectors are all FOOx4, so we can concat_idents - // so we don't have to pass in the extra args to the macro - let mut from = simd_cast(concat_idents!($from, x4)(a, b, c, d)); - let mut to = concat_idents!($to, x4)(a as $to, - b as $to, - c as $to, - d as $to); - // assist type inference, it needs to know what `from` is - // for the `if` statements. - to == from; + unsafe { + let u = V::([i16::MIN as u32, i16::MAX as u32]); + let i: V = simd_cast(u); + assert_eq!(i.0[0], u.0[0] as i16); + assert_eq!(i.0[1], u.0[1] as i16); + } - // there are platform differences for some out of range - // casts, so we just normalize such things: it's OK for - // "invalid" calculations to result in nonsense answers. - // (e.g., negative float to unsigned integer goes through a - // library routine on the default i686 platforms, and the - // implementation of that routine differs on e.g., Linux - // vs. macOS, resulting in different answers.) - if $from::is_float() { - if !$to::in_range(A) { from.0 = 0 as $to; to.0 = 0 as $to; } - if !$to::in_range(B) { from.1 = 0 as $to; to.1 = 0 as $to; } - if !$to::in_range(C) { from.2 = 0 as $to; to.2 = 0 as $to; } - if !$to::in_range(D) { from.3 = 0 as $to; to.3 = 0 as $to; } - } + unsafe { + let f = V::([i16::MIN as f32, i16::MAX as f32]); + let i: V = simd_cast(f); + assert_eq!(i.0[0], f.0[0] as i16); + assert_eq!(i.0[1], f.0[1] as i16); + } - assert!(to == from, - "{} -> {} ({:?} != {:?})", stringify!($from), stringify!($to), - from, to); - }} + unsafe { + let f = V::([u8::MIN as f32, u8::MAX as f32]); + let u: V = simd_cast(f); + assert_eq!(u.0[0], f.0[0] as u8); + assert_eq!(u.0[1], f.0[1] as u8); } - macro_rules! tests { - (: $($to: ident),*) => { () }; - // repeating the list twice is easier than writing a cartesian - // product macro - ($from: ident $(, $from_: ident)*: $($to: ident),*) => { - fn $from() { unsafe { $( test!($from, $to); )* } } - tests!($($from_),*: $($to),*) - }; - ($($types: ident),*) => {{ - tests!($($types),* : $($types),*); - $($types();)* - }} + + unsafe { + // We would like to do isize::MIN..=isize::MAX, but those values are not representable in + // an f64, so we clamp to the range of an i32 to prevent running into UB. + let f = V::([ + max(isize::MIN, i32::MIN as isize) as f64, + min(isize::MAX, i32::MAX as isize) as f64, + ]); + let i: V = simd_cast(f); + assert_eq!(i.0[0], f.0[0] as isize); + assert_eq!(i.0[1], f.0[1] as isize); } - // test various combinations, including truncation, - // signed/unsigned extension, and floating point casts. - tests!(i32, i8, u32, u8, f32); - tests!(i32, u32, f32, f64) + unsafe { + let f = V::([ + max(usize::MIN, u32::MIN as usize) as f64, + min(usize::MAX, u32::MAX as usize) as f64, + ]); + let u: V = simd_cast(f); + assert_eq!(u.0[0], f.0[0] as usize); + assert_eq!(u.0[1], f.0[1] as usize); + } } diff --git a/tests/ui/simd/intrinsic/generic-gather-pass.rs b/tests/ui/simd/intrinsic/generic-gather-pass.rs index 805caebe5b1f8..7d4b3dbd7b411 100644 --- a/tests/ui/simd/intrinsic/generic-gather-pass.rs +++ b/tests/ui/simd/intrinsic/generic-gather-pass.rs @@ -24,9 +24,9 @@ fn main() { // reading from *const unsafe { - let pointer = &x[0] as *const f32; + let pointer = x.as_ptr(); let pointers = x4( - pointer.offset(0) as *const f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) @@ -39,9 +39,9 @@ fn main() { // reading from *mut unsafe { - let pointer = &mut x[0] as *mut f32; + let pointer = x.as_mut_ptr(); let pointers = x4( - pointer.offset(0) as *mut f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) @@ -54,9 +54,9 @@ fn main() { // writing to *mut unsafe { - let pointer = &mut x[0] as *mut f32; + let pointer = x.as_mut_ptr(); let pointers = x4( - pointer.offset(0) as *mut f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) @@ -85,9 +85,9 @@ fn main() { // reading from *const unsafe { - let pointer = &y[0] as *const *const f32; + let pointer = y.as_ptr(); let pointers = x4( - pointer.offset(0) as *const *const f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) @@ -100,9 +100,9 @@ fn main() { // reading from *mut unsafe { - let pointer = &mut y[0] as *mut *const f32; + let pointer = y.as_mut_ptr(); let pointers = x4( - pointer.offset(0) as *mut *const f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) @@ -115,9 +115,9 @@ fn main() { // writing to *mut unsafe { - let pointer = &mut y[0] as *mut *const f32; + let pointer = y.as_mut_ptr(); let pointers = x4( - pointer.offset(0) as *mut *const f32, + pointer.offset(0), pointer.offset(2), pointer.offset(4), pointer.offset(6) diff --git a/tests/ui/simd/issue-89193.rs b/tests/ui/simd/issue-89193.rs index 79c4e6a312c0d..cd24d6675b2f8 100644 --- a/tests/ui/simd/issue-89193.rs +++ b/tests/ui/simd/issue-89193.rs @@ -17,13 +17,14 @@ extern "platform-intrinsic" { fn main() { let x: [usize; 4] = [10, 11, 12, 13]; let default = x4(0_usize, 1, 2, 3); - let mask = x4(1_i32, 1, 1, 1); + let all_set = u8::MAX as i8; // aka -1 + let mask = x4(all_set, all_set, all_set, all_set); let expected = x4(10_usize, 11, 12, 13); unsafe { - let pointer = &x[0] as *const usize; + let pointer = x.as_ptr(); let pointers = x4( - pointer.offset(0) as *const usize, + pointer.offset(0), pointer.offset(1), pointer.offset(2), pointer.offset(3) @@ -38,9 +39,9 @@ fn main() { let expected = x4(10_isize, 11, 12, 13); unsafe { - let pointer = &x[0] as *const isize; + let pointer = x.as_ptr(); let pointers = x4( - pointer.offset(0) as *const isize, + pointer.offset(0), pointer.offset(1), pointer.offset(2), pointer.offset(3)