Skip to content

Commit 5e706b9

Browse files
zachs18RalfJung
andauthored
Update compiler/rustc_const_eval/src/const_eval/machine.rs
Co-authored-by: Ralf Jung <[email protected]>
1 parent c4c848c commit 5e706b9

File tree

1 file changed

+2
-0
lines changed
  • compiler/rustc_const_eval/src/const_eval

1 file changed

+2
-0
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
284284
// `ptr-int` with null, so we can reduce this case to a `scalar_may_be_null` test.
285285
(Scalar::Int(int), Scalar::Ptr(ptr, _)) | (Scalar::Ptr(ptr, _), Scalar::Int(int)) => {
286286
let int = int.to_target_usize(*self.tcx);
287+
// The `wrapping_neg` here may produce a value that is not
288+
// a valid target usize any more... but `wrapping_offset` handles that correctly.
287289
let offset_ptr = ptr.wrapping_offset(Size::from_bytes(int.wrapping_neg()), self);
288290
if !self.scalar_may_be_null(Scalar::from_pointer(offset_ptr, self))? {
289291
// `ptr.wrapping_sub(int)` is definitely not equal to `0`, so `ptr != int`

0 commit comments

Comments
 (0)