always check overflow in CheckedBinOp in CTFE
This commit is contained in:
parent
6f01ff61b3
commit
2f6e996662
3 changed files with 13 additions and 3 deletions
|
@ -144,6 +144,9 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether CheckedBinOp MIR statements should actually check for overflow.
|
||||||
|
fn check_binop_checks_overflow(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
||||||
|
|
||||||
/// Entry point for obtaining the MIR of anything that should get evaluated.
|
/// Entry point for obtaining the MIR of anything that should get evaluated.
|
||||||
/// So not just functions and shims, but also const/static initializers, anonymous
|
/// So not just functions and shims, but also const/static initializers, anonymous
|
||||||
/// constants, ...
|
/// constants, ...
|
||||||
|
@ -468,6 +471,11 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn check_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn call_extra_fn(
|
fn call_extra_fn(
|
||||||
_ecx: &mut InterpCx<$mir, $tcx, Self>,
|
_ecx: &mut InterpCx<$mir, $tcx, Self>,
|
||||||
|
|
|
@ -32,7 +32,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
);
|
);
|
||||||
// As per https://github.com/rust-lang/rust/pull/98738, we always return `false` in the 2nd
|
// As per https://github.com/rust-lang/rust/pull/98738, we always return `false` in the 2nd
|
||||||
// component when overflow checking is disabled.
|
// component when overflow checking is disabled.
|
||||||
let overflowed = overflowed && (force_overflow_checks || self.tcx.sess.overflow_checks());
|
let overflowed =
|
||||||
|
overflowed && (force_overflow_checks || M::check_binop_checks_overflow(self));
|
||||||
// Write the result to `dest`.
|
// Write the result to `dest`.
|
||||||
if let Abi::ScalarPair(..) = dest.layout.abi {
|
if let Abi::ScalarPair(..) = dest.layout.abi {
|
||||||
// We can use the optimized path and avoid `place_field` (which might do
|
// We can use the optimized path and avoid `place_field` (which might do
|
||||||
|
|
|
@ -993,8 +993,9 @@ pub enum Rvalue<'tcx> {
|
||||||
|
|
||||||
/// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
|
/// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
|
||||||
///
|
///
|
||||||
/// When overflow checking is disabled, the error condition is false. Otherwise, the error
|
/// When overflow checking is disabled and we are generating run-time code, the error condition
|
||||||
/// condition is determined as described below.
|
/// is false. Otherwise, and always during CTFE, the error condition is determined as described
|
||||||
|
/// below.
|
||||||
///
|
///
|
||||||
/// For addition, subtraction, and multiplication on integers the error condition is set when
|
/// For addition, subtraction, and multiplication on integers the error condition is set when
|
||||||
/// the infinite precision result would be unequal to the actual result.
|
/// the infinite precision result would be unequal to the actual result.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue