Skip to content

Commit

Permalink
rustc_trans: do not pass floating-point values to LLVM through FFI.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 2, 2017
1 parent 559ea1c commit 18cdb63
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,7 @@ fn create_imps(sess: &Session,
let imp = llvm::LLVMAddGlobal(llvm_module.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);
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_trans/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 18cdb63

Please sign in to comment.