Skip to content

Commit 195147c

Browse files
authored
Rollup merge of #70437 - RalfJung:miri-saturate, r=hanna-kruppe
Miri float->int casts: be explicit that this is saturating r? @hanna-kruppe Cc rust-lang/miri#1264
2 parents e5c5e02 + 27777e2 commit 195147c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/librustc_mir/interpret/cast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
229229
// float -> uint
230230
Uint(t) => {
231231
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits());
232+
// `to_u128` is a saturating cast, which is what we need
233+
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
232234
let v = f.to_u128(usize::try_from(width).unwrap()).value;
233235
// This should already fit the bit width
234236
Ok(Scalar::from_uint(v, Size::from_bits(width)))
235237
}
236238
// float -> int
237239
Int(t) => {
238240
let width = t.bit_width().unwrap_or_else(|| self.pointer_size().bits());
241+
// `to_i128` is a saturating cast, which is what we need
242+
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
239243
let v = f.to_i128(usize::try_from(width).unwrap()).value;
240244
Ok(Scalar::from_int(v, Size::from_bits(width)))
241245
}

0 commit comments

Comments
 (0)