Skip to content

Commit 5a8f9e5

Browse files
committed
properly compare unequal function pointers
1 parent 4e4569c commit 5a8f9e5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/operator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
145145
// Dead allocations in miri cannot overlap with live allocations, but
146146
// on read hardware this can easily happen. Thus for comparisons we require
147147
// both pointers to be live.
148-
self.memory().get(left.alloc_id)?.check_bounds_ptr(left)?;
149-
self.memory().get(right.alloc_id)?.check_bounds_ptr(right)?;
148+
self.memory().check_bounds_ptr(left, InboundsCheck::Live)?;
149+
self.memory().check_bounds_ptr(right, InboundsCheck::Live)?;
150150
// Two in-bounds pointers, we can compare across allocations
151151
left == right
152152
}

tests/run-pass/function_pointers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ fn main() {
4444
let g = f as fn() -> i32;
4545
assert!(return_fn_ptr(g) == g);
4646
assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32);
47+
assert!(return_fn_ptr(f) != f);
4748
}

0 commit comments

Comments
 (0)