1
Fork 0

offset_from: "the difference must fit in an isize" is a corollary

also, isize::MIN is an impossible distance
This commit is contained in:
Ralf Jung 2024-07-03 16:04:37 +02:00
parent 7d97c59438
commit 273d253ce6
6 changed files with 40 additions and 77 deletions

View file

@ -301,9 +301,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
}
// The signed form of the intrinsic allows this. If we interpret the
// difference as isize, we'll get the proper signed difference. If that
// seems *positive*, they were more than isize::MAX apart.
// seems *positive* or equal to isize::MIN, they were more than isize::MAX apart.
let dist = val.to_target_isize(self)?;
if dist >= 0 {
if dist >= 0 || i128::from(dist) == self.pointer_size().signed_int_min() {
throw_ub_custom!(
fluent::const_eval_offset_from_underflow,
name = intrinsic_name,