From 8bcb021991879b676769eb593c043abe4837369b Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 20 Nov 2016 05:06:53 +0100 Subject: [PATCH] Use LLVMRustConstInt128Get on stage1 too llvm::LLVMConstIntGetZExtValue doesn't accept values with more than 64 bits. This fixes an LLVM assertion error when compiling libcore with stage1: src/llvm/include/llvm/ADT/APInt.h:1336: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed. --- src/librustc_trans/common.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index f4c7d2973bf6..79aa56637658 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -592,23 +592,18 @@ fn is_const_integral(v: ValueRef) -> bool { } } - +#[inline] #[cfg(stage0)] -pub fn const_to_opt_u128(v: ValueRef, sign_ext: bool) -> Option { - unsafe { - if is_const_integral(v) { - if !sign_ext { - Some(llvm::LLVMConstIntGetZExtValue(v)) - } else { - Some(llvm::LLVMConstIntGetSExtValue(v) as u64) - } - } else { - None - } - } +fn hi_lo_to_u128(lo: u64, _: u64) -> u128 { + lo as u128 } +#[inline] #[cfg(not(stage0))] +fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 { + ((hi as u128) << 64) | (lo as u128) +} + pub fn const_to_opt_u128(v: ValueRef, sign_ext: bool) -> Option { unsafe { if is_const_integral(v) { @@ -616,7 +611,7 @@ pub fn const_to_opt_u128(v: ValueRef, sign_ext: bool) -> Option { let success = llvm::LLVMRustConstInt128Get(v, sign_ext, &mut hi as *mut u64, &mut lo as *mut u64); if success { - Some(((hi as u128) << 64) | (lo as u128)) + Some(hi_lo_to_u128(lo, hi)) } else { None }