Skip to content

Commit

Permalink
Make float -> int casts actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed May 19, 2015
1 parent 32fe2e3 commit 27d2bd1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/librustc_trans/trans/consts.rs
Expand Up @@ -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(_)) => {
Expand Down
1 change: 0 additions & 1 deletion src/test/run-pass/cast-rfc0401.rs
Expand Up @@ -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);
Expand Down

0 comments on commit 27d2bd1

Please sign in to comment.