Skip to content

Commit e2f5f1b

Browse files
committed
Make float -> int casts actually work
1 parent 24ec21b commit e2f5f1b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/librustc_trans/trans/consts.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,11 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
660660
(CastTy::Float, CastTy::Float) => {
661661
llvm::LLVMConstFPCast(v, llty.to_ref())
662662
}
663+
(CastTy::Float, CastTy::Int(IntTy::I)) => {
664+
llvm::LLVMConstFPToSI(v, llty.to_ref())
665+
}
663666
(CastTy::Float, CastTy::Int(_)) => {
664-
if ty::type_is_signed(t_expr) { llvm::LLVMConstFPToSI(v, llty.to_ref()) }
665-
else { llvm::LLVMConstFPToUI(v, llty.to_ref()) }
667+
llvm::LLVMConstFPToUI(v, llty.to_ref())
666668
}
667669
(CastTy::Ptr(_), CastTy::Ptr(_)) | (CastTy::FnPtr, CastTy::Ptr(_))
668670
| (CastTy::RPtr(_), CastTy::Ptr(_)) => {

src/test/run-pass/cast-rfc0401.rs

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ fn main()
7575
assert_eq!(9.223372036854775e18f64 as i64, 0x7ffffffffffffc00i64);
7676
assert_eq!(-9.223372036854776e18f64 as i64, 0x8000000000000000u64 as i64);
7777

78-
7978
// addr-ptr-cast/ptr-addr-cast (thin ptr)
8079
let p: *const [u8; 1] = lsz as *const [u8; 1];
8180
assert_eq!(p as usize, lsz);

0 commit comments

Comments
 (0)