Skip to content

Commit

Permalink
testsuite: Fix missing handling of big endian.
Browse files Browse the repository at this point in the history
Some failures occur in the testsuite because we
did not account for the big-endian case.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1446.rs: Add swap_bytes function.
	* rust/compile/iterators1.rs: Remove unused {to, from}_le functions.
  • Loading branch information
CohenArthur committed Jan 18, 2024
1 parent 0cd26bd commit ffc7884
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
10 changes: 9 additions & 1 deletion gcc/testsuite/rust/compile/issue-1446.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// fake function
pub fn swap_bytes(this: u32) -> u32 {
(((this) & 0xff000000) >> 24)
| (((this) & 0x00ff0000) >> 8)
| (((this) & 0x0000ff00) << 8)
| (((this) & 0x000000ff) << 24)
}

pub fn to_le(this: u32) -> u32 {
#[cfg(target_endian = "little")]
{
this
}
#[cfg(not(target_endian = "little"))]
{
this.swap_bytes()
swap_bytes(this)
}
}
18 changes: 0 additions & 18 deletions gcc/testsuite/rust/compile/iterators1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,6 @@ macro_rules! impl_uint {
}
}

pub fn to_le(self) -> Self {
#[cfg(target_endian = "little")]
{
self
}
}

pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}

pub const fn from_le(x: Self) -> Self {
#[cfg(target_endian = "little")]
{
x
}
}

pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
Expand Down

0 comments on commit ffc7884

Please sign in to comment.