Skip to content

Commit 08d9e09

Browse files
committed
rustc_trans: do not pass floating-point values to LLVM through FFI.
1 parent 8b2db58 commit 08d9e09

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

src/librustc_llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ extern "C" {
598598
// Operations on scalar constants
599599
pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) -> ValueRef;
600600
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: TypeRef, Wn: c_uint, Ws: *const u64) -> ValueRef;
601-
pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
602601
pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
603602
pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
604603
pub fn LLVMRustConstInt128Get(ConstantVal: ValueRef, SExt: bool,

src/librustc_trans/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,7 @@ fn create_imps(sess: &Session,
832832
let imp = llvm::LLVMAddGlobal(ll.llmod,
833833
i8p_ty.to_ref(),
834834
imp_name.as_ptr() as *const _);
835-
let init = llvm::LLVMConstBitCast(val, i8p_ty.to_ref());
836-
llvm::LLVMSetInitializer(imp, init);
835+
llvm::LLVMSetInitializer(imp, consts::ptrcast(val, i8p_ty));
837836
llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage);
838837
}
839838
}

src/librustc_trans/common.rs

-6
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ pub fn C_big_integral(t: Type, u: u128) -> ValueRef {
223223
}
224224
}
225225

226-
pub fn C_floating_f64(f: f64, t: Type) -> ValueRef {
227-
unsafe {
228-
llvm::LLVMConstReal(t.to_ref(), f)
229-
}
230-
}
231-
232226
pub fn C_nil(ccx: &CrateContext) -> ValueRef {
233227
C_struct(ccx, &[], false)
234228
}

src/librustc_trans/consts.rs

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ pub fn ptrcast(val: ValueRef, ty: Type) -> ValueRef {
3636
}
3737
}
3838

39+
pub fn bitcast(val: ValueRef, ty: Type) -> ValueRef {
40+
unsafe {
41+
llvm::LLVMConstBitCast(val, ty.to_ref())
42+
}
43+
}
44+
3945
pub fn addr_of_mut(ccx: &CrateContext,
4046
cv: ValueRef,
4147
align: machine::llalign,

src/librustc_trans/mir/constant.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use abi::{self, Abi};
2727
use callee;
2828
use builder::Builder;
2929
use common::{self, CrateContext, const_get_elt, val_ty};
30-
use common::{C_array, C_bool, C_bytes, C_floating_f64, C_integral, C_big_integral};
30+
use common::{C_array, C_bool, C_bytes, C_integral, C_big_integral};
3131
use common::{C_null, C_struct, C_str_slice, C_undef, C_uint, C_vector, is_undef};
3232
use common::const_to_opt_u128;
3333
use consts;
@@ -96,11 +96,11 @@ impl<'tcx> Const<'tcx> {
9696
let llty = type_of::type_of(ccx, ty);
9797
let val = match cv {
9898
ConstVal::Float(v) => {
99-
let v_f64 = match v {
100-
ConstFloat::F32(v) => f32::from_bits(v) as f64,
101-
ConstFloat::F64(v) => f64::from_bits(v)
99+
let bits = match v {
100+
ConstFloat::F32(v) => U32(v),
101+
ConstFloat::F64(v) => U64(v)
102102
};
103-
C_floating_f64(v_f64, llty)
103+
consts::bitcast(Const::from_constint(ccx, &bits).llval, llty)
104104
}
105105
ConstVal::Bool(v) => C_bool(ccx, v),
106106
ConstVal::Integral(ref i) => return Const::from_constint(ccx, i),

0 commit comments

Comments
 (0)