Skip to content

Commit

Permalink
rust185: fix cross-build of mipsel-unknown-netbsd target.
Browse files Browse the repository at this point in the history
Following on from rust-lang/rust#137630
apply patch gracefully supplied in
beetrees/rust@21f8bda
.patch
by @beetrees.

Fixes cross-build for the mipsel-unknown-netbsd target on NetBSD
which does not (yet?) support the f16 data type, at least not with
the LLVM embedded in 1.85.0 (which is LLVM version 19.1.7).
  • Loading branch information
he32 committed Feb 27, 2025
1 parent 442b0fd commit e0d6a41
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rust185/distinfo
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ SHA1 (patch-src_llvm-project_llvm_include_llvm_Analysis_ConstantFolding.h) = 39d
SHA1 (patch-src_llvm-project_llvm_utils_FileCheck_FileCheck.cpp) = 2587c2f4d11ad8f75bf8a16de625135b26bacc15
SHA1 (patch-src_tools_cargo_src_cargo_core_profiles.rs) = e1af7fde97416e0a269ee34efd37f4f47fcf7a95
SHA1 (patch-src_tools_cargo_tests_testsuite_build.rs) = 333ec513b9b94750b2424a7c1b21c809e6ea25b8
SHA1 (patch-src_tools_clippy_clippy__utils_src_consts.rs) = bfebd1fa83be18626751d1059eaf32c275f43d28
SHA1 (patch-src_tools_clippy_clippy__utils_src_lib.rs) = 68df85b3758a03860ec38b8d0b2cca30d4b02286
SHA1 (patch-src_tools_rust-installer_install-template.sh) = 6984546c34a2e4d55a6dbe59baa0d4958184e0b7
SHA1 (patch-tests_assembly_targets_targets-elf.rs) = ee7d036c055ed2a2b3b303f381ad4694327c739b
SHA1 (patch-tools_rust-analyzer_lib_line-index-src_lib.rs) = 4ed527174447ee23fa81dd6840e18b9949d5a273
Expand Down
91 changes: 91 additions & 0 deletions rust185/patches/patch-src_tools_clippy_clippy__utils_src_consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
$NetBSD$

Following on from https://github.com/rust-lang/rust/issues/137630
apply patch gracefully supplied in
https://github.com/beetrees/rust/commit/21f8bda79b2904c827b9d8d769a1307acfd855a1.patch

Fixes cross-build for 32-bit mips on NetBSD which
does not (yet?) support the f16 data type.

--- src/tools/clippy/clippy_utils/src/consts.rs.orig 2025-02-17 18:17:27.000000000 +0000
+++ src/tools/clippy/clippy_utils/src/consts.rs
@@ -41,14 +41,16 @@ pub enum Constant<'tcx> {
Char(char),
/// An integer's bit representation.
Int(u128),
- /// An `f16`.
- F16(f16),
+ /// An `f16` bitcast to a `u16`.
+ // FIXME(f16_f128): use `f16` once builtins are available on all host tools platforms.
+ F16(u16),
/// An `f32`.
F32(f32),
/// An `f64`.
F64(f64),
- /// An `f128`.
- F128(f128),
+ /// An `f128` bitcast to a `u128`.
+ // FIXME(f16_f128): use `f128` once builtins are available on all host tools platforms.
+ F128(u128),
/// `true` or `false`.
Bool(bool),
/// An array of constants.
@@ -175,7 +177,7 @@ impl Hash for Constant<'_> {
},
Self::F16(f) => {
// FIXME(f16_f128): once conversions to/from `f128` are available on all platforms,
- f.to_bits().hash(state);
+ f.hash(state);
},
Self::F32(f) => {
f64::from(f).to_bits().hash(state);
@@ -184,7 +186,7 @@ impl Hash for Constant<'_> {
f.to_bits().hash(state);
},
Self::F128(f) => {
- f.to_bits().hash(state);
+ f.hash(state);
},
Self::Bool(b) => {
b.hash(state);
@@ -290,12 +292,12 @@ impl Constant<'_> {

fn parse_f16(s: &str) -> Self {
let f: Half = s.parse().unwrap();
- Self::F16(f16::from_bits(f.to_bits().try_into().unwrap()))
+ Self::F16(f.to_bits().try_into().unwrap())
}

fn parse_f128(s: &str) -> Self {
let f: Quad = s.parse().unwrap();
- Self::F128(f128::from_bits(f.to_bits()))
+ Self::F128(f.to_bits())
}
}

@@ -851,10 +853,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'t
ty::Adt(adt_def, _) if adt_def.is_struct() => Some(Constant::Adt(result)),
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.to_bits(int.size()))),
- ty::Float(FloatTy::F16) => Some(Constant::F16(f16::from_bits(int.into()))),
+ ty::Float(FloatTy::F16) => Some(Constant::F16(int.into())),
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(int.into()))),
ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(int.into()))),
- ty::Float(FloatTy::F128) => Some(Constant::F128(f128::from_bits(int.into()))),
+ ty::Float(FloatTy::F128) => Some(Constant::F128(int.into())),
ty::RawPtr(_, _) => Some(Constant::RawPtr(int.to_bits(int.size()))),
_ => None,
},
@@ -875,10 +877,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'t
let range = alloc_range(offset + size * idx, size);
let val = alloc.read_scalar(&tcx, range, /* read_provenance */ false).ok()?;
res.push(match flt {
- FloatTy::F16 => Constant::F16(f16::from_bits(val.to_u16().discard_err()?)),
+ FloatTy::F16 => Constant::F16(val.to_u16().discard_err()?),
FloatTy::F32 => Constant::F32(f32::from_bits(val.to_u32().discard_err()?)),
FloatTy::F64 => Constant::F64(f64::from_bits(val.to_u64().discard_err()?)),
- FloatTy::F128 => Constant::F128(f128::from_bits(val.to_u128().discard_err()?)),
+ FloatTy::F128 => Constant::F128(val.to_u128().discard_err()?),
});
}
Some(Constant::Vec(res))
20 changes: 20 additions & 0 deletions rust185/patches/patch-src_tools_clippy_clippy__utils_src_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$NetBSD$

Following on from https://github.com/rust-lang/rust/issues/137630
apply patch gracefully supplied in
https://github.com/beetrees/rust/commit/21f8bda79b2904c827b9d8d769a1307acfd855a1
.patch

Fixes cross-build for 32-bit mips on NetBSD which
does not (yet?) support the f16 data type.

--- src/tools/clippy/clippy_utils/src/lib.rs.orig 2025-02-17 18:17:27.000000000 +0000
+++ src/tools/clippy/clippy_utils/src/lib.rs
@@ -1,7 +1,5 @@
#![feature(array_chunks)]
#![feature(box_patterns)]
-#![feature(f128)]
-#![feature(f16)]
#![feature(if_let_guard)]
#![feature(macro_metavar_expr_concat)]
#![feature(let_chains)]

0 comments on commit e0d6a41

Please sign in to comment.