-
Notifications
You must be signed in to change notification settings - Fork 349
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
Properly compare unequal function pointers #581
Conversation
47c575a
to
dd19264
Compare
tests/run-pass/fn_ptr_comparison.rs
Outdated
} | ||
|
||
fn main() { | ||
assert!(return_fn_ptr() != f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to the existing fn ptr test instead?
} | ||
|
||
fn main() { | ||
assert!(return_fn_ptr() == f); //~ ERROR assertion failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this test? We already test elsewhere that assert!(false)
fails, don't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to make sure we're getting the right error. But I guess the run-pass test kinda guarantees that
// Two in-bounds pointers, we can compare across allocations | ||
left == right | ||
|
||
let check = |ptr: Pointer<Borrow>| match self.memory().get(ptr.alloc_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not nice. :/
For once, it's not correct: A pointer into a function allocation is only in-bounds if its offset is 0.
But also, the previous behavior that memory().check_bounds
would accept offset-0-size-0 pointers into function allocations was fully intended. These pointers are in-bounds. There is nothing wrong with a &()
pointing to a function allocation. So I don't think fixing this here is how we want to proceed.
For example, pointer_offset_inbounds
now also fails to compute a 0-offset on a function pointer. This affects every user of the old check_bounds
method that was converted to memory().get
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reintroduce the check_bounds
method on Memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think that would make most sense.
Superseded by #587 |
fixes #577