Rollup merge of #146915 - clarfonthey:safe-intrinsics-2, r=RalfJung

Make missed precondition-free float intrinsics safe

So, in my defence, these were both separated out from the other intrinsics in the file *and* had a different safety comment in the stable versions, so, I didn't notice them before. But, in my offence, the entire reason I did the previous PR was because I was using them for SIMD intrinsic fallbacks, and `fabs` is needed for those too, so, I don't really have an excuse.

Extra follow-up to rust-lang/rust#146683.

r? ```@RalfJung``` who reviewed the previous one

These don't appear to be used anywhere outside of the standard locations, at least.
This commit is contained in:
Matthias Krüger 2025-09-24 20:34:22 +02:00 committed by GitHub
commit 2320fc3a38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 22 additions and 20 deletions

View file

@ -90,6 +90,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
| sym::contract_check_ensures
| sym::contract_check_requires
| sym::contract_checks
| sym::copysignf16
| sym::copysignf32
| sym::copysignf64
| sym::copysignf128
| sym::cosf16
| sym::cosf32
| sym::cosf64
@ -106,6 +110,10 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
| sym::expf32
| sym::expf64
| sym::expf128
| sym::fabsf16
| sym::fabsf32
| sym::fabsf64
| sym::fabsf128
| sym::fadd_algebraic
| sym::fdiv_algebraic
| sym::floorf16

View file

@ -3170,7 +3170,7 @@ pub const fn maximumf128(x: f128, y: f128) -> f128 {
/// [`f16::abs`](../../std/primitive.f16.html#method.abs)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn fabsf16(x: f16) -> f16;
pub const fn fabsf16(x: f16) -> f16;
/// Returns the absolute value of an `f32`.
///
@ -3179,7 +3179,7 @@ pub const unsafe fn fabsf16(x: f16) -> f16;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn fabsf32(x: f32) -> f32;
pub const fn fabsf32(x: f32) -> f32;
/// Returns the absolute value of an `f64`.
///
@ -3188,7 +3188,7 @@ pub const unsafe fn fabsf32(x: f32) -> f32;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn fabsf64(x: f64) -> f64;
pub const fn fabsf64(x: f64) -> f64;
/// Returns the absolute value of an `f128`.
///
@ -3196,7 +3196,7 @@ pub const unsafe fn fabsf64(x: f64) -> f64;
/// [`f128::abs`](../../std/primitive.f128.html#method.abs)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn fabsf128(x: f128) -> f128;
pub const fn fabsf128(x: f128) -> f128;
/// Copies the sign from `y` to `x` for `f16` values.
///
@ -3204,7 +3204,7 @@ pub const unsafe fn fabsf128(x: f128) -> f128;
/// [`f16::copysign`](../../std/primitive.f16.html#method.copysign)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
pub const fn copysignf16(x: f16, y: f16) -> f16;
/// Copies the sign from `y` to `x` for `f32` values.
///
@ -3213,7 +3213,7 @@ pub const unsafe fn copysignf16(x: f16, y: f16) -> f16;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
pub const fn copysignf32(x: f32, y: f32) -> f32;
/// Copies the sign from `y` to `x` for `f64` values.
///
/// The stabilized version of this intrinsic is
@ -3221,7 +3221,7 @@ pub const unsafe fn copysignf32(x: f32, y: f32) -> f32;
#[rustc_nounwind]
#[rustc_intrinsic_const_stable_indirect]
#[rustc_intrinsic]
pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
pub const fn copysignf64(x: f64, y: f64) -> f64;
/// Copies the sign from `y` to `x` for `f128` values.
///
@ -3229,7 +3229,7 @@ pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
/// [`f128::copysign`](../../std/primitive.f128.html#method.copysign)
#[rustc_nounwind]
#[rustc_intrinsic]
pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
pub const fn copysignf128(x: f128, y: f128) -> f128;
/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
/// with `df` as the derivative function and `args` as its arguments.

View file

@ -1367,8 +1367,7 @@ impl f128 {
#[rustc_const_unstable(feature = "f128", issue = "116909")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn copysign(self, sign: f128) -> f128 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf128(self, sign) }
intrinsics::copysignf128(self, sign)
}
/// Float addition that allows optimizations based on algebraic rules.

View file

@ -1344,8 +1344,7 @@ impl f16 {
#[rustc_const_unstable(feature = "f16", issue = "116909")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn copysign(self, sign: f16) -> f16 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf16(self, sign) }
intrinsics::copysignf16(self, sign)
}
/// Float addition that allows optimizations based on algebraic rules.

View file

@ -1450,8 +1450,7 @@ impl f32 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn abs(self) -> f32 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::fabsf32(self) }
intrinsics::fabsf32(self)
}
/// Returns a number that represents the sign of `self`.
@ -1509,8 +1508,7 @@ impl f32 {
#[stable(feature = "copysign", since = "1.35.0")]
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
pub const fn copysign(self, sign: f32) -> f32 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf32(self, sign) }
intrinsics::copysignf32(self, sign)
}
/// Float addition that allows optimizations based on algebraic rules.

View file

@ -1448,8 +1448,7 @@ impl f64 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn abs(self) -> f64 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::fabsf64(self) }
intrinsics::fabsf64(self)
}
/// Returns a number that represents the sign of `self`.
@ -1507,8 +1506,7 @@ impl f64 {
#[rustc_const_stable(feature = "const_float_methods", since = "1.85.0")]
#[inline]
pub const fn copysign(self, sign: f64) -> f64 {
// SAFETY: this is actually a safe intrinsic
unsafe { intrinsics::copysignf64(self, sign) }
intrinsics::copysignf64(self, sign)
}
/// Float addition that allows optimizations based on algebraic rules.