Skip to content

Commit e1a855c

Browse files
Centri3NCGThompson
authored andcommitted
Clarify that both branches must have the same side effects
1 parent 64982cd commit e1a855c

File tree

2 files changed

+2
-56
lines changed

2 files changed

+2
-56
lines changed

library/core/src/intrinsics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2542,7 +2542,8 @@ extern "rust-intrinsic" {
25422542
///
25432543
/// When calling this in a `const fn`, both paths must be semantically
25442544
/// equivalent, that is, the result of the `true` branch and the `false`
2545-
/// branch return the same value *no matter what*.
2545+
/// branch must return the same value and have the same side-effects *no
2546+
/// matter what*.
25462547
#[rustc_const_unstable(feature = "is_val_statically_known", issue = "none")]
25472548
#[rustc_nounwind]
25482549
#[cfg(not(bootstrap))]

src/tools/miri/src/shims/intrinsics/mod.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -429,59 +429,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
429429

430430
Ok(())
431431
}
432-
<<<<<<< HEAD
433-
=======
434-
435-
fn float_to_int_unchecked<F>(
436-
&self,
437-
f: F,
438-
dest_ty: Ty<'tcx>,
439-
) -> InterpResult<'tcx, Scalar<Provenance>>
440-
where
441-
F: Float + Into<Scalar<Provenance>>,
442-
{
443-
let this = self.eval_context_ref();
444-
445-
// Step 1: cut off the fractional part of `f`. The result of this is
446-
// guaranteed to be precisely representable in IEEE floats.
447-
let f = f.round_to_integral(Round::TowardZero).value;
448-
449-
// Step 2: Cast the truncated float to the target integer type and see if we lose any information in this step.
450-
Ok(match dest_ty.kind() {
451-
// Unsigned
452-
ty::Uint(t) => {
453-
let size = Integer::from_uint_ty(this, *t).size();
454-
let res = f.to_u128(size.bits_usize());
455-
if res.status.is_empty() {
456-
// No status flags means there was no further rounding or other loss of precision.
457-
Scalar::from_uint(res.value, size)
458-
} else {
459-
// `f` was not representable in this integer type.
460-
throw_ub_format!(
461-
"`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`",
462-
);
463-
}
464-
}
465-
// Signed
466-
ty::Int(t) => {
467-
let size = Integer::from_int_ty(this, *t).size();
468-
let res = f.to_i128(size.bits_usize());
469-
if res.status.is_empty() {
470-
// No status flags means there was no further rounding or other loss of precision.
471-
Scalar::from_int(res.value, size)
472-
} else {
473-
// `f` was not representable in this integer type.
474-
throw_ub_format!(
475-
"`float_to_int_unchecked` intrinsic called on {f} which cannot be represented in target type `{dest_ty:?}`",
476-
);
477-
}
478-
}
479-
// Nothing else
480-
_ => span_bug!(
481-
this.cur_span(),
482-
"`float_to_int_unchecked` called with non-int output type {dest_ty:?}"
483-
),
484-
})
485-
}
486-
>>>>>>> acbf90a9489 (Make MIRI choose the path randomly and rename the intrinsic)
487432
}

0 commit comments

Comments
 (0)