Make float -> int casts actually work

This commit is contained in:
Ariel Ben-Yehuda 2015-05-15 11:44:26 +03:00
parent 32fe2e3ad4
commit 27d2bd13c3
2 changed files with 4 additions and 3 deletions

View File

@ -660,9 +660,11 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
(CastTy::Float, CastTy::Float) => {
llvm::LLVMConstFPCast(v, llty.to_ref())
}
(CastTy::Float, CastTy::Int(IntTy::I)) => {
llvm::LLVMConstFPToSI(v, llty.to_ref())
}
(CastTy::Float, CastTy::Int(_)) => {
if ty::type_is_signed(t_expr) { llvm::LLVMConstFPToSI(v, llty.to_ref()) }
else { llvm::LLVMConstFPToUI(v, llty.to_ref()) }
llvm::LLVMConstFPToUI(v, llty.to_ref())
}
(CastTy::Ptr(_), CastTy::Ptr(_)) | (CastTy::FnPtr, CastTy::Ptr(_))
| (CastTy::RPtr(_), CastTy::Ptr(_)) => {

View File

@ -75,7 +75,6 @@ fn main()
assert_eq!(9.223372036854775e18f64 as i64, 0x7ffffffffffffc00i64);
assert_eq!(-9.223372036854776e18f64 as i64, 0x8000000000000000u64 as i64);
// addr-ptr-cast/ptr-addr-cast (thin ptr)
let p: *const [u8; 1] = lsz as *const [u8; 1];
assert_eq!(p as usize, lsz);