Skip to content

(Shot at) Fix endian bugs in i128 intrinsic impls #39094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/libcompiler_builtins/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub mod reimpls {
self.wrapping_shr(32) as i32
}
fn from_parts(low: u32, high: i32) -> i64 {
low as i64 | (high as i64).wrapping_shl(32)
u64::from_parts(low, high as u32) as i64
}
}
#[cfg(not(stage0))]
Expand All @@ -404,11 +404,10 @@ pub mod reimpls {
self as u64
}
fn high(self) -> u64 {
unsafe { *(&self as *const u128 as *const u64).offset(1) }
self.wrapping_shr(64) as u64
}
fn from_parts(low: u64, high: u64) -> u128 {
#[repr(C, packed)] struct Parts(u64, u64);
unsafe { ::core::mem::transmute(Parts(low, high)) }
(high as u128).wrapping_shl(64) | low as u128
}
}
#[cfg(not(stage0))]
Expand All @@ -420,7 +419,7 @@ pub mod reimpls {
self as u64
}
fn high(self) -> i64 {
unsafe { *(&self as *const i128 as *const i64).offset(1) }
self.wrapping_shr(64) as i64
}
fn from_parts(low: u64, high: i64) -> i128 {
u128::from_parts(low, high as u64) as i128
Expand Down