diff options
| author | Ralf Jung <post@ralfj.de> | 2020-03-26 19:09:31 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-03-26 19:09:31 +0100 |
| commit | 27777e2e7b72a28349cfa79d4950aef7869af118 (patch) | |
| tree | d0cb3513e5163013d0d27a36ef3d17d24bf2b041 /src | |
| parent | 2fbb07525e2f07a815e780a4268b11916248b5a9 (diff) | |
| download | rust-27777e2e7b72a28349cfa79d4950aef7869af118.tar.gz rust-27777e2e7b72a28349cfa79d4950aef7869af118.zip | |
Miri float->int casts: be explicit that this is saturating
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/interpret/cast.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index f7327825ca4..24176427ba5 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -229,6 +229,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // float -> uint Uint(t) => { let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits()); + // `to_u128` is a saturating cast, which is what we need + // (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r). let v = f.to_u128(usize::try_from(width).unwrap()).value; // This should already fit the bit width Ok(Scalar::from_uint(v, Size::from_bits(width))) @@ -236,6 +238,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // float -> int Int(t) => { let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits()); + // `to_i128` is a saturating cast, which is what we need + // (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r). let v = f.to_i128(usize::try_from(width).unwrap()).value; Ok(Scalar::from_int(v, Size::from_bits(width))) } |
