Skip to content

Commit d0f57c7

Browse files
authored
Merge pull request #587 from solson/rustup
Fix comparing function pointers
2 parents 821f29b + 55107d5 commit d0f57c7

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2018-12-24
1+
nightly-2018-12-26

src/operator.rs

Lines changed: 6 additions & 4 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
}
@@ -161,12 +161,14 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
161161
if bits == 0 {
162162
// Test if the ptr is in-bounds. Then it cannot be NULL.
163163
// Even dangling pointers cannot be NULL.
164-
if self.memory().check_bounds_ptr_maybe_dead(ptr).is_ok() {
164+
if self.memory().check_bounds_ptr(ptr, InboundsCheck::MaybeDead).is_ok() {
165165
return Ok(false);
166166
}
167167
}
168168

169-
let (alloc_size, alloc_align) = self.memory().get_size_and_align(ptr.alloc_id);
169+
let (alloc_size, alloc_align) = self.memory()
170+
.get_size_and_align(ptr.alloc_id, InboundsCheck::MaybeDead)
171+
.expect("determining size+align of dead ptr cannot fail");
170172

171173
// Case II: Alignment gives it away
172174
if ptr.offset.bytes() % alloc_align.bytes() == 0 {

tests/run-pass/async-fn.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
async_await,
33
await_macro,
44
futures_api,
5-
pin,
65
)]
76

87
use std::{future::Future, pin::Pin, task::Poll};

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)