Skip to content

Fix comparing function pointers #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2018-12-24
nightly-2018-12-26
10 changes: 6 additions & 4 deletions src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
// Dead allocations in miri cannot overlap with live allocations, but
// on read hardware this can easily happen. Thus for comparisons we require
// both pointers to be live.
self.memory().get(left.alloc_id)?.check_bounds_ptr(left)?;
self.memory().get(right.alloc_id)?.check_bounds_ptr(right)?;
self.memory().check_bounds_ptr(left, InboundsCheck::Live)?;
self.memory().check_bounds_ptr(right, InboundsCheck::Live)?;
// Two in-bounds pointers, we can compare across allocations
left == right
}
Expand All @@ -161,12 +161,14 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
if bits == 0 {
// Test if the ptr is in-bounds. Then it cannot be NULL.
// Even dangling pointers cannot be NULL.
if self.memory().check_bounds_ptr_maybe_dead(ptr).is_ok() {
if self.memory().check_bounds_ptr(ptr, InboundsCheck::MaybeDead).is_ok() {
return Ok(false);
}
}

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

// Case II: Alignment gives it away
if ptr.offset.bytes() % alloc_align.bytes() == 0 {
Expand Down
1 change: 0 additions & 1 deletion tests/run-pass/async-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
async_await,
await_macro,
futures_api,
pin,
)]

use std::{future::Future, pin::Pin, task::Poll};
Expand Down
1 change: 1 addition & 0 deletions tests/run-pass/function_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ fn main() {
let g = f as fn() -> i32;
assert!(return_fn_ptr(g) == g);
assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32);
assert!(return_fn_ptr(f) != f);
}