diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 24d4040ccb082..20735af69e378 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -598,7 +598,6 @@ extern "C" { // Operations on scalar constants pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) -> ValueRef; pub fn LLVMConstIntOfArbitraryPrecision(IntTy: TypeRef, Wn: c_uint, Ws: *const u64) -> ValueRef; - pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef; pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong; pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong; pub fn LLVMRustConstInt128Get(ConstantVal: ValueRef, SExt: bool, diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 7b836399f9cb5..bb864ff919498 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -832,8 +832,7 @@ fn create_imps(sess: &Session, let imp = llvm::LLVMAddGlobal(ll.llmod, i8p_ty.to_ref(), imp_name.as_ptr() as *const _); - let init = llvm::LLVMConstBitCast(val, i8p_ty.to_ref()); - llvm::LLVMSetInitializer(imp, init); + llvm::LLVMSetInitializer(imp, consts::ptrcast(val, i8p_ty)); llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage); } } diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 9b0803908b162..61766a3db2c9d 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -223,12 +223,6 @@ pub fn C_big_integral(t: Type, u: u128) -> ValueRef { } } -pub fn C_floating_f64(f: f64, t: Type) -> ValueRef { - unsafe { - llvm::LLVMConstReal(t.to_ref(), f) - } -} - pub fn C_nil(ccx: &CrateContext) -> ValueRef { C_struct(ccx, &[], false) } diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index da2a58398634e..310cd6fe9559d 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -36,6 +36,12 @@ pub fn ptrcast(val: ValueRef, ty: Type) -> ValueRef { } } +pub fn bitcast(val: ValueRef, ty: Type) -> ValueRef { + unsafe { + llvm::LLVMConstBitCast(val, ty.to_ref()) + } +} + pub fn addr_of_mut(ccx: &CrateContext, cv: ValueRef, align: machine::llalign, diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 2a16cecb4fe6d..f50d7abb8be6d 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -27,7 +27,7 @@ use abi::{self, Abi}; use callee; use builder::Builder; use common::{self, CrateContext, const_get_elt, val_ty}; -use common::{C_array, C_bool, C_bytes, C_floating_f64, C_integral, C_big_integral}; +use common::{C_array, C_bool, C_bytes, C_integral, C_big_integral}; use common::{C_null, C_struct, C_str_slice, C_undef, C_uint, C_vector, is_undef}; use common::const_to_opt_u128; use consts; @@ -96,11 +96,11 @@ impl<'tcx> Const<'tcx> { let llty = type_of::type_of(ccx, ty); let val = match cv { ConstVal::Float(v) => { - let v_f64 = match v { - ConstFloat::F32(v) => f32::from_bits(v) as f64, - ConstFloat::F64(v) => f64::from_bits(v) + let bits = match v { + ConstFloat::F32(v) => U32(v), + ConstFloat::F64(v) => U64(v) }; - C_floating_f64(v_f64, llty) + consts::bitcast(Const::from_constint(ccx, &bits).llval, llty) } ConstVal::Bool(v) => C_bool(ccx, v), ConstVal::Integral(ref i) => return Const::from_constint(ccx, i),